summaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
diff options
context:
space:
mode:
authorChen-Yu Tsai <wens@csie.org>2019-05-23 00:21:47 +0800
committerLaurent Vivier <laurent@vivier.eu>2019-05-24 13:16:21 +0200
commit5f992db605e2c9ed0c8816c2b0f68b9bc8698f1b (patch)
tree0273686a28c3b55ab71a90ea8f5f3021316c4ee5 /linux-user/syscall.c
parent443b7505c6b04c5b7ab9611ac3ffd115fbf60cbf (diff)
downloadqemu-5f992db605e2c9ed0c8816c2b0f68b9bc8698f1b.zip
linux-user: Pass through nanosecond timestamp components for stat syscalls
Since Linux 2.6 the stat syscalls have mostly supported nanosecond components for each of the file-related timestamps. QEMU user mode emulation currently does not pass through the nanosecond portion of the timestamp, even when the host system fills in the value. This results in a mismatch when run on subsecond resolution filesystems such as ext4 or XFS. An example of this leading to inconsistency is cross-debootstraping a full desktop root filesystem of Debian Buster. Recent versions of fontconfig store the full timestamp (instead of just the second portion) of the directory in its per-directory cache file, and checks this against the directory to see if the cache is up-to-date. With QEMU user mode emulation, the timestamp stored is incorrect, and upon booting the rootfs natively, fontconfig discovers the mismatch, and proceeds to rebuild the cache on the comparatively slow machine (low-power ARM vs x86). This stalls the first attempt to open whatever application that incorporates fontconfig. This patch renames the "unused" padding trailing each timestamp element to its nanosecond counterpart name if such an element exists in the kernel sources for the given platform. Not all do. Then have the syscall wrapper fill in the nanosecond portion if the host supports it, as specified by the _POSIX_C_SOURCE and _XOPEN_SOURCE feature macros. Recent versions of glibc only use stat64 and newfstatat syscalls on 32-bit and 64-bit platforms respectively. The changes in this patch were tested by directly calling the stat, stat64 and newfstatat syscalls directly, in addition to the glibc wrapper, on arm and aarch64 little endian targets. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Chen-Yu Tsai <wens@csie.org> Message-Id: <20190522162147.26303-1-wens@kernel.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'linux-user/syscall.c')
-rw-r--r--linux-user/syscall.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 51cc049e06..0d6c764502 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6409,6 +6409,11 @@ static inline abi_long host_to_target_stat64(void *cpu_env,
__put_user(host_st->st_atime, &target_st->target_st_atime);
__put_user(host_st->st_mtime, &target_st->target_st_mtime);
__put_user(host_st->st_ctime, &target_st->target_st_ctime);
+#if _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
+ __put_user(host_st->st_atim.tv_nsec, &target_st->target_st_atime_nsec);
+ __put_user(host_st->st_mtim.tv_nsec, &target_st->target_st_mtime_nsec);
+ __put_user(host_st->st_ctim.tv_nsec, &target_st->target_st_ctime_nsec);
+#endif
unlock_user_struct(target_st, target_addr, 1);
} else
#endif
@@ -6439,6 +6444,11 @@ static inline abi_long host_to_target_stat64(void *cpu_env,
__put_user(host_st->st_atime, &target_st->target_st_atime);
__put_user(host_st->st_mtime, &target_st->target_st_mtime);
__put_user(host_st->st_ctime, &target_st->target_st_ctime);
+#if _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
+ __put_user(host_st->st_atim.tv_nsec, &target_st->target_st_atime_nsec);
+ __put_user(host_st->st_mtim.tv_nsec, &target_st->target_st_mtime_nsec);
+ __put_user(host_st->st_ctim.tv_nsec, &target_st->target_st_ctime_nsec);
+#endif
unlock_user_struct(target_st, target_addr, 1);
}
@@ -8892,6 +8902,15 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
__put_user(st.st_atime, &target_st->target_st_atime);
__put_user(st.st_mtime, &target_st->target_st_mtime);
__put_user(st.st_ctime, &target_st->target_st_ctime);
+#if (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) && \
+ defined(TARGET_STAT_HAVE_NSEC)
+ __put_user(st.st_atim.tv_nsec,
+ &target_st->target_st_atime_nsec);
+ __put_user(st.st_mtim.tv_nsec,
+ &target_st->target_st_mtime_nsec);
+ __put_user(st.st_ctim.tv_nsec,
+ &target_st->target_st_ctime_nsec);
+#endif
unlock_user_struct(target_st, arg2, 1);
}
}