qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, dietmar@proxmox.com,
	stefanha@gmail.com
Subject: Re: [Qemu-devel] [PATCH V2 5/5] block: make all steps in qmp_transaction() as callback
Date: Tue, 16 Apr 2013 15:52:24 +0200	[thread overview]
Message-ID: <20130416135223.GB19758@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <1365851501-3037-6-git-send-email-xiawenc@linux.vnet.ibm.com>

Am 13.04.2013 um 13:11 hat Wenchao Xia geschrieben:
>   Now qmp_transaction() can be extended with other operation,
> external snapshot or backing chain creation, is just one case it.
> 
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  blockdev.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
>  1 files changed, 58 insertions(+), 10 deletions(-)
> 
> diff --git a/blockdev.c b/blockdev.c
> index 3e69569..9f0acfb 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -779,14 +779,35 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
>  
>  
>  /* New and old BlockDriverState structs for group snapshots */
> +
> +/* Only in prepare() it may fail, so roll back just need to take care
> +   what is done in prepare(). */
> +typedef struct BdrvActionOps {
> +    /* Prepare the work, must NOT be NULL. */
> +    int (*prepare)(BlockdevAction *action, void **p_opaque, Error **errp);
> +    /* Commit the changes, can be NULL. */
> +    void (*commit)(BlockdevAction *action, void *opaque);
> +    /* Rollback the changes on fail, mut NOT be NULL. */

Typo: s/mut/must/

> +    void (*rollback)(BlockdevAction *action, void *opaque);
> +    /* Clean up resource in the end, can be NULL. */
> +    void (*clean)(BlockdevAction *action, void *opaque);
> +} BdrvActionOps;

What's the reason that commit can be NULL, but rollback can't? I can't
imagine a case where a commit isn't needed, but one without a rollback
action sounds possible.

> +
>  typedef struct BlkTransactionStates {
> -    BlockDriverState *old_bs;
> -    BlockDriverState *new_bs;
> +    BlockdevAction *action;
> +    void *opaque;
> +    const BdrvActionOps *ops;
>      QSIMPLEQ_ENTRY(BlkTransactionStates) entry;
>  } BlkTransactionStates;
>  
> +/* external snapshot private data */
> +typedef struct ExternalSnapshotState {
> +    BlockDriverState *old_bs;
> +    BlockDriverState *new_bs;
> +} ExternalSnapshotState;
> +
>  static int external_snapshot_prepare(BlockdevAction *action,
> -                                     BlkTransactionStates *states,
> +                                     void **p_opaque,

Call it just opaque.

>                                       Error **errp)
>  {
>      BlockDriver *proto_drv;
> @@ -797,6 +818,7 @@ static int external_snapshot_prepare(BlockdevAction *action,
>      const char *new_image_file;
>      const char *format = "qcow2";
>      enum NewImageMode mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
> +    ExternalSnapshotState *states;
>  
>      /* get parameters */
>      g_assert(action->kind == BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC);
> @@ -817,6 +839,9 @@ static int external_snapshot_prepare(BlockdevAction *action,
>          goto fail;
>      }
>  
> +    *p_opaque = g_malloc0(sizeof(ExternalSnapshotState));
> +    states = *p_opaque;
> +
>      states->old_bs = bdrv_find(device);
>      if (!states->old_bs) {
>          error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> @@ -878,8 +903,10 @@ static int external_snapshot_prepare(BlockdevAction *action,
>  }
>  
>  static void external_snapshot_commit(BlockdevAction *action,
> -                                     BlkTransactionStates *states)
> +                                     void *opaque)
>  {
> +    ExternalSnapshotState *states = opaque;
> +
>      /* This removes our old bs from the bdrv_states, and adds the new bs */
>      bdrv_append(states->new_bs, states->old_bs);
>      /* We don't need (or want) to use the transactional
> @@ -890,13 +917,27 @@ static void external_snapshot_commit(BlockdevAction *action,
>  }
>  
>  static void external_snapshot_rollback(BlockdevAction *action,
> -                                       BlkTransactionStates *states)
> +                                       void *opaque)
>  {
> +    ExternalSnapshotState *states = opaque;
>      if (states->new_bs) {
>          bdrv_delete(states->new_bs);
>      }
>  }
>  
> +static void external_snapshot_clean(BlockdevAction *action,
> +                                    void *opaque)

This fits in a single line.

> +{
> +    g_free(opaque);
> +}
> +
> +const BdrvActionOps external_snapshot_ops = {
> +    .prepare = external_snapshot_prepare,
> +    .commit = external_snapshot_commit,
> +    .rollback = external_snapshot_rollback,
> +    .clean = external_snapshot_clean,
> +};

Please align all = to the same column.

Kevin

  reply	other threads:[~2013-04-16 14:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-13 11:11 [Qemu-devel] [PATCH V2 0/5] block: make qmp_transaction extendable Wenchao Xia
2013-04-13 11:11 ` [Qemu-devel] [PATCH V2 1/5] block: package preparation code in qmp_transaction() Wenchao Xia
2013-04-16 13:19   ` Kevin Wolf
2013-04-16 14:56   ` Eric Blake
2013-04-13 11:11 ` [Qemu-devel] [PATCH V2 2/5] block: move input parsing " Wenchao Xia
2013-04-16 15:15   ` Eric Blake
2013-04-13 11:11 ` [Qemu-devel] [PATCH V2 3/5] block: package committing " Wenchao Xia
2013-04-16 15:26   ` Eric Blake
2013-04-13 11:11 ` [Qemu-devel] [PATCH V2 4/5] block: package rolling back " Wenchao Xia
2013-04-16 15:27   ` Eric Blake
2013-04-13 11:11 ` [Qemu-devel] [PATCH V2 5/5] block: make all steps in qmp_transaction() as callback Wenchao Xia
2013-04-16 13:52   ` Kevin Wolf [this message]
2013-04-17  3:59     ` Wenchao Xia
2013-04-16 15:41   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130416135223.GB19758@dhcp-200-207.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=dietmar@proxmox.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=xiawenc@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).