Skip to content

Commit af9c495

Browse files
Cyrill GorcunovKAGA-KOKO
authored andcommitted
timerfd: Implement show_fdinfo method
For checkpoint/restore of timerfd files we need to know how exactly the timer were armed, to be able to recreate it on restore stage. Thus implement show_fdinfo method which provides enough information for that. One of significant changes I think is the addition of @settime_flags member. Currently there are two flags TFD_TIMER_ABSTIME and TFD_TIMER_CANCEL_ON_SET, and the second can be found from @might_cancel variable but in case if the flags will be extended in future we most probably will have to somehow remember them explicitly anyway so I guss doing that right now won't hurt. To not bloat the timerfd_ctx structure I've converted @Expired to short integer and defined @settime_flags as short too. v2 (by avagin@, vdavydov@ and tglx@): - Add it_value/it_interval fields - Save flags being used in timerfd_setup in context v3 (by tglx@): - don't forget to use CONFIG_PROC_FS v4 (by akpm@): -Use define timerfd_show NULL for non c/r config Signed-off-by: Cyrill Gorcunov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Michael Kerrisk <[email protected]> Cc: Andrey Vagin <[email protected]> Cc: Pavel Emelyanov <[email protected]> Cc: Vladimir Davydov <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent afdb094 commit af9c495

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

fs/timerfd.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ struct timerfd_ctx {
3535
ktime_t moffs;
3636
wait_queue_head_t wqh;
3737
u64 ticks;
38-
int expired;
3938
int clockid;
39+
short unsigned expired;
40+
short unsigned settime_flags; /* to show in fdinfo */
4041
struct rcu_head rcu;
4142
struct list_head clist;
4243
bool might_cancel;
@@ -196,6 +197,8 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
196197
if (timerfd_canceled(ctx))
197198
return -ECANCELED;
198199
}
200+
201+
ctx->settime_flags = flags & TFD_SETTIME_FLAGS;
199202
return 0;
200203
}
201204

@@ -284,11 +287,40 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
284287
return res;
285288
}
286289

290+
#ifdef CONFIG_PROC_FS
291+
static int timerfd_show(struct seq_file *m, struct file *file)
292+
{
293+
struct timerfd_ctx *ctx = file->private_data;
294+
struct itimerspec t;
295+
296+
spin_lock_irq(&ctx->wqh.lock);
297+
t.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
298+
t.it_interval = ktime_to_timespec(ctx->tintv);
299+
spin_unlock_irq(&ctx->wqh.lock);
300+
301+
return seq_printf(m,
302+
"clockid: %d\n"
303+
"ticks: %llu\n"
304+
"settime flags: 0%o\n"
305+
"it_value: (%llu, %llu)\n"
306+
"it_interval: (%llu, %llu)\n",
307+
ctx->clockid, (unsigned long long)ctx->ticks,
308+
ctx->settime_flags,
309+
(unsigned long long)t.it_value.tv_sec,
310+
(unsigned long long)t.it_value.tv_nsec,
311+
(unsigned long long)t.it_interval.tv_sec,
312+
(unsigned long long)t.it_interval.tv_nsec);
313+
}
314+
#else
315+
#define timerfd_show NULL
316+
#endif
317+
287318
static const struct file_operations timerfd_fops = {
288319
.release = timerfd_release,
289320
.poll = timerfd_poll,
290321
.read = timerfd_read,
291322
.llseek = noop_llseek,
323+
.show_fdinfo = timerfd_show,
292324
};
293325

294326
static int timerfd_fget(int fd, struct fd *p)

0 commit comments

Comments
 (0)