qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org,
	qemu-devel@nongnu.org, mreitz@redhat.com,
	vsementsov@parallels.com
Subject: Re: [Qemu-devel] [PATCH v5 05/10] block: add transactional callbacks feature
Date: Fri, 5 Jun 2015 13:45:36 +0100	[thread overview]
Message-ID: <20150605124536.GG23825@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1433454372-16356-6-git-send-email-jsnow@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3974 bytes --]

On Thu, Jun 04, 2015 at 05:46:07PM -0400, John Snow wrote:
> The goal here is to add a new method to transactions that allows
> developers to specify a callback that will get invoked only once
> all jobs spawned by a transaction are completed, allowing developers
> the chance to perform actions conditionally pending complete success,
> partial failure, or complete failure.
> 
> In order to register the new callback to be invoked, a user must request
> a callback pointer and closure by calling new_action_cb_wrapper, which
> creates a wrapper around an opaque pointer and callback that would have
> originally been passed to e.g. backup_start().
> 
> The function will return a function pointer and a new opaque pointer to
> be passed instead. The transaction system will effectively intercept the
> original callbacks and perform book-keeping on the transaction after it
> has delivered the original enveloped callback.
> 
> This means that Transaction Action callback methods will be called after
> all callbacks triggered by all Actions in the Transactional group have
> been received.
> 
> This feature has no knowledge of any jobs spawned by Actions that do not
> inform the system via new_action_cb_wrapper().
> 
> For an example of how to use the feature, please skip ahead to:
> 'block: drive_backup transaction callback support' which serves as an example
> for how to hook up a post-transaction callback to the Drive Backup action.
> 
> 
> Note 1: Defining a callback method alone is not sufficient to have the new
>         method invoked. You must call new_action_cb_wrapper() AND ensure the
>         callback it returns is the one used as the callback for the job
>         launched by the action.
> 
> Note 2: You can use this feature for any system that registers completions of
>         an asynchronous task via a callback of the form
>         (void *opaque, int ret), not just block job callbacks.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  blockdev.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 179 insertions(+), 4 deletions(-)
> 
> diff --git a/blockdev.c b/blockdev.c
> index dea57b4..9db8202 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -1240,6 +1240,8 @@ typedef struct BlkActionState BlkActionState;
>   * @abort: Abort the changes on fail, can be NULL.
>   * @clean: Clean up resources after all transaction actions have called
>   *         commit() or abort(). Can be NULL.
> + * @cb: Executed after all jobs launched by actions in the transaction finish,
> + *      but only if requested by new_action_cb_wrapper() prior to clean().
>   *
>   * Only prepare() may fail. In a single transaction, only one of commit() or
>   * abort() will be called. clean() will always be called if it is present.
> @@ -1250,6 +1252,7 @@ typedef struct BlkActionOps {
>      void (*commit)(BlkActionState *common);
>      void (*abort)(BlkActionState *common);
>      void (*clean)(BlkActionState *common);
> +    void (*cb)(BlkActionState *common);
>  } BlkActionOps;
>  
>  /**
> @@ -1258,19 +1261,46 @@ typedef struct BlkActionOps {
>   * by a transaction group.
>   *
>   * @refcnt: A reference count for this object.
> + * @status: A cumulative return code for all actions that have reported
> + *          a return code via callback in the transaction.
>   * @actions: A list of all Actions in the Transaction.
> + *           However, once the transaction has completed, it will be only a list
> + *           of transactions that have registered a post-transaction callback.
>   */
>  typedef struct BlkTransactionState {
>      int refcnt;
> +    int status;
>      QTAILQ_HEAD(actions, BlkActionState) actions;
>  } BlkTransactionState;
>  
> +typedef void (CallbackFn)(void *opaque, int ret);

Please use BlockCompletionFunc from aio.h:

  typedef void BlockCompletionFunc(void *opaque, int ret);

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2015-06-05 12:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-04 21:46 [Qemu-devel] [PATCH v5 00/10] block: incremental backup transactions John Snow
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 01/10] qapi: Add transaction support to block-dirty-bitmap operations John Snow
2015-06-05 12:12   ` Stefan Hajnoczi
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 02/10] iotests: add transactional incremental backup test John Snow
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 03/10] block: rename BlkTransactionState and BdrvActionOps John Snow
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 04/10] block: re-add BlkTransactionState John Snow
2015-06-05 17:27   ` Max Reitz
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 05/10] block: add transactional callbacks feature John Snow
2015-06-05 12:45   ` Stefan Hajnoczi [this message]
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 06/10] block: add delayed bitmap successor cleanup John Snow
2015-06-05 12:56   ` Stefan Hajnoczi
2015-06-05 15:56     ` John Snow
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 07/10] qmp: Add an implementation wrapper for qmp_drive_backup John Snow
2015-06-05 17:31   ` Max Reitz
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 08/10] block: drive_backup transaction callback support John Snow
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 09/10] iotests: 124 - transactional failure test John Snow
2015-06-04 21:46 ` [Qemu-devel] [PATCH v5 10/10] qmp-commands.hx: Update the supported 'transaction' operations John Snow

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=20150605124536.GG23825@stefanha-thinkpad.redhat.com \
    --to=stefanha@redhat.com \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@parallels.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).