timens: show clock symbolic names in /proc/pid/timens_offsets
Subsystems (4)
PATCH 1/1 timens: show clock symbolic names in /proc/pid/timens_offsets
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.
--- fs/proc/base.c | 14 +++++++++++++- kernel/time/namespace.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-)
fs/proc/base.c +13 -1
@@ -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)
kernel/time/namespace.c +14 -1
@@ -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 ; + } +seq_printf (m,"%s\t%10lld\t%10ld\n" , clock, ts->tv_sec, ts->tv_nsec); }void proc_timens_show_offsets (struct task_struct *p,struct seq_file *m)
Signature · 1 line
2.24.1
Hello Andrei,
Quoted 10 lines · Andrei Vagin
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 0For setting offsets, both representations of clocks can be used.
Quoted 7 lines
As for compatibility, it is acceptable to change things as long as userspace doesn't care. The format of
timens_offsetsfiles 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:
But, I do have one small suggestion below.
Quoted 60 lines
Fixes 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Eric W. Biederman <[email protected]>Cc Michael Kerrisk <[email protected]>Cc Dmitry Safonov <[email protected]>Suggested-by Michael Kerrisk <[email protected]>Signed-off-by Andrei Vagin <[email protected]>--- fs/proc/base.c | 14 +++++++++++++- kernel/time/namespace.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-)fs/proc/base.c +13
-1@@ -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)kernel/time/namespace.c +3
-1@@ -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) {
kernel/time/namespace.c static struct user_namespace *timens_owner(struct ns_common *ns) · line 353
Quoted 10 lines
kernel/time/namespace.c +10
-0+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:
kernel/time/namespace.c static struct user_namespace *timens_owner(struct ns_common *ns) · line 354
Quoted 1 line
kernel/time/namespace.c +1
-0+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
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 8 lines
As things stand, there is to my eye an excessive amount of white space in the output produced by this line:
kernel/time/namespace.c static struct user_namespace *timens_owner(struct ns_common *ns) · line 354
Quoted 1 line
kernel/time/namespace.c +1
-0+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);
Actually, how about even s/-16s/-10s/ for that first field.
Thanks,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
PATCH v2 1/1 timens: show clock symbolic names in /proc/pid/timens_offsets
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 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.
---
v2: use the more compact format of timens_offsets files.
fs/proc/base.c | 14 +++++++++++++- kernel/time/namespace.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-)
fs/proc/base.c +13 -1
@@ -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)
kernel/time/namespace.c +14 -1
@@ -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 ; + } +seq_printf (m,"%-10s %10lld %9ld\n" , clock, ts->tv_sec, ts->tv_nsec); }void proc_timens_show_offsets (struct task_struct *p,struct seq_file *m)
Signature · 1 line
2.24.1
Hi Andrei,
Quoted 8 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0
Thanks.
Assuming no-one has objections to the patch, please do mark for stable@.
Cheers,
Michael
Quoted 7 lines · On Sun, 12 Apr 2020 07:51:47 +0200 "Michael Kerrisk (man-pages)"…
Hi Andrei,
Quoted 4 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Quoted 9 lines
Quoted 4 lines
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0Thanks.
Assuming no-one has objections to the patch, please do mark for stable@.
`grep -r timens_offsets Documentation' comes up blank. Is /proc/pid/timens_offsets documented anywhere? If not, it should be! And this patch should update that documentation.
I assume the time namespace feature itself is documented under clone(2)?
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Sun, 12 Apr 2020 07:51:47 +0200 "Michael Kerrisk (man-pages)"…
Hi Andrei,
Quoted 8 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0Thanks.
Quoted 8 lines
Quoted 2 lines
Assuming no-one has objections to the patch, please do mark for stable@.
`grep -r
timens_offsetsDocumentation' comes up blank. Is/proc/pid/timens_offsetsdocumented anywhere? If not, it should be! And this patch should update that documentation.I assume the time namespace feature itself is documented under clone(2)?
Thanks to Michael, we have the man page for time namespaces:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/man7/time_namespaces.7
And it will be updated according with this change.
Thanks,
Andrei
Quoted 17 lines · Andrew Morton
Quoted 14 lines · On Sun, 12 Apr 2020 07:51:47 +0200 "Michael Kerrisk (man-pages)"…
Hi Andrei,
Quoted 8 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0Thanks.
Quoted 8 lines
Quoted 2 lines
Assuming no-one has objections to the patch, please do mark for stable@.
`grep -r
timens_offsetsDocumentation' comes up blank. Is/proc/pid/timens_offsetsdocumented anywhere? If not, it should be! And this patch should update that documentation.I assume the time namespace feature itself is documented under clone(2)?
We're good, so far. There's time_namespaces(7) [1] and documentation of CLONE_NEWTIME in unshare(2) [2].
CLONE_NEWTIME support for clone3() is still a work in progress [3].
Thanks,
Michael
[1] http://man7.org/linux/man-pages/man7/time_namespaces.7.html
[2] http://man7.org/linux/man-pages/man2/unshare.2.html
[3] https://lore.kernel.org/lkml/[email protected]/
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 18 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0For 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_offsetsfiles 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.
Quoted 6 lines
Fixes 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Eric W. Biederman <[email protected]>Cc Dmitry Safonov <[email protected]>Acked-by Michael Kerrisk <[email protected]>
Thomas and Andrew, could you merge this patch? I am sorry, I used the wrong subsystem prefix. Let me know if I need to send the third version of this patch.
Thanks,
Andrei
Hi Andrei,
Quoted 27 lines · Andrei Vagin
Quoted 18 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0For 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_offsetsfiles 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.
Quoted 6 lines
Fixes 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Eric W. Biederman <[email protected]>Cc Dmitry Safonov <[email protected]>Acked-by Michael Kerrisk <[email protected]>
Quoted 3 lines
Thomas and Andrew, could you merge this patch? I am sorry, I used the wrong subsystem prefix. Let me know if I need to send the third version of this patch.
This patch should also be marked for stable@.
Thanks,
Michael
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Quoted 26 lines · Andrei Vagin
Quoted 18 lines · Andrei Vagin
Michael Kerrisk suggested to replace numeric clock IDs on symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0For 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_offsetsfiles 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.
Quoted 6 lines
Fixes 04a8682a71be ("fs/proc: Introduce /proc/pid/timens_offsets")Cc Thomas Gleixner <[email protected]>Cc Andrew Morton <[email protected]>Cc Eric W. Biederman <[email protected]>Cc Dmitry Safonov <[email protected]>Acked-by Michael Kerrisk <[email protected]>
Quoted 3 lines
Thomas and Andrew, could you merge this patch? I am sorry, I used the wrong subsystem prefix. Let me know if I need to send the third version of this patch.
Picking it up.
[tip: timers/urgent] proc, time/namespace: Show clock symbolic names in /proc/pid/timens_offsets
In reply to Andrei VaginThe following commit has been merged into the timers/urgent branch of tip:
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: 94d440d618467806009c8edc70b094d64e12ee5a Gitweb: https://git.kernel.org/tip/94d440d618467806009c8edc70b094d64e12ee5a Author: Andrei Vagin <[email protected]> AuthorDate: Sat, 11 Apr 2020 08:40:31 -07:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 16 Apr 2020 12:10:54 +02:00
proc, time/namespace: Show clock symbolic names in /proc/pid/timens_offsets
Michael Kerrisk suggested to replace numeric clock IDs with symbolic names.
Now the content of these files looks like this:
$ cat /proc/774/timens_offsets monotonic 864000 0 boottime 1728000 0
For setting offsets, both representations of clocks (numeric and symbolic) 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 yet which rely on this format.
But three projects crun, util-linux and criu rely on the interface of setting time offsets and this is why it's required to continue supporting the numeric clock IDs on write.
--- fs/proc/base.c | 14 +++++++++++++- kernel/time/namespace.c | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-)
fs/proc/base.c +13 -1
@@ -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)
kernel/time/namespace.c +14 -1
@@ -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 ; + } +seq_printf (m,"%-10s %10lld %9ld\n" , clock, ts->tv_sec, ts->tv_nsec); }void proc_timens_show_offsets (struct task_struct *p,struct seq_file *m)