diff mbox

[v3,7/8] blockdev: add Abort transaction

Message ID 1368628476-19622-8-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi May 15, 2013, 2:34 p.m. UTC
The Abort action can be used to test QMP 'transaction' failure.  Add it
as the last action to exercise the .abort() and .cleanup() code paths
for all previous actions.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 blockdev.c       | 15 +++++++++++++++
 qapi-schema.json | 11 ++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

Comments

Eric Blake May 15, 2013, 7:01 p.m. UTC | #1
On 05/15/2013 08:34 AM, Stefan Hajnoczi wrote:
> The Abort action can be used to test QMP 'transaction' failure.  Add it
> as the last action to exercise the .abort() and .cleanup() code paths
> for all previous actions.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  blockdev.c       | 15 +++++++++++++++
>  qapi-schema.json | 11 ++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)

I like it!  Even though libvirt will never use it, I can see how having
it definitely helps development of other transaction actions.

> +++ b/qapi-schema.json
> @@ -1630,6 +1630,14 @@
>              '*mode': 'NewImageMode', '*speed': 'int' } }
>  
>  ##
> +# @Abort
> +#
> +# This action can be used to test transaction failure.
> +###
> +{ 'type': 'Abort',
> +  'data': { } }
> +

Probably should add a Since: 1.6 notation.  With that,

Reviewed-by: Eric Blake <eblake@redhat.com>
Wayne Xia May 16, 2013, 2:26 a.m. UTC | #2
于 2013-5-16 3:01, Eric Blake 写道:
> On 05/15/2013 08:34 AM, Stefan Hajnoczi wrote:
>> The Abort action can be used to test QMP 'transaction' failure.  Add it
>> as the last action to exercise the .abort() and .cleanup() code paths
>> for all previous actions.
>>
>> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>> ---
>>   blockdev.c       | 15 +++++++++++++++
>>   qapi-schema.json | 11 ++++++++++-
>>   2 files changed, 25 insertions(+), 1 deletion(-)
>
> I like it!  Even though libvirt will never use it, I can see how having
> it definitely helps development of other transaction actions.
>
>> +++ b/qapi-schema.json
>> @@ -1630,6 +1630,14 @@
>>               '*mode': 'NewImageMode', '*speed': 'int' } }
>>
>>   ##
>> +# @Abort
>> +#
>> +# This action can be used to test transaction failure.
>> +###
>> +{ 'type': 'Abort',
>> +  'data': { } }
>> +
>
> Probably should add a Since: 1.6 notation.  With that,
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
   Nice to have it for injecting error.

Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Stefan Hajnoczi May 16, 2013, 7:37 a.m. UTC | #3
On Wed, May 15, 2013 at 01:01:15PM -0600, Eric Blake wrote:
> On 05/15/2013 08:34 AM, Stefan Hajnoczi wrote:
> > +++ b/qapi-schema.json
> > @@ -1630,6 +1630,14 @@
> >              '*mode': 'NewImageMode', '*speed': 'int' } }
> >  
> >  ##
> > +# @Abort
> > +#
> > +# This action can be used to test transaction failure.
> > +###
> > +{ 'type': 'Abort',
> > +  'data': { } }
> > +
> 
> Probably should add a Since: 1.6 notation.  With that,

Will add in v4.
diff mbox

Patch

diff --git a/blockdev.c b/blockdev.c
index c386bb6..fcce219 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -973,6 +973,16 @@  static void drive_backup_abort(BlkTransactionState *common)
     }
 }
 
+static void abort_prepare(BlkTransactionState *common, Error **errp)
+{
+    error_setg(errp, "Transaction aborted using Abort action");
+}
+
+static void abort_commit(BlkTransactionState *common)
+{
+    assert(false); /* this action never succeeds */
+}
+
 static const BdrvActionOps actions[] = {
     [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = {
         .instance_size = sizeof(ExternalSnapshotState),
@@ -986,6 +996,11 @@  static const BdrvActionOps actions[] = {
         .commit = drive_backup_commit,
         .abort = drive_backup_abort,
     },
+    [TRANSACTION_ACTION_KIND_ABORT] = {
+        .instance_size = sizeof(BlkTransactionState),
+        .prepare = abort_prepare,
+        .commit = abort_commit,
+    },
 };
 
 /*
diff --git a/qapi-schema.json b/qapi-schema.json
index 9ca9352..15221a5 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1630,6 +1630,14 @@ 
             '*mode': 'NewImageMode', '*speed': 'int' } }
 
 ##
+# @Abort
+#
+# This action can be used to test transaction failure.
+###
+{ 'type': 'Abort',
+  'data': { } }
+
+##
 # @TransactionAction
 #
 # A discriminated record of operations that can be performed with
@@ -1638,7 +1646,8 @@ 
 { 'union': 'TransactionAction',
   'data': {
        'blockdev-snapshot-sync': 'BlockdevSnapshot',
-       'drive-backup': 'DriveBackup'
+       'drive-backup': 'DriveBackup',
+       'abort': 'Abort'
    } }
 
 ##