On Wed, Oct 26, 2022 at 06:19:36PM -0500, Mike Christie wrote: > For Reservation Report support we need to also convert from the NVMe spec > PR type back to the block PR definition. This moves us to an array, so in > the next patch we can add another helper to do the conversion without > having to manage 2 switches. > > Signed-off-by: Mike Christie <michael.chris...@oracle.com> > --- > drivers/nvme/host/pr.c | 42 +++++++++++++++++++++++------------------- > include/linux/nvme.h | 9 +++++++++ > 2 files changed, 32 insertions(+), 19 deletions(-) > > diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c > index df7eb2440c67..5c4611d15d9c 100644 > --- a/drivers/nvme/host/pr.c > +++ b/drivers/nvme/host/pr.c > @@ -6,24 +6,28 @@ > > #include "nvme.h" > > -static char nvme_pr_type(enum pr_type type) > +static const struct { > + enum nvme_pr_type nvme_type; > + enum pr_type blk_type; > +} nvme_pr_types[] = { > + { NVME_PR_WRITE_EXCLUSIVE, PR_WRITE_EXCLUSIVE }, > + { NVME_PR_EXCLUSIVE_ACCESS, PR_EXCLUSIVE_ACCESS }, > + { NVME_PR_WRITE_EXCLUSIVE_REG_ONLY, PR_WRITE_EXCLUSIVE_REG_ONLY }, > + { NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY, PR_EXCLUSIVE_ACCESS_REG_ONLY }, > + { NVME_PR_WRITE_EXCLUSIVE_ALL_REGS, PR_WRITE_EXCLUSIVE_ALL_REGS }, > + { NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS, PR_EXCLUSIVE_ACCESS_ALL_REGS }, > +};
Wouldn't it be easier to use the block type as the array index to avoid the whole looped lookup? enum nvme_pr_type types[] = { .PR_WRITE_EXCLUSIVE = NVME_PR_WRITE_EXCLUSIVE, .PR_EXCLUSIVE_ACCESS = NVME_PR_EXCLUSIVE_ACCESS, ... }; ? -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel