Block migration if any of the block device is busy
v4 cover Block migration if any of the block device is busy
From: Benoît Canet <[email protected]>
This patchset is designed to avoid starting a live migration while any of the block device is busy.
Tested with the following sequence:
QEMU 1.1.50 monitor - type 'help' for more information (qemu) block_stream virtio0 1k
(qemu) migrate tcp:localhost:4444
migrate: Migration is blocked by streaming (qemu) block_job_cancel virtio0
(qemu) migrate tcp:localhost:4444
migrate: Connection can not be completed immediately (qemu)
=> migration then succeed
in v2:
stefanha: Rename bdrv_have_block_jobs() to bdrv_are_busy() and make it return -EBUSY.
paolo: remove spurious bdrv_close()
in v3
pm215: rewrite confusing error message
in v4:
stefanha: make the error message more general
Benoît Canet (3):
block: Add bdrv_are_busy()
qerror: Add error telling that block dev usage prevents migration
migration: block migration when streaming block jobs are running.
block.c | 13 +++++++++++++ block.h | 2 ++ migration.c | 5 +++++ qerror.c | 4 ++++ qerror.h | 3 +++ 5 files changed, 27 insertions(+)
Signature · 1 line
1.7.9.5
PATCH v4 1/3 block: Add bdrv_are_busy()
From: Benoît Canet <[email protected]>
bdrv_are_busy will be used to check if any of the bs are in use or if one of them have a running block job.
The first user will be qmp_migrate().
--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)
block.c +13 -0
@@ -4027,6 +4027,19 @@ out:return ret; } +int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + } + +return 0 ; +} +void *block_job_create (const BlockJobType *job_type,BlockDriverState *bs,int64_t speed,BlockDriverCompletionFunc *cb,void *opaque,Error **errp)
block.h +2 -0
@@ -337,6 +337,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +int bdrv_are_busy (void ); +enum BlockAcctType {BDRV_ACCT_READ ,BDRV_ACCT_WRITE ,
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy()
Quoted 20 lines · On Mon, 23 Jul 2012 16:22:58 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
bdrv_are_busywill be used to check if any of the bs are in use or if one of them have a running block job.The first user will be
qmp_migrate().Signed-off-by Benoit Canet <[email protected]>--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)block.c +0
-0@@ -4027,6 +4027,19 @@ out:return ret; }
block.c out: · line 4038
Quoted 10 lines
block.c +9
-0+int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + }
IMO, this should return true/false. The name is a bit misleading too, as it gives the impression that are existing bdrvs are busy. I'd call it bdrv_any_busy() or bdrv_any_in_use().
Quoted 20 lines
block.c +4
-0+ +return 0 ; +} +void *block_job_create (const BlockJobType *job_type,BlockDriverState *bs,int64_t speed,BlockDriverCompletionFunc *cb,void *opaque,Error **errp)block.h +2
-0@@ -337,6 +337,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +int bdrv_are_busy (void ); +enum BlockAcctType {BDRV_ACCT_READ ,BDRV_ACCT_WRITE ,
Re: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy()
Quoted 24 lines · Luiz Capitulino
Quoted 21 lines · On Mon, 23 Jul 2012 16:22:58 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
bdrv_are_busywill be used to check if any of the bs are in use or if one of them have a running block job.The first user will be
qmp_migrate().Signed-off-by Benoit Canet <[email protected]>--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)block.c +0
-0@@ -4027,6 +4027,19 @@ out:return ret; }
Quoted 13 lines
block.c out: · line 4038
Quoted 9 lines
block.c +9
-0+int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + }IMO, this should return true/false. The name is a bit misleading too, as it gives the impression that are existing bdrvs are busy. I'd call it
bdrv_any_busy()orbdrv_any_in_use().
Hello Anthony,
Stefanha is in favor of returning -EBUSY and Luiz Capitulino would prefer the function to return a boolean.
Could you decide which option is the best ?
Regards
Benoît
Quoted 22 lines
Quoted 21 lines
block.c +4
-0+ +return 0 ; +} +void *block_job_create (const BlockJobType *job_type,BlockDriverState *bs,int64_t speed,BlockDriverCompletionFunc *cb,void *opaque,Error **errp)block.h +2
-0@@ -337,6 +337,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +int bdrv_are_busy (void ); +enum BlockAcctType {BDRV_ACCT_READ ,BDRV_ACCT_WRITE ,
Re: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy()
Quoted 39 lines · On Tue, 24 Jul 2012 12:10:39 +0200 Benoît Canet <[email protected]>…
Quoted 24 lines · Luiz Capitulino
Quoted 21 lines · On Mon, 23 Jul 2012 16:22:58 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
bdrv_are_busywill be used to check if any of the bs are in use or if one of them have a running block job.The first user will be
qmp_migrate().Signed-off-by Benoit Canet <[email protected]>--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)block.c +0
-0@@ -4027,6 +4027,19 @@ out:return ret; }Quoted 13 lines
block.c out: · line 4038
Quoted 9 lines
block.c +9
-0+int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + }IMO, this should return true/false. The name is a bit misleading too, as it gives the impression that are existing bdrvs are busy. I'd call it
bdrv_any_busy()orbdrv_any_in_use().
Quoted 5 lines
Hello Anthony,
Stefanha is in favor of returning
-EBUSYand Luiz Capitulino would prefer the function to return a boolean.
Could you decide which option is the best ?
Stefan's opnion certainly has precedence over mine on block layer stuff, this was just an IMO.
Stefan, did you consider returning a boolean?
Quoted 28 lines
Regards
Benoît
Quoted 22 lines
Quoted 21 lines
block.c +4
-0+ +return 0 ; +} +void *block_job_create (const BlockJobType *job_type,BlockDriverState *bs,int64_t speed,BlockDriverCompletionFunc *cb,void *opaque,Error **errp)block.h +2
-0@@ -337,6 +337,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);void bdrv_set_in_use (BlockDriverState *bs,int in_use);int bdrv_in_use (BlockDriverState *bs); +int bdrv_are_busy (void ); +enum BlockAcctType {BDRV_ACCT_READ ,BDRV_ACCT_WRITE ,
Re: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy()
Am 24.07.2012 14:55, schrieb Luiz Capitulino:
Quoted 44 lines
Quoted 41 lines · On Tue, 24 Jul 2012 12:10:39 +0200 Benoît Canet <[email protected]>…
Quoted 24 lines · Luiz Capitulino
Quoted 21 lines · On Mon, 23 Jul 2012 16:22:58 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
bdrv_are_busywill be used to check if any of the bs are in use or if one of them have a running block job.The first user will be
qmp_migrate().Signed-off-by Benoit Canet <[email protected]>--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)block.c +0
-0@@ -4027,6 +4027,19 @@ out:return ret; }Quoted 13 lines
block.c out: · line 4038
Quoted 9 lines
block.c +9
-0+int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + }IMO, this should return true/false. The name is a bit misleading too, as it gives the impression that are existing bdrvs are busy. I'd call it
bdrv_any_busy()orbdrv_any_in_use().Hello Anthony,
Quoted 8 lines
Quoted 3 lines
Stefanha is in favor of returning
-EBUSYand Luiz Capitulino would prefer the function to return a boolean.
Could you decide which option is the best ?Stefan's opnion certainly has precedence over mine on block layer stuff, this was just an IMO.
Stefan, did you consider returning a boolean?
I'm with you in this point, Luiz (as well as with the rename to bdrv_is_any_busy). And actually I think Benoît may have misunderstood and Stefan is as well. What he said is:
Quoted 2 lines
I think
bdrv_have_block_jobs()is too specific and would usebdrv_in_use(bs)here to give basically an EBUSY-type error.
I don't think this was about bool vs. -errno, but more about checking only block jobs vs. all kinds of things that can have a block device in use.
Anyway, I believe we came to the conclusion that even the intention of the series is wrong, as in many cases migrating while an image is being streamed is perfectly fine. So the details don't really matter any more.
Kevin
Re: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy()
Quoted 61 lines · Kevin Wolf
Am 24.07.2012 14:55, schrieb Luiz Capitulino:
Quoted 44 lines
Quoted 41 lines · On Tue, 24 Jul 2012 12:10:39 +0200 Benoît Canet <[email protected]>…
Quoted 24 lines · Luiz Capitulino
Quoted 21 lines · On Mon, 23 Jul 2012 16:22:58 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
bdrv_are_busywill be used to check if any of the bs are in use or if one of them have a running block job.The first user will be
qmp_migrate().Signed-off-by Benoit Canet <[email protected]>--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)block.c +0
-0@@ -4027,6 +4027,19 @@ out:return ret; }Quoted 13 lines
block.c out: · line 4038
Quoted 9 lines
block.c +9
-0+int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + }IMO, this should return true/false. The name is a bit misleading too, as it gives the impression that are existing bdrvs are busy. I'd call it
bdrv_any_busy()orbdrv_any_in_use().Hello Anthony,
Quoted 8 lines
Quoted 3 lines
Stefanha is in favor of returning
-EBUSYand Luiz Capitulino would prefer the function to return a boolean.
Could you decide which option is the best ?Stefan's opnion certainly has precedence over mine on block layer stuff, this was just an IMO.
Stefan, did you consider returning a boolean?
I'm with you in this point, Luiz (as well as with the rename to
bdrv_is_any_busy). And actually I think Benoît may have misunderstood and Stefan is as well. What he said is:Quoted 2 lines
I think
bdrv_have_block_jobs()is too specific and would usebdrv_in_use(bs)here to give basically an EBUSY-type error.
Quoted 7 lines
I don't think this was about bool vs. -errno, but more about checking only block jobs vs. all kinds of things that can have a block device in use.
Anyway, I believe we came to the conclusion that even the intention of the series is wrong, as in many cases migrating while an image is being streamed is perfectly fine. So the details don't really matter any more.
Just to be sure.
In case of a migration with shared storage the migration stops the streaming when the switch between vm is done.
So starting a streaming after the begining of a migration is also right. Is that correct ?
Benoît
Re: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy()
Am 24.07.2012 16:37, schrieb Benoît Canet:
Quoted 70 lines · Kevin Wolf
Quoted 61 lines
Am 24.07.2012 14:55, schrieb Luiz Capitulino:
Quoted 44 lines
Quoted 41 lines · On Tue, 24 Jul 2012 12:10:39 +0200 Benoît Canet <[email protected]>…
Quoted 24 lines · Luiz Capitulino
Quoted 21 lines · On Mon, 23 Jul 2012 16:22:58 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
bdrv_are_busywill be used to check if any of the bs are in use or if one of them have a running block job.The first user will be
qmp_migrate().Signed-off-by Benoit Canet <[email protected]>--- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+)block.c +0
-0@@ -4027,6 +4027,19 @@ out:return ret; }Quoted 13 lines
block.c out: · line 4038
Quoted 9 lines
block.c +9
-0+int bdrv_are_busy (void ) +{ +BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { +if (bs->job ||bdrv_in_use (bs)) { +return -EBUSY ; + } + }IMO, this should return true/false. The name is a bit misleading too, as it gives the impression that are existing bdrvs are busy. I'd call it
bdrv_any_busy()orbdrv_any_in_use().Hello Anthony,
Quoted 8 lines
Quoted 3 lines
Stefanha is in favor of returning
-EBUSYand Luiz Capitulino would prefer the function to return a boolean.
Could you decide which option is the best ?Stefan's opnion certainly has precedence over mine on block layer stuff, this was just an IMO.
Stefan, did you consider returning a boolean?
I'm with you in this point, Luiz (as well as with the rename to
bdrv_is_any_busy). And actually I think Benoît may have misunderstood and Stefan is as well. What he said is:Quoted 2 lines
I think
bdrv_have_block_jobs()is too specific and would usebdrv_in_use(bs)here to give basically an EBUSY-type error.Quoted 7 lines
I don't think this was about bool vs. -errno, but more about checking only block jobs vs. all kinds of things that can have a block device in use.
Anyway, I believe we came to the conclusion that even the intention of the series is wrong, as in many cases migrating while an image is being streamed is perfectly fine. So the details don't really matter any more.
Quoted 6 lines
Just to be sure.
In case of a migration with shared storage the migration stops the streaming when the switch between vm is done.
So starting a streaming after the begining of a migration is also right. Is that correct ?
Yes, starting streaming itself shouldn't be a problem. Usually streaming is combined with doing a snapshot first, though, and that could become a problem if the destination didn't already know the snapshot when it was started. I believe it's already blocked today.
Kevin
PATCH v4 2/3 qerror: Add error telling that block dev usage prevents migration
In reply to [email protected]From: Benoît Canet <[email protected]>
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+)
qerror.c +4 -0
@@ -283,6 +283,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Could not set password", }, { + .error_fmt = QERR_BLOCK_DEV_IN_USE_MIGRATION_PREVENTED, + .desc = "Block device in use migration prevented", + }, + { .error_fmt = QERR_TOO_MANY_FILES, .desc = "Too many open files", },
qerror.h +3 -0
@@ -233,6 +233,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_SET_PASSWD_FAILED \ "{ 'class': 'SetPasswdFailed', 'data': {} }" +#define QERR_BLOCK_DEV_IN_USE_MIGRATION_PREVENTED \ + "{ 'class': 'BlockDevInUseMigrationPrevented', 'data': {} }" +#define QERR_TOO_MANY_FILES \ "{ 'class': 'TooManyFiles', 'data': {} }"
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH V4 2/3] qerror: Add error telling that block dev usage prevents migration
Quoted 13 lines · On Mon, 23 Jul 2012 16:22:59 +0200 [email protected] wrote:
From: Benoît Canet <[email protected]>
Signed-off-by Benoit Canet <[email protected]>--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+)qerror.c +0
-0
qerror.c static const QErrorStringTable qerror_table[] = { · line 288
Quoted 6 lines
qerror.c +3
-0@@ -283,6 +283,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Could not set password", }, { + .error_fmt = QERR_BLOCK_DEV_IN_USE_MIGRATION_PREVENTED, + .desc = "Block device in use migration prevented", + },
Let's avoid an specific error. We have two options:
1. Use QERR_MIGRATION_NOT_SUPPORTED
2. Add QERR_MIGRATION_BLOCKED
Quoted 18 lines
qerror.c +1
-0+ { .error_fmt = QERR_TOO_MANY_FILES, .desc = "Too many open files", },qerror.h +3
-0@@ -233,6 +233,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_SET_PASSWD_FAILED \ "{ 'class': 'SetPasswdFailed', 'data': {} }" +#define QERR_BLOCK_DEV_IN_USE_MIGRATION_PREVENTED \ + "{ 'class': 'BlockDevInUseMigrationPrevented', 'data': {} }" +#define QERR_TOO_MANY_FILES \ "{ 'class': 'TooManyFiles', 'data': {} }"
PATCH v4 3/3 migration: block migration when any of the block device is busy
In reply to [email protected]From: Benoît Canet <[email protected]>
--- migration.c | 5 +++++ 1 file changed, 5 insertions(+)
migration.c +5 -0
@@ -425,6 +425,11 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,return ; } +if (bdrv_are_busy ()) { +error_set (errp,QERR_BLOCK_DEV_IN_USE_MIGRATION_PREVENTED ); +return ; + } + s =migrate_init (¶ms);if (strstart (uri,"tcp:" , &p)) {
Signature · 1 line
1.7.9.5
Quoted 39 lines · On Mon, Jul 23, 2012 at 3:22 PM, <[email protected]> wrote:
From: Benoît Canet <[email protected]>
This patchset is designed to avoid starting a live migration while any of the block device is busy.
Tested with the following sequence:
QEMU 1.1.50 monitor - type 'help' for more information (qemu)
block_streamvirtio0 1k
(qemu) migrate tcp:localhost:4444
migrate: Migration is blocked by streaming (qemu)block_job_cancelvirtio0
(qemu) migrate tcp:localhost:4444
migrate: Connection can not be completed immediately (qemu)
=> migration then succeedin v2:
stefanha: Renamebdrv_have_block_jobs()tobdrv_are_busy()and make it return-EBUSY.
paolo: remove spuriousbdrv_close()in v3
pm215: rewrite confusing error messagein v4:
stefanha: make the error message more generalBenoît Canet (3):
block: Addbdrv_are_busy()
qerror: Add error telling that block dev usage prevents migration
migration: block migration when streaming block jobs are running.block.c | 13 +++++++++++++ block.h | 2 ++ migration.c | 5 +++++ qerror.c | 4 ++++ qerror.h | 3 +++ 5 files changed, 27 insertions(+)
Quoted 2 lines
--
1.7.9.5
Am 23.07.2012 16:22, schrieb [email protected]:
Quoted 7 lines
From: Benoît Canet <[email protected]>
This patchset is designed to avoid starting a live migration while any of the block device is busy.
Tested with the following sequence:
Quoted 9 lines
QEMU 1.1.50 monitor - type 'help' for more information (qemu)
block_streamvirtio0 1k
(qemu) migrate tcp:localhost:4444
migrate: Migration is blocked by streaming (qemu)block_job_cancelvirtio0
(qemu) migrate tcp:localhost:4444
migrate: Connection can not be completed immediately (qemu)
=> migration then succeed
Maybe I'm missing the obvious, but why? Migration will stop the streaming if it isn't restarted explicitly on the destination, but I think that's expected.
Also, there are migration blockers. Wouldn't it be better to use them instead of adding more special-case code to migration.c?
Kevin
Quoted 18 lines · Kevin Wolf
Am 23.07.2012 16:22, schrieb [email protected]:
Quoted 7 lines
From: Benoît Canet <[email protected]>
This patchset is designed to avoid starting a live migration while any of the block device is busy.
Tested with the following sequence:
Quoted 9 lines
QEMU 1.1.50 monitor - type 'help' for more information (qemu)
block_streamvirtio0 1k
(qemu) migrate tcp:localhost:4444
migrate: Migration is blocked by streaming (qemu)block_job_cancelvirtio0
(qemu) migrate tcp:localhost:4444
migrate: Connection can not be completed immediately (qemu)
=> migration then succeed
Quoted 3 lines
Maybe I'm missing the obvious, but why? Migration will stop the streaming if it isn't restarted explicitly on the destination, but I think that's expected.
Hmm...maybe this is a policy decision. I figure if you are running image streaming and try to migrate, chances are you're migration will break on the destination host because you were trying to do pre-copy storage migration and never finished.
Stefan
Am 24.07.2012 12:04, schrieb Stefan Hajnoczi:
Quoted 19 lines · Kevin Wolf
Quoted 18 lines
Am 23.07.2012 16:22, schrieb [email protected]:
Quoted 16 lines
From: Benoît Canet <[email protected]>
This patchset is designed to avoid starting a live migration while any of the block device is busy.
Tested with the following sequence:
QEMU 1.1.50 monitor - type 'help' for more information (qemu)
block_streamvirtio0 1k
(qemu) migrate tcp:localhost:4444
migrate: Migration is blocked by streaming (qemu)block_job_cancelvirtio0
(qemu) migrate tcp:localhost:4444
migrate: Connection can not be completed immediately (qemu)
=> migration then succeed
Quoted 8 lines
Quoted 3 lines
Maybe I'm missing the obvious, but why? Migration will stop the streaming if it isn't restarted explicitly on the destination, but I think that's expected.
Hmm...maybe this is a policy decision. I figure if you are running image streaming and try to migrate, chances are you're migration will break on the destination host because you were trying to do pre-copy storage migration and never finished.
Sure, if you're migrating without shared storage, you always need to know what you're doing.
But you could be doing a post-copy storage migration and migrate to the next host before it has completed. I think this is a completely legitimate action that shouldn't be blocked.
Kevin
Quoted 5 lines
Quoted 5 lines
Hmm...maybe this is a policy decision. I figure if you are running image streaming and try to migrate, chances are you're migration will break on the destination host because you were trying to do pre-copy storage migration and never finished.
Streaming is post-copy, and can be interrupted every time you want.
Mirroring is pre-copy. That's another story, but even then the way to "emulate" migrate -b/-i (and make it much more efficient, as you can see from the last few patches I just posted) is exactly to run mirroring in parallel to RAM migration. This is relatively difficult to do by hand (though I'd like to improve it in 1.3 if only to get rid of block-migration.c) and requires giving the user a considerable amount of rope, but it is doable.
So, thinking about it a bit more, this patch looks like a good idea in principle, but actually it is counterproductive.
Paolo