From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Andrei Vagin <avagin@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>
Cc: mtk.manpages@gmail.com, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Eric W . Biederman" <ebiederm@xmission.com>,
Dmitry Safonov <0x7f454c46@gmail.com>
Subject: Re: [PATCH] timens: show clock symbolic names in /proc/pid/timens_offsets
Date: Sat, 11 Apr 2020 12:32:45 +0200 [thread overview]
Message-ID: <afd9a489-bea7-c34c-14c2-405b536deb0d@gmail.com> (raw)
In-Reply-To: <20200411065209.622679-1-avagin@gmail.com>
Hello Andrei,
On 4/11/20 8:52 AM, Andrei Vagin wrote:
> Michael Kerrisk suggested to replace numeric clock IDs on symbolic
> names.
>
> Now the content of these files looks like this:
> $ cat /proc/5362/timens_offsets
> monotonic 9504000 0
> boottime 3456000 0
>
> For setting offsets, both representations of clocks can be used.
>
> As for compatibility, it is acceptable to change things as long as
> userspace doesn't care. The format of timens_offsets files is very
> new and there are no userspace tools that rely on this format.
>
> But three projects crun, util-linux and criu rely on the interface of
> setting time offsets and this is why we need to continue supporting the
> clock IDs in this case.
Thanks very much for this patch, which I've tested. So:
Acked-by: Michael Kerrisk <mtk.manpages@gmail.com>
Tested-by: Michael Kerrisk <mtk.manpages@gmail.com>
But, I do have one small suggestion below.
> Fixes: 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Eric W. Biederman <ebiederm@xmission.com>
> Cc: Michael Kerrisk <mtk.manpages@gmail.com>
> Cc: Dmitry Safonov <0x7f454c46@gmail.com>
> Suggested-by: Michael Kerrisk <mtk.manpages@gmail.com>
> Signed-off-by: Andrei Vagin <avagin@gmail.com>
> ---
> fs/proc/base.c | 14 +++++++++++++-
> kernel/time/namespace.c | 15 ++++++++++++++-
> 2 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 6042b646ab27..572898dd16a0 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -1573,6 +1573,7 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
> noffsets = 0;
> for (pos = kbuf; pos; pos = next_line) {
> struct proc_timens_offset *off = &offsets[noffsets];
> + char clock[10];
> int err;
>
> /* Find the end of line and ensure we don't look past it */
> @@ -1584,10 +1585,21 @@ static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
> next_line = NULL;
> }
>
> - err = sscanf(pos, "%u %lld %lu", &off->clockid,
> + err = sscanf(pos, "%9s %lld %lu", clock,
> &off->val.tv_sec, &off->val.tv_nsec);
> if (err != 3 || off->val.tv_nsec >= NSEC_PER_SEC)
> goto out;
> +
> + clock[sizeof(clock) - 1] = 0;
> + if (strcmp(clock, "monotonic") == 0 ||
> + strcmp(clock, __stringify(CLOCK_MONOTONIC)) == 0)
> + off->clockid = CLOCK_MONOTONIC;
> + else if (strcmp(clock, "boottime") == 0 ||
> + strcmp(clock, __stringify(CLOCK_BOOTTIME)) == 0)
> + off->clockid = CLOCK_BOOTTIME;
> + else
> + goto out;
> +
> noffsets++;
> if (noffsets == ARRAY_SIZE(offsets)) {
> if (next_line)
> diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c
> index e6ba064ce773..8127d2647064 100644
> --- a/kernel/time/namespace.c
> +++ b/kernel/time/namespace.c
> @@ -338,7 +338,20 @@ static struct user_namespace *timens_owner(struct ns_common *ns)
>
> static void show_offset(struct seq_file *m, int clockid, struct timespec64 *ts)
> {
> - seq_printf(m, "%d %lld %ld\n", clockid, ts->tv_sec, ts->tv_nsec);
> + char *clock;
> +
> + switch (clockid) {
> + case CLOCK_BOOTTIME:
> + clock = "boottime";
> + break;
> + case CLOCK_MONOTONIC:
> + clock = "monotonic";
> + break;
> + default:
> + clock = "unknown";
> + break;
> + }
As things stand, there is to my eye an excessive amount of white space
in the output produced by this line:
> + seq_printf(m, "%s\t%10lld\t%10ld\n", clock, ts->tv_sec, ts->tv_nsec);
Can I suggest instead something like:
seq_printf(m, "%-16s %10lld %9ld\n", clock, ts->tv_sec, ts->tv_nsec);
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
next prev parent reply other threads:[~2020-04-11 10:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-11 6:52 [PATCH] timens: show clock symbolic names in /proc/pid/timens_offsets Andrei Vagin
2020-04-11 10:32 ` Michael Kerrisk (man-pages) [this message]
2020-04-11 10:36 ` Michael Kerrisk (man-pages)
2020-04-11 15:40 ` [PATCH v2] " Andrei Vagin
2020-04-12 5:51 ` Michael Kerrisk (man-pages)
2020-04-13 22:47 ` Andrew Morton
2020-04-14 0:04 ` Andrei Vagin
2020-04-14 9:51 ` Michael Kerrisk (man-pages)
2020-04-16 6:56 ` Andrei Vagin
2020-04-16 7:10 ` Michael Kerrisk (man-pages)
2020-04-16 9:52 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afd9a489-bea7-c34c-14c2-405b536deb0d@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=0x7f454c46@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@gmail.com \
--cc=ebiederm@xmission.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).