From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1HBn-0001Z4-UD for qemu-devel@nongnu.org; Tue, 24 Nov 2015 12:15:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1HBk-0008Hu-NY for qemu-devel@nongnu.org; Tue, 24 Nov 2015 12:15:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1HBk-0008Hq-Gr for qemu-devel@nongnu.org; Tue, 24 Nov 2015 12:15:32 -0500 References: <1448382858-28616-1-git-send-email-marcandre.lureau@redhat.com> From: Eric Blake Message-ID: <56549B2E.6070205@redhat.com> Date: Tue, 24 Nov 2015 10:15:26 -0700 MIME-Version: 1.0 In-Reply-To: <1448382858-28616-1-git-send-email-marcandre.lureau@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TAGO9UM2ruWHvsJE7ELiXudqr0DujhImP" Subject: Re: [Qemu-devel] [PATCH 1/2] qga: flush implicitely when needed List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Cc: Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --TAGO9UM2ruWHvsJE7ELiXudqr0DujhImP Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/24/2015 09:34 AM, marcandre.lureau@redhat.com wrote: > From: Marc-Andr=C3=A9 Lureau In the subject: s/implicitely/implicitly/ if you are fixing the typo, or s/implicitely/explicitly/ if you are trying to make it match what the patch actually does. No 0/2 cover letter? ALL multi-patch series should include a cover letter, as it is easier on tooling to be able to base series-wide conversations on the cover letter. >=20 > According to the specification: > http://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html >=20 > "the application shall ensure that output is not directly followed by > input without an intervening call to fflush() or to a file positioning > function (fseek(), fsetpos(), or rewind()), and input is not directly > followed by output without an intervening call to a file positioning > function, unless the input operation encounters end-of-file." >=20 > Without this change, a write() followed by a read() may lose the > previously written content, as shown in the following test. >=20 > Fixes: > https://bugzilla.redhat.com/show_bug.cgi?id=3D1210246 >=20 > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > qga/commands-posix.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) >=20 > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index 0ebd473..3c86a4e 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -219,6 +219,7 @@ void qmp_guest_set_time(bool has_time, int64_t time= _ns, Error **errp) > typedef struct GuestFileHandle { > uint64_t id; > FILE *fh; > + bool writing; > QTAILQ_ENTRY(GuestFileHandle) next; > } GuestFileHandle; > =20 > @@ -460,6 +461,17 @@ struct GuestFileRead *qmp_guest_file_read(int64_t = handle, bool has_count, > } > =20 > fh =3D gfh->fh; > + > + /* implicitely flush when switching from writing to reading */ Again, s/implicitely/explicitly/ > + if (gfh->writing) { > + int ret =3D fflush(fh); > + if (ret =3D=3D EOF) { > + error_setg_errno(errp, errno, "failed to flush file"); > + return NULL; > + } > + gfh->writing =3D false; > + } > + > buf =3D g_malloc0(count+1); > read_count =3D fread(buf, 1, count, fh); > if (ferror(fh)) { > @@ -496,6 +508,16 @@ GuestFileWrite *qmp_guest_file_write(int64_t handl= e, const char *buf_b64, > } > =20 > fh =3D gfh->fh; > + > + if (!gfh->writing) { > + int ret =3D fseek(fh, 0, SEEK_CUR); Seems a bit odd to use fflush() in one place and fseek() in the other, but the net result is the same either way. > + if (ret =3D=3D -1) { > + error_setg_errno(errp, errno, "failed to seek file"); > + return NULL; > + } > + gfh->writing =3D true; > + } > + With typos fixed, Reviewed-by: Eric Blake > buf =3D g_base64_decode(buf_b64, &buf_len); > =20 > if (!has_count) { >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --TAGO9UM2ruWHvsJE7ELiXudqr0DujhImP 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/ iQEcBAEBCAAGBQJWVJsuAAoJEKeha0olJ0Nqo0kH/jMg/bYXp9DPGSDH2BaQMHjy gfWvAE6rZQx66mpitc9s7LlnEV0VoW/bHuvpoCP6VCdJTQJmIJiQHc8yljp7uzS2 /vd8/m8lJ7PHpqc6pVcyEyNkHYyxbz045wtIMhBci/o2kwLSxYBmc3Za1UTTfcv+ 8igmF7nRoazy/LxXOIbZwKdTB5Sdy6GIaNhVRtpzMWR58BmbrAsC5M2307LBp1S+ N7Cjq2WwQ/4Tt1AOHCTIhjHW4qN0svXtMJ3dnD+UkeDnntpXnhXw4FQUCiD8LmHh 4vurgr7F12WaDcg5TjLg3LvoTMtYGln8eUeBD8+n/2mRHYwLqHplj7mHAt22yIg= =JRNz -----END PGP SIGNATURE----- --TAGO9UM2ruWHvsJE7ELiXudqr0DujhImP--