[PATCH v2 08/15] blktrace: pass blk_user_trace2 to setup functions

Johannes Thumshirn
2025-09-25T15:03:10Z

Pass struct blk_user_trace_setup2 to blktrace_setup_finalize(). This
prepares for the incoming extension of the blktrace protocol with a 64bit
act_mask.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
include/linux/blktrace_api.h | 3 ++-
kernel/trace/blktrace.c | 27 ++++++++++++++++++++-------
2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
index 122c62e561fc..05c8754456aa 100644
--- a/include/linux/blktrace_api.h
+++ b/include/linux/blktrace_api.h
@@ -14,11 +14,12 @@
#include <linux/sysfs.h>

struct blk_trace {
+ int version;
int trace_state;
struct rchan *rchan;
unsigned long __percpu *sequence;
unsigned char __percpu *msg_data;
- u16 act_mask;
+ u64 act_mask;
u64 start_lba;
u64 end_lba;
u32 pid;
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index f6a41e9510f6..9cd8eb9e7b4b 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -599,7 +599,7 @@ static struct blk_trace *blk_trace_setup_prepare(struct request_queue *q,

static void blk_trace_setup_finalize(struct request_queue *q,
char *name, struct blk_trace *bt,
- struct blk_user_trace_setup *buts)
+ struct blk_user_trace_setup2 *buts)

{
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE);
@@ -631,6 +631,7 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
struct block_device *bdev,
char __user *arg)
{
+ struct blk_user_trace_setup2 buts2;
struct blk_user_trace_setup buts;
struct blk_trace *bt;
int ret;
@@ -642,6 +643,15 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
if (!buts.buf_size || !buts.buf_nr)
return -EINVAL;

+ buts2 = (struct blk_user_trace_setup2) {
+ .act_mask = buts.act_mask,
+ .buf_size = buts.buf_size,
+ .buf_nr = buts.buf_nr,
+ .start_lba = buts.start_lba,
+ .end_lba = buts.end_lba,
+ .pid = buts.pid,
+ };
+
mutex_lock(&q->debugfs_mutex);
bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
bdev);
@@ -649,7 +659,9 @@ int blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
mutex_unlock(&q->debugfs_mutex);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, bt, &buts);
+ bt->version = 1;
+ blk_trace_setup_finalize(q, name, bt, &buts2);
+ strcpy(buts.name, buts2.name);
mutex_unlock(&q->debugfs_mutex);

if (copy_to_user(arg, &buts, sizeof(buts))) {
@@ -665,7 +677,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
dev_t dev, struct block_device *bdev,
char __user *arg)
{
- struct blk_user_trace_setup buts;
+ struct blk_user_trace_setup2 buts2;
struct compat_blk_user_trace_setup cbuts;
struct blk_trace *bt;

@@ -675,7 +687,7 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
if (!cbuts.buf_size || !cbuts.buf_nr)
return -EINVAL;

- buts = (struct blk_user_trace_setup) {
+ buts2 = (struct blk_user_trace_setup2) {
.act_mask = cbuts.act_mask,
.buf_size = cbuts.buf_size,
.buf_nr = cbuts.buf_nr,
@@ -685,16 +697,17 @@ static int compat_blk_trace_setup(struct request_queue *q, char *name,
};

mutex_lock(&q->debugfs_mutex);
- bt = blk_trace_setup_prepare(q, name, dev, buts.buf_size, buts.buf_nr,
+ bt = blk_trace_setup_prepare(q, name, dev, buts2.buf_size, buts2.buf_nr,
bdev);
if (IS_ERR(bt)) {
mutex_unlock(&q->debugfs_mutex);
return PTR_ERR(bt);
}
- blk_trace_setup_finalize(q, name, bt, &buts);
+ bt->version = 1;
+ blk_trace_setup_finalize(q, name, bt, &buts2);
mutex_unlock(&q->debugfs_mutex);

- if (copy_to_user(arg, &buts.name, ARRAY_SIZE(buts.name))) {
+ if (copy_to_user(arg, &buts2.name, ARRAY_SIZE(buts2.name))) {
blk_trace_remove(q);
return -EFAULT;
}
--
2.51.0