From: Hannes Reinecke <hare@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
James Bottomley <james.bottomley@hansenpartnership.com>,
Hannes Reinecke <hare@kernel.org>
Subject: [PATCH 1/3] block: add 'read_keys' persistent reservation ioctl
Date: Tue, 3 Jun 2025 12:04:14 +0200 [thread overview]
Message-ID: <20250603100416.131490-2-hare@kernel.org> (raw)
In-Reply-To: <20250603100416.131490-1-hare@kernel.org>
The persistent reservation operations already have a callback for
'read_keys', but this is not accessible via an ioctl (unlike the
other callbacks). So add a new persistent reservation ioctl 'READ_KEYS'
to allow userspace to use this functionality.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
block/ioctl.c | 39 +++++++++++++++++++++++++++++++++++++++
include/linux/pr.h | 6 ------
include/uapi/linux/pr.h | 7 +++++++
3 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/block/ioctl.c b/block/ioctl.c
index e472cc1030c6..71f87974e044 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -422,6 +422,43 @@ static int blkdev_pr_clear(struct block_device *bdev, blk_mode_t mode,
return ops->pr_clear(bdev, c.key);
}
+static int blkdev_pr_read_keys(struct block_device *bdev, blk_mode_t mode,
+ struct pr_keys __user *arg)
+{
+ const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
+ struct pr_keys k_in, *k_out;
+ size_t k_len;
+ int ret, num_keys;
+
+ if (!blkdev_pr_allowed(bdev, mode))
+ return -EPERM;
+ if (!ops || !ops->pr_read_keys)
+ return -EOPNOTSUPP;
+
+ if (copy_from_user(&k_in, arg, sizeof(k_in)))
+ return -EFAULT;
+
+ num_keys = k_in.num_keys;
+ k_out = kzalloc(sizeof(struct pr_keys) + num_keys * sizeof(u64),
+ GFP_KERNEL);
+ if (!k_out)
+ return -ENOMEM;
+
+ k_out->num_keys = num_keys;
+ ret = ops->pr_read_keys(bdev, k_out);
+ if (ret) {
+ kfree(k_out);
+ return ret;
+ }
+
+ k_len = sizeof(k_in) + num_keys * sizeof(u64);
+ if (copy_to_user(arg, k_out, k_len))
+ ret = -EFAULT;
+
+ kfree(k_out);
+ return ret;
+}
+
static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
unsigned long arg)
{
@@ -643,6 +680,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
return blkdev_pr_preempt(bdev, mode, argp, true);
case IOC_PR_CLEAR:
return blkdev_pr_clear(bdev, mode, argp);
+ case IOC_PR_READ_KEYS:
+ return blkdev_pr_read_keys(bdev, mode, argp);
default:
return -ENOIOCTLCMD;
}
diff --git a/include/linux/pr.h b/include/linux/pr.h
index 3003daec28a5..6f293c3e27a1 100644
--- a/include/linux/pr.h
+++ b/include/linux/pr.h
@@ -4,12 +4,6 @@
#include <uapi/linux/pr.h>
-struct pr_keys {
- u32 generation;
- u32 num_keys;
- u64 keys[];
-};
-
struct pr_held_reservation {
u64 key;
u32 generation;
diff --git a/include/uapi/linux/pr.h b/include/uapi/linux/pr.h
index d8126415966f..6e0d91d43c54 100644
--- a/include/uapi/linux/pr.h
+++ b/include/uapi/linux/pr.h
@@ -56,6 +56,12 @@ struct pr_clear {
__u32 __pad;
};
+struct pr_keys {
+ __u32 generation;
+ __u32 num_keys;
+ __u64 keys[];
+};
+
#define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */
#define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration)
@@ -64,5 +70,6 @@ struct pr_clear {
#define IOC_PR_PREEMPT _IOW('p', 203, struct pr_preempt)
#define IOC_PR_PREEMPT_ABORT _IOW('p', 204, struct pr_preempt)
#define IOC_PR_CLEAR _IOW('p', 205, struct pr_clear)
+#define IOC_PR_READ_KEYS _IOWR('p', 206, struct pr_keys)
#endif /* _UAPI_PR_H */
--
2.35.3
next prev parent reply other threads:[~2025-06-03 10:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-03 10:04 [PATCH 0/3] block: expose 'read_keys' and 'read_reservation' PR callbacks Hannes Reinecke
2025-06-03 10:04 ` Hannes Reinecke [this message]
2025-06-03 10:04 ` [PATCH 2/3] block: add 'read_reservation' persistent reservation ioctl Hannes Reinecke
2025-06-03 10:04 ` [PATCH 3/3] scsi: return PR generation if no reservation is held Hannes Reinecke
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=20250603100416.131490-2-hare@kernel.org \
--to=hare@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.