From patchwork Mon Feb 17 13:43:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 320981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C44F52C00BB for ; Tue, 18 Feb 2014 00:47:23 +1100 (EST) Received: from localhost ([::1]:40621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFOXZ-0003I2-N1 for incoming@patchwork.ozlabs.org; Mon, 17 Feb 2014 08:47:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFOUl-0000TB-Vi for qemu-devel@nongnu.org; Mon, 17 Feb 2014 08:44:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFOUd-0000fR-Hm for qemu-devel@nongnu.org; Mon, 17 Feb 2014 08:44:27 -0500 Received: from mail-qg0-x22d.google.com ([2607:f8b0:400d:c04::22d]:61773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFOUd-0000fH-Da for qemu-devel@nongnu.org; Mon, 17 Feb 2014 08:44:19 -0500 Received: by mail-qg0-f45.google.com with SMTP id j5so4952401qga.4 for ; Mon, 17 Feb 2014 05:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tIm2zR59LxHpdcsc5W8dtIkovaDIA6xbvrqhImv6ngQ=; b=JsEWGzjR8hra6jmK0DEeAq+ciSdWL13w/I87asaORUdUQUF/PAHhmYe3Wf0QRf0I/G fZpihOBELKMGQfThUFBHm6FWGrrkNynoIPnbfDw/ioWnDm9UqQJMxudviyRk8yUkoas6 oPsO7esLFBuPVcE0hpGbppBGFzMgBPnR2yCmKpj6zKhczAAbqQEQcS616x2g+WEk3WRv VoLdvKu6w6ilGZ/VkwrqEi1QyFztwiGRsq8AmYPDqGR3Ew35lDFSZ+3u/6BtJlSBy7Ce dPJO+ZwZdf4hMDkkQVJn3NmF6+IlKo1LRvhothJw3Iqmr6v566bB26qZEYo+A1USX1rV SKFw== X-Received: by 10.229.209.193 with SMTP id gh1mr2199003qcb.19.1392644658942; Mon, 17 Feb 2014 05:44:18 -0800 (PST) Received: from yakj.usersys.redhat.com (net-37-117-154-249.cust.vodafonedsl.it. [37.117.154.249]) by mx.google.com with ESMTPSA id p10sm45265803qag.8.2014.02.17.05.44.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Feb 2014 05:44:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 17 Feb 2014 14:43:48 +0100 Message-Id: <1392644647-9897-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1392644647-9897-1-git-send-email-pbonzini@redhat.com> References: <1392644647-9897-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::22d Cc: kwolf@redhat.com, jcody@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v3 01/20] nbd: produce a better error if neither host nor port is passed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Before: $ qemu-io-old qemu-io-old> open -r -o file.driver=nbd qemu-io-old: can't open device (null): Could not open image: Invalid argument $ ./qemu-io-old qemu-io-old> open -r -o file.driver=nbd,file.host=foo,file.path=bar path and host may not be used at the same time. qemu-io-old: can't open device (null): Could not open image: Invalid argument After: $ ./qemu-io qemu-io> open -r -o file.driver=nbd one of path and host must be specified. qemu-io: can't open device (null): Could not open image: Invalid argument $ ./qemu-io qemu-io> open -r -o file.driver=nbd,file.host=foo,file.path=bar path and host may not be used at the same time. qemu-io: can't open device (null): Could not open image: Invalid argument Next patch will fix the error propagation. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake --- block/nbd.c | 13 ++++++------- tests/qemu-iotests/051.out | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 327e913..fd89083 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -192,19 +192,18 @@ static int nbd_config(BDRVNBDState *s, QDict *options, char **export) { Error *local_err = NULL; - if (qdict_haskey(options, "path")) { - if (qdict_haskey(options, "host")) { + if (qdict_haskey(options, "path") == qdict_haskey(options, "host")) { + if (qdict_haskey(options, "path")) { qerror_report(ERROR_CLASS_GENERIC_ERROR, "path and host may not " "be used at the same time."); - return -EINVAL; + } else { + qerror_report(ERROR_CLASS_GENERIC_ERROR, "one of path and host " + "must be specified."); } - s->client.is_unix = true; - } else if (qdict_haskey(options, "host")) { - s->client.is_unix = false; - } else { return -EINVAL; } + s->client.is_unix = qdict_haskey(options, "path"); s->socket_opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index 30e2dbd..3e8d962 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -231,6 +231,7 @@ Testing: -drive driver=file QEMU_PROG: -drive driver=file: could not open disk image ide0-hd0: The 'file' block driver requires a file name Testing: -drive driver=nbd +QEMU_PROG: -drive driver=nbd: one of path and host must be specified. QEMU_PROG: -drive driver=nbd: could not open disk image ide0-hd0: Could not open image: Invalid argument Testing: -drive driver=raw @@ -240,6 +241,7 @@ Testing: -drive file.driver=file QEMU_PROG: -drive file.driver=file: could not open disk image ide0-hd0: The 'file' block driver requires a file name Testing: -drive file.driver=nbd +QEMU_PROG: -drive file.driver=nbd: one of path and host must be specified. QEMU_PROG: -drive file.driver=nbd: could not open disk image ide0-hd0: Could not open image: Invalid argument Testing: -drive file.driver=raw