diff mbox

[3/3] block: prohibit migration during transactions

Message ID 1443717273-5280-4-git-send-email-jsnow@redhat.com
State New
Headers show

Commit Message

John Snow Oct. 1, 2015, 4:34 p.m. UTC
Similarly to BlockJobs, prohibit migration at least
during the synchronous phase of a transaction.

In particular, this guards internal and external
snapshots, which are implemented via transaction actions
through blockdev_do_action.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 blockdev.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Paolo Bonzini Oct. 1, 2015, 6:01 p.m. UTC | #1
On 01/10/2015 18:34, John Snow wrote:
> +
> +    error_setg(&blocker, "Block device(s) are in use by a Block Transaction");

s/Block Transaction/transaction command/

But how can migration start during a transaction?

> +    ret = migrate_add_blocker(blocker, errp);
> +    if (ret < 0) {
> +        goto cleanup_mig;
> +    }
>  
>      QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states;
>      QSIMPLEQ_INIT(&snap_bdrv_states);
> @@ -1814,6 +1823,9 @@ exit:
>          }
>          g_free(state);
>      }
> + cleanup_mig:
> +    migrate_del_blocker(blocker);
> +    error_free(blocker);
John Snow Oct. 2, 2015, 6:20 p.m. UTC | #2
On 10/01/2015 02:01 PM, Paolo Bonzini wrote:
> 
> 
> On 01/10/2015 18:34, John Snow wrote:
>> +
>> +    error_setg(&blocker, "Block device(s) are in use by a Block Transaction");
> 
> s/Block Transaction/transaction command/
> 
> But how can migration start during a transaction?
> 

Well, it definitely can't now ! :)

This is actually more for the other case: The migration starts, and we
want to prohibit snapshots and transactions during that period. Together
with the patch this depends on, we accomplish that.

The workflow of snapshot/transaction-before-migration isn't currently
possible.

>> +    ret = migrate_add_blocker(blocker, errp);
>> +    if (ret < 0) {
>> +        goto cleanup_mig;
>> +    }
>>  
>>      QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states;
>>      QSIMPLEQ_INIT(&snap_bdrv_states);
>> @@ -1814,6 +1823,9 @@ exit:
>>          }
>>          g_free(state);
>>      }
>> + cleanup_mig:
>> +    migrate_del_blocker(blocker);
>> +    error_free(blocker);
>
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index 32b04b4..231dcf6 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -49,6 +49,7 @@ 
 #include "qmp-commands.h"
 #include "trace.h"
 #include "sysemu/arch_init.h"
+#include "migration/migration.h"
 
 static const char *const if_name[IF_COUNT] = {
     [IF_NONE] = "none",
@@ -1759,6 +1760,14 @@  void qmp_transaction(TransactionActionList *dev_list, Error **errp)
     TransactionActionList *dev_entry = dev_list;
     BlkTransactionState *state, *next;
     Error *local_err = NULL;
+    Error *blocker = NULL;
+    int ret;
+
+    error_setg(&blocker, "Block device(s) are in use by a Block Transaction");
+    ret = migrate_add_blocker(blocker, errp);
+    if (ret < 0) {
+        goto cleanup_mig;
+    }
 
     QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states;
     QSIMPLEQ_INIT(&snap_bdrv_states);
@@ -1814,6 +1823,9 @@  exit:
         }
         g_free(state);
     }
+ cleanup_mig:
+    migrate_del_blocker(blocker);
+    error_free(blocker);
 }