Skip to content

Commit 2831934

Browse files
Hannes Reineckekawasaki
authored andcommitted
block: add 'read_reservation' persistent reservation ioctl
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 <[email protected]>
1 parent f64cfd8 commit 2831934

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

block/ioctl.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,26 @@ static int blkdev_pr_read_keys(struct block_device *bdev, blk_mode_t mode,
459459
return ret;
460460
}
461461

462+
static int blkdev_pr_read_reservation(struct block_device *bdev,
463+
blk_mode_t mode, struct pr_held_reservation __user *arg)
464+
{
465+
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
466+
struct pr_held_reservation r;
467+
int ret;
468+
469+
if (!blkdev_pr_allowed(bdev, mode))
470+
return -EPERM;
471+
if (!ops || !ops->pr_read_reservation)
472+
return -EOPNOTSUPP;
473+
474+
ret = ops->pr_read_reservation(bdev, &r);
475+
if (ret)
476+
return ret;
477+
if (copy_to_user(arg, &r, sizeof(r)))
478+
return -EFAULT;
479+
return 0;
480+
}
481+
462482
static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
463483
unsigned long arg)
464484
{
@@ -682,6 +702,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode,
682702
return blkdev_pr_clear(bdev, mode, argp);
683703
case IOC_PR_READ_KEYS:
684704
return blkdev_pr_read_keys(bdev, mode, argp);
705+
case IOC_PR_READ_RESV:
706+
return blkdev_pr_read_reservation(bdev, mode, argp);
685707
default:
686708
return -ENOIOCTLCMD;
687709
}

include/linux/pr.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
#include <uapi/linux/pr.h>
66

7-
struct pr_held_reservation {
8-
u64 key;
9-
u32 generation;
10-
enum pr_type type;
11-
};
12-
137
struct pr_ops {
148
int (*pr_register)(struct block_device *bdev, u64 old_key, u64 new_key,
159
u32 flags);

include/uapi/linux/pr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ struct pr_keys {
6262
__u64 keys[];
6363
};
6464

65+
struct pr_held_reservation {
66+
__u64 key;
67+
__u32 generation;
68+
__u32 type;
69+
};
70+
6571
#define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */
6672

6773
#define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration)
@@ -71,5 +77,6 @@ struct pr_keys {
7177
#define IOC_PR_PREEMPT_ABORT _IOW('p', 204, struct pr_preempt)
7278
#define IOC_PR_CLEAR _IOW('p', 205, struct pr_clear)
7379
#define IOC_PR_READ_KEYS _IOWR('p', 206, struct pr_keys)
80+
#define IOC_PR_READ_RESV _IOWR('p', 207, struct pr_held_reservation)
7481

7582
#endif /* _UAPI_PR_H */

0 commit comments

Comments
 (0)