From patchwork Tue Oct 11 07:37:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9370207 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 AEBB16048F for ; Tue, 11 Oct 2016 07:44:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7ACB529B0B for ; Tue, 11 Oct 2016 07:44:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F37029B0E; Tue, 11 Oct 2016 07:44:41 +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=-3.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID 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 1F98E29B0B for ; Tue, 11 Oct 2016 07:44:41 +0000 (UTC) Received: from localhost ([::1]:54195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrjs-0007DR-9e for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Oct 2016 03:44:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrg3-0004Lf-PE for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:40:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btrfy-0006cA-K9 for qemu-devel@nongnu.org; Tue, 11 Oct 2016 03:40:42 -0400 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]:32801) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btrfy-0006bi-6c; Tue, 11 Oct 2016 03:40:38 -0400 Received: by mail-pa0-x242.google.com with SMTP id hh10so1113775pac.0; Tue, 11 Oct 2016 00:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9qIhR9pXYMpy6MLj6nyF//6RcNLSpBjKUL0jF7AXEtY=; b=ufdixx547GQXN5T7O1Y4+OrXKu8cVqvG2GPZxLxR3GP+bbjNP5GJkjJ6rGJkJWlQuP XusEf0ZVpmQ7B3FRFA1BHmsdj98tnphFVMLRTx25D9j/1u/+emG8aapyYGiJkhqxHoRs HVUR9wi2umsJCAu70ImHNX9Wblr+F6A5fqpmaT8EfK8TrHFaj3y1K91rHBa0vpK836eD pjK6blrMGmJA5Qzdk3vmzZjByxOTfFeksw0x4/CVxGxVw5C9avxDlg7l4p8RYLbqzOHO JRjwF9i01ejvbKpzyzrWpXpvXGUVNc6JZerz6FW0PEOQoH8RfxfJ4kP5lt5c0FCzzo6z aoGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9qIhR9pXYMpy6MLj6nyF//6RcNLSpBjKUL0jF7AXEtY=; b=SG6966ar9W/gjaFtRsVpRH4HsRS8y9vgQIbCtk2PVeRng9NOXZs3w7fbpSyMIH91Dn oGFtYKPszRQpogHVC/bQcYDJjWo5g8/OXLcv/W5TLc8eqRxEjQgHCb/ib+LmgiFBLXyS 27D/NYKkGEp+uAdpmoUfMgtPDUIAYvp9WNXeDz1TR0lqXxNeHkLiU9TOto5Fhl2Mk2Yj A9REeMdGivXemG7yKQlVKbz6okBGVZN4T8VnhFy2nPpEUMvFHbqu1kdxEv2OooeHLBHS OaFlELzJoj+1u8Fb98ZxX+/SNUpwayXT6Tj4+sKvvYLD5AgMGMyy3bQGlZSea/vLx1cy lZMw== X-Gm-Message-State: AA6/9RlFHctZhu0V97zqr3WMFeB7SEXqy/D6NZB1WnyF6eqk+74fwYeypuXHv60QYeAStA== X-Received: by 10.66.122.239 with SMTP id lv15mr4669297pab.192.1476171637470; Tue, 11 Oct 2016 00:40:37 -0700 (PDT) Received: from linux.local ([27.251.197.196]) by smtp.gmail.com with ESMTPSA id v86sm2475563pfa.91.2016.10.11.00.40.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Oct 2016 00:40:37 -0700 (PDT) From: Ashijeet Acharya To: kwolf@redhat.com Date: Tue, 11 Oct 2016 13:07:14 +0530 Message-Id: <1476171437-11830-2-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1476171437-11830-1-git-send-email-ashijeetacharya@gmail.com> References: <1476171437-11830-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::242 Subject: [Qemu-devel] [PATCH 1/4] block/ssh: Add ssh_has_filename_options_conflict() 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: qemu-block@nongnu.org, rjones@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, Ashijeet Acharya , mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We have 5 options plus ("server") option which is added in the next patch that conflict with specifying a SSH filename. We need to iterate over all the options to check whether its key has an "server." prefix. This iteration will help us adding the new option "server" easily. Signed-off-by: Ashijeet Acharya --- block/ssh.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/block/ssh.c b/block/ssh.c index 5ce12b6..75cb7bc 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -254,15 +254,30 @@ static int parse_uri(const char *filename, QDict *options, Error **errp) return -EINVAL; } +static bool ssh_has_filename_options_conflict(QDict *options, Error **errp) +{ + const QDictEntry *qe; + + for (qe = qdict_first(options); qe; qe = qdict_next(options, qe)) { + if (!strcmp(qe->key, "host") || + !strcmp(qe->key, "port") || + !strcmp(qe->key, "path") || + !strcmp(qe->key, "user") || + !strcmp(qe->key, "host_key_check")) + { + error_setg(errp, "Option '%s' cannot be used with a file name", + qe->key); + return true; + } + } + + return false; +} + static void ssh_parse_filename(const char *filename, QDict *options, Error **errp) { - if (qdict_haskey(options, "user") || - qdict_haskey(options, "host") || - qdict_haskey(options, "port") || - qdict_haskey(options, "path") || - qdict_haskey(options, "host_key_check")) { - error_setg(errp, "user, host, port, path, host_key_check cannot be used at the same time as a file option"); + if (ssh_has_filename_options_conflict(options, errp)) { return; }