Skip to content

Commit 014c8e9

Browse files
authored
Merge pull request #164 from sc108-lee/add/flbas_to_lbaf_inuse
util: modify flbas rsvd bits to be used
2 parents 87d04f4 + 563cc59 commit 014c8e9

7 files changed

Lines changed: 48 additions & 23 deletions

File tree

doc/libnvme.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7745,9 +7745,9 @@ Returns true if given offset is 64bit register, otherwise it returns false.
77457745

77467746
**Constants**
77477747

7748-
``NVME_NS_FLBAS_LBA_MASK``
7749-
Mask to get the index of one of the 16 supported
7750-
LBA Formats indicated in :c:type:`struct nvme_id_ns <nvme_id_ns>`.lbaf.
7748+
``NVME_NS_FLBAS_LOWER_MASK``
7749+
Mask to get the index of one of the supported LBA Formats's least significant
7750+
4bits indicated in :c:type:`struct nvme_id_ns <nvme_id_ns>`.lbaf.
77517751

77527752
``NVME_NS_FLBAS_META_EXT``
77537753
Applicable only if format contains metadata. If
@@ -7757,7 +7757,9 @@ Returns true if given offset is 64bit register, otherwise it returns false.
77577757
of the metadata for a command is transferred as a
77587758
separate contiguous buffer of data.
77597759

7760-
7760+
``NVME_NS_FLBAS_HIGHER_MASK``
7761+
Mask to get the index of one of the supported LBA Formats's most significant
7762+
2bits indicated in :c:type:`struct nvme_id_ns <nvme_id_ns>`.lbaf.
77617763

77627764

77637765
.. c:type:: enum nvme_id_ns_mc

doc/man/enum nvme_id_ns_flbas.2

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@ enum nvme_id_ns_flbas \- This field indicates the LBA data size & metadata size
44
.SH SYNOPSIS
55
enum nvme_id_ns_flbas {
66
.br
7-
.BI " NVME_NS_FLBAS_LBA_MASK"
7+
.BI " NVME_NS_FLBAS_LOWER_MASK"
88
,
99
.br
1010
.br
1111
.BI " NVME_NS_FLBAS_META_EXT"
12-
12+
,
13+
.br
14+
.br
15+
.BI " NVME_NS_FLBAS_HIGHER_MASK"
1316
};
1417
.SH Constants
15-
.IP "NVME_NS_FLBAS_LBA_MASK" 12
16-
Mask to get the index of one of the 16 supported
17-
LBA Formats indicated in \fIstruct nvme_id_ns\fP.lbaf.
18+
.IP "NVME_NS_FLBAS_LOWER_MASK" 12
19+
Mask to get the index of one of the supported LBA Formats's
20+
least significant 4bits indicated in \fIstruct nvme_id_ns\fP.lbaf.
21+
1822
.IP "NVME_NS_FLBAS_META_EXT" 12
1923
Applicable only if format contains metadata. If
2024
this bit is set, indicates that the metadata is
2125
transferred at the end of the data LBA, creating an
2226
extended data LBA. If cleared, indicates that all
2327
of the metadata for a command is transferred as a
2428
separate contiguous buffer of data.
29+
30+
.IP "NVME_NS_FLBAS_HIGHER_MASK" 12
31+
Mask to get the index of one of the supported LBA Formats's
32+
most significant 2bits indicated in \fIstruct nvme_id_ns\fP.lbaf.

src/nvme/linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ int nvme_get_ana_log_len(int fd, size_t *analen)
337337
int nvme_get_logical_block_size(int fd, __u32 nsid, int *blksize)
338338
{
339339
struct nvme_id_ns ns;
340-
int flbas;
340+
__u8 flbas;
341341
int ret;
342342

343343
ret = nvme_identify_ns(fd, nsid, &ns);
344344
if (ret)
345345
return ret;
346346

347-
flbas = ns.flbas & NVME_NS_FLBAS_LBA_MASK;
347+
nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &flbas);
348348
*blksize = 1 << ns.lbaf[flbas].ds;
349349

350350
return 0;

src/nvme/tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,14 +1670,14 @@ static int nvme_ns_init(struct nvme_ns *n)
16701670
struct nvme_id_ns ns = { };
16711671
uint8_t buffer[NVME_IDENTIFY_DATA_SIZE] = { };
16721672
struct nvme_ns_id_desc *descs = (void *)buffer;
1673-
int flbas;
1673+
uint8_t flbas;
16741674
int ret;
16751675

16761676
ret = nvme_ns_identify(n, &ns);
16771677
if (ret)
16781678
return ret;
16791679

1680-
flbas = ns.flbas & NVME_NS_FLBAS_LBA_MASK;
1680+
nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &flbas);
16811681
n->lba_shift = ns.lbaf[flbas].ds;
16821682
n->lba_size = 1 << n->lba_shift;
16831683
n->lba_count = le64_to_cpu(ns.nsze);

src/nvme/types.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,18 +1700,25 @@ enum nvme_id_nsfeat {
17001700
* enum nvme_id_ns_flbas - This field indicates the LBA data size & metadata
17011701
* size combination that the namespace has been
17021702
* formatted with
1703-
* @NVME_NS_FLBAS_LBA_MASK: Mask to get the index of one of the 16 supported
1704-
* LBA Formats indicated in &struct nvme_id_ns.lbaf.
1705-
* @NVME_NS_FLBAS_META_EXT: Applicable only if format contains metadata. If
1706-
* this bit is set, indicates that the metadata is
1707-
* transferred at the end of the data LBA, creating an
1708-
* extended data LBA. If cleared, indicates that all
1709-
* of the metadata for a command is transferred as a
1710-
* separate contiguous buffer of data.
1703+
* @NVME_NS_FLBAS_LOWER_MASK: Mask to get the index of one of the supported
1704+
* LBA Formats's least significant
1705+
* 4bits indicated in
1706+
* :c:type:`struct nvme_id_ns <nvme_id_ns>`.lbaf.
1707+
* @NVME_NS_FLBAS_META_EXT: Applicable only if format contains metadata. If
1708+
* this bit is set, indicates that the metadata is
1709+
* transferred at the end of the data LBA, creating an
1710+
* extended data LBA. If cleared, indicates that all
1711+
* of the metadata for a command is transferred as a
1712+
* separate contiguous buffer of data.
1713+
* @NVME_NS_FLBAS_HIGHER_MASK: Mask to get the index of one of
1714+
* the supported LBA Formats's most significant
1715+
* 2bits indicated in
1716+
* :c:type:`struct nvme_id_ns <nvme_id_ns>`.lbaf.
17111717
*/
17121718
enum nvme_id_ns_flbas {
1713-
NVME_NS_FLBAS_LBA_MASK = 15 << 0,
1719+
NVME_NS_FLBAS_LOWER_MASK = 15 << 0,
17141720
NVME_NS_FLBAS_META_EXT = 1 << 4,
1721+
NVME_NS_FLBAS_HIGHER_MASK = 3 << 5,
17151722
};
17161723

17171724
/**

src/nvme/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,10 @@ static inline void nvme_feature_decode_namespace_write_protect(__u32 value,
385385
{
386386
*wps = NVME_FEAT_WP_WPS(value);
387387
}
388+
389+
static inline void nvme_id_ns_flbas_to_lbaf_inuse(__u8 flbas, __u8 *lbaf_inuse)
390+
{
391+
*lbaf_inuse = (((flbas & NVME_NS_FLBAS_HIGHER_MASK) >> 1) \
392+
| (flbas & NVME_NS_FLBAS_LOWER_MASK));
393+
}
388394
#endif /* _LIBNVME_UTIL_H */

test/test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,15 @@ static int test_namespace(nvme_ns_t n)
267267
struct nvme_id_ns ns = { 0 }, allocated = { 0 };
268268
struct nvme_ns_id_desc descs = { 0 };
269269
__u32 result = 0;
270+
__u8 flbas;
270271

271272
ret = nvme_ns_identify(n, &ns);
272273
if (ret)
273274
return ret;
274275

276+
nvme_id_ns_flbas_to_lbaf_inuse(ns.flbas, &flbas);
275277
printf("%s: nsze:%lx lba size:%d\n", nvme_ns_get_name(n), le64_to_cpu(ns.nsze),
276-
1 << ns.lbaf[ns.flbas & NVME_NS_FLBAS_LBA_MASK].ds);
278+
1 << ns.lbaf[flbas].ds);
277279

278280
ret = nvme_identify_allocated_ns(fd, nsid, &allocated);
279281
if (!ret)

0 commit comments

Comments
 (0)