Skip to content

Commit 45a0dac

Browse files
committed
libnvdimm, dax: record the specified alignment of a dax-device instance
We want to use the alignment as the allocation and mapping unit. Previously this information was only useful for establishing the data offset, but now it is important to remember the granularity for the later use. Signed-off-by: Dan Williams <[email protected]>
1 parent 52ac23b commit 45a0dac

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

drivers/nvdimm/pfn.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ struct nd_pfn_sb {
3333
/* minor-version-1 additions for section alignment */
3434
__le32 start_pad;
3535
__le32 end_trunc;
36-
u8 padding[4004];
36+
/* minor-version-2 record the base alignment of the mapping */
37+
__le32 align;
38+
u8 padding[4000];
3739
__le64 checksum;
3840
};
3941

drivers/nvdimm/pfn_devs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn)
394394
pfn_sb->end_trunc = 0;
395395
}
396396

397+
if (__le16_to_cpu(pfn_sb->version_minor) < 2)
398+
pfn_sb->align = 0;
399+
397400
switch (le32_to_cpu(pfn_sb->mode)) {
398401
case PFN_MODE_RAM:
399402
case PFN_MODE_PMEM:
@@ -433,7 +436,7 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn)
433436
return -EBUSY;
434437
}
435438

436-
nd_pfn->align = 1UL << ilog2(offset);
439+
nd_pfn->align = le32_to_cpu(pfn_sb->align);
437440
if (!is_power_of_2(offset) || offset < PAGE_SIZE) {
438441
dev_err(&nd_pfn->dev, "bad offset: %#llx dax disabled\n",
439442
offset);
@@ -629,9 +632,10 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
629632
memcpy(pfn_sb->uuid, nd_pfn->uuid, 16);
630633
memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16);
631634
pfn_sb->version_major = cpu_to_le16(1);
632-
pfn_sb->version_minor = cpu_to_le16(1);
635+
pfn_sb->version_minor = cpu_to_le16(2);
633636
pfn_sb->start_pad = cpu_to_le32(start_pad);
634637
pfn_sb->end_trunc = cpu_to_le32(end_trunc);
638+
pfn_sb->align = cpu_to_le32(nd_pfn->align);
635639
checksum = nd_sb_checksum((struct nd_gen_sb *) pfn_sb);
636640
pfn_sb->checksum = cpu_to_le64(checksum);
637641

0 commit comments

Comments
 (0)