提交 9e694d9c 编写于 作者: T Toshi Kani 提交者: Dan Williams

libnvdimm, label: change nvdimm_num_label_slots per UEFI 2.7

sizeof_namespace_index() fails when NVDIMM devices have the minimum
1024 bytes label storage area.  nvdimm_num_label_slots() returns 3
slots while the area is only big enough for 2 slots.

Change nvdimm_num_label_slots() to calculate a number of label slots
according to UEFI 2.7 spec.
Signed-off-by: NToshi Kani <toshi.kani@hpe.com>
Signed-off-by: NDan Williams <dan.j.williams@intel.com>
上级 36de6f51
...@@ -45,9 +45,27 @@ unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd) ...@@ -45,9 +45,27 @@ unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd)
return ndd->nslabel_size; return ndd->nslabel_size;
} }
static size_t __sizeof_namespace_index(u32 nslot)
{
return ALIGN(sizeof(struct nd_namespace_index) + DIV_ROUND_UP(nslot, 8),
NSINDEX_ALIGN);
}
static int __nvdimm_num_label_slots(struct nvdimm_drvdata *ndd,
size_t index_size)
{
return (ndd->nsarea.config_size - index_size * 2) /
sizeof_namespace_label(ndd);
}
int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd) int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd)
{ {
return ndd->nsarea.config_size / (sizeof_namespace_label(ndd) + 1); u32 tmp_nslot, n;
tmp_nslot = ndd->nsarea.config_size / sizeof_namespace_label(ndd);
n = __sizeof_namespace_index(tmp_nslot) / NSINDEX_ALIGN;
return __nvdimm_num_label_slots(ndd, NSINDEX_ALIGN * n);
} }
size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd) size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd)
...@@ -55,18 +73,14 @@ size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd) ...@@ -55,18 +73,14 @@ size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd)
u32 nslot, space, size; u32 nslot, space, size;
/* /*
* The minimum index space is 512 bytes, with that amount of * Per UEFI 2.7, the minimum size of the Label Storage Area is large
* index we can describe ~1400 labels which is less than a byte * enough to hold 2 index blocks and 2 labels. The minimum index
* of overhead per label. Round up to a byte of overhead per * block size is 256 bytes, and the minimum label size is 256 bytes.
* label and determine the size of the index region. Yes, this
* starts to waste space at larger config_sizes, but it's
* unlikely we'll ever see anything but 128K.
*/ */
nslot = nvdimm_num_label_slots(ndd); nslot = nvdimm_num_label_slots(ndd);
space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd); space = ndd->nsarea.config_size - nslot * sizeof_namespace_label(ndd);
size = ALIGN(sizeof(struct nd_namespace_index) + DIV_ROUND_UP(nslot, 8), size = __sizeof_namespace_index(nslot) * 2;
NSINDEX_ALIGN) * 2; if (size <= space && nslot >= 2)
if (size <= space)
return size / 2; return size / 2;
dev_err(ndd->dev, "label area (%d) too small to host (%d byte) labels\n", dev_err(ndd->dev, "label area (%d) too small to host (%d byte) labels\n",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册