From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=42694 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PFLTC-0000fx-0R for qemu-devel@nongnu.org; Mon, 08 Nov 2010 01:44:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PFLTA-000885-HU for qemu-devel@nongnu.org; Mon, 08 Nov 2010 01:44:45 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:40307) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PFLT9-00087A-VW for qemu-devel@nongnu.org; Mon, 08 Nov 2010 01:44:44 -0500 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp07.au.ibm.com (8.14.4/8.13.1) with ESMTP id oA86iWME019404 for ; Mon, 8 Nov 2010 17:44:32 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oA86iWuF1560820 for ; Mon, 8 Nov 2010 17:44:32 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oA86iWti003331 for ; Mon, 8 Nov 2010 17:44:32 +1100 From: "M. Mohan Kumar" Subject: Re: [Qemu-devel] [PATCH] virtio-9p: fix build on !CONFIG_UTIMENSAT v2 Date: Mon, 8 Nov 2010 12:14:27 +0530 References: <20101104170303.GE15211@sequoia.sous-sol.org> <4CD3A513.2010102@jp.fujitsu.com> In-Reply-To: <4CD3A513.2010102@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201011081214.28202.mohan@in.ibm.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Blue Swirl , Hidetoshi Seto , "kvm@vger.kernel.org" , "Hao, Xudong" , Chris Wright , Avi Kivity > This patch introduce a fallback mechanism for old systems that do not > support utimensat. This will fix build failure with following warnings: > > hw/virtio-9p-local.c: In function 'local_utimensat': > hw/virtio-9p-local.c:479: warning: implicit declaration of function > 'utimensat' hw/virtio-9p-local.c:479: warning: nested extern declaration > of 'utimensat' > > and > > hw/virtio-9p.c: In function 'v9fs_setattr_post_chmod': > hw/virtio-9p.c:1410: error: 'UTIME_NOW' undeclared (first use in this > function) hw/virtio-9p.c:1410: error: (Each undeclared identifier is > reported only once hw/virtio-9p.c:1410: error: for each function it > appears in.) > hw/virtio-9p.c:1413: error: 'UTIME_OMIT' undeclared (first use in this > function) hw/virtio-9p.c: In function 'v9fs_wstat_post_chmod': > hw/virtio-9p.c:2905: error: 'UTIME_OMIT' undeclared (first use in this > function) > > Signed-off-by: Hidetoshi Seto > --- > hw/virtio-9p-local.c | 32 ++++++++++++++++++++++++++++++-- > hw/virtio-9p.h | 10 ++++++++++ > 2 files changed, 40 insertions(+), 2 deletions(-) > > diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c > index 0d52020..7811d2c 100644 > --- a/hw/virtio-9p-local.c > +++ b/hw/virtio-9p-local.c > @@ -479,10 +479,38 @@ static int local_chown(FsContext *fs_ctx, const char > *path, FsCred *credp) return -1; > } > > +/* TODO: relocate this to proper file, and make it more generic */ > +static int qemu_utimensat(int dirfd, const char *path, > + const struct timespec *times, int flags) > +{ IMHO, this code can be moved to cutils.c > +#ifdef CONFIG_UTIMENSAT > + return utimensat(dirfd, path, times, flags); > +#else > + /* > + * Fallback: use utimes() instead of utimensat(). > + * See commit 74bc02b2d2272dc88fb98d43e631eb154717f517 for known > problem. + */ > + struct timeval tv[2]; > + int i; > + > + for (i = 0; i < 2; i++) { > + if (times[i].tv_nsec == UTIME_OMIT || times[i].tv_nsec == > UTIME_NOW) { + tv[i].tv_sec = 0; > + tv[i].tv_usec = 0; > + } else { > + tv[i].tv_sec = times[i].tv_sec; > + tv[i].tv_usec = times[i].tv_nsec / 1000; > + } > + } > + > + return utimes(path, &tv[0]); > +#endif The idea of introducing utimensat was to avoid resetting atime to 1970-01-01 05:30:00 (utime does not give option to not change atime). But as per utimes man page, if any of the time field is 0, it would be set to current time. As per stat man page, truncate will not update atime, only mtime will be updated.