Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: add IOC_PR_READ_RESERVATION ioctl

Add a Persistent Reservations ioctl to read the current reservation.
This calls the pr_ops->read_reservation() function that was previously
added in commit c787f1baa503 ("block: Add PR callouts for read keys and
reservation") but was only used by the in-kernel SCSI target so far.

The IOC_PR_READ_RESERVATION ioctl is necessary so that userspace
applications that rely on Persistent Reservations ioctls have a way of
inspecting the current state. Cluster managers and validation tests need
this functionality.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Stefan Hajnoczi and committed by
Jens Axboe
3e2cb9ee 22a1ffea

+35
+28
block/ioctl.c
··· 477 477 return ret; 478 478 } 479 479 480 + static int blkdev_pr_read_reservation(struct block_device *bdev, 481 + blk_mode_t mode, struct pr_read_reservation __user *arg) 482 + { 483 + const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops; 484 + struct pr_held_reservation rsv = {}; 485 + struct pr_read_reservation out = {}; 486 + int ret; 487 + 488 + if (!blkdev_pr_allowed(bdev, mode)) 489 + return -EPERM; 490 + if (!ops || !ops->pr_read_reservation) 491 + return -EOPNOTSUPP; 492 + 493 + ret = ops->pr_read_reservation(bdev, &rsv); 494 + if (ret) 495 + return ret; 496 + 497 + out.key = rsv.key; 498 + out.generation = rsv.generation; 499 + out.type = rsv.type; 500 + 501 + if (copy_to_user(arg, &out, sizeof(out))) 502 + return -EFAULT; 503 + return 0; 504 + } 505 + 480 506 static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd, 481 507 unsigned long arg) 482 508 { ··· 727 701 return blkdev_pr_clear(bdev, mode, argp); 728 702 case IOC_PR_READ_KEYS: 729 703 return blkdev_pr_read_keys(bdev, mode, argp); 704 + case IOC_PR_READ_RESERVATION: 705 + return blkdev_pr_read_reservation(bdev, mode, argp); 730 706 default: 731 707 return blk_get_meta_cap(bdev, cmd, argp); 732 708 }
+7
include/uapi/linux/pr.h
··· 62 62 __u64 keys_ptr; 63 63 }; 64 64 65 + struct pr_read_reservation { 66 + __u64 key; 67 + __u32 generation; 68 + __u32 type; 69 + }; 70 + 65 71 #define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */ 66 72 67 73 #define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration) ··· 77 71 #define IOC_PR_PREEMPT_ABORT _IOW('p', 204, struct pr_preempt) 78 72 #define IOC_PR_CLEAR _IOW('p', 205, struct pr_clear) 79 73 #define IOC_PR_READ_KEYS _IOWR('p', 206, struct pr_read_keys) 74 + #define IOC_PR_READ_RESERVATION _IOR('p', 207, struct pr_read_reservation) 80 75 81 76 #endif /* _UAPI_PR_H */