From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF4Jx-0001Oj-6S for qemu-devel@nongnu.org; Mon, 20 Jun 2016 14:53:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF4Jv-0002RQ-43 for qemu-devel@nongnu.org; Mon, 20 Jun 2016 14:53:16 -0400 References: From: Eric Blake Message-ID: <57683B94.2060902@redhat.com> Date: Mon, 20 Jun 2016 12:53:08 -0600 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ViI2TNH56011mHVrntDRMxXF6NlnX8LEO" Subject: Re: [Qemu-devel] [PATCH 04/15] block: Simplify find_block_job() and make it accept a job ID List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Max Reitz , Kevin Wolf , Jeff Cody This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ViI2TNH56011mHVrntDRMxXF6NlnX8LEO From: Eric Blake To: Alberto Garcia , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Max Reitz , Kevin Wolf , Jeff Cody Message-ID: <57683B94.2060902@redhat.com> Subject: Re: [PATCH 04/15] block: Simplify find_block_job() and make it accept a job ID References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/09/2016 02:20 AM, Alberto Garcia wrote: > find_block_job() looks for a block backend with a specified name, > checks whether it has a block job and acquires its AioContext. This > patch uses block_job_next() and iterate directly over the block jobs. >=20 > In addition to that we want to identify jobs primarily by their ID, so > this patch updates find_block_job() to allow IDs too. Only one of ID > and device name can be specified when looking for a block job. >=20 > Signed-off-by: Alberto Garcia > --- > blockdev.c | 66 +++++++++++++++++++++++++++++++++---------------------= -------- > 1 file changed, 35 insertions(+), 31 deletions(-) >=20 > diff --git a/blockdev.c b/blockdev.c > index 52ec4ae..bd0d5a1 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -3689,48 +3689,52 @@ void qmp_blockdev_mirror(const char *device, co= nst char *target, > aio_context_release(aio_context); > } > =20 > -/* Get the block job for a given device name and acquire its AioContex= t */ > -static BlockJob *find_block_job(const char *device, AioContext **aio_c= ontext, > - Error **errp) > +/* Get a block job using its ID or device name and acquire its AioCont= ext */ > +static BlockJob *find_block_job(const char *id, const char *device, > + AioContext **aio_context, Error **errp= ) Can this signature just be const char *id_or_device, rather than two parameters,... > { > - BlockBackend *blk; > - BlockDriverState *bs; > + BlockJob *job =3D NULL; > =20 > *aio_context =3D NULL; > =20 > - blk =3D blk_by_name(device); > - if (!blk) { > - goto notfound; > + if ((id && device) || (!id && !device)) { > + error_setg(errp, "Only one of ID or device name " > + "must be specified when looking for a block job"); > + return NULL; > } If you keep this check, you could simplify it to: if (!id =3D=3D !device) { =2E..at which point you don't need this check,... > =20 > - *aio_context =3D blk_get_aio_context(blk); > - aio_context_acquire(*aio_context); > - > - if (!blk_is_available(blk)) { > - goto notfound; > + if (id) { > + job =3D block_job_get(id); > + } else { =2E..and this would become: job =3D block_job_get(id); if (!job) { --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --ViI2TNH56011mHVrntDRMxXF6NlnX8LEO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXaDuUAAoJEKeha0olJ0Nq80UH/0zdocR1cbpdqz82eujd+2WF qDRgqAmcjvE7YTHktgzlOBxcdgG+0Nyii7gLUMP0OIDfnpLWsTGh6Zv+J1t8SVLI FUYn3w3AeFXv96hWaWfNpPAYovcYmv/wlcHWpMHgm99OJJIMT+2djd/J7kojSzWt 77WC4B//P6Ff3VngD1Zjp7F2h7xeg6Hyx0u5SqsQO7JPjsIPl7kI/n82C9RkhI17 pdsDxaffd2YCgDBRPjmZDF6se3yZnMZ6Qicg3EpZy0cncjFEqeq6z9QvN5LBWyO0 8y/C7JoMR/SrjS2g+NrZ/oskRbAInat9CWUl/VtjzR1frq5rzFasFt+EM7ORO6w= =Bc6W -----END PGP SIGNATURE----- --ViI2TNH56011mHVrntDRMxXF6NlnX8LEO--