From patchwork Thu Nov 18 00:41:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hidetoshi Seto X-Patchwork-Id: 72021 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2C523B7192 for ; Thu, 18 Nov 2010 11:43:40 +1100 (EST) Received: from localhost ([127.0.0.1]:55338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PIsb9-0001jS-IU for incoming@patchwork.ozlabs.org; Wed, 17 Nov 2010 19:43:35 -0500 Received: from [140.186.70.92] (port=51527 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PIsaI-0001jD-JK for qemu-devel@nongnu.org; Wed, 17 Nov 2010 19:42:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PIsaG-0000p8-Tz for qemu-devel@nongnu.org; Wed, 17 Nov 2010 19:42:42 -0500 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:43266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PIsaG-0000on-AP for qemu-devel@nongnu.org; Wed, 17 Nov 2010 19:42:40 -0500 Received: from m6.gw.fujitsu.co.jp ([10.0.50.76]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id oAI0gYPG017876 for (envelope-from seto.hidetoshi@jp.fujitsu.com); Thu, 18 Nov 2010 09:42:35 +0900 Received: from smail (m6 [127.0.0.1]) by outgoing.m6.gw.fujitsu.co.jp (Postfix) with ESMTP id A6E7A45DE4F for ; Thu, 18 Nov 2010 09:42:34 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (s6.gw.fujitsu.co.jp [10.0.50.96]) by m6.gw.fujitsu.co.jp (Postfix) with ESMTP id 8B50A45DE4E for ; Thu, 18 Nov 2010 09:42:34 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id 6C7211DB8012 for ; Thu, 18 Nov 2010 09:42:34 +0900 (JST) Received: from m108.s.css.fujitsu.com (m108.s.css.fujitsu.com [10.249.87.108]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id 064CA1DB801A for ; Thu, 18 Nov 2010 09:42:31 +0900 (JST) Received: from m108.css.fujitsu.com (m108 [127.0.0.1]) by m108.s.css.fujitsu.com (Postfix) with ESMTP id BA43C428061; Thu, 18 Nov 2010 09:42:30 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.101.84]) by m108.s.css.fujitsu.com (Postfix) with ESMTP id CD64CB68002; Thu, 18 Nov 2010 09:42:29 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.3.1 Received: from FMVDA2A041[10.124.101.84] by FMVDA2A041 (FujitsuOutboundMailChecker v1.3.1/9992[10.124.101.84]); Thu, 18 Nov 2010 09:42:24 +0900 (JST) Message-ID: <4CE47643.7030808@jp.fujitsu.com> Date: Thu, 18 Nov 2010 09:41:39 +0900 From: Hidetoshi Seto User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Blue Swirl , "kvm@vger.kernel.org" , Jes Sorensen , "Hao, Xudong" , Chris Wright , "M. Mohan Kumar" , Avi Kivity Subject: [Qemu-devel] [PATCH v4] virtio-9p: fix build on !CONFIG_UTIMENSAT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch introduce a fallback mechanism for old systems that do not support utimensat(). This 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) v4: - Use tv_now.tv_usec - Rebased on latest qemu.git v3: - Use better alternative handling for UTIME_NOW/OMIT - Move qemu_utimensat() to cutils.c V2: - Introduce qemu_utimensat() Acked-by: Chris Wright Acked-by: M. Mohan Kumar Signed-off-by: Hidetoshi Seto --- cutils.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-9p-local.c | 4 ++-- qemu-common.h | 10 ++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/cutils.c b/cutils.c index 28089aa..dbeb3f2 100644 --- a/cutils.c +++ b/cutils.c @@ -371,3 +371,47 @@ fail: return retval; } + +int qemu_utimensat(int dirfd, const char *path, const struct timespec *times, + int flags) +{ +#ifdef CONFIG_UTIMENSAT + return utimensat(dirfd, path, times, flags); +#else + /* Fallback: use utimes() instead of utimensat() */ + struct timeval tv[2], tv_now; + struct stat st; + int i; + + /* happy if special cases */ + if (times[0].tv_nsec == UTIME_OMIT && times[1].tv_nsec == UTIME_OMIT) { + return 0; + } + if (times[0].tv_nsec == UTIME_NOW && times[1].tv_nsec == UTIME_NOW) { + return utimes(path, NULL); + } + + /* prepare for hard cases */ + if (times[0].tv_nsec == UTIME_NOW || times[1].tv_nsec == UTIME_NOW) { + gettimeofday(&tv_now, NULL); + } + if (times[0].tv_nsec == UTIME_OMIT || times[1].tv_nsec == UTIME_OMIT) { + stat(path, &st); + } + + for (i = 0; i < 2; i++) { + if (times[i].tv_nsec == UTIME_NOW) { + tv[i].tv_sec = tv_now.tv_sec; + tv[i].tv_usec = tv_now.tv_usec; + } else if (times[i].tv_nsec == UTIME_OMIT) { + tv[i].tv_sec = (i == 0) ? st.st_atime : st.st_mtime; + 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 +} diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c index 0d52020..41603ea 100644 --- a/hw/virtio-9p-local.c +++ b/hw/virtio-9p-local.c @@ -480,9 +480,9 @@ static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp) } static int local_utimensat(FsContext *s, const char *path, - const struct timespec *buf) + const struct timespec *buf) { - return utimensat(AT_FDCWD, rpath(s, path), buf, AT_SYMLINK_NOFOLLOW); + return qemu_utimensat(AT_FDCWD, rpath(s, path), buf, AT_SYMLINK_NOFOLLOW); } static int local_remove(FsContext *ctx, const char *path) diff --git a/qemu-common.h b/qemu-common.h index b3957f1..f0b2c9d 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -150,6 +150,16 @@ int qemu_fls(int i); int qemu_fdatasync(int fd); int fcntl_setfl(int fd, int flag); ssize_t strtosz(const char *nptr, char **end); +#ifndef CONFIG_UTIMENSAT +#ifndef UTIME_NOW +# define UTIME_NOW ((1l << 30) - 1l) +#endif +#ifndef UTIME_OMIT +# define UTIME_OMIT ((1l << 30) - 2l) +#endif +#endif +int qemu_utimensat(int dirfd, const char *path, const struct timespec *times, + int flags); /* path.c */ void init_paths(const char *prefix);