nvme: use macro definitions for setting reservation values
Subsystems (2)
PATCH v2 1/1 nvme: use macro definitions for setting reservation values
This makes the code more readable.
---
Changes from v1:
- remove comments (Sagi/Keith)
- use tabs for constants alignment, similar to 'enum pr_type' (Keith)
--- drivers/nvme/host/core.c | 12 ++++++------ include/linux/nvme.h | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +6 -6
@@ -2068,17 +2068,17 @@ static char nvme_pr_type(enum pr_type type) {switch (type) {case PR_WRITE_EXCLUSIVE : -return 1 ; +return NVME_PR_WRITE_EXCLUSIVE ;case PR_EXCLUSIVE_ACCESS : -return 2 ; +return NVME_PR_EXCLUSIVE_ACCESS ;case PR_WRITE_EXCLUSIVE_REG_ONLY : -return 3 ; +return NVME_PR_WRITE_EXCLUSIVE_REG_ONLY ;case PR_EXCLUSIVE_ACCESS_REG_ONLY : -return 4 ; +return NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY ;case PR_WRITE_EXCLUSIVE_ALL_REGS : -return 5 ; +return NVME_PR_WRITE_EXCLUSIVE_ALL_REGS ;case PR_EXCLUSIVE_ACCESS_ALL_REGS : -return 6 ; +return NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS ;default :return 0 ; }
include/linux/nvme.h +9 -0
@@ -238,6 +238,15 @@ enum { NVME_CAP_CRMS_CRIMS = 1ULL << 60, }; +enum { +NVME_PR_WRITE_EXCLUSIVE =1 , +NVME_PR_EXCLUSIVE_ACCESS =2 , +NVME_PR_WRITE_EXCLUSIVE_REG_ONLY =3 , +NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY =4 , +NVME_PR_WRITE_EXCLUSIVE_ALL_REGS =5 , +NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS =6 , +}; +struct nvme_id_power_state {__le16 max_power;/* centiwatts */ __u8 rsvd2;
Signature · 1 line
2.18.1
Sagi Grimberg
maintainerQuoted 46 lines
This makes the code more readable.
Signed-off-by Max Gurtovoy <[email protected]>---
Changes from v1:
- remove comments (Sagi/Keith)
- use tabs for constants alignment, similar to 'enumpr_type' (Keith)--- drivers/nvme/host/core.c | 12 ++++++------ include/linux/nvme.h | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-)drivers/nvme/host/core.c +6
-6@@ -2068,17 +2068,17 @@ static char nvme_pr_type(enum pr_type type) {switch (type) {case PR_WRITE_EXCLUSIVE : -return 1 ; +return NVME_PR_WRITE_EXCLUSIVE ;case PR_EXCLUSIVE_ACCESS : -return 2 ; +return NVME_PR_EXCLUSIVE_ACCESS ;case PR_WRITE_EXCLUSIVE_REG_ONLY : -return 3 ; +return NVME_PR_WRITE_EXCLUSIVE_REG_ONLY ;case PR_EXCLUSIVE_ACCESS_REG_ONLY : -return 4 ; +return NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY ;case PR_WRITE_EXCLUSIVE_ALL_REGS : -return 5 ; +return NVME_PR_WRITE_EXCLUSIVE_ALL_REGS ;case PR_EXCLUSIVE_ACCESS_ALL_REGS : -return 6 ; +return NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS ;default :return 0 ; }include/linux/nvme.h +0
-0
include/linux/nvme.h enum { · line 241
Quoted 4 lines
include/linux/nvme.h +1
-0@@ -238,6 +238,15 @@ enum { NVME_CAP_CRMS_CRIMS = 1ULL << 60, }; +enum {
I'd make this named nvme_pr_type
Quoted 43 lines · Sagi Grimberg
Quoted 43 lines
This makes the code more readable.
Signed-off-by Max Gurtovoy <[email protected]>---
Changes from v1:
- remove comments (Sagi/Keith)
- use tabs for constants alignment, similar to 'enumpr_type' (Keith)
---
drivers/nvme/host/core.c| 12 ++++++------ include/linux/nvme.h | 9 +++++++++2 files changed, 15 insertions(+), 6 deletions(-)drivers/nvme/host/core.c +0
-0@@ -2068,17 +2068,17 @@ static char nvme_pr_type(enum pr_type type) { switch (type) {case
PR_WRITE_EXCLUSIVE:
- return 1;
+ returnNVME_PR_WRITE_EXCLUSIVE; casePR_EXCLUSIVE_ACCESS:
- return 2;
+ returnNVME_PR_EXCLUSIVE_ACCESS; casePR_WRITE_EXCLUSIVE_REG_ONLY:
- return 3;
+ returnNVME_PR_WRITE_EXCLUSIVE_REG_ONLY; casePR_EXCLUSIVE_ACCESS_REG_ONLY:
- return 4;
+ returnNVME_PR_EXCLUSIVE_ACCESS_REG_ONLY; casePR_WRITE_EXCLUSIVE_ALL_REGS:
- return 5;
+ returnNVME_PR_WRITE_EXCLUSIVE_ALL_REGS; casePR_EXCLUSIVE_ACCESS_ALL_REGS:
- return 6;
+ returnNVME_PR_EXCLUSIVE_ACCESS_ALL_REGS; default:
return 0;
}include/linux/nvme.h +0
-0
Quoted 8 lines
include/linux/nvme.h enum { · line 240
Quoted 6 lines
include/linux/nvme.h +0
-0@@ -238,6 +238,15 @@ enum { NVME_CAP_CRMS_CRIMS = 1ULL << 60, }; +enum {I'd make this named
nvme_pr_type
Most of the enums of this header are not named.
I don't understand what is the convention here.
Usually, if it's not a new header file I'm trying to keep the file convention and this is what I did.
If all agree on named, I'll send another version.
Christoph Hellwig
maintainerQuoted 10 lines · Max Gurtovoy
Quoted 1 line
I'd make this named
nvme_pr_typeMost of the enums of this header are not named.
I don't understand what is the convention here.
Usually, if it's not a new header file I'm trying to keep the file convention and this is what I did.
If all agree on named, I'll send another version.
I think named is better, nvme has some weird unnamed enums that even combine totally unrelated fields which I always found confusing.
Keith Busch
maintainerQuoted 7 lines · Christoph Hellwig
Quoted 6 lines · Max Gurtovoy
Quoted 1 line
I'd make this named
nvme_pr_typeMost of the enums of this header are not named.
I don't understand what is the convention here.
Quoted 7 lines
Quoted 4 lines
Usually, if it's not a new header file I'm trying to keep the file convention and this is what I did.
If all agree on named, I'll send another version.
I think named is better, nvme has some weird unnamed enums that even combine totally unrelated fields which I always found confusing.
It's carry-over from the early days when structures had so few constants that giving each field values their own enum looked a bit silly, and enums were considered better than a bunch of #define's.
As far as naming them goes, if the only usage is its definition, then what's the point? If there's a use for a named enum somewhere else, then yah, that improves readability.
Christoph Hellwig
maintainerQuoted 3 lines · Keith Busch
As far as naming them goes, if the only usage is its definition, then what's the point? If there's a use for a named enum somewhere else, then yah, that improves readability.
I think it is nice bit of documentation. E.g. if the enum is for the bits or value in a nvme filed naming it after that field can be handy.
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Keith Busch
As far as naming them goes, if the only usage is its definition, then what's the point? If there's a use for a named enum somewhere else, then yah, that improves readability.
I think it is nice bit of documentation. E.g. if the enum is for the bits or value in a nvme filed naming it after that field can be handy.
I also preferred my V1 with more documentation but was asked to remove it:
+/*
+ * Reservation Type Encoding
+ */
+enum {
+ NVME_PR_WRITE_EXCLUSIVE = 1, /* Write Exclusive Reservation */
+ NVME_PR_EXCLUSIVE_ACCESS = 2, /* Exclusive Access Reservation */
+ NVME_PR_WRITE_EXCLUSIVE_REG_ONLY = 3, /* Write Exclusive - Registrants Only Reservation */ + NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY = 4, /* Exclusive Access - Registrants Only Reservation */ + NVME_PR_WRITE_EXCLUSIVE_ALL_REGS = 5, /* Write Exclusive - All Registrants Reservation */ + NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS = 6, /* Exclusive Access - All Registrants Reservation */ +};
regarding the naming of the enum I tend to agree that this is not a must here since this is currently the style of this header and since we use only its internal definitions.
So I'm ok we both v1 and v2.
We can do some work to improve the confusing enums in nvme.h but we need to agree on the strategy before we go implement.
Quoted 3 lines · Max Gurtovoy
This makes the code more readable.
Signed-off-by Max Gurtovoy <[email protected]>
Looks good to me.