* [ndctl PATCH] test, libndctl: check btt size
@ 2016-08-25 23:58 Dan Williams
2016-08-26 16:31 ` Vishal Verma
0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2016-08-25 23:58 UTC (permalink / raw)
To: linux-nvdimm
Now that the kernel reports the size of the btt, lets check that the
size stays constant across kernel updates. I.e. if we inadvertently
introduce a change that causes the btt to reduce the effective capacity
of the block device, this test is meant to catch it.
Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
test/libndctl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/test/libndctl.c b/test/libndctl.c
index 5f86addc5c7e..e36fe8a4fe6f 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -937,6 +937,68 @@ static int check_pfn_create(struct ndctl_region *region,
return rc;
}
+static int check_btt_size(struct ndctl_btt *btt)
+{
+ struct ndctl_namespace *ndns = ndctl_btt_get_namespace(btt);
+ unsigned long long ns_size = ndctl_namespace_get_size(ndns);
+ unsigned long sect_size = ndctl_btt_get_sector_size(btt);
+ unsigned long long actual, expect;
+ int size_select, sect_select;
+ unsigned long long expect_table[][2] = {
+ [0] = {
+ [0] = 0x11b4400,
+ [1] = 0x8da2000,
+ },
+ [1] = {
+ [0] = 0x13b0400,
+ [1] = 0x9d82000,
+ },
+ [2] = {
+ [0] = 0x1aa2600,
+ [1] = 0xd513000,
+ },
+ };
+
+ if (sect_size >= SZ_4K)
+ sect_select = 1;
+ else if (sect_size >= 512)
+ sect_select = 0;
+ else {
+ fprintf(stderr, "%s: %s unexpected sector size: %lx\n",
+ __func__, ndctl_btt_get_devname(btt),
+ sect_size);
+ return -ENXIO;
+ }
+
+ switch (ns_size) {
+ case SZ_18M:
+ size_select = 0;
+ break;
+ case SZ_20M:
+ size_select = 1;
+ break;
+ case SZ_27M:
+ size_select = 2;
+ break;
+ default:
+ fprintf(stderr, "%s: %s unexpected namespace size: %llx\n",
+ __func__, ndctl_namespace_get_devname(ndns),
+ ns_size);
+ break;
+ }
+
+ expect = expect_table[size_select][sect_select];
+ actual = ndctl_btt_get_size(btt);
+ if (expect != actual) {
+ fprintf(stderr, "%s: namespace: %s unexpected size: %llx (expected: %llx)\n",
+ ndctl_btt_get_devname(btt),
+ ndctl_namespace_get_devname(ndns), actual, expect);
+ return -ENXIO;
+ }
+
+ return 0;
+}
+
static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace *ndns,
struct namespace *namespace)
{
@@ -982,6 +1044,10 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace
fprintf(stderr, "%s: expected safe mode got: %d\n",
devname, mode);
+ rc = check_btt_size(btt);
+ if (rc)
+ goto err;
+
if (btt_seed == ndctl_region_get_btt_seed(region)
&& btt == btt_seed) {
fprintf(stderr, "%s: failed to advance btt seed\n",
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [ndctl PATCH] test, libndctl: check btt size
2016-08-25 23:58 [ndctl PATCH] test, libndctl: check btt size Dan Williams
@ 2016-08-26 16:31 ` Vishal Verma
0 siblings, 0 replies; 2+ messages in thread
From: Vishal Verma @ 2016-08-26 16:31 UTC (permalink / raw)
To: Dan Williams; +Cc: linux-nvdimm
On 08/25, Dan Williams wrote:
> Now that the kernel reports the size of the btt, lets check that the
> size stays constant across kernel updates. I.e. if we inadvertently
> introduce a change that causes the btt to reduce the effective capacity
> of the block device, this test is meant to catch it.
>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> test/libndctl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 66 insertions(+)
>
Good idea!
Reviewed-by: Vishal Verma <vishal.l.verma@intel.com>
> diff --git a/test/libndctl.c b/test/libndctl.c
> index 5f86addc5c7e..e36fe8a4fe6f 100644
> --- a/test/libndctl.c
> +++ b/test/libndctl.c
> @@ -937,6 +937,68 @@ static int check_pfn_create(struct ndctl_region *region,
> return rc;
> }
>
> +static int check_btt_size(struct ndctl_btt *btt)
> +{
> + struct ndctl_namespace *ndns = ndctl_btt_get_namespace(btt);
> + unsigned long long ns_size = ndctl_namespace_get_size(ndns);
> + unsigned long sect_size = ndctl_btt_get_sector_size(btt);
> + unsigned long long actual, expect;
> + int size_select, sect_select;
> + unsigned long long expect_table[][2] = {
> + [0] = {
> + [0] = 0x11b4400,
> + [1] = 0x8da2000,
> + },
> + [1] = {
> + [0] = 0x13b0400,
> + [1] = 0x9d82000,
> + },
> + [2] = {
> + [0] = 0x1aa2600,
> + [1] = 0xd513000,
> + },
> + };
> +
> + if (sect_size >= SZ_4K)
> + sect_select = 1;
> + else if (sect_size >= 512)
> + sect_select = 0;
> + else {
> + fprintf(stderr, "%s: %s unexpected sector size: %lx\n",
> + __func__, ndctl_btt_get_devname(btt),
> + sect_size);
> + return -ENXIO;
> + }
> +
> + switch (ns_size) {
> + case SZ_18M:
> + size_select = 0;
> + break;
> + case SZ_20M:
> + size_select = 1;
> + break;
> + case SZ_27M:
> + size_select = 2;
> + break;
> + default:
> + fprintf(stderr, "%s: %s unexpected namespace size: %llx\n",
> + __func__, ndctl_namespace_get_devname(ndns),
> + ns_size);
> + break;
> + }
> +
> + expect = expect_table[size_select][sect_select];
> + actual = ndctl_btt_get_size(btt);
> + if (expect != actual) {
> + fprintf(stderr, "%s: namespace: %s unexpected size: %llx (expected: %llx)\n",
> + ndctl_btt_get_devname(btt),
> + ndctl_namespace_get_devname(ndns), actual, expect);
> + return -ENXIO;
> + }
> +
> + return 0;
> +}
> +
> static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace *ndns,
> struct namespace *namespace)
> {
> @@ -982,6 +1044,10 @@ static int check_btt_create(struct ndctl_region *region, struct ndctl_namespace
> fprintf(stderr, "%s: expected safe mode got: %d\n",
> devname, mode);
>
> + rc = check_btt_size(btt);
> + if (rc)
> + goto err;
> +
> if (btt_seed == ndctl_region_get_btt_seed(region)
> && btt == btt_seed) {
> fprintf(stderr, "%s: failed to advance btt seed\n",
>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-26 16:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-25 23:58 [ndctl PATCH] test, libndctl: check btt size Dan Williams
2016-08-26 16:31 ` Vishal Verma
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.