Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: fix lba_count size calculation #803

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/nvme/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,7 @@ struct __mi_mctp_socket_ops {
};
void __nvme_mi_mctp_set_ops(const struct __mi_mctp_socket_ops *newops);

#define SECTOR_SIZE 512
#define SECTOR_SHIFT 9

#endif /* _LIBNVME_PRIVATE_H */
8 changes: 7 additions & 1 deletion src/nvme/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2442,11 +2442,12 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns)
{
_cleanup_free_ char *attr = NULL;
struct stat sb;
uint64_t size;
int ret;

struct sysfs_attr_table base[] = {
{ &ns->nsid, nvme_strtou32, true, "nsid" },
{ &ns->lba_count, nvme_strtou64, true, "size" },
{ &size, nvme_strtou64, true, "size" },
{ &ns->lba_size, nvme_strtou64, true, "queue/logical_block_size" },
{ ns->eui64, nvme_strtoeuid, false, "eui" },
{ ns->nguid, nvme_strtouuid, false, "nguid" },
Expand All @@ -2458,6 +2459,11 @@ static int nvme_ns_init(const char *path, struct nvme_ns *ns)
return ret;

ns->lba_shift = GETSHIFT(ns->lba_size);
/*
* size is in 512 bytes units and lba_count is in lba_size which are not
* necessarily the same.
*/
ns->lba_count = size >> (ns->lba_shift - SECTOR_SHIFT);

if (asprintf(&attr, "%s/csi", path) < 0)
return -errno;
Expand Down