From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCae3-0004UX-T9 for qemu-devel@nongnu.org; Mon, 04 Mar 2013 14:02:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCady-0003lO-Ts for qemu-devel@nongnu.org; Mon, 04 Mar 2013 14:01:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCady-0003lB-M5 for qemu-devel@nongnu.org; Mon, 04 Mar 2013 14:01:50 -0500 Message-ID: <5134EF97.7020202@redhat.com> Date: Mon, 04 Mar 2013 12:01:43 -0700 From: Eric Blake MIME-Version: 1.0 References: <1362388590-13010-1-git-send-email-lilei@linux.vnet.ibm.com> <1362388590-13010-3-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1362388590-13010-3-git-send-email-lilei@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2DJGTCXJMFBTLVSXFLQHE" Subject: Re: [Qemu-devel] [PATCH 2/2] qga: add guest-set-time command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lei Li Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2DJGTCXJMFBTLVSXFLQHE Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/04/2013 02:16 AM, Lei Li wrote: > Signed-off-by: Lei Li > --- > qga/commands-posix.c | 54 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > qga/qapi-schema.json | 27 ++++++++++++++++++++++++++ > 2 files changed, 81 insertions(+) >=20 > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index 6fc6003..0515f5f 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -135,6 +135,60 @@ int64_t qmp_guest_get_time(Error **errp) > return time_ns; > } > =20 > +void qmp_guest_set_time(int64_t time_ns, Error **errp) > +{ > + int ret; > + int status; > + pid_t pid; > + Error *local_err =3D NULL; > + struct timeval tv; > + > + /* year-2038 will overflow in case time_t is 32bit */ > + if (time_ns / 1000000000 !=3D (time_t)(time_ns / 1000000000)) { > + error_setg(errp, "Time %" PRId64 " is too large", time_ns); You set the error, but then fall through... > + } > + > + tv.tv_sec =3D time_ns / 1000000000; > + tv.tv_usec =3D (time_ns % 1000000000) / 1000; > + > + ret =3D settimeofday(&tv, NULL); =2E..and change the guest time to an invalid value anyways. This could cause the guest to severely misbehave. > + if (ret < 0) { > + error_setg_errno(errp, errno, "Failed to set time to guest"); > + return; You should have done an early exit on the other error, like you did here.= > +# > +# This command tries to set guest time based on the information > +# from host or an absolute value given by management app, and The absolute value given by the management app _is_ information from the host. I'd simplify this to just: This command tries to set guest time to the given value, then > +# set the Hardware Clock to the current System Time. This s/set/sets/ > +# will make it easier for a guest to resynchronize without > +# waiting for NTP. > +# > +# @time: time of nanoseconds, relative to the Epoch of > +# 1970-01-01 in UTC. > +# --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2DJGTCXJMFBTLVSXFLQHE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJRNO+XAAoJEKeha0olJ0NqUzIIAIxqKT9AYkvl+aoda8Xe9WTH ZhEKRl8aimoSK6hYf/yPWkNHjkxd3c7P5gQkMxsVRH+Afbd8t7gJmZX1BLhIPavQ 8kznCFkMr8ynxNYxWZM8zKf5vfy5wZtNM9nFMv5ezbJGxsM5D3qjQBh6emEpC18q v+prNJ/m4BKnASH7h8gmmnalC0ansb1agIx+T9wbLXYTrj9PfDblrWD7t69Vj0QO 1iaHXOHOJdH73iG+eCtqMISgI/kNKIenDopEZOc6GsIpz5i3OGp9kMiK5HHbVlBG Vj4qYhggXoAgJiIRM4125zdcos2zOK9Xnbg4OmFOW2uLA0eoJIiBBTUH5WAOndE= =sl8F -----END PGP SIGNATURE----- ------enig2DJGTCXJMFBTLVSXFLQHE--