From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502199702225621.5724622997153; Tue, 8 Aug 2017 06:41:42 -0700 (PDT) Received: from localhost ([::1]:42646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4lQ-0007hr-R6 for importer@patchew.org; Tue, 08 Aug 2017 09:41:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jI-0005ns-5w for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jD-0008Ar-D9 for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j3-00083U-2g; Tue, 08 Aug 2017 09:39:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A818C047B7B; Tue, 8 Aug 2017 13:39:10 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CAB991288; Tue, 8 Aug 2017 13:39:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5A818C047B7B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:02 -0400 Message-Id: <7f210a8d031e371be1e3bc578b8f641ce141f224.1502198932.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 08 Aug 2017 13:39:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 1/7] block/ssh: don't call libssh2_init() in block_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We don't need libssh2 failure to be fatal (we could just opt to not register the driver on failure). But, it is probably a good idea to avoid external library calls during the block_init(), and call the libssh2 global init function on the first usage, returning any errors. Signed-off-by: Jeff Cody --- block/ssh.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index e8f0404..cbb0e34 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -83,12 +83,28 @@ typedef struct BDRVSSHState { bool unsafe_flush_warning; } BDRVSSHState; =20 -static void ssh_state_init(BDRVSSHState *s) +static bool ssh_libinit_called; + +static int ssh_state_init(BDRVSSHState *s, Error **errp) { + int ret; + + if (!ssh_libinit_called) { + ret =3D libssh2_init(0); + if (ret) { + error_setg(errp, "libssh2 initialization failed with %d", ret); + return ret; + } + ssh_libinit_called =3D true; + } + + memset(s, 0, sizeof *s); s->sock =3D -1; s->offset =3D -1; qemu_co_mutex_init(&s->lock); + + return 0; } =20 static void ssh_state_free(BDRVSSHState *s) @@ -772,8 +788,13 @@ static int ssh_file_open(BlockDriverState *bs, QDict *= options, int bdrv_flags, BDRVSSHState *s =3D bs->opaque; int ret; int ssh_flags; + Error *local_err =3D NULL; =20 - ssh_state_init(s); + ret =3D ssh_state_init(s, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return ret; + } =20 ssh_flags =3D LIBSSH2_FXF_READ; if (bdrv_flags & BDRV_O_RDWR) { @@ -821,8 +842,13 @@ static int ssh_create(const char *filename, QemuOpts *= opts, Error **errp) BDRVSSHState s; ssize_t r2; char c[1] =3D { '\0' }; + Error *local_err =3D NULL; =20 - ssh_state_init(&s); + ret =3D ssh_state_init(&s, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return ret; + } =20 /* Get desired file size. */ total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), @@ -1213,14 +1239,6 @@ static BlockDriver bdrv_ssh =3D { =20 static void bdrv_ssh_init(void) { - int r; - - r =3D libssh2_init(0); - if (r !=3D 0) { - fprintf(stderr, "libssh2 initialization failed, %d\n", r); - exit(EXIT_FAILURE); - } - bdrv_register(&bdrv_ssh); } =20 --=20 2.9.4 From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502199694791744.0426943926532; Tue, 8 Aug 2017 06:41:34 -0700 (PDT) Received: from localhost ([::1]:42644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4lJ-0007bC-04 for importer@patchew.org; Tue, 08 Aug 2017 09:41:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jK-0005oT-Ij for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jE-0008Ch-Ki for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33808) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j4-00083l-46; Tue, 08 Aug 2017 09:39:14 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A0A7356D0; Tue, 8 Aug 2017 13:39:11 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D83C5F92A; Tue, 8 Aug 2017 13:39:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4A0A7356D0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:03 -0400 Message-Id: <4d5999f33db7bd8433a80a9ea0f776fdef340ac1.1502198932.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 08 Aug 2017 13:39:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 2/7] block/ssh: make compliant with coding guidelines X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jeff Cody --- block/ssh.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index cbb0e34..97f7673 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -241,7 +241,7 @@ static int parse_uri(const char *filename, QDict *optio= ns, Error **errp) goto err; } =20 - if(uri->user && strcmp(uri->user, "") !=3D 0) { + if (uri->user && strcmp(uri->user, "") !=3D 0) { qdict_put_str(options, "user", uri->user); } =20 @@ -268,7 +268,7 @@ static int parse_uri(const char *filename, QDict *optio= ns, Error **errp) =20 err: if (uri) { - uri_free(uri); + uri_free(uri); } return -EINVAL; } @@ -342,7 +342,7 @@ static int check_host_key_knownhosts(BDRVSSHState *s, libssh2_knownhost_readfile(knh, knh_file, LIBSSH2_KNOWNHOST_FILE_OPENS= SH); =20 r =3D libssh2_knownhost_checkp(knh, host, port, hostkey, len, - LIBSSH2_KNOWNHOST_TYPE_PLAIN| + LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW, &found); switch (r) { @@ -405,15 +405,18 @@ static int compare_fingerprint(const unsigned char *f= ingerprint, size_t len, unsigned c; =20 while (len > 0) { - while (*host_key_check =3D=3D ':') + while (*host_key_check =3D=3D ':') { host_key_check++; + } if (!qemu_isxdigit(host_key_check[0]) || - !qemu_isxdigit(host_key_check[1])) + !qemu_isxdigit(host_key_check[1])) { return 1; + } c =3D hex2decimal(host_key_check[0]) * 16 + hex2decimal(host_key_check[1]); - if (c - *fingerprint !=3D 0) + if (c - *fingerprint !=3D 0) { return c - *fingerprint; + } fingerprint++; len--; host_key_check +=3D 2; @@ -433,8 +436,8 @@ check_host_key_hash(BDRVSSHState *s, const char *hash, return -EINVAL; } =20 - if(compare_fingerprint((unsigned char *) fingerprint, fingerprint_len, - hash) !=3D 0) { + if (compare_fingerprint((unsigned char *) fingerprint, fingerprint_len, + hash) !=3D 0) { error_setg(errp, "remote host key does not match host_key_check '%= s'", hash); return -EPERM; @@ -507,7 +510,7 @@ static int authenticate(BDRVSSHState *s, const char *us= er, Error **errp) goto out; } =20 - for(;;) { + for (;;) { r =3D libssh2_agent_get_identity(agent, &identity, prev_identity); if (r =3D=3D 1) { /* end of list */ break; @@ -863,8 +866,8 @@ static int ssh_create(const char *filename, QemuOpts *o= pts, Error **errp) } =20 r =3D connect_to_ssh(&s, uri_options, - LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE| - LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC, + LIBSSH2_FXF_READ | LIBSSH2_FXF_WRITE | + LIBSSH2_FXF_CREAT | LIBSSH2_FXF_TRUNC, 0644, errp); if (r < 0) { ret =3D r; @@ -872,7 +875,7 @@ static int ssh_create(const char *filename, QemuOpts *o= pts, Error **errp) } =20 if (total_size > 0) { - libssh2_sftp_seek64(s.sftp_handle, total_size-1); + libssh2_sftp_seek64(s.sftp_handle, total_size - 1); r2 =3D libssh2_sftp_write(s.sftp_handle, c, 1); if (r2 < 0) { sftp_error_setg(errp, &s, "truncate failed"); @@ -1111,7 +1114,7 @@ static int ssh_write(BDRVSSHState *s, BlockDriverStat= e *bs, * works for me. */ if (r =3D=3D 0) { - ssh_seek(s, offset + written, SSH_SEEK_WRITE|SSH_SEEK_FORCE); + ssh_seek(s, offset + written, SSH_SEEK_WRITE | SSH_SEEK_FORCE); co_yield(s, bs); goto again; } @@ -1125,8 +1128,9 @@ static int ssh_write(BDRVSSHState *s, BlockDriverStat= e *bs, end_of_vec =3D i->iov_base + i->iov_len; } =20 - if (offset + written > s->attrs.filesize) + if (offset + written > s->attrs.filesize) { s->attrs.filesize =3D offset + written; + } } =20 return 0; --=20 2.9.4 From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502199820767862.6877334312325; Tue, 8 Aug 2017 06:43:40 -0700 (PDT) Received: from localhost ([::1]:42655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4nL-0000to-H9 for importer@patchew.org; Tue, 08 Aug 2017 09:43:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jK-0005oS-If for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jE-0008CI-0R for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51024) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j3-00084C-GZ; Tue, 08 Aug 2017 09:39:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CECAC047B65; Tue, 8 Aug 2017 13:39:12 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EBB3C70930; Tue, 8 Aug 2017 13:39:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6CECAC047B65 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:04 -0400 Message-Id: <2235394af212ea818a6546e427cf2438a042d6c9.1502198932.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 08 Aug 2017 13:39:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 3/7] block/sheepdog: remove spurious NULL check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 'tag' is already checked in the lines immediately preceding this check, and set to non-NULL if NULL. No need to check again, it hasn't changed. Signed-off-by: Jeff Cody --- block/sheepdog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index abb2e79..bbbfa72 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1632,7 +1632,7 @@ static int sd_open(BlockDriverState *bs, QDict *optio= ns, int flags, if (!tag) { tag =3D ""; } - if (tag && strlen(tag) >=3D SD_MAX_VDI_TAG_LEN) { + if (strlen(tag) >=3D SD_MAX_VDI_TAG_LEN) { error_setg(errp, "value of parameter 'tag' is too long"); ret =3D -EINVAL; goto err_no_fd; --=20 2.9.4 From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502199987406624.1894895206644; Tue, 8 Aug 2017 06:46:27 -0700 (PDT) Received: from localhost ([::1]:42670 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4q2-0002p2-2A for importer@patchew.org; Tue, 08 Aug 2017 09:46:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jK-0005on-TV for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jF-0008DF-KS for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j4-00084t-Ey; Tue, 08 Aug 2017 09:39:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5ED7265D12; Tue, 8 Aug 2017 13:39:13 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19F6C5C549; Tue, 8 Aug 2017 13:39:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5ED7265D12 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:05 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 08 Aug 2017 13:39:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 4/7] block/sheepdog: code beautification X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No functional changes, just whitespace manipulation. Signed-off-by: Jeff Cody --- block/sheepdog.c | 162 +++++++++++++++++++++++++++------------------------= ---- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index bbbfa72..ad461f1 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -400,7 +400,7 @@ typedef struct BDRVSheepdogReopenState { int cache_flags; } BDRVSheepdogReopenState; =20 -static const char * sd_strerror(int err) +static const char *sd_strerror(int err) { int i; =20 @@ -3078,111 +3078,111 @@ static QemuOptsList sd_create_opts =3D { }; =20 static BlockDriver bdrv_sheepdog =3D { - .format_name =3D "sheepdog", - .protocol_name =3D "sheepdog", - .instance_size =3D sizeof(BDRVSheepdogState), - .bdrv_parse_filename =3D sd_parse_filename, - .bdrv_file_open =3D sd_open, - .bdrv_reopen_prepare =3D sd_reopen_prepare, - .bdrv_reopen_commit =3D sd_reopen_commit, - .bdrv_reopen_abort =3D sd_reopen_abort, - .bdrv_close =3D sd_close, - .bdrv_create =3D sd_create, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_getlength =3D sd_getlength, + .format_name =3D "sheepdog", + .protocol_name =3D "sheepdog", + .instance_size =3D sizeof(BDRVSheepdogState), + .bdrv_parse_filename =3D sd_parse_filename, + .bdrv_file_open =3D sd_open, + .bdrv_reopen_prepare =3D sd_reopen_prepare, + .bdrv_reopen_commit =3D sd_reopen_commit, + .bdrv_reopen_abort =3D sd_reopen_abort, + .bdrv_close =3D sd_close, + .bdrv_create =3D sd_create, + .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, - .bdrv_truncate =3D sd_truncate, + .bdrv_truncate =3D sd_truncate, =20 - .bdrv_co_readv =3D sd_co_readv, - .bdrv_co_writev =3D sd_co_writev, - .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, - .bdrv_co_pdiscard =3D sd_co_pdiscard, - .bdrv_co_get_block_status =3D sd_co_get_block_status, + .bdrv_co_readv =3D sd_co_readv, + .bdrv_co_writev =3D sd_co_writev, + .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, + .bdrv_co_pdiscard =3D sd_co_pdiscard, + .bdrv_co_get_block_status =3D sd_co_get_block_status, =20 - .bdrv_snapshot_create =3D sd_snapshot_create, - .bdrv_snapshot_goto =3D sd_snapshot_goto, - .bdrv_snapshot_delete =3D sd_snapshot_delete, - .bdrv_snapshot_list =3D sd_snapshot_list, + .bdrv_snapshot_create =3D sd_snapshot_create, + .bdrv_snapshot_goto =3D sd_snapshot_goto, + .bdrv_snapshot_delete =3D sd_snapshot_delete, + .bdrv_snapshot_list =3D sd_snapshot_list, =20 - .bdrv_save_vmstate =3D sd_save_vmstate, - .bdrv_load_vmstate =3D sd_load_vmstate, + .bdrv_save_vmstate =3D sd_save_vmstate, + .bdrv_load_vmstate =3D sd_load_vmstate, =20 - .bdrv_detach_aio_context =3D sd_detach_aio_context, - .bdrv_attach_aio_context =3D sd_attach_aio_context, + .bdrv_detach_aio_context =3D sd_detach_aio_context, + .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 - .create_opts =3D &sd_create_opts, + .create_opts =3D &sd_create_opts, }; =20 static BlockDriver bdrv_sheepdog_tcp =3D { - .format_name =3D "sheepdog", - .protocol_name =3D "sheepdog+tcp", - .instance_size =3D sizeof(BDRVSheepdogState), - .bdrv_parse_filename =3D sd_parse_filename, + .format_name =3D "sheepdog", + .protocol_name =3D "sheepdog+tcp", + .instance_size =3D sizeof(BDRVSheepdogState), + .bdrv_parse_filename =3D sd_parse_filename, .bdrv_file_open =3D sd_open, - .bdrv_reopen_prepare =3D sd_reopen_prepare, - .bdrv_reopen_commit =3D sd_reopen_commit, - .bdrv_reopen_abort =3D sd_reopen_abort, - .bdrv_close =3D sd_close, - .bdrv_create =3D sd_create, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_getlength =3D sd_getlength, + .bdrv_reopen_prepare =3D sd_reopen_prepare, + .bdrv_reopen_commit =3D sd_reopen_commit, + .bdrv_reopen_abort =3D sd_reopen_abort, + .bdrv_close =3D sd_close, + .bdrv_create =3D sd_create, + .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, - .bdrv_truncate =3D sd_truncate, + .bdrv_truncate =3D sd_truncate, =20 - .bdrv_co_readv =3D sd_co_readv, - .bdrv_co_writev =3D sd_co_writev, - .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, - .bdrv_co_pdiscard =3D sd_co_pdiscard, - .bdrv_co_get_block_status =3D sd_co_get_block_status, + .bdrv_co_readv =3D sd_co_readv, + .bdrv_co_writev =3D sd_co_writev, + .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, + .bdrv_co_pdiscard =3D sd_co_pdiscard, + .bdrv_co_get_block_status =3D sd_co_get_block_status, =20 - .bdrv_snapshot_create =3D sd_snapshot_create, - .bdrv_snapshot_goto =3D sd_snapshot_goto, - .bdrv_snapshot_delete =3D sd_snapshot_delete, - .bdrv_snapshot_list =3D sd_snapshot_list, + .bdrv_snapshot_create =3D sd_snapshot_create, + .bdrv_snapshot_goto =3D sd_snapshot_goto, + .bdrv_snapshot_delete =3D sd_snapshot_delete, + .bdrv_snapshot_list =3D sd_snapshot_list, =20 - .bdrv_save_vmstate =3D sd_save_vmstate, - .bdrv_load_vmstate =3D sd_load_vmstate, + .bdrv_save_vmstate =3D sd_save_vmstate, + .bdrv_load_vmstate =3D sd_load_vmstate, =20 - .bdrv_detach_aio_context =3D sd_detach_aio_context, - .bdrv_attach_aio_context =3D sd_attach_aio_context, + .bdrv_detach_aio_context =3D sd_detach_aio_context, + .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 - .create_opts =3D &sd_create_opts, + .create_opts =3D &sd_create_opts, }; =20 static BlockDriver bdrv_sheepdog_unix =3D { - .format_name =3D "sheepdog", - .protocol_name =3D "sheepdog+unix", - .instance_size =3D sizeof(BDRVSheepdogState), - .bdrv_parse_filename =3D sd_parse_filename, - .bdrv_file_open =3D sd_open, - .bdrv_reopen_prepare =3D sd_reopen_prepare, - .bdrv_reopen_commit =3D sd_reopen_commit, - .bdrv_reopen_abort =3D sd_reopen_abort, - .bdrv_close =3D sd_close, - .bdrv_create =3D sd_create, - .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_getlength =3D sd_getlength, + .format_name =3D "sheepdog", + .protocol_name =3D "sheepdog+unix", + .instance_size =3D sizeof(BDRVSheepdogState), + .bdrv_parse_filename =3D sd_parse_filename, + .bdrv_file_open =3D sd_open, + .bdrv_reopen_prepare =3D sd_reopen_prepare, + .bdrv_reopen_commit =3D sd_reopen_commit, + .bdrv_reopen_abort =3D sd_reopen_abort, + .bdrv_close =3D sd_close, + .bdrv_create =3D sd_create, + .bdrv_has_zero_init =3D bdrv_has_zero_init_1, + .bdrv_getlength =3D sd_getlength, .bdrv_get_allocated_file_size =3D sd_get_allocated_file_size, - .bdrv_truncate =3D sd_truncate, + .bdrv_truncate =3D sd_truncate, =20 - .bdrv_co_readv =3D sd_co_readv, - .bdrv_co_writev =3D sd_co_writev, - .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, - .bdrv_co_pdiscard =3D sd_co_pdiscard, - .bdrv_co_get_block_status =3D sd_co_get_block_status, + .bdrv_co_readv =3D sd_co_readv, + .bdrv_co_writev =3D sd_co_writev, + .bdrv_co_flush_to_disk =3D sd_co_flush_to_disk, + .bdrv_co_pdiscard =3D sd_co_pdiscard, + .bdrv_co_get_block_status =3D sd_co_get_block_status, =20 - .bdrv_snapshot_create =3D sd_snapshot_create, - .bdrv_snapshot_goto =3D sd_snapshot_goto, - .bdrv_snapshot_delete =3D sd_snapshot_delete, - .bdrv_snapshot_list =3D sd_snapshot_list, + .bdrv_snapshot_create =3D sd_snapshot_create, + .bdrv_snapshot_goto =3D sd_snapshot_goto, + .bdrv_snapshot_delete =3D sd_snapshot_delete, + .bdrv_snapshot_list =3D sd_snapshot_list, =20 - .bdrv_save_vmstate =3D sd_save_vmstate, - .bdrv_load_vmstate =3D sd_load_vmstate, + .bdrv_save_vmstate =3D sd_save_vmstate, + .bdrv_load_vmstate =3D sd_load_vmstate, =20 - .bdrv_detach_aio_context =3D sd_detach_aio_context, - .bdrv_attach_aio_context =3D sd_attach_aio_context, + .bdrv_detach_aio_context =3D sd_detach_aio_context, + .bdrv_attach_aio_context =3D sd_attach_aio_context, =20 - .create_opts =3D &sd_create_opts, + .create_opts =3D &sd_create_opts, }; =20 static void bdrv_sheepdog_init(void) --=20 2.9.4 From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502199921559681.2951355580332; Tue, 8 Aug 2017 06:45:21 -0700 (PDT) Received: from localhost ([::1]:42665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4oy-0002A9-0z for importer@patchew.org; Tue, 08 Aug 2017 09:45:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jL-0005p8-5w for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jG-0008Dt-CU for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j5-00085f-Ta; Tue, 08 Aug 2017 09:39:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA0C7916A2; Tue, 8 Aug 2017 13:39:14 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C60170937; Tue, 8 Aug 2017 13:39:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA0C7916A2 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:06 -0400 Message-Id: <41c9e9625dde9b8ff3ca5a147576cf5ef2062a10.1502198932.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 08 Aug 2017 13:39:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 5/7] block/curl: check error return of curl_global_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If curl_global_init() fails, per the documentation no other curl functions may be called, so make sure to check the return value. Also, some minor changes to the initialization latch variable 'inited': - Make it static in the file, for clarity - Change the name for clarity - Make it a bool Signed-off-by: Jeff Cody --- block/curl.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/block/curl.c b/block/curl.c index 2a244e2..00a9879 100644 --- a/block/curl.c +++ b/block/curl.c @@ -89,6 +89,8 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_= handle, =20 struct BDRVCURLState; =20 +static bool libcurl_initialized; + typedef struct CURLAIOCB { Coroutine *co; QEMUIOVector *qiov; @@ -686,14 +688,23 @@ static int curl_open(BlockDriverState *bs, QDict *opt= ions, int flags, double d; const char *secretid; const char *protocol_delimiter; + int ret; =20 - static int inited =3D 0; =20 if (flags & BDRV_O_RDWR) { error_setg(errp, "curl block device does not support writes"); return -EROFS; } =20 + if (!libcurl_initialized) { + ret =3D curl_global_init(CURL_GLOBAL_ALL); + if (ret) { + error_setg(errp, "libcurl initialization failed with %d", ret); + return -EIO; + } + libcurl_initialized =3D true; + } + qemu_mutex_init(&s->mutex); opts =3D qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); @@ -772,11 +783,6 @@ static int curl_open(BlockDriverState *bs, QDict *opti= ons, int flags, } } =20 - if (!inited) { - curl_global_init(CURL_GLOBAL_ALL); - inited =3D 1; - } - DPRINTF("CURL: Opening %s\n", file); QSIMPLEQ_INIT(&s->free_state_waitq); s->aio_context =3D bdrv_get_aio_context(bs); --=20 2.9.4 From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150220008353472.64127554815627; Tue, 8 Aug 2017 06:48:03 -0700 (PDT) Received: from localhost ([::1]:42678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4rV-0003sW-Cm for importer@patchew.org; Tue, 08 Aug 2017 09:47:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jL-0005q4-Vf for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jH-0008Ec-8Q for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j6-00086H-WF; Tue, 08 Aug 2017 09:39:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1CDB6146C; Tue, 8 Aug 2017 13:39:15 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 714F982717; Tue, 8 Aug 2017 13:39:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C1CDB6146C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:07 -0400 Message-Id: <660a17fc092624db77a9aff20a7fa6bb11bf25c3.1502198932.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 08 Aug 2017 13:39:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 6/7] block/curl: fix minor memory leaks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jeff Cody --- block/curl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/curl.c b/block/curl.c index 00a9879..35cf417 100644 --- a/block/curl.c +++ b/block/curl.c @@ -857,6 +857,9 @@ out_noclean: qemu_mutex_destroy(&s->mutex); g_free(s->cookie); g_free(s->url); + g_free(s->username); + g_free(s->proxyusername); + g_free(s->proxypassword); qemu_opts_del(opts); return -EINVAL; } @@ -955,6 +958,9 @@ static void curl_close(BlockDriverState *bs) =20 g_free(s->cookie); g_free(s->url); + g_free(s->username); + g_free(s->proxyusername); + g_free(s->proxypassword); } =20 static int64_t curl_getlength(BlockDriverState *bs) --=20 2.9.4 From nobody Sun May 5 01:40:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502199696305424.06365126975857; Tue, 8 Aug 2017 06:41:36 -0700 (PDT) Received: from localhost ([::1]:42645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4lK-0007dL-VG for importer@patchew.org; Tue, 08 Aug 2017 09:41:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4jQ-0005vw-Aa for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1df4jK-0008Gp-Ug for qemu-devel@nongnu.org; Tue, 08 Aug 2017 09:39:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1df4j7-00086r-QQ; Tue, 08 Aug 2017 09:39:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B37C080462; Tue, 8 Aug 2017 13:39:16 +0000 (UTC) Received: from localhost (ovpn-116-54.phx2.redhat.com [10.3.116.54]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69F615C549; Tue, 8 Aug 2017 13:39:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B37C080462 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 8 Aug 2017 09:39:08 -0400 Message-Id: <1962836ff62e2cc75d602496ee8ac8c9d465193a.1502198932.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 08 Aug 2017 13:39:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 7/7] block/curl: code cleanup to comply with coding style X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mitake.hitoshi@lab.ntt.co.jp, namei.unix@gmail.com, kwolf@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This addresses non-functional changes to help curl.c better comply with the coding styles (comments, indentation, brackets, etc.). One minor code change is the combination of two if statements into a single if statement. Signed-off-by: Jeff Cody --- block/curl.c | 100 +++++++++++++++++++++++++++++++------------------------= ---- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/block/curl.c b/block/curl.c index 35cf417..c557b59 100644 --- a/block/curl.c +++ b/block/curl.c @@ -32,8 +32,10 @@ #include #include "qemu/cutils.h" =20 -// #define DEBUG_CURL -// #define DEBUG_VERBOSE +/* + #define DEBUG_CURL + #define DEBUG_VERBOSE +*/ =20 #ifdef DEBUG_CURL #define DEBUG_CURL_PRINT 1 @@ -76,15 +78,15 @@ static CURLMcode __curl_multi_socket_action(CURLM *mult= i_handle, #define CURL_TIMEOUT_DEFAULT 5 #define CURL_TIMEOUT_MAX 10000 =20 -#define CURL_BLOCK_OPT_URL "url" -#define CURL_BLOCK_OPT_READAHEAD "readahead" -#define CURL_BLOCK_OPT_SSLVERIFY "sslverify" -#define CURL_BLOCK_OPT_TIMEOUT "timeout" -#define CURL_BLOCK_OPT_COOKIE "cookie" -#define CURL_BLOCK_OPT_COOKIE_SECRET "cookie-secret" -#define CURL_BLOCK_OPT_USERNAME "username" -#define CURL_BLOCK_OPT_PASSWORD_SECRET "password-secret" -#define CURL_BLOCK_OPT_PROXY_USERNAME "proxy-username" +#define CURL_BLOCK_OPT_URL "url" +#define CURL_BLOCK_OPT_READAHEAD "readahead" +#define CURL_BLOCK_OPT_SSLVERIFY "sslverify" +#define CURL_BLOCK_OPT_TIMEOUT "timeout" +#define CURL_BLOCK_OPT_COOKIE "cookie" +#define CURL_BLOCK_OPT_COOKIE_SECRET "cookie-secret" +#define CURL_BLOCK_OPT_USERNAME "username" +#define CURL_BLOCK_OPT_PASSWORD_SECRET "password-secret" +#define CURL_BLOCK_OPT_PROXY_USERNAME "proxy-username" #define CURL_BLOCK_OPT_PROXY_PASSWORD_SECRET "proxy-password-secret" =20 struct BDRVCURLState; @@ -110,8 +112,7 @@ typedef struct CURLSocket { QLIST_ENTRY(CURLSocket) next; } CURLSocket; =20 -typedef struct CURLState -{ +typedef struct CURLState { struct BDRVCURLState *s; CURLAIOCB *acb[CURL_NUM_ACB]; CURL *curl; @@ -196,22 +197,22 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd,= int action, =20 DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd); switch (action) { - case CURL_POLL_IN: - aio_set_fd_handler(s->aio_context, fd, false, - curl_multi_read, NULL, NULL, state); - break; - case CURL_POLL_OUT: - aio_set_fd_handler(s->aio_context, fd, false, - NULL, curl_multi_do, NULL, state); - break; - case CURL_POLL_INOUT: - aio_set_fd_handler(s->aio_context, fd, false, - curl_multi_read, curl_multi_do, NULL, state= ); - break; - case CURL_POLL_REMOVE: - aio_set_fd_handler(s->aio_context, fd, false, - NULL, NULL, NULL, NULL); - break; + case CURL_POLL_IN: + aio_set_fd_handler(s->aio_context, fd, false, + curl_multi_read, NULL, NULL, state); + break; + case CURL_POLL_OUT: + aio_set_fd_handler(s->aio_context, fd, false, + NULL, curl_multi_do, NULL, state); + break; + case CURL_POLL_INOUT: + aio_set_fd_handler(s->aio_context, fd, false, + curl_multi_read, curl_multi_do, NULL, state); + break; + case CURL_POLL_REMOVE: + aio_set_fd_handler(s->aio_context, fd, false, + NULL, NULL, NULL, NULL); + break; } =20 return 0; @@ -235,7 +236,7 @@ static size_t curl_header_cb(void *ptr, size_t size, si= ze_t nmemb, void *opaque) /* Called from curl_multi_do_locked, with s->mutex held. */ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opa= que) { - CURLState *s =3D ((CURLState*)opaque); + CURLState *s =3D ((CURLState *)opaque); size_t realsize =3D size * nmemb; int i; =20 @@ -253,11 +254,12 @@ static size_t curl_read_cb(void *ptr, size_t size, si= ze_t nmemb, void *opaque) memcpy(s->orig_buf + s->buf_off, ptr, realsize); s->buf_off +=3D realsize; =20 - for(i=3D0; iacb[i]; =20 - if (!acb) + if (!acb) { continue; + } =20 if ((s->buf_off >=3D acb->end)) { size_t request_length =3D acb->bytes; @@ -293,17 +295,16 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t = start, uint64_t len, uint64_t clamped_end =3D MIN(end, s->len); uint64_t clamped_len =3D clamped_end - start; =20 - for (i=3D0; istates[i]; uint64_t buf_end =3D (state->buf_start + state->buf_off); uint64_t buf_fend =3D (state->buf_start + state->buf_len); =20 - if (!state->orig_buf) - continue; - if (!state->buf_off) + if (!state->orig_buf || !state->buf_off) { continue; + } =20 - // Does the existing buffer cover our section? + /* Does the existing buffer cover our section? */ if ((start >=3D state->buf_start) && (start <=3D buf_end) && (clamped_end >=3D state->buf_start) && @@ -319,7 +320,7 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t st= art, uint64_t len, return true; } =20 - // Wait for unfinished chunks + /* Wait for unfinished chunks */ if (state->in_use && (start >=3D state->buf_start) && (start <=3D buf_fend) && @@ -331,7 +332,7 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t st= art, uint64_t len, acb->start =3D start - state->buf_start; acb->end =3D acb->start + clamped_len; =20 - for (j=3D0; jacb[j]) { state->acb[j] =3D acb; return true; @@ -355,8 +356,9 @@ static void curl_multi_check_completion(BDRVCURLState *= s) msg =3D curl_multi_info_read(s->multi, &msgs_in_queue); =20 /* Quit when there are no more completions */ - if (!msg) + if (!msg) { break; + } =20 if (msg->msg =3D=3D CURLMSG_DONE) { CURLState *state =3D NULL; @@ -540,12 +542,14 @@ static void curl_clean_state(CURLState *s) { CURLAIOCB *next; int j; + for (j =3D 0; j < CURL_NUM_ACB; j++) { assert(!s->acb[j]); } =20 - if (s->s->multi) + if (s->s->multi) { curl_multi_remove_handle(s->s->multi, s->curl); + } =20 while (!QLIST_EMPTY(&s->sockets)) { CURLSocket *socket =3D QLIST_FIRST(&s->sockets); @@ -794,7 +798,7 @@ static int curl_open(BlockDriverState *bs, QDict *optio= ns, int flags, goto out_noclean; } =20 - // Get file size + /* Get file size */ =20 if (curl_init_state(s, state) < 0) { goto out; @@ -802,11 +806,11 @@ static int curl_open(BlockDriverState *bs, QDict *opt= ions, int flags, =20 s->accept_range =3D false; curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1); - curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION, - curl_header_cb); + curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION, curl_header_cb); curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s); - if (curl_easy_perform(state->curl)) + if (curl_easy_perform(state->curl)) { goto out; + } if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &= d)) { goto out; } @@ -876,13 +880,13 @@ static void curl_setup_preadv(BlockDriverState *bs, C= URLAIOCB *acb) =20 qemu_mutex_lock(&s->mutex); =20 - // In case we have the requested data already (e.g. read-ahead), - // we can just call the callback and be done. + /* In case we have the requested data already (e.g. read-ahead), + we can just call the callback and be done. */ if (curl_find_buf(s, start, acb->bytes, acb)) { goto out; } =20 - // No cache found, so let's start a new request + /* No cache found, so let's start a new request */ for (;;) { state =3D curl_find_state(s); if (state) { --=20 2.9.4