mirror of
https://github.com/qemu/qemu.git
synced 2025-08-09 19:15:32 +00:00
block: Catch simultaneous usage of options and their aliases
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=on,read-only=off). Rather than specifying the order of precedence, we should simply forbid such combinations. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Benoît Canet <benoit.canet@nodalink.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
247147fbc1
commit
5abbf0ee4d
16
blockdev.c
16
blockdev.c
@ -538,12 +538,18 @@ err_no_opts:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
const char *value;
|
||||||
|
|
||||||
value = qemu_opt_get(opts, from);
|
value = qemu_opt_get(opts, from);
|
||||||
if (value) {
|
if (value) {
|
||||||
|
if (qemu_opt_find(opts, to)) {
|
||||||
|
error_setg(errp, "'%s' and its alias '%s' can't be used at the "
|
||||||
|
"same time", to, from);
|
||||||
|
return;
|
||||||
|
}
|
||||||
qemu_opt_set(opts, to, value);
|
qemu_opt_set(opts, to, value);
|
||||||
qemu_opt_unset(opts, from);
|
qemu_opt_unset(opts, from);
|
||||||
}
|
}
|
||||||
@ -676,7 +682,13 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(opt_renames); i++) {
|
for (i = 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value = qemu_opt_get(all_opts, "cache");
|
value = qemu_opt_get(all_opts, "cache");
|
||||||
|
@ -198,6 +198,29 @@ run_qemu -drive file.driver=nbd
|
|||||||
run_qemu -drive file.driver=raw
|
run_qemu -drive file.driver=raw
|
||||||
run_qemu -drive foo=bar
|
run_qemu -drive foo=bar
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo === Specifying both an option and its legacy alias ===
|
||||||
|
echo
|
||||||
|
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops=1234,throttling.iops-total=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops_rd=1234,throttling.iops-read=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops_wr=1234,throttling.iops-write=5678
|
||||||
|
|
||||||
|
run_qemu -drive file="$TEST_IMG",bps=1234,throttling.bps-total=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",bps_rd=1234,throttling.bps-read=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",bps_wr=1234,throttling.bps-write=5678
|
||||||
|
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops_max=1234,throttling.iops-total-max=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops_rd_max=1234,throttling.iops-read-max=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops_wr_max=1234,throttling.iops-write-max=5678
|
||||||
|
|
||||||
|
run_qemu -drive file="$TEST_IMG",bps_max=1234,throttling.bps-total-max=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",bps_rd_max=1234,throttling.bps-read-max=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",bps_wr_max=1234,throttling.bps-write-max=5678
|
||||||
|
|
||||||
|
run_qemu -drive file="$TEST_IMG",iops_size=1234,throttling.iops-size=5678
|
||||||
|
run_qemu -drive file="$TEST_IMG",readonly=on,read-only=off
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo === Parsing protocol from file name ===
|
echo === Parsing protocol from file name ===
|
||||||
echo
|
echo
|
||||||
|
@ -274,6 +274,51 @@ Testing: -drive foo=bar
|
|||||||
QEMU_PROG: -drive foo=bar: could not open disk image ide0-hd0: Must specify either driver or file
|
QEMU_PROG: -drive foo=bar: could not open disk image ide0-hd0: Must specify either driver or file
|
||||||
|
|
||||||
|
|
||||||
|
=== Specifying both an option and its legacy alias ===
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops=1234,throttling.iops-total=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops=1234,throttling.iops-total=5678: 'throttling.iops-total' and its alias 'iops' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops_rd=1234,throttling.iops-read=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops_rd=1234,throttling.iops-read=5678: 'throttling.iops-read' and its alias 'iops_rd' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops_wr=1234,throttling.iops-write=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops_wr=1234,throttling.iops-write=5678: 'throttling.iops-write' and its alias 'iops_wr' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,bps=1234,throttling.bps-total=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,bps=1234,throttling.bps-total=5678: 'throttling.bps-total' and its alias 'bps' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,bps_rd=1234,throttling.bps-read=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,bps_rd=1234,throttling.bps-read=5678: 'throttling.bps-read' and its alias 'bps_rd' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,bps_wr=1234,throttling.bps-write=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,bps_wr=1234,throttling.bps-write=5678: 'throttling.bps-write' and its alias 'bps_wr' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops_max=1234,throttling.iops-total-max=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops_max=1234,throttling.iops-total-max=5678: 'throttling.iops-total-max' and its alias 'iops_max' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops_rd_max=1234,throttling.iops-read-max=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops_rd_max=1234,throttling.iops-read-max=5678: 'throttling.iops-read-max' and its alias 'iops_rd_max' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops_wr_max=1234,throttling.iops-write-max=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops_wr_max=1234,throttling.iops-write-max=5678: 'throttling.iops-write-max' and its alias 'iops_wr_max' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,bps_max=1234,throttling.bps-total-max=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,bps_max=1234,throttling.bps-total-max=5678: 'throttling.bps-total-max' and its alias 'bps_max' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,bps_rd_max=1234,throttling.bps-read-max=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,bps_rd_max=1234,throttling.bps-read-max=5678: 'throttling.bps-read-max' and its alias 'bps_rd_max' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,bps_wr_max=1234,throttling.bps-write-max=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,bps_wr_max=1234,throttling.bps-write-max=5678: 'throttling.bps-write-max' and its alias 'bps_wr_max' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,iops_size=1234,throttling.iops-size=5678
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,iops_size=1234,throttling.iops-size=5678: 'throttling.iops-size' and its alias 'iops_size' can't be used at the same time
|
||||||
|
|
||||||
|
Testing: -drive file=TEST_DIR/t.qcow2,readonly=on,read-only=off
|
||||||
|
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,readonly=on,read-only=off: 'read-only' and its alias 'readonly' can't be used at the same time
|
||||||
|
|
||||||
|
|
||||||
=== Parsing protocol from file name ===
|
=== Parsing protocol from file name ===
|
||||||
|
|
||||||
Testing: -hda foo:bar
|
Testing: -hda foo:bar
|
||||||
|
Loading…
Reference in New Issue
Block a user