Quorum maintainance operations
v6 cover Quorum maintainance operations
in V6:
rebased on latest Stefanha's block branch
Benoît Canet (3):
quorum: Add the rewrite-corrupted parameter to quorum.
block: Add drive-mirror-replace command
qemu-iotests: Add 096 new test for drive-mirror-replace.
block.c | 8 +- block/mirror.c | 118 +++++++++++++++++++++- block/quorum.c | 97 ++++++++++++++++-- blockdev.c | 27 +++++ include/block/block.h | 3 + include/block/block_int.h | 15 +++ qapi/block-core.json | 38 +++++++- qmp-commands.hx | 5 + tests/qemu-iotests/041 | 34 +------ tests/qemu-iotests/081 | 15 ++- tests/qemu-iotests/081.out | 10 ++ tests/qemu-iotests/096 | 222 ++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/096.out | 5 + tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 33 +++++++ trace-events | 1 + 16 files changed, 585 insertions(+), 47 deletions(-) create mode 100755 tests/qemu-iotests/096 create mode 100644 tests/qemu-iotests/096.out
Signature · 1 line
1.9.1
PATCH v6 1/3 quorum: Add the rewrite-corrupted parameter to quorum.
On read operations when this parameter is set and some replicas are corrupted while quorum can be reached quorum will proceed to rewrite the correct version of the data to fix the corrupted replicas.
This will shine with SSD where the FTL will remap the same block at another place on rewrite.
--- block/quorum.c | 97 +++++++++++++++++++++++++++++++++++++++++++--- qapi/block-core.json | 5 ++- tests/qemu-iotests/081 | 15 ++++++- tests/qemu-iotests/081.out | 10 +++++ 4 files changed, 119 insertions(+), 8 deletions(-)
block/quorum.c +91 -6
@@ -22,6 +22,7 @@#define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold"#define QUORUM_OPT_BLKVERIFY "blkverify" +#define QUORUM_OPT_REWRITE "rewrite-corrupted"/* This union holds a vote hash value */ typedef union QuorumVoteValue {
@@ -69,6 +70,9 @@ typedef struct BDRVQuorumState {* It is useful to debug other block drivers by * comparing them with a reference one. */ +bool rewrite_corrupted;/* true if the driver must rewrite-on-read corrupted +* block if Quorum is reached. +*/ } BDRVQuorumState;typedef struct QuorumAIOCB QuorumAIOCB ;
@@ -104,13 +108,17 @@ struct QuorumAIOCB {int count;/* number of completed AIOCB */ int success_count;/* number of successfully completed AIOCB */ +int rewrite_count;/* number of replica to rewrite: count down to +* zero once writes are fired +*/ +QuorumVotes votes;bool is_read;int vote_ret; }; -static void quorum_vote (QuorumAIOCB *acb); +static bool quorum_vote (QuorumAIOCB *acb);static void quorum_aio_cancel (BlockDriverAIOCB *blockacb) {
@@ -182,6 +190,7 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s, acb->qcrs =g_new0 (QuorumChildRequest, s->num_children); acb->count =0 ; acb->success_count =0 ; + acb->rewrite_count =0 ; acb->votes.compare = quorum_sha256_compare;QLIST_INIT (&acb->votes.vote_list); acb->is_read = false;
@@ -241,11 +250,27 @@ static bool quorum_has_too_much_io_failed(QuorumAIOCB *acb)return false; } +static void quorum_rewrite_aio_cb (void *opaque,int ret) +{ +QuorumAIOCB *acb = opaque; + +/* one less rewrite to do */ + acb->rewrite_count--; + +/* wait until all rewrite callbacks have completed */ +if (acb->rewrite_count) { +return ; + } + +quorum_aio_finalize (acb); +} +static void quorum_aio_cb (void *opaque,int ret) {QuorumChildRequest *sacb = opaque;QuorumAIOCB *acb = sacb->parent;BDRVQuorumState *s = acb->common.bs->opaque; +bool rewrite = false; sacb->ret = ret; acb->count++;
@@ -262,12 +287,15 @@ static void quorum_aio_cb(void *opaque, int ret)/* Do the vote on read */ if (acb->is_read) { -quorum_vote (acb); + rewrite =quorum_vote (acb); }else {quorum_has_too_much_io_failed (acb); } -quorum_aio_finalize (acb); +/* if no rewrite is done the code will finish right away */ +if (!rewrite) { +quorum_aio_finalize (acb); + } } static void quorum_report_bad_versions(BDRVQuorumState *s,
@@ -287,6 +315,43 @@ static void quorum_report_bad_versions(BDRVQuorumState *s, } } +static bool quorum_rewrite_bad_versions (BDRVQuorumState *s,QuorumAIOCB *acb, +QuorumVoteValue *value) +{ +QuorumVoteVersion *version; +QuorumVoteItem *item; +int count =0 ; + +/* first count the number of bad versions: done first to avoid concurrency +* issues. +*/ + QLIST_FOREACH(version, &acb->votes.vote_list, next) { +if (acb->votes.compare (&version->value, value)) { +continue ; + } + QLIST_FOREACH(item, &version->items, next) { + count++; + } + } + +/* quorum_rewrite_aio_cb will count down this to zero */ + acb->rewrite_count = count; + +/* now fire the correcting rewrites */ + QLIST_FOREACH(version, &acb->votes.vote_list, next) { +if (acb->votes.compare (&version->value, value)) { +continue ; + } + QLIST_FOREACH(item, &version->items, next) { +bdrv_aio_writev (s->bs[item->index], acb->sector_num, acb->qiov, + acb->nb_sectors, quorum_rewrite_aio_cb, acb); + } + } + +/* return true if any rewrite is done else false */ +return count; +} +static void quorum_copy_qiov (QEMUIOVector *dest,QEMUIOVector *source) {int i;
@@ -477,16 +542,17 @@ static int quorum_vote_error(QuorumAIOCB *acb)return ret; } -static void quorum_vote (QuorumAIOCB *acb) +static bool quorum_vote (QuorumAIOCB *acb) {bool quorum = true; +bool rewrite = false;int i, j, ret;QuorumVoteValue hash;BDRVQuorumState *s = acb->common.bs->opaque;QuorumVoteVersion *winner;if (quorum_has_too_much_io_failed (acb)) { -return ; +return false; }/* get the index of the first successful read */
@@ -514,7 +580,7 @@ static void quorum_vote(QuorumAIOCB *acb)/* Every successful read agrees */ if (quorum) {quorum_copy_qiov (acb->qiov, &acb->qcrs[i].qiov); -return ; +return false; }/* compute hashes for each successful read, also store indexes */
@@ -547,9 +613,15 @@ static void quorum_vote(QuorumAIOCB *acb)/* some versions are bad print them */ quorum_report_bad_versions (s, acb, &winner->value); +/* corruption correction is enabled */ +if (s->rewrite_corrupted) { + rewrite =quorum_rewrite_bad_versions (s, acb, &winner->value); + } + free_exit:/* free lists */ quorum_free_vote_list (&acb->votes); +return rewrite; } static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
@@ -714,6 +786,11 @@ static QemuOptsList quorum_runtime_opts = { .type = QEMU_OPT_BOOL, .help = "Trigger block verify mode if set", }, + { + .name = QUORUM_OPT_REWRITE, + .type = QEMU_OPT_BOOL, + .help = "Rewrite corrupted block on read quorum", + }, {/* end of list */ } }, };
@@ -775,6 +852,14 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, "and using two files with vote_threshold=2\n"); } + s->rewrite_corrupted =qemu_opt_get_bool (opts,QUORUM_OPT_REWRITE , false); +if (s->rewrite_corrupted && s->is_blkverify) { +error_setg (&local_err, +"rewrite-corrupted=on cannot be used with blkverify=on" ); + ret = -EINVAL ; + goto exit; + } +/* allocate the children BlockDriverState array */ s->bs = g_new0(BlockDriverState *, s->num_children); opened =g_new0 (bool, s->num_children);
qapi/block-core.json +4 -1
@@ -1333,12 +1333,15 @@ # # @vote-threshold: the vote limit under which a read will fail # +# @rewrite-corrupted: #optional rewrite corrupted data when quorum is reached +# (Since 2.1) +# # Since: 2.0 ## { 'type': 'BlockdevOptionsQuorum', 'data': { '*blkverify': 'bool', 'children': [ 'BlockdevRef' ], - 'vote-threshold': 'int' } } + 'vote-threshold': 'int', '*rewrite-corrupted': 'bool' } } ## # @BlockdevOptions
tests/qemu-iotests/081 +14 -1
@@ -134,15 +134,28 @@ run_qemu -drive "file=$TEST_DIR/2.raw,format=$IMGFMT,if=none,id=drive2" <<EOF EOF echo +echo "== using quorum rewrite corrupted mode ==" + +quorum="$quorum,file.rewrite-corrupted=on" + +$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io + +echo +echo "== checking that quorum has corrected the corrupted file ==" + +$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io + +echo echo "== breaking quorum ==" $QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io +$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io + echo echo "== checking that quorum is broken ==" $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io - # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/081.out +10 -0
@@ -40,9 +40,19 @@ read 10485760/10485760 bytes at offset 0 {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "floppy0", "tray-open": true}} +== using quorum rewrite corrupted mode == +read 10485760/10485760 bytes at offset 0 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== checking that quorum has corrected the corrupted file == +read 10485760/10485760 bytes at offset 0 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + == breaking quorum == wrote 10485760/10485760 bytes at offset 0 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 10485760/10485760 bytes at offset 0 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) == checking that quorum is broken == qemu-io: can't open device (null): Could not read image for determining its format: Input/output error
Signature · 1 line
1.9.1
PATCH v6 2/3 block: Add drive-mirror-replace command
In reply to Benoît CanetWhen a quorum file is totally destroyed (broken NAS or SAN) the user can start a drive-mirror job on the quorum block backend and then replace the broken quorum file with drive-mirror-replace given it has a node-name.
--- block.c | 8 ++-- block/mirror.c | 118 ++++++++++++++++++++++++++++++++++++++++++++-- blockdev.c | 27 +++++++++++ include/block/block.h | 3 ++ include/block/block_int.h | 15 ++++++ qapi/block-core.json | 33 +++++++++++++ qmp-commands.hx | 5 ++ trace-events | 1 + 8 files changed, 204 insertions(+), 6 deletions(-)
block.c +5 -3
@@ -844,10 +844,12 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)return open_flags; } -static void bdrv_assign_node_name (BlockDriverState *bs, -const char *node_name, -Error **errp) +void bdrv_assign_node_name (BlockDriverState *bs, +const char *node_name, +Error **errp) { +assert (bs->node_name[0 ] =='\0' ); +if (!node_name) {return ; }
block/mirror.c +115 -3
156 lines not on this page · raw message
blockdev.c +27 -0
@@ -2326,6 +2326,33 @@ void qmp_block_job_complete(const char *device, Error **errp)block_job_complete (job, errp); } +void qmp_drive_mirror_replace (const char *device,const char *target_reference, +bool has_new_node_name, +const char *new_node_name, +Error **errp) +{ +BlockJob *job =find_block_job (device); + +if (!job) { +error_set (errp,QERR_BLOCK_JOB_NOT_ACTIVE , device); +return ; + } + +if (!job->driver || job->driver->job_type !=BLOCK_JOB_TYPE_MIRROR ) { +error_setg (errp,"Can only be used on a drive-mirror block job" ); +return ; + } + +if (!mirror_set_replace_target (job, target_reference, has_new_node_name, + new_node_name, errp)) { +return ; + } + +trace_qmp_drive_mirror_replace (job, target_reference, + has_new_node_name ? new_node_name :"" ); +block_job_complete (job, errp); +} +void qmp_blockdev_add (BlockdevOptions *options,Error **errp) {QmpOutputVisitor *ov =qmp_output_visitor_new ();
include/block/block.h +3 -0
@@ -179,6 +179,7 @@ typedef enum BlockOpType {BLOCK_OP_TYPE_MIRROR ,BLOCK_OP_TYPE_RESIZE ,BLOCK_OP_TYPE_STREAM , +BLOCK_OP_TYPE_REPLACE ,BLOCK_OP_TYPE_MAX , } BlockOpType;
@@ -217,6 +218,8 @@ int bdrv_open_image(BlockDriverState **pbs, const char *filename, QDict *options, const char *bdref_key, int flags, bool allow_none, Error **errp);void bdrv_set_backing_hd (BlockDriverState *bs,BlockDriverState *backing_hd); +void bdrv_assign_node_name (BlockDriverState *bs,const char *node_name, +Error **errp);int bdrv_open_backing_file (BlockDriverState *bs,QDict *options,Error **errp);void bdrv_append_temp_snapshot (BlockDriverState *bs,int flags,Error **errp); int bdrv_open(BlockDriverState **pbs, const char *filename,
include/block/block_int.h +15 -0
@@ -515,6 +515,21 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target, void *opaque, Error **errp);/* +* mirror_set_replace_target: +* @job: An active mirroring block job started with sync=full. +* @reference: id or node-name of the BDS to replace when the mirror is done. +* @has_new_node_name: Set to true if new_node_name if provided +* @new_node_name: The optional new node name of the new mirror. +* @errp: Error object. +* +* Prepare a mirroring operation to replace a BDS pointed to by reference with +* the new mirror. +*/ +bool mirror_set_replace_target (BlockJob *job,const char *reference, +bool has_new_node_name, +const char *new_node_name,Error **errp); + +/* * backup_start: * @bs: Block device to operate on. * @target: Block device to write to.
qapi/block-core.json +33 -0
@@ -1417,3 +1417,36 @@ ## { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } } +## +# @drive-mirror-replace: +# +# Manually trigger completion of an active background drive-mirror operation +# and replace the target reference with the new mirror. +# This switches the device to write to the target path only. +# The ability to complete is signaled with a BLOCK_JOB_READY event. +# +# This command completes an active drive-mirror background operation +# synchronously and replaces the target reference with the mirror. +# The ordering of this command's return with the BLOCK_JOB_COMPLETED event +# is not defined. Note that if an I/O error occurs during the processing of +# this command: 1) the command itself will fail; 2) the error will be processed +# according to the rerror/werror arguments that were specified when starting +# the operation. +# +# A cancelled or paused drive-mirror job cannot be completed. +# +# @device: the device name +# @target-reference: the id or node name of the block driver state to replace +# @new-node-name: #optional set the node-name of the new block driver state +# needed if the target reference points to a regular node of +# the graph +# +# Returns: Nothing on success +# If no background operation is active on this device, DeviceNotActive +# +# Since: 2.1 +## +{ 'command': 'drive-mirror-replace', + 'data': { 'device': 'str', 'target-reference': 'str', + '*new-node-name': 'str' } } +
qmp-commands.hx +5 -0
@@ -1106,6 +1106,11 @@ EQMP .mhandler.cmd_new = qmp_marshal_input_block_job_complete, }, { + .name = "drive-mirror-replace", + .args_type = "device:B,target-reference:s,new-node-name:s?", + .mhandler.cmd_new = qmp_marshal_input_drive_mirror_replace, + }, + { .name = "transaction", .args_type = "actions:q", .mhandler.cmd_new = qmp_marshal_input_transaction,
trace-events +1 -0
@@ -103,6 +103,7 @@ qmp_block_job_cancel(void *job) "job %p" qmp_block_job_pause(void *job) "job %p" qmp_block_job_resume(void *job) "job %p" qmp_block_job_complete(void *job) "job %p" +qmp_drive_mirror_replace(void *job, const char *target_reference, const char *new_node_name) "job %p target_reference %s new_node_name %s" block_job_cb(void *bs, void *job, int ret) "bs %p job %p ret %d" qmp_block_stream(void *bs, void *job) "bs %p job %p"
Signature · 1 line
1.9.1
PATCH v6 3/3 qemu-iotests: Add 096 new test for drive-mirror-replace.
In reply to Benoît CanetTests for drive-mirror-replace whose purpose is to enable quorum file mirroring and replacement after failure.
--- tests/qemu-iotests/041 | 34 +------ tests/qemu-iotests/096 | 222 ++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/096.out | 5 + tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 33 +++++++ 5 files changed, 262 insertions(+), 33 deletions(-) create mode 100755 tests/qemu-iotests/096 create mode 100644 tests/qemu-iotests/096.out
tests/qemu-iotests/041 +1 -33
@@ -21,45 +21,13 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_io, ImageMirroringTestCase backing_img = os.path.join(iotests.test_dir, 'backing.img') target_backing_img = os.path.join(iotests.test_dir, 'target-backing.img') test_img = os.path.join(iotests.test_dir, 'test.img') target_img = os.path.join(iotests.test_dir, 'target.img') -class ImageMirroringTestCase(iotests.QMPTestCase): - '''Abstract base class for image mirroring test cases''' - - def wait_ready(self, drive='drive0'): - '''Wait until a block job BLOCK_JOB_READY event''' - ready = False - while not ready: - for event in self.vm.get_qmp_events(wait=True): - if event['event'] == 'BLOCK_JOB_READY': - self.assert_qmp(event, 'data/type', 'mirror') - self.assert_qmp(event, 'data/device', drive) - ready = True - - def wait_ready_and_cancel(self, drive='drive0'): - self.wait_ready(drive) - event = self.cancel_and_wait() - self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') - self.assert_qmp(event, 'data/type', 'mirror') - self.assert_qmp(event, 'data/offset', self.image_len) - self.assert_qmp(event, 'data/len', self.image_len) - - def complete_and_wait(self, drive='drive0', wait_ready=True): - '''Complete a block job and wait for it to finish''' - if wait_ready: - self.wait_ready() - - result = self.vm.qmp('block-job-complete', device=drive) - self.assert_qmp(result, 'return', {}) - - event = self.wait_until_completed() - self.assert_qmp(event, 'data/type', 'mirror') - class TestSingleDrive(ImageMirroringTestCase): image_len = 1 * 1024 * 1024 # MB
tests/qemu-iotests/096 new file +222 -0
222 lines not on this page · raw message
tests/qemu-iotests/096.out new file +5 -0
@@ -0,0 +1,5 @@ +........ +---------------------------------------------------------------------- +Ran 8 tests + +OK
tests/qemu-iotests/group +1 -0
@@ -99,3 +99,4 @@ 090 rw auto quick 091 rw auto 092 rw auto quick +096 rw auto
tests/qemu-iotests/iotests.py +33 -0
@@ -273,6 +273,39 @@ class QMPTestCase(unittest.TestCase): self.assert_no_active_block_jobs() return event +# made common here for 041 and 096 +class ImageMirroringTestCase(QMPTestCase): + '''Abstract base class for image mirroring test cases''' + + def wait_ready(self, drive='drive0'): + '''Wait until a block job BLOCK_JOB_READY event''' + ready = False + while not ready: + for event in self.vm.get_qmp_events(wait=True): + if event['event'] == 'BLOCK_JOB_READY': + self.assert_qmp(event, 'data/type', 'mirror') + self.assert_qmp(event, 'data/device', drive) + ready = True + + def wait_ready_and_cancel(self, drive='drive0'): + self.wait_ready(drive=drive) + event = self.cancel_and_wait(drive=drive) + self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED') + self.assert_qmp(event, 'data/type', 'mirror') + self.assert_qmp(event, 'data/offset', self.image_len) + self.assert_qmp(event, 'data/len', self.image_len) + + def complete_and_wait(self, drive='drive0', wait_ready=True): + '''Complete a block job and wait for it to finish''' + if wait_ready: + self.wait_ready(drive=drive) + + result = self.vm.qmp('block-job-complete', device=drive) + self.assert_qmp(result, 'return', {}) + + event = self.wait_until_completed(drive=drive) + self.assert_qmp(event, 'data/type', 'mirror') + def notrun(reason): '''Skip this test suite''' # Each test in qemu-iotests has a number ("seq")
Signature · 1 line
1.9.1
Quoted 19 lines · Benoît Canet
in V6:
rebased on latest Stefanha's block branchBenoît Canet (3):
quorum: Add the rewrite-corrupted parameter to quorum.
block: Add drive-mirror-replace command
qemu-iotests: Add 096 new test for drive-mirror-replace.block.c | 8 +- block/mirror.c | 118 +++++++++++++++++++++- block/quorum.c | 97 ++++++++++++++++-- blockdev.c | 27 +++++ include/block/block.h | 3 + include/block/block_int.h | 15 +++ qapi/block-core.json | 38 +++++++- qmp-commands.hx | 5 + tests/qemu-iotests/041 | 34 +------ tests/qemu-iotests/081 | 15 ++- tests/qemu-iotests/081.out | 10 ++
Quoted 8 lines
tests/qemu-iotests/096 | 222 ++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/096.out | 5 + tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 33 +++++++ trace-events | 1 + 16 files changed, 585 insertions(+), 47 deletions(-) create mode 100755 tests/qemu-iotests/096 create mode 100644 tests/qemu-iotests/096.out
My comment on v5 still applies. There is no need for a new QAPI command. The "replace" operation just requires an extra argument to the drive-mirror command.
Stefan