Skip to content

Commit 4851c9b

Browse files
committed
nvme: enforce ns granularity on ns create
When the device supports the namespace granularity feature, update the alignment requirements accordingly. Because this is likely to change the capacity of the namespace also issue a info what is going to happen. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 2b7a6d7 commit 4851c9b

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Documentation/nvme-create-ns.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ OPTIONS
9999
-S::
100100
--nsze-si::
101101
The namespace size (NSZE) in standard SI units (aligned on 1Mib boundaries,
102-
unless the controller recommends a smaller value).
102+
unless the controller recommends a different value, see namespace
103+
granularity).
103104
The value SI suffixed is divided by the namespace LBA size to set as NSZE.
104105
If the value not suffixed it is set as same with the nsze option.
105106

106107
-C::
107108
--ncap-si::
108109
The namespace capacity (NCAP) in standard SI units (aligned on 1Mib boundaries,
109-
unless the controller recommends a smaller value).
110+
unless the controller recommends a different value, see namespace
111+
granularity).
110112
The value SI suffixed is divided by the namespace LBA size to set as NCAP.
111113
If the value not suffixed it is set as same with the ncap option.
112114

nvme.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,7 @@ static int detach_ns(int argc, char **argv, struct command *cmd, struct plugin *
30013001
}
30023002

30033003
static int parse_lba_num_si(struct nvme_dev *dev, const char *opt,
3004-
const char *val, __u8 flbas, __u64 *num, __u32 align)
3004+
const char *val, __u8 flbas, __u64 *num, __u64 align)
30053005
{
30063006
_cleanup_free_ struct nvme_ns_list *ns_list = NULL;
30073007
_cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
@@ -3134,8 +3134,8 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
31343134
uint16_t phndl[128] = { 0, };
31353135
_cleanup_free_ struct nvme_id_ctrl *id = NULL;
31363136
_cleanup_free_ struct nvme_id_ns_granularity_list *gr_list = NULL;
3137-
__u32 align_nsze = 1 << 20; /* Default 1 MiB */
3138-
__u32 align_ncap = align_nsze;
3137+
__u64 align_nsze = 1 << 20; /* Default 1 MiB */
3138+
__u64 align_ncap = align_nsze;
31393139
nvme_print_flags_t flags;
31403140

31413141
struct config {
@@ -3284,7 +3284,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
32843284
int index = cfg.flbas;
32853285

32863286
/* FIXME: add a proper bitmask to libnvme */
3287-
if (!(gr_list->attributes & 1)) {
3287+
if (!(le32_to_cpu(gr_list->attributes) & 1)) {
32883288
/* Only the first descriptor is valid */
32893289
index = 0;
32903290
} else if (index > gr_list->num_descriptors) {
@@ -3296,10 +3296,18 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
32963296
}
32973297
desc = &gr_list->entry[index];
32983298

3299-
if (desc->nszegran && desc->nszegran < align_nsze)
3300-
align_nsze = desc->nszegran;
3301-
if (desc->ncapgran && desc->ncapgran < align_ncap)
3302-
align_ncap = desc->ncapgran;
3299+
if (desc->nszegran) {
3300+
print_info("enforce nsze alignment to %"PRIx64
3301+
" because of namespace granularity requirements\n",
3302+
le64_to_cpu(desc->nszegran));
3303+
align_nsze = le64_to_cpu(desc->nszegran);
3304+
}
3305+
if (desc->ncapgran) {
3306+
print_info("enforce ncap alignment to %"PRIx64
3307+
" because of namespace granularity requirements\n",
3308+
le64_to_cpu(desc->ncapgran));
3309+
align_ncap = le64_to_cpu(desc->ncapgran);
3310+
}
33033311
}
33043312
}
33053313

0 commit comments

Comments
 (0)