diff mbox

[v4] virtio-9p: fix build on !CONFIG_UTIMENSAT

Message ID 4CE47643.7030808@jp.fujitsu.com
State New
Headers show

Commit Message

Hidetoshi Seto Nov. 18, 2010, 12:41 a.m. UTC
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 <chrisw@sous-sol.org>
Acked-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
---
 cutils.c             |   44 ++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-9p-local.c |    4 ++--
 qemu-common.h        |   10 ++++++++++
 3 files changed, 56 insertions(+), 2 deletions(-)

Comments

Jes Sorensen Nov. 18, 2010, 8:02 a.m. UTC | #1
On 11/18/10 01:41, Hidetoshi Seto wrote:
> 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 <chrisw@sous-sol.org>
> Acked-by: M. Mohan Kumar <mohan@in.ibm.com>
> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>

Hi Hidetoshi,

I think the idea of the patch is good, but please move qemu_utimensat()
to oslib-posix.c and provide a wrapper for oslib-win32.c. It is
emulation for a system library function, so it doesn't belong in
cutils.c, but rather in the oslib group.

Thanks,
Jes
Hidetoshi Seto Nov. 18, 2010, 8:48 a.m. UTC | #2
(2010/11/18 17:02), Jes Sorensen wrote:
> On 11/18/10 01:41, Hidetoshi Seto wrote:
>> 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 <chrisw@sous-sol.org>
>> Acked-by: M. Mohan Kumar <mohan@in.ibm.com>
>> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
> 
> Hi Hidetoshi,
> 
> I think the idea of the patch is good, but please move qemu_utimensat()
> to oslib-posix.c and provide a wrapper for oslib-win32.c. It is
> emulation for a system library function, so it doesn't belong in
> cutils.c, but rather in the oslib group.

Unfortunately one fact is that I'm not familiar with win32 codes so I don't
have any idea how the wrapper for win32 will be...
If someone could kindly tell me about the win32 part, I could update this
patch to v5, but even though I have no test environment for the new part :-<

Could we wait an incremental patch on this v4?
Can somebody help me?  Volunteers?


Thanks,
H.Seto
Jes Sorensen Nov. 18, 2010, 9:09 a.m. UTC | #3
On 11/18/10 09:48, Hidetoshi Seto wrote:
> (2010/11/18 17:02), Jes Sorensen wrote:
>> Hi Hidetoshi,
>>
>> I think the idea of the patch is good, but please move qemu_utimensat()
>> to oslib-posix.c and provide a wrapper for oslib-win32.c. It is
>> emulation for a system library function, so it doesn't belong in
>> cutils.c, but rather in the oslib group.
> 
> Unfortunately one fact is that I'm not familiar with win32 codes so I don't
> have any idea how the wrapper for win32 will be...
> If someone could kindly tell me about the win32 part, I could update this
> patch to v5, but even though I have no test environment for the new part :-<
> 
> Could we wait an incremental patch on this v4?
> Can somebody help me?  Volunteers?

Hi Hidetoshi,

I don't actually know much about win32 myself, the only thing I do is to
try and cross-compile for it using mingw32 to make sure the build
doesn't break. One option is to leave it open, or put in a dummy wrapper
which asserts in the win32 part of the code, so that someone who is
interested in win32 can fix it up.

That should be pretty easy to do, and I think thats a fine starting point.

Cheers,
Jes
diff mbox

Patch

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);