From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGyLQ-0001jB-Ik for qemu-devel@nongnu.org; Fri, 21 Feb 2014 17:13:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGyLK-0000T9-9O for qemu-devel@nongnu.org; Fri, 21 Feb 2014 17:13:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGyLK-0000Sy-19 for qemu-devel@nongnu.org; Fri, 21 Feb 2014 17:13:14 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1LMDDOQ014804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Feb 2014 17:13:13 -0500 From: Kevin Wolf Date: Fri, 21 Feb 2014 23:12:08 +0100 Message-Id: <1393020771-32712-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1393020771-32712-1-git-send-email-kwolf@redhat.com> References: <1393020771-32712-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 11/54] nbd: produce a better error if neither host nor port is passed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Paolo Bonzini 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: Fam Zheng Signed-off-by: Kevin Wolf --- 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 abae506..a83e856 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 -- 1.8.1.4