[PATCH 2/3] block: add 'read_reservation' persistent reservation ioctl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The persistent reservation operations already have a callback for
'read_reservation', but this is not accessible via an ioctl (unlike the
other callbacks). So add a new persistent reservation ioctl 'READ_RESV'
to allow userspace to use this functionality.

Signed-off-by: Hannes Reinecke <hare@xxxxxxxxxx>
---
 block/ioctl.c           | 22 ++++++++++++++++++++++
 include/linux/pr.h      |  6 ------
 include/uapi/linux/pr.h |  7 +++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/block/ioctl.c b/block/ioctl.c
index 71f87974e044..3612352a1d83 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -459,6 +459,26 @@ static int blkdev_pr_read_keys(struct block_device *bdev, blk_mode_t mode,
 	return ret;
 }
 
+static int blkdev_pr_read_reservation(struct block_device *bdev,
+		blk_mode_t mode, struct pr_held_reservation __user *arg)
+{
+	const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
+	struct pr_held_reservation r;
+	int ret;
+
+	if (!blkdev_pr_allowed(bdev, mode))
+		return -EPERM;
+	if (!ops || !ops->pr_read_reservation)
+		return -EOPNOTSUPP;
+
+	ret = ops->pr_read_reservation(bdev, &r);
+	if (ret)
+		return ret;
+	if (copy_to_user(arg, &r, sizeof(r)))
+		return -EFAULT;
+	return 0;
+}
+
 static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
 		unsigned long arg)
 {
@@ -682,6 +702,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
 		return blkdev_pr_clear(bdev, mode, argp);
 	case IOC_PR_READ_KEYS:
 		return blkdev_pr_read_keys(bdev, mode, argp);
+	case IOC_PR_READ_RESV:
+		return blkdev_pr_read_reservation(bdev, mode, argp);
 	default:
 		return -ENOIOCTLCMD;
 	}
diff --git a/include/linux/pr.h b/include/linux/pr.h
index 6f293c3e27a1..e3ccfbd9dfba 100644
--- a/include/linux/pr.h
+++ b/include/linux/pr.h
@@ -4,12 +4,6 @@
 
 #include <uapi/linux/pr.h>
 
-struct pr_held_reservation {
-	u64		key;
-	u32		generation;
-	enum pr_type	type;
-};
-
 struct pr_ops {
 	int (*pr_register)(struct block_device *bdev, u64 old_key, u64 new_key,
 			u32 flags);
diff --git a/include/uapi/linux/pr.h b/include/uapi/linux/pr.h
index 6e0d91d43c54..20198c7e68e8 100644
--- a/include/uapi/linux/pr.h
+++ b/include/uapi/linux/pr.h
@@ -62,6 +62,12 @@ struct pr_keys {
 	__u64	keys[];
 };
 
+struct pr_held_reservation {
+	__u64		key;
+	__u32		generation;
+	__u32		type;
+};
+
 #define PR_FL_IGNORE_KEY	(1 << 0)	/* ignore existing key */
 
 #define IOC_PR_REGISTER		_IOW('p', 200, struct pr_registration)
@@ -71,5 +77,6 @@ struct pr_keys {
 #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)
+#define IOC_PR_READ_RESV	_IOWR('p', 207, struct pr_held_reservation)
 
 #endif /* _UAPI_PR_H */
-- 
2.35.3





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux