virtiofsd: use g_date_time_get_microsecond to get subsecond
PATCH 1/1 virtiofsd: use g_date_time_get_microsecond to get subsecond
From: Yusuke Okada <[email protected]>
The "%f" specifier in g_date_time_format() is only available in glib 2.65.2 or later. If combined with older glib, the function returns null and the timestamp displayed as "(null)".
For backward compatibility, g_date_time_get_microsecond should be used to retrieve subsecond.
In this patch the g_date_time_format() leaves subsecond field as "%06d" and let next snprintf to format with g_date_time_get_microsecond.
--- tools/virtiofsd/passthrough_ll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/virtiofsd/passthrough_ll.c +5 -2
@@ -4185,6 +4185,7 @@ static void setup_nofile_rlimit(unsigned long rlimit_nofile)static void log_func (enum fuse_log_level level,const char *fmt,va_list ap) { g_autofree char *localfmt = NULL; +char buf[64 ];if (current_log_level < level) {return ;
@@ -4197,9 +4198,11 @@ static void log_func(enum fuse_log_level level, const char *fmt, va_list ap) fmt); }else {g_autoptr (GDateTime) now =g_date_time_new_now_utc (); - g_autofree char *nowstr = g_date_time_format(now, "%Y-%m-%d %H:%M:%S.%f%z"); + g_autofree char *nowstr = g_date_time_format(now, +"%Y-%m-%d %H:%M:%S.%%06d%z" ); +snprintf (buf,64 , nowstr,g_date_time_get_microsecond (now)); localfmt =g_strdup_printf ("[%s] [ID: %08ld] %s" , - nowstr,syscall (__NR_gettid), fmt); + buf,syscall (__NR_gettid), fmt); } fmt = localfmt; }
Signature · 1 line
2.31.1
Hi,
Because the first mail doesn't include "From" line in its body, I sent it again. Sorry for bothering.
Best Regards,
Yusuke Okada
Quoted 5 lines · * Yusuke Okada ([email protected]) wrote:
From: Yusuke Okada <[email protected]>
The "%f" specifier in
g_date_time_format()is only available in glib 2.65.2 or later. If combined with older glib, the function returns null and the timestamp displayed as "(null)".
Well spotted; thanks for the patch.
I notice there's also a use in rocker and qga (Copying Dan and Marc-Andre in who added them)
Quoted 7 lines
For backward compatibility,
g_date_time_get_microsecondshould be used to retrieve subsecond.In this patch the
g_date_time_format()leaves subsecond field as "%06d" and let next snprintf to format withg_date_time_get_microsecond.Signed-off-by Yusuke Okada <[email protected]>
Quoted 33 lines
--- tools/virtiofsd/passthrough_ll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)tools/virtiofsd/passthrough_ll.c +5
-2@@ -4185,6 +4185,7 @@ static void setup_nofile_rlimit(unsigned long rlimit_nofile)static void log_func (enum fuse_log_level level,const char *fmt,va_list ap) { g_autofree char *localfmt = NULL; +char buf[64 ];if (current_log_level < level) {return ;@@ -4197,9 +4198,11 @@ static void log_func(enum fuse_log_level level, const char *fmt, va_list ap) fmt); }else {g_autoptr (GDateTime) now =g_date_time_new_now_utc (); - g_autofree char *nowstr = g_date_time_format(now, "%Y-%m-%d %H:%M:%S.%f%z"); + g_autofree char *nowstr = g_date_time_format(now, +"%Y-%m-%d %H:%M:%S.%%06d%z" ); +snprintf (buf,64 , nowstr,g_date_time_get_microsecond (now)); localfmt =g_strdup_printf ("[%s] [ID: %08ld] %s" , - nowstr,syscall (__NR_gettid), fmt); + buf,syscall (__NR_gettid), fmt); } fmt = localfmt; }Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Stefan Hajnoczi
AppliedQuoted 9 lines · Yusuke Okada
From: Yusuke Okada <[email protected]>
The "%f" specifier in
g_date_time_format()is only available in glib 2.65.2 or later. If combined with older glib, the function returns null and the timestamp displayed as "(null)".For backward compatibility,
g_date_time_get_microsecondshould be used to retrieve subsecond.
Quoted 7 lines
In this patch the
g_date_time_format()leaves subsecond field as "%06d" and let next snprintf to format withg_date_time_get_microsecond.Signed-off-by Yusuke Okada <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Thanks, applied to my block tree for QEMU 7.2:
https://gitlab.com/stefanha/qemu/commits/block
Stefan
Quoted 13 lines · Stefan Hajnoczi
Quoted 12 lines · Yusuke Okada
From: Yusuke Okada <[email protected]>
The "%f" specifier in
g_date_time_format()is only available in glib 2.65.2 or later. If combined with older glib, the function returns null and the timestamp displayed as "(null)".For backward compatibility,
g_date_time_get_microsecondshould be used to retrieve subsecond.In this patch the
g_date_time_format()leaves subsecond field as "%06d" and let next snprintf to format withg_date_time_get_microsecond.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Yusuke Okada <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)Thanks, applied to my block tree for QEMU 7.2:
https://gitlab.com/stefanha/qemu/commits/block
Hi Stefan,
Wondering when do you plan to send it for merge. This seems like a simple fix. Not sure why it does not qualify as a fix for 7.1 instead.
Thanks
Vivek
Quoted 20 lines · Vivek Goyal
Quoted 18 lines · Stefan Hajnoczi
Quoted 16 lines · Yusuke Okada
From: Yusuke Okada <[email protected]>
The "%f" specifier in
g_date_time_format()is only available in glib 2.65.2 or later. If combined with older glib, the function returns null and the timestamp displayed as "(null)".For backward compatibility,
g_date_time_get_microsecondshould be used to retrieve subsecond.In this patch the
g_date_time_format()leaves subsecond field as "%06d" and let next snprintf to format withg_date_time_get_microsecond.Signed-off-by Yusuke Okada <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines
Quoted 2 lines
Thanks, applied to my block tree for QEMU 7.2:
https://gitlab.com/stefanha/qemu/commits/blockHi Stefan,
Wondering when do you plan to send it for merge. This seems like a simple fix. Not sure why it does not qualify as a fix for 7.1 instead.
The pull request with this patch was merged into qemu.git/master today.
Regarding 7.1, it needs to go through the -stable tree. I have CCed qemu-stable so this patch can be picked up.
Thanks,
Stefan