Received: from eggs.gnu.org ([2001:4830:134:3::10]:36146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ea0Sy-0007IZ-OA for qemu-devel@nongnu.org; Fri, 12 Jan 2018 09:37:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ea0Sx-0001xC-Ia for qemu-devel@nongnu.org; Fri, 12 Jan 2018 09:37:56 -0500 References: <20180110230825.18321-1-eblake@redhat.com> <20180110230825.18321-6-eblake@redhat.com> <76132a6d-3d2f-92ba-d05d-93c20dbe9025@virtuozzo.com> From: Eric Blake Message-ID: Date: Fri, 12 Jan 2018 08:37:45 -0600 MIME-Version: 1.0 In-Reply-To: <76132a6d-3d2f-92ba-d05d-93c20dbe9025@virtuozzo.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="YDRheeTFkgZV9yJyK2MYJ01WcJyLwvdyb" Subject: Re: [Qemu-devel] [PATCH v2 5/6] nbd/server: Add helper functions for parsing option payload List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Paolo Bonzini This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --YDRheeTFkgZV9yJyK2MYJ01WcJyLwvdyb From: Eric Blake To: Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Paolo Bonzini Message-ID: Subject: Re: [PATCH v2 5/6] nbd/server: Add helper functions for parsing option payload References: <20180110230825.18321-1-eblake@redhat.com> <20180110230825.18321-6-eblake@redhat.com> <76132a6d-3d2f-92ba-d05d-93c20dbe9025@virtuozzo.com> In-Reply-To: <76132a6d-3d2f-92ba-d05d-93c20dbe9025@virtuozzo.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/12/2018 04:20 AM, Vladimir Sementsov-Ogievskiy wrote: > 11.01.2018 02:08, Eric Blake wrote: >> Rather than making every callsite perform length sanity checks >> and error reporting, add the helper functions nbd_opt_read() >> and nbd_opt_drop() that use the length stored in the client >> struct; also add an assertion that optlen is reduced to zero >> after each option is handled. >> >> Note that the call in nbd_negotiate_handle_export_name() does >> not use the new helper (in part because the server cannot >> reply to NBD_OPT_EXPORT_NAME - it either succeeds or the >> connection drops). >> >> >> +/* Drop remainder of the current option, after sending a reply with >=20 > looks a bit weird: actually you drop the remainder _before_ sending a > reply) Good catch. I'll fix it with s/after/and/ >=20 >> + * the given error type and message. Return -errno on read or write >=20 > also, unrelated note, -errno is always forced to -EIO, because of > nbd_read realization. > and this note applies to many other places here. It is correct (EIO is > errno, why not?), > but it may be not bad to note it somewhere.. Someday nbd_read() might fail with something other than EIO (ESHUTDOWN, perhaps?), in which case leaving this documented as -errno would be better than hardcoding that EIO is the only failure for now. >> @@ -812,14 +819,9 @@ static int nbd_negotiate_options(NBDClient >> *client, uint16_t myflags, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 default: >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (nbd_drop(client->ioc, length, errp) < 0) { >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return -EIO; >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 }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A0=C2=A0=C2=A0=C2=A0 break; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 } >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else { >> @@ -842,6 +844,7 @@ static int nbd_negotiate_options(NBDClient >> *client, uint16_t myflags, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (ret < 0) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 return ret; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 assert(!client->optlen); >=20 > isn't it from 2/6? No, this is a second instance of the assertion, the one that applies between each option (which I couldn't do in 2/6 because not all options were manipulating optlen back then). Maybe I can tweak the commit messages to make that more obvious. >=20 >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0 } >> >=20 > anyway, >=20 > Reviewed-by: Vladimir Sementsov-Ogievskiy Thanks for the careful attention to detail. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --YDRheeTFkgZV9yJyK2MYJ01WcJyLwvdyb Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAlpYyDkACgkQp6FrSiUn Q2oxWwf/Q6xAfiZwG4/npZnzPMloYbnaS0NW0mj7dPjuPiXh6aTsCnaebg7fJpTP TnjoQADYvEVOXLXQ4m6BijBJrwXSR33W6T+29ObNqcFnYiY2mHZSlhsxpFamSGCm wJ+RJ/iI8DnIFkNFf/92dFIO+T6jFrhF65NYPK8W6MshqHzrcL016S/r2bH/cN/0 oD45yWWu5YOjY3LbnKPyxvO7xkn/LgZ+mZpVyE3SnhPPUCv6EpcoiwuWuK3QrAA0 p0dIjGZt+0y2CQVvmMajb8OSALRp89fti4KMvt6IwOD/Cr0OPn/InRpGBPmdakAD gFg+xwt8BxJYLrlccD/BpNzqUYwXvg== =g58J -----END PGP SIGNATURE----- --YDRheeTFkgZV9yJyK2MYJ01WcJyLwvdyb--