Accept BLKTRACE_FLAG_IOPRIO in BLKTRACESETUP2 and, if it is set, mark all events that belong to a bio or request with __BLK_TA_IOPRIO, so user space knows that blk_io_trace2::ioprio is valid. Old kernels reject the flag with -EINVAL, so user space can detect the support. BLKTRACESETUP (v1) has no flags and therefore never gets I/O priorities. For the ftrace blk tracer the TRACE_BLK_OPT_IOPRIO flag is checked instead, the corresponding tracer option is added together with the decoding of the I/O priority in the next patch. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Johannes Thumshirn --- include/linux/blktrace_api.h | 1 + kernel/trace/blktrace.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h index 05c8754456aa..63d76a176e9a 100644 --- a/include/linux/blktrace_api.h +++ b/include/linux/blktrace_api.h @@ -27,6 +27,7 @@ struct blk_trace { struct dentry *dir; struct list_head running_list; atomic_t dropped; + u32 flags; }; extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *); diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index c57df30750e9..f1a3407d36c9 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -40,6 +40,7 @@ static __cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(running_trace_lock); #define TRACE_BLK_OPT_CLASSIC 0x1 #define TRACE_BLK_OPT_CGROUP 0x2 #define TRACE_BLK_OPT_CGNAME 0x4 +#define TRACE_BLK_OPT_IOPRIO 0x8 static struct tracer_opt blk_tracer_opts[] = { /* Default disable the minimalistic output */ @@ -308,6 +309,13 @@ static const u32 ddir_act[2] = { BLK_TC_ACT(BLK_TC_READ), #define MASK_TC_BIT(rw, __name) ((__force u32)(rw & REQ_ ## __name) << \ (ilog2(BLK_TC_ ## __name) + BLK_TC_SHIFT - __REQ_ ## __name)) +static bool blk_trace_want_ioprio(struct blk_trace *bt, bool blk_tracer) +{ + if (blk_tracer) + return blk_tracer_flags.val & TRACE_BLK_OPT_IOPRIO; + return bt->version == 2 && (bt->flags & BLKTRACE_FLAG_IOPRIO); +} + /* * The worker for the various blk_add_trace*() types. Fills out a * blk_io_trace structure and places it in a per-cpu subbuffer. @@ -381,6 +389,8 @@ static void __blk_add_trace(struct blk_trace *bt, sector_t sector, int bytes, if (cgid) what |= __BLK_TA_CGROUP; + if (ioprio >= 0 && blk_trace_want_ioprio(bt, blk_tracer)) + what |= __BLK_TA_IOPRIO; pid = tsk->pid; if (act_log_check(bt, what, sector, pid)) @@ -760,6 +770,7 @@ static void blk_trace_setup_finalize(struct request_queue *q, bt->pid = buts->pid; bt->trace_state = Blktrace_setup; + bt->flags = buts->flags; rcu_assign_pointer(q->blk_trace, bt); get_probe_ref(); @@ -823,7 +834,7 @@ static int blk_trace_setup2(struct request_queue *q, char *name, dev_t dev, if (!buts2.buf_size || !buts2.buf_nr) return -EINVAL; - if (buts2.flags != 0) + if (buts2.flags & ~BLKTRACE_FLAGS_MASK) return -EINVAL; memflags = blk_debugfs_lock(q); -- 2.56.1