Patchwork [1/3] block: Add bdrv_have_block_jobs() so migration code abort if needed.

login
register
mail settings
Submitter Benoit Canet
Date July 20, 2012, 7:32 p.m.
Message ID <1342812757-2651-2-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/172347/
State New
Headers show

Comments

Benoit Canet - July 20, 2012, 7:32 p.m.
From: Benoît Canet <benoit@irqsave.net>

qmp_migrate() will be able to check if some block jobs are
running using bdrv_have_block_jobs() and abort safely if needed.

Signed-off-by: Benoit Canet <benoit@irqsave.net>
---
 block.c |   14 ++++++++++++++
 block.h |    2 ++
 2 files changed, 16 insertions(+)
Paolo Bonzini - July 23, 2012, 10:02 a.m.
Il 20/07/2012 21:32, benoit.canet@gmail.com ha scritto:
> +bool bdrv_have_block_jobs(void)
> +{
> +    BlockDriverState *bs;
> +
> +    QTAILQ_FOREACH(bs, &bdrv_states, list) {
> +        if (bs->job || bdrv_in_use(bs)) {
> +            return true;
> +        }
> +        bdrv_close(bs);

Why close the device here?

Paolo

> +    }
> +
> +    return false;
> +}
> +
Benoît Canet - July 23, 2012, 10:25 a.m.
> Why close the device here?

Thanks

Benoît

Patch

diff --git a/block.c b/block.c
index ce7eb8f..2b7b999 100644
--- a/block.c
+++ b/block.c
@@ -4027,6 +4027,20 @@  out:
     return ret;
 }
 
+bool bdrv_have_block_jobs(void)
+{
+    BlockDriverState *bs;
+
+    QTAILQ_FOREACH(bs, &bdrv_states, list) {
+        if (bs->job || bdrv_in_use(bs)) {
+            return true;
+        }
+        bdrv_close(bs);
+    }
+
+    return false;
+}
+
 void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs,
                        int64_t speed, BlockDriverCompletionFunc *cb,
                        void *opaque, Error **errp)
diff --git a/block.h b/block.h
index c89590d..1335a2b 100644
--- a/block.h
+++ b/block.h
@@ -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);
 
+bool bdrv_have_block_jobs(void);
+
 enum BlockAcctType {
     BDRV_ACCT_READ,
     BDRV_ACCT_WRITE,