block: auto-generated node-names
If a node-name is not specified, automatically generate the node-name. Generated node-names will use the "block" sub-system identifier. Signed-off-by: Jeff Cody <jcody@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
a0f1913637
commit
15489c769b
19
block.c
19
block.c
@ -763,12 +763,15 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
|
|||||||
const char *node_name,
|
const char *node_name,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
if (!node_name) {
|
char *gen_node_name = NULL;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for empty string or invalid characters */
|
if (!node_name) {
|
||||||
if (!id_wellformed(node_name)) {
|
node_name = gen_node_name = id_generate(ID_BLOCK);
|
||||||
|
} else if (!id_wellformed(node_name)) {
|
||||||
|
/*
|
||||||
|
* Check for empty string or invalid characters, but not if it is
|
||||||
|
* generated (generated names use characters not available to the user)
|
||||||
|
*/
|
||||||
error_setg(errp, "Invalid node name");
|
error_setg(errp, "Invalid node name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -777,18 +780,20 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
|
|||||||
if (blk_by_name(node_name)) {
|
if (blk_by_name(node_name)) {
|
||||||
error_setg(errp, "node-name=%s is conflicting with a device id",
|
error_setg(errp, "node-name=%s is conflicting with a device id",
|
||||||
node_name);
|
node_name);
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* takes care of avoiding duplicates node names */
|
/* takes care of avoiding duplicates node names */
|
||||||
if (bdrv_find_node(node_name)) {
|
if (bdrv_find_node(node_name)) {
|
||||||
error_setg(errp, "Duplicate node name");
|
error_setg(errp, "Duplicate node name");
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy node name into the bs and insert it into the graph list */
|
/* copy node name into the bs and insert it into the graph list */
|
||||||
pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
|
pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
|
||||||
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
|
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
|
||||||
|
out:
|
||||||
|
g_free(gen_node_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QemuOptsList bdrv_runtime_opts = {
|
static QemuOptsList bdrv_runtime_opts = {
|
||||||
|
@ -780,7 +780,7 @@ class TestRepairQuorum(iotests.QMPTestCase):
|
|||||||
# here we check that the last registered quorum file has not been
|
# here we check that the last registered quorum file has not been
|
||||||
# swapped out and unref
|
# swapped out and unref
|
||||||
result = self.vm.qmp('query-named-block-nodes')
|
result = self.vm.qmp('query-named-block-nodes')
|
||||||
self.assert_qmp(result, 'return[0]/file', quorum_img3)
|
self.assert_qmp(result, 'return[1]/file', quorum_img3)
|
||||||
self.vm.shutdown()
|
self.vm.shutdown()
|
||||||
|
|
||||||
def test_cancel_after_ready(self):
|
def test_cancel_after_ready(self):
|
||||||
@ -799,7 +799,7 @@ class TestRepairQuorum(iotests.QMPTestCase):
|
|||||||
result = self.vm.qmp('query-named-block-nodes')
|
result = self.vm.qmp('query-named-block-nodes')
|
||||||
# here we check that the last registered quorum file has not been
|
# here we check that the last registered quorum file has not been
|
||||||
# swapped out and unref
|
# swapped out and unref
|
||||||
self.assert_qmp(result, 'return[0]/file', quorum_img3)
|
self.assert_qmp(result, 'return[1]/file', quorum_img3)
|
||||||
self.vm.shutdown()
|
self.vm.shutdown()
|
||||||
self.assertTrue(iotests.compare_images(quorum_img2, quorum_repair_img),
|
self.assertTrue(iotests.compare_images(quorum_img2, quorum_repair_img),
|
||||||
'target image does not match source after mirroring')
|
'target image does not match source after mirroring')
|
||||||
|
@ -108,7 +108,8 @@ echo
|
|||||||
echo === Overriding backing file ===
|
echo === Overriding backing file ===
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig" -nodefaults
|
echo "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig" -nodefaults\
|
||||||
|
| _filter_generated_node_ids
|
||||||
|
|
||||||
# Drivers that don't support backing files
|
# Drivers that don't support backing files
|
||||||
run_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig"
|
run_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig"
|
||||||
|
@ -59,7 +59,7 @@ QEMU X.Y.Z monitor - type 'help' for more information
|
|||||||
Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DIR/t.qcow2.orig -nodefaults
|
Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DIR/t.qcow2.orig -nodefaults
|
||||||
QEMU X.Y.Z monitor - type 'help' for more information
|
QEMU X.Y.Z monitor - type 'help' for more information
|
||||||
(qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K
|
(qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K
|
||||||
ide0-hd0: TEST_DIR/t.qcow2 (qcow2)
|
ide0-hd0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2)
|
||||||
Cache mode: writeback
|
Cache mode: writeback
|
||||||
Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1)
|
Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1)
|
||||||
(qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K
|
(qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K
|
||||||
|
@ -48,7 +48,8 @@ function do_run_qemu()
|
|||||||
function run_qemu()
|
function run_qemu()
|
||||||
{
|
{
|
||||||
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \
|
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \
|
||||||
| sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g'
|
| sed -e 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g' \
|
||||||
|
| _filter_generated_node_ids
|
||||||
}
|
}
|
||||||
|
|
||||||
size=128M
|
size=128M
|
||||||
|
@ -40,6 +40,7 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virti
|
|||||||
},
|
},
|
||||||
"iops_wr": 0,
|
"iops_wr": 0,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
|
"node-name": "NODE_NAME",
|
||||||
"backing_file_depth": 0,
|
"backing_file_depth": 0,
|
||||||
"drv": "qcow2",
|
"drv": "qcow2",
|
||||||
"iops": 0,
|
"iops": 0,
|
||||||
@ -151,6 +152,7 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk
|
|||||||
},
|
},
|
||||||
"iops_wr": 0,
|
"iops_wr": 0,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
|
"node-name": "NODE_NAME",
|
||||||
"backing_file_depth": 0,
|
"backing_file_depth": 0,
|
||||||
"drv": "qcow2",
|
"drv": "qcow2",
|
||||||
"iops": 0,
|
"iops": 0,
|
||||||
@ -270,6 +272,7 @@ Testing:
|
|||||||
},
|
},
|
||||||
"iops_wr": 0,
|
"iops_wr": 0,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
|
"node-name": "NODE_NAME",
|
||||||
"backing_file_depth": 0,
|
"backing_file_depth": 0,
|
||||||
"drv": "qcow2",
|
"drv": "qcow2",
|
||||||
"iops": 0,
|
"iops": 0,
|
||||||
@ -390,6 +393,7 @@ Testing:
|
|||||||
},
|
},
|
||||||
"iops_wr": 0,
|
"iops_wr": 0,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
|
"node-name": "NODE_NAME",
|
||||||
"backing_file_depth": 0,
|
"backing_file_depth": 0,
|
||||||
"drv": "qcow2",
|
"drv": "qcow2",
|
||||||
"iops": 0,
|
"iops": 0,
|
||||||
@ -480,6 +484,7 @@ Testing:
|
|||||||
},
|
},
|
||||||
"iops_wr": 0,
|
"iops_wr": 0,
|
||||||
"ro": false,
|
"ro": false,
|
||||||
|
"node-name": "NODE_NAME",
|
||||||
"backing_file_depth": 0,
|
"backing_file_depth": 0,
|
||||||
"drv": "qcow2",
|
"drv": "qcow2",
|
||||||
"iops": 0,
|
"iops": 0,
|
||||||
|
@ -53,7 +53,8 @@ function do_run_qemu()
|
|||||||
|
|
||||||
function run_qemu()
|
function run_qemu()
|
||||||
{
|
{
|
||||||
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp | _filter_qemu_io
|
do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\
|
||||||
|
| _filter_qemu_io | _filter_generated_node_ids
|
||||||
}
|
}
|
||||||
|
|
||||||
test_quorum=$($QEMU_IMG --help|grep quorum)
|
test_quorum=$($QEMU_IMG --help|grep quorum)
|
||||||
|
@ -30,7 +30,7 @@ Testing: -drive file=TEST_DIR/2.IMGFMT,format=IMGFMT,if=none,id=drive2
|
|||||||
QMP_VERSION
|
QMP_VERSION
|
||||||
{"return": {}}
|
{"return": {}}
|
||||||
{"return": {}}
|
{"return": {}}
|
||||||
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "QUORUM_REPORT_BAD", "data": {"node-name": "", "sectors-count": 20480, "sector-num": 0}}
|
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "QUORUM_REPORT_BAD", "data": {"node-name": "NODE_NAME", "sectors-count": 20480, "sector-num": 0}}
|
||||||
read 10485760/10485760 bytes at offset 0
|
read 10485760/10485760 bytes at offset 0
|
||||||
10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
|
||||||
{"return": ""}
|
{"return": ""}
|
||||||
|
@ -128,6 +128,11 @@ _filter_date()
|
|||||||
-e 's/[A-Z][a-z][a-z] [A-z][a-z][a-z] *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/DATE/'
|
-e 's/[A-Z][a-z][a-z] [A-z][a-z][a-z] *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/DATE/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_filter_generated_node_ids()
|
||||||
|
{
|
||||||
|
sed -re 's/\#block[0-9]{3,}/NODE_NAME/'
|
||||||
|
}
|
||||||
|
|
||||||
# replace occurrences of the actual TEST_DIR value with TEST_DIR
|
# replace occurrences of the actual TEST_DIR value with TEST_DIR
|
||||||
_filter_testdir()
|
_filter_testdir()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user