From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8uMp-0005Om-KO for qemu-devel@nongnu.org; Fri, 03 Jun 2016 15:02:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8uMo-0000fk-A7 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 15:02:47 -0400 References: <1464978048-32189-1-git-send-email-clord@redhat.com> From: Eric Blake Message-ID: <5751D44E.4060800@redhat.com> Date: Fri, 3 Jun 2016 13:02:38 -0600 MIME-Version: 1.0 In-Reply-To: <1464978048-32189-1-git-send-email-clord@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="DiOMp2Txoj1nGPbEjjPf0wjjBRxPw8LP4" Subject: Re: [Qemu-devel] [PATCH] blockdev: fix error handling in do_open_tray List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: clord@redhat.com, qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --DiOMp2Txoj1nGPbEjjPf0wjjBRxPw8LP4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/03/2016 12:20 PM, clord@redhat.com wrote: > From: Colin Lord You may want to update your ~/.gitconfig to set sendemail.from to list your name in the same manner in which you add S-o-b. (Not strictly a problem, as 'git am' does the right thing either way, but it will avoid this secondary From: line in patch mails you send) >=20 > Returns negative error codes and accompanying error messages in cases w= here > the device has no tray or the tray is locked and isn't forced open. Thi= s > extra information should result in better flexibility in functions that= > call do_open_tray. >=20 > Signed-off-by: Colin Lord > --- > blockdev.c | 29 ++++++++++++++++++----------- > 1 file changed, 18 insertions(+), 11 deletions(-) >=20 > diff --git a/blockdev.c b/blockdev.c > index 717785e..d10ab35 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -2286,17 +2286,14 @@ void qmp_eject(const char *device, bool has_for= ce, bool force, Error **errp) > } > =20 > rc =3D do_open_tray(device, force, &local_err); > - if (local_err) { > + if (rc =3D=3D -ENOSYS) { > + error_free(local_err); > + local_err =3D NULL; > + } else if (local_err) { > error_propagate(errp, local_err); > return; > } > =20 > - if (rc =3D=3D EINPROGRESS) { > - error_setg(errp, "Device '%s' is locked and force was not spec= ified, " > - "wait for tray to open and try again", device); > - return; > - } > - So in this function, we still ignore ENOSYS, and the EINPROGRESS error message has now moved to the helper function. No change in overall behavior, good. > qmp_x_blockdev_remove_medium(device, errp); > } > =20 > @@ -2348,8 +2345,8 @@ static int do_open_tray(const char *device, bool = force, Error **errp) > } > =20 > if (!blk_dev_has_tray(blk)) { > - /* Ignore this command on tray-less devices */ > - return ENOSYS; > + error_setg(errp, "Device '%s' does not have a tray", device); > + return -ENOSYS; > } > =20 > if (blk_dev_is_tray_open(blk)) { > @@ -2366,7 +2363,9 @@ static int do_open_tray(const char *device, bool = force, Error **errp) > } > =20 > if (locked && !force) { > - return EINPROGRESS; > + error_setg(errp, "Device '%s' is locked and force was not spec= ified, " > + "wait for tray to open and try again", device); > + return -EINPROGRESS; And here, we always return negative error. Oops, you forgot to update the comments before this function, describing its new (simpler) semantics. > } > =20 > return 0; > @@ -2375,10 +2374,18 @@ static int do_open_tray(const char *device, boo= l force, Error **errp) > void qmp_blockdev_open_tray(const char *device, bool has_force, bool f= orce, > Error **errp) > { > + Error *local_err =3D NULL; > + int rc; > + > if (!has_force) { > force =3D false; > } > - do_open_tray(device, force, errp); > + rc =3D do_open_tray(device, force, &local_err); > + if (local_err && (rc =3D=3D -EINPROGRESS || rc =3D=3D -ENOSYS)) { The 'local_err &&' portion of the conditional is dead code. You could go straight into the comparison of particular rc values. > + error_free(local_err); > + } else { > + error_propagate(errp, local_err); > + } > } > =20 > void qmp_blockdev_close_tray(const char *device, Error **errp) >=20 This appears to be your first qemu patch - congratulations, and welcome to the community. Looking forward to v2. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --DiOMp2Txoj1nGPbEjjPf0wjjBRxPw8LP4 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/ iQEcBAEBCAAGBQJXUdROAAoJEKeha0olJ0NqDAwH/RESecIm+bscZyYva/oBRNtm C9jnUBe95GZIXjGbTeXGNi9hEjjJ8ADCMd/sX7Kb3mcQkWFUPtd2ZSBHl83w4cRc oIcQGpDsbYRI8fTjTxE5I0/zYwiIKKZK3YdvMN4sEq2Arbes76qJX7wBGrey6WnT 77jssfHrnvTgeP9UQ7b7D9E8QcsKrf5K123UCZ5yZzVfhcGV3XLsvR2kaTUvEmhx K3uxYg3diBxB0AMt2gZE9A+7mmYRspEMxybQFQsYOzaKxMO8Aw8LPX3NXV973SJN QVRw8V2l2xlZ8eF8DVzo+5V4QwHm/5HQPQZkD8Bayoh5xpphb2Oro24YmtJgwTU= =TCqe -----END PGP SIGNATURE----- --DiOMp2Txoj1nGPbEjjPf0wjjBRxPw8LP4--