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

nvme: Add a nvme_pr_type enum

The next patch adds support to report the reservation type, so we need to
be able to convert from the NVMe PR value we get from the device to the
linux block layer PR value that will be returned to callers. To prepare
for that, this patch adds a nvme_pr_type enum and renames the nvme_pr_type
function.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230407200551.12660-13-michael.christie@oracle.com
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Mike Christie and committed by
Martin K. Petersen
be1a7cd2 5fd96a4e

+21 -12
+12 -12
drivers/nvme/host/pr.c
··· 9 9 10 10 #include "nvme.h" 11 11 12 - static char nvme_pr_type(enum pr_type type) 12 + static enum nvme_pr_type nvme_pr_type_from_blk(enum pr_type type) 13 13 { 14 14 switch (type) { 15 15 case PR_WRITE_EXCLUSIVE: 16 - return 1; 16 + return NVME_PR_WRITE_EXCLUSIVE; 17 17 case PR_EXCLUSIVE_ACCESS: 18 - return 2; 18 + return NVME_PR_EXCLUSIVE_ACCESS; 19 19 case PR_WRITE_EXCLUSIVE_REG_ONLY: 20 - return 3; 20 + return NVME_PR_WRITE_EXCLUSIVE_REG_ONLY; 21 21 case PR_EXCLUSIVE_ACCESS_REG_ONLY: 22 - return 4; 22 + return NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY; 23 23 case PR_WRITE_EXCLUSIVE_ALL_REGS: 24 - return 5; 24 + return NVME_PR_WRITE_EXCLUSIVE_ALL_REGS; 25 25 case PR_EXCLUSIVE_ACCESS_ALL_REGS: 26 - return 6; 27 - default: 28 - return 0; 26 + return NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS; 29 27 } 28 + 29 + return 0; 30 30 } 31 31 32 32 static int nvme_send_ns_head_pr_command(struct block_device *bdev, ··· 127 127 if (flags & ~PR_FL_IGNORE_KEY) 128 128 return -EOPNOTSUPP; 129 129 130 - cdw10 = nvme_pr_type(type) << 8; 130 + cdw10 = nvme_pr_type_from_blk(type) << 8; 131 131 cdw10 |= ((flags & PR_FL_IGNORE_KEY) ? 1 << 3 : 0); 132 132 return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_acquire); 133 133 } ··· 135 135 static int nvme_pr_preempt(struct block_device *bdev, u64 old, u64 new, 136 136 enum pr_type type, bool abort) 137 137 { 138 - u32 cdw10 = nvme_pr_type(type) << 8 | (abort ? 2 : 1); 138 + u32 cdw10 = nvme_pr_type_from_blk(type) << 8 | (abort ? 2 : 1); 139 139 140 140 return nvme_pr_command(bdev, cdw10, old, new, nvme_cmd_resv_acquire); 141 141 } ··· 149 149 150 150 static int nvme_pr_release(struct block_device *bdev, u64 key, enum pr_type type) 151 151 { 152 - u32 cdw10 = nvme_pr_type(type) << 8 | (key ? 0 : 1 << 3); 152 + u32 cdw10 = nvme_pr_type_from_blk(type) << 8 | (key ? 0 : 1 << 3); 153 153 154 154 return nvme_pr_command(bdev, cdw10, key, 0, nvme_cmd_resv_release); 155 155 }
+9
include/linux/nvme.h
··· 759 759 NVME_LBART_ATTRIB_HIDE = 1 << 1, 760 760 }; 761 761 762 + enum nvme_pr_type { 763 + NVME_PR_WRITE_EXCLUSIVE = 1, 764 + NVME_PR_EXCLUSIVE_ACCESS = 2, 765 + NVME_PR_WRITE_EXCLUSIVE_REG_ONLY = 3, 766 + NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY = 4, 767 + NVME_PR_WRITE_EXCLUSIVE_ALL_REGS = 5, 768 + NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS = 6, 769 + }; 770 + 762 771 enum nvme_eds { 763 772 NVME_EXTENDED_DATA_STRUCT = 0x1, 764 773 };