From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXajh-0001Of-Mn for qemu-devel@nongnu.org; Fri, 26 Sep 2014 14:59:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XXajc-0002dn-89 for qemu-devel@nongnu.org; Fri, 26 Sep 2014 14:59:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XXajc-0002cd-1L for qemu-devel@nongnu.org; Fri, 26 Sep 2014 14:59:16 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8QIxAER022244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 26 Sep 2014 14:59:10 -0400 From: Kevin Wolf Date: Fri, 26 Sep 2014 20:58:53 +0200 Message-Id: <1411757937-9087-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1411757937-9087-1-git-send-email-kwolf@redhat.com> References: <1411757937-9087-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 07/11] block: Catch simultaneous usage of options and their aliases List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com While thinking about precedence of conflicting block device options from different sources, I noticed that you can specify both an option and its legacy alias at the same time (e.g. readonly=3Don,read-only=3Doff). Rathe= r than specifying the order of precedence, we should simply forbid such combinations. Signed-off-by: Kevin Wolf Reviewed-by: Beno=C3=AEt Canet Reviewed-by: Markus Armbruster --- blockdev.c | 16 ++++++++++++++-- tests/qemu-iotests/051 | 23 +++++++++++++++++++++++ tests/qemu-iotests/051.out | 45 ++++++++++++++++++++++++++++++++++++++++= +++++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 88f7928..ad43648 100644 --- a/blockdev.c +++ b/blockdev.c @@ -538,12 +538,18 @@ err_no_opts: return NULL; } =20 -static void qemu_opt_rename(QemuOpts *opts, const char *from, const char= *to) +static void qemu_opt_rename(QemuOpts *opts, const char *from, const char= *to, + Error **errp) { const char *value; =20 value =3D qemu_opt_get(opts, from); if (value) { + if (qemu_opt_find(opts, to)) { + error_setg(errp, "'%s' and its alias '%s' can't be used at t= he " + "same time", to, from); + return; + } qemu_opt_set(opts, to, value); qemu_opt_unset(opts, from); } @@ -676,7 +682,13 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterf= aceType block_default_type) }; =20 for (i =3D 0; i < ARRAY_SIZE(opt_renames); i++) { - qemu_opt_rename(all_opts, opt_renames[i].from, opt_renames[i].to= ); + qemu_opt_rename(all_opts, opt_renames[i].from, opt_renames[i].to= , + &local_err); + if (local_err) { + error_report("%s", error_get_pretty(local_err)); + error_free(local_err); + return NULL; + } } =20 value =3D qemu_opt_get(all_opts, "cache"); diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index a41334e..11c858f 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -199,6 +199,29 @@ run_qemu -drive file.driver=3Draw run_qemu -drive foo=3Dbar =20 echo +echo =3D=3D=3D Specifying both an option and its legacy alias =3D=3D=3D +echo + +run_qemu -drive file=3D"$TEST_IMG",iops=3D1234,throttling.iops-total=3D5= 678 +run_qemu -drive file=3D"$TEST_IMG",iops_rd=3D1234,throttling.iops-read=3D= 5678 +run_qemu -drive file=3D"$TEST_IMG",iops_wr=3D1234,throttling.iops-write=3D= 5678 + +run_qemu -drive file=3D"$TEST_IMG",bps=3D1234,throttling.bps-total=3D567= 8 +run_qemu -drive file=3D"$TEST_IMG",bps_rd=3D1234,throttling.bps-read=3D5= 678 +run_qemu -drive file=3D"$TEST_IMG",bps_wr=3D1234,throttling.bps-write=3D= 5678 + +run_qemu -drive file=3D"$TEST_IMG",iops_max=3D1234,throttling.iops-total= -max=3D5678 +run_qemu -drive file=3D"$TEST_IMG",iops_rd_max=3D1234,throttling.iops-re= ad-max=3D5678 +run_qemu -drive file=3D"$TEST_IMG",iops_wr_max=3D1234,throttling.iops-wr= ite-max=3D5678 + +run_qemu -drive file=3D"$TEST_IMG",bps_max=3D1234,throttling.bps-total-m= ax=3D5678 +run_qemu -drive file=3D"$TEST_IMG",bps_rd_max=3D1234,throttling.bps-read= -max=3D5678 +run_qemu -drive file=3D"$TEST_IMG",bps_wr_max=3D1234,throttling.bps-writ= e-max=3D5678 + +run_qemu -drive file=3D"$TEST_IMG",iops_size=3D1234,throttling.iops-size= =3D5678 +run_qemu -drive file=3D"$TEST_IMG",readonly=3Don,read-only=3Doff + +echo echo =3D=3D=3D Parsing protocol from file name =3D=3D=3D echo =20 diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index a3f2820..2c7e808 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -274,6 +274,51 @@ Testing: -drive foo=3Dbar QEMU_PROG: -drive foo=3Dbar: could not open disk image ide0-hd0: Must sp= ecify either driver or file =20 =20 +=3D=3D=3D Specifying both an option and its legacy alias =3D=3D=3D + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops=3D1234,throttling.iops-tota= l=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops=3D1234,throttling.iops-to= tal=3D5678: 'throttling.iops-total' and its alias 'iops' can't be used at= the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops_rd=3D1234,throttling.iops-r= ead=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops_rd=3D1234,throttling.iops= -read=3D5678: 'throttling.iops-read' and its alias 'iops_rd' can't be use= d at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops_wr=3D1234,throttling.iops-w= rite=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops_wr=3D1234,throttling.iops= -write=3D5678: 'throttling.iops-write' and its alias 'iops_wr' can't be u= sed at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,bps=3D1234,throttling.bps-total=3D= 5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,bps=3D1234,throttling.bps-tota= l=3D5678: 'throttling.bps-total' and its alias 'bps' can't be used at the= same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,bps_rd=3D1234,throttling.bps-rea= d=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,bps_rd=3D1234,throttling.bps-r= ead=3D5678: 'throttling.bps-read' and its alias 'bps_rd' can't be used at= the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,bps_wr=3D1234,throttling.bps-wri= te=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,bps_wr=3D1234,throttling.bps-w= rite=3D5678: 'throttling.bps-write' and its alias 'bps_wr' can't be used = at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops_max=3D1234,throttling.iops-= total-max=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops_max=3D1234,throttling.iop= s-total-max=3D5678: 'throttling.iops-total-max' and its alias 'iops_max' = can't be used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops_rd_max=3D1234,throttling.io= ps-read-max=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops_rd_max=3D1234,throttling.= iops-read-max=3D5678: 'throttling.iops-read-max' and its alias 'iops_rd_m= ax' can't be used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops_wr_max=3D1234,throttling.io= ps-write-max=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops_wr_max=3D1234,throttling.= iops-write-max=3D5678: 'throttling.iops-write-max' and its alias 'iops_wr= _max' can't be used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,bps_max=3D1234,throttling.bps-to= tal-max=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,bps_max=3D1234,throttling.bps-= total-max=3D5678: 'throttling.bps-total-max' and its alias 'bps_max' can'= t be used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,bps_rd_max=3D1234,throttling.bps= -read-max=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,bps_rd_max=3D1234,throttling.b= ps-read-max=3D5678: 'throttling.bps-read-max' and its alias 'bps_rd_max' = can't be used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,bps_wr_max=3D1234,throttling.bps= -write-max=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,bps_wr_max=3D1234,throttling.b= ps-write-max=3D5678: 'throttling.bps-write-max' and its alias 'bps_wr_max= ' can't be used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,iops_size=3D1234,throttling.iops= -size=3D5678 +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,iops_size=3D1234,throttling.io= ps-size=3D5678: 'throttling.iops-size' and its alias 'iops_size' can't be= used at the same time + +Testing: -drive file=3DTEST_DIR/t.qcow2,readonly=3Don,read-only=3Doff +QEMU_PROG: -drive file=3DTEST_DIR/t.qcow2,readonly=3Don,read-only=3Doff:= 'read-only' and its alias 'readonly' can't be used at the same time + + =3D=3D=3D Parsing protocol from file name =3D=3D=3D =20 Testing: -hda foo:bar --=20 1.8.3.1