Received: from eggs.gnu.org ([2001:4830:134:3::10]:50586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0r0N-0006h3-SH for qemu-devel@nongnu.org; Fri, 05 Jun 2015 08:45:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0r0L-0004gM-Qz for qemu-devel@nongnu.org; Fri, 05 Jun 2015 08:45:47 -0400 Date: Fri, 5 Jun 2015 13:45:36 +0100 From: Stefan Hajnoczi Message-ID: <20150605124536.GG23825@stefanha-thinkpad.redhat.com> References: <1433454372-16356-1-git-send-email-jsnow@redhat.com> <1433454372-16356-6-git-send-email-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="TdkiTnkLhLQllcMS" Content-Disposition: inline In-Reply-To: <1433454372-16356-6-git-send-email-jsnow@redhat.com> Subject: Re: [Qemu-devel] [PATCH v5 05/10] block: add transactional callbacks feature List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: kwolf@redhat.com, famz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, vsementsov@parallels.com --TdkiTnkLhLQllcMS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > 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(). >=20 > 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. >=20 > This means that Transaction Action callback methods will be called after > all callbacks triggered by all Actions in the Transactional group have > been received. >=20 > This feature has no knowledge of any jobs spawned by Actions that do not > inform the system via new_action_cb_wrapper(). >=20 > For an example of how to use the feature, please skip ahead to: > 'block: drive_backup transaction callback support' which serves as an exa= mple > for how to hook up a post-transaction callback to the Drive Backup action. >=20 >=20 > 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. >=20 > Note 2: You can use this feature for any system that registers completion= s of > an asynchronous task via a callback of the form > (void *opaque, int ret), not just block job callbacks. >=20 > Signed-off-by: John Snow > --- > blockdev.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++-- > 1 file changed, 179 insertions(+), 4 deletions(-) >=20 > 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 f= inish, > + * 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 presen= t. > @@ -1250,6 +1252,7 @@ typedef struct BlkActionOps { > void (*commit)(BlkActionState *common); > void (*abort)(BlkActionState *common); > void (*clean)(BlkActionState *common); > + void (*cb)(BlkActionState *common); > } BlkActionOps; > =20 > /** > @@ -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 onl= y a list > + * of transactions that have registered a post-transaction cal= lback. > */ > typedef struct BlkTransactionState { > int refcnt; > + int status; > QTAILQ_HEAD(actions, BlkActionState) actions; > } BlkTransactionState; > =20 > +typedef void (CallbackFn)(void *opaque, int ret); Please use BlockCompletionFunc from aio.h: typedef void BlockCompletionFunc(void *opaque, int ret); --TdkiTnkLhLQllcMS Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVcZnwAAoJEJykq7OBq3PIbygIAMpfEcAJwyY0EjS+n9FKUpdP qgWrxSomVOw5x7vMsTYbsItMeSgTP+f0g975B2K7RcT52uUgqBwFhx1pz01ooAWg OBvaXQ3CpbxW9VtyYaBDC/hxv3CVRvVM4J+K619VS6HFR+DAiCMrJEguh4vAIh58 Je59kGJm2kZ4tFY1GEYvAhvitRkOhdAjGJQZ+8R0PStwgZXAUWk4cqTlDB/TvclY ZiuTOq/gs+DKDS3zoUL7LvLuH1zUkGxjTV35+vkO5m0qtDgxh65D5he2PfHqoFdc ToD221I6giD/5dQ0PSZvZjjO1CZbsnHzKQ9xVjngIdvIJ0L7rBfisOOqVL4ozeU= =zlL4 -----END PGP SIGNATURE----- --TdkiTnkLhLQllcMS--