From patchwork Wed Aug 30 16:56:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9930341 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 56F3060380 for ; Wed, 30 Aug 2017 17:31:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 443B928696 for ; Wed, 30 Aug 2017 17:31:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3916A286E7; Wed, 30 Aug 2017 17:31:42 +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 D3A1728696 for ; Wed, 30 Aug 2017 17:31:41 +0000 (UTC) Received: from localhost ([::1]:51797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn6q5-0002im-38 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Aug 2017 13:31:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn6Ik-0005Tq-0A for qemu-devel@nongnu.org; Wed, 30 Aug 2017 12:57:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn6Ii-0006pV-U2 for qemu-devel@nongnu.org; Wed, 30 Aug 2017 12:57:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44712) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn6If-0006mZ-01; Wed, 30 Aug 2017 12:57:09 -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 DF352495; Wed, 30 Aug 2017 16:57:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DF352495 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 Received: from localhost (ovpn-116-70.phx2.redhat.com [10.3.116.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB09E6951E; Wed, 30 Aug 2017 16:57:07 +0000 (UTC) From: Jeff Cody To: qemu-devel@nongnu.org Date: Wed, 30 Aug 2017 12:56:59 -0400 Message-Id: <393d6a245f52394f0aa094ec1e97194aef9ab0bc.1504112061.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.29]); Wed, 30 Aug 2017 16:57:08 +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 v2 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jeff Cody Reviewed-by: Eric Blake --- 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 *options, Error **errp) goto err; } - if(uri->user && strcmp(uri->user, "") != 0) { + if (uri->user && strcmp(uri->user, "") != 0) { qdict_put_str(options, "user", uri->user); } @@ -268,7 +268,7 @@ static int parse_uri(const char *filename, QDict *options, Error **errp) 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_OPENSSH); r = 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 *fingerprint, size_t len, unsigned c; while (len > 0) { - while (*host_key_check == ':') + while (*host_key_check == ':') { 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 = hex2decimal(host_key_check[0]) * 16 + hex2decimal(host_key_check[1]); - if (c - *fingerprint != 0) + if (c - *fingerprint != 0) { return c - *fingerprint; + } fingerprint++; len--; host_key_check += 2; @@ -433,8 +436,8 @@ check_host_key_hash(BDRVSSHState *s, const char *hash, return -EINVAL; } - if(compare_fingerprint((unsigned char *) fingerprint, fingerprint_len, - hash) != 0) { + if (compare_fingerprint((unsigned char *) fingerprint, fingerprint_len, + hash) != 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 *user, Error **errp) goto out; } - for(;;) { + for (;;) { r = libssh2_agent_get_identity(agent, &identity, prev_identity); if (r == 1) { /* end of list */ break; @@ -863,8 +866,8 @@ static int ssh_create(const char *filename, QemuOpts *opts, Error **errp) } r = 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 = r; @@ -872,7 +875,7 @@ static int ssh_create(const char *filename, QemuOpts *opts, Error **errp) } if (total_size > 0) { - libssh2_sftp_seek64(s.sftp_handle, total_size-1); + libssh2_sftp_seek64(s.sftp_handle, total_size - 1); r2 = 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, BlockDriverState *bs, * works for me. */ if (r == 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, BlockDriverState *bs, end_of_vec = i->iov_base + i->iov_len; } - if (offset + written > s->attrs.filesize) + if (offset + written > s->attrs.filesize) { s->attrs.filesize = offset + written; + } } return 0;