Received: from eggs.gnu.org ([2001:4830:134:3::10]:46668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCSTd-0006vZ-Bs for qemu-devel@nongnu.org; Tue, 07 Jul 2015 08:59:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCSTY-0006zt-4X for qemu-devel@nongnu.org; Tue, 07 Jul 2015 08:59:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43328) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCSTX-0006z3-Vq for qemu-devel@nongnu.org; Tue, 07 Jul 2015 08:59:52 -0400 Date: Tue, 7 Jul 2015 13:59:49 +0100 From: Stefan Hajnoczi Message-ID: <20150707125949.GA28673@stefanha-thinkpad.redhat.com> References: <1436192669-10062-1-git-send-email-stefanha@redhat.com> <1436192669-10062-6-git-send-email-stefanha@redhat.com> <20150707073245.GD9515@ad.nay.redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="u3/rZRmxL6MmkK24" Content-Disposition: inline In-Reply-To: <20150707073245.GD9515@ad.nay.redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 05/10] block: add block job transactions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , Jeff Cody , qemu-devel@nongnu.org, Max Reitz , vsementsov@parallels.com, John Snow --u3/rZRmxL6MmkK24 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 07, 2015 at 03:32:45PM +0800, Fam Zheng wrote: > On Mon, 07/06 15:24, Stefan Hajnoczi wrote: > > +/** > > + * block_job_txn_add_job: > > + * @txn: The transaction (may be NULL) > > + * @job: Job to add to the transaction > > + * > > + * Add @job to the transaction. The @job must not already be in a tra= nsaction. > > + * The block job driver must call block_job_txn_prepare_to_complete() = before >=20 > s/block_job_txn_prepare_to_complete/block_job_txn_job_done/ >=20 > Reading this for a second time I start to feel it too complicated for the= good. >=20 > I have another idea: in block_job_completed, check if other jobs have fai= led, > and call this job driver's (imaginary) "abort()" callback accordingly; if= all > jobs has succeeded, call a "commit" callback during last block_job_comple= ted. >=20 > Does that make sense? I think you've skipped the hard part: immediate cancellation. If a job is cancelled by the user or a job fails, then all other jobs are cancelled immediately. Immediate cancellation has the problem that jobs could be running in any AioContext, so you need to handle concurrency. That's where the locking, juggling AioContexts, and interaction between blockjobs comes in. If immediate cancellation is removed then this patch becomes simple: block_job_txn_job_done() becomes a yield and until the jobs_pending counter reaches 0. But now the user must handle cancellation and error cases manually by invoking QMP block-job-cancel on all the other jobs. In other words, we're requiring that the user implements their own BlockJobTxn struct that keeps track of related jobs. If they don't keep track then they may not be able to terminate jobs after failure. This is why QEMU should be the one to complete or fail all block jobs in the transaction. It's simpler if we don't do that but the API then requires more complexity in the user to be used correctly. Stefan --u3/rZRmxL6MmkK24 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVm81FAAoJEJykq7OBq3PI26UH/Azwu42D6S4cvtkvBDafgYEr REP6FnJuS2zeknbNpkVkDjs8yAFpQRz2hh0lj90Gy1AE0wIeFpmm+F/GREr7jPrU DfZKz6FLTrI7v9D8g3FHW/Bcp6KCVVHjR+vMv44IHDf+AE0G7GbzN+Po9is25vyi oBQusntB5uzeFheFoOGcIR0qtZaOoWaQHKx6k8Ov0mOoWSqb7rK3VceRDwr8wr5q AeoJEx85bN1MNMY/C2VFdhov1CzwDbBoWh70cxZ5L3d3FmGHpI9mbGMEQn1+tUr1 ciL5Wr5hsx8/d2iZwuMZS/LU9Nq2n4Y+7vgsGBErenTaJh+rjazXeqSHFe5jFdQ= =N404 -----END PGP SIGNATURE----- --u3/rZRmxL6MmkK24--