From patchwork Tue Aug 8 13:39:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9888305 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12522601EB for ; Tue, 8 Aug 2017 13:41:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 041A728867 for ; Tue, 8 Aug 2017 13:41:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED1E828911; Tue, 8 Aug 2017 13:41:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 20AE628867 for ; Tue, 8 Aug 2017 13:41:03 +0000 (UTC) Received: from localhost ([::1]:42635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1df4ko-0006Db-8M for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Aug 2017 09:41:02 -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) 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 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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" -// #define DEBUG_CURL -// #define DEBUG_VERBOSE +/* + #define DEBUG_CURL + #define DEBUG_VERBOSE +*/ #ifdef DEBUG_CURL #define DEBUG_CURL_PRINT 1 @@ -76,15 +78,15 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle, #define CURL_TIMEOUT_DEFAULT 5 #define CURL_TIMEOUT_MAX 10000 -#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" struct BDRVCURLState; @@ -110,8 +112,7 @@ typedef struct CURLSocket { QLIST_ENTRY(CURLSocket) next; } CURLSocket; -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, 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; } return 0; @@ -235,7 +236,7 @@ static size_t curl_header_cb(void *ptr, size_t size, size_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 *opaque) { - CURLState *s = ((CURLState*)opaque); + CURLState *s = ((CURLState *)opaque); size_t realsize = size * nmemb; int i; @@ -253,11 +254,12 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque) memcpy(s->orig_buf + s->buf_off, ptr, realsize); s->buf_off += realsize; - for(i=0; iacb[i]; - if (!acb) + if (!acb) { continue; + } if ((s->buf_off >= acb->end)) { size_t request_length = acb->bytes; @@ -293,17 +295,16 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t start, uint64_t len, uint64_t clamped_end = MIN(end, s->len); uint64_t clamped_len = clamped_end - start; - for (i=0; istates[i]; uint64_t buf_end = (state->buf_start + state->buf_off); uint64_t buf_fend = (state->buf_start + state->buf_len); - if (!state->orig_buf) - continue; - if (!state->buf_off) + if (!state->orig_buf || !state->buf_off) { continue; + } - // Does the existing buffer cover our section? + /* Does the existing buffer cover our section? */ if ((start >= state->buf_start) && (start <= buf_end) && (clamped_end >= state->buf_start) && @@ -319,7 +320,7 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t start, uint64_t len, return true; } - // Wait for unfinished chunks + /* Wait for unfinished chunks */ if (state->in_use && (start >= state->buf_start) && (start <= buf_fend) && @@ -331,7 +332,7 @@ static bool curl_find_buf(BDRVCURLState *s, uint64_t start, uint64_t len, acb->start = start - state->buf_start; acb->end = acb->start + clamped_len; - for (j=0; jacb[j]) { state->acb[j] = acb; return true; @@ -355,8 +356,9 @@ static void curl_multi_check_completion(BDRVCURLState *s) msg = curl_multi_info_read(s->multi, &msgs_in_queue); /* Quit when there are no more completions */ - if (!msg) + if (!msg) { break; + } if (msg->msg == CURLMSG_DONE) { CURLState *state = NULL; @@ -540,12 +542,14 @@ static void curl_clean_state(CURLState *s) { CURLAIOCB *next; int j; + for (j = 0; j < CURL_NUM_ACB; j++) { assert(!s->acb[j]); } - if (s->s->multi) + if (s->s->multi) { curl_multi_remove_handle(s->s->multi, s->curl); + } while (!QLIST_EMPTY(&s->sockets)) { CURLSocket *socket = QLIST_FIRST(&s->sockets); @@ -794,7 +798,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags, goto out_noclean; } - // Get file size + /* Get file size */ if (curl_init_state(s, state) < 0) { goto out; @@ -802,11 +806,11 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags, s->accept_range = 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, CURLAIOCB *acb) qemu_mutex_lock(&s->mutex); - // 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; } - // No cache found, so let's start a new request + /* No cache found, so let's start a new request */ for (;;) { state = curl_find_state(s); if (state) {