Skip to content

Commit

Permalink
wire up ioctl read keys/reservation in uapi
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed Sep 30, 2024
1 parent 03cf828 commit 116e113
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
48 changes: 48 additions & 0 deletions block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,50 @@ 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 *argp)
{
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
struct pr_keys k;
int err;

if (!blkdev_pr_allowed(bdev, mode))
return -EPERM;
if (!ops || !ops->pr_read_keys)
return -EOPNOTSUPP;
if (copy_from_user(&k, argp, sizeof(k)))
return -EFAULT;

err = ops->pr_read_keys(bdev, &k);
if (err == 0) {
if (copy_to_user(argp, &k, sizeof(k)))
err = -EFAULT;
}
return err;
}

static int blkdev_pr_read_reservation(struct block_device *bdev,
blk_mode_t mode, struct pr_held_reservation __user *argp)
{
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
struct pr_held_reservation r;
int err;

if (!blkdev_pr_allowed(bdev, mode))
return -EPERM;
if (!ops || !ops->pr_read_reservation)
return -EOPNOTSUPP;
if (copy_from_user(&r, argp, sizeof(r)))
return -EFAULT;

err = ops->pr_read_reservation(bdev, &r);
if (err == 0) {
if (copy_to_user(argp, &r, sizeof(r)))
err = -EFAULT;
}
return err;
}

static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
unsigned long arg)
{
Expand Down Expand Up @@ -571,6 +615,10 @@ 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, argp);
case IOC_PR_READ_RESV:
return blkdev_pr_read_reservation(bdev, argp);
default:
return -ENOIOCTLCMD;
}
Expand Down
12 changes: 0 additions & 12 deletions include/linux/pr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +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;
enum pr_type type;
};

struct pr_ops {
int (*pr_register)(struct block_device *bdev, u64 old_key, u64 new_key,
u32 flags);
Expand Down
15 changes: 14 additions & 1 deletion include/uapi/linux/pr.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ struct pr_clear {
__u32 __pad;
};

struct pr_keys {
u32 generation;
u32 num_keys;
u64 keys[];
};

struct pr_held_reservation {
u64 key;
u32 generation;
enum pr_type type;
};

#define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */

#define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration)
Expand All @@ -64,5 +76,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 _IOW('p', 206, struct pr_keys)
#define IOC_PR_READ_RESV _IOW('p', 207, struct pr_held_reservation)
#endif /* _UAPI_PR_H */

0 comments on commit 116e113

Please sign in to comment.