diff mbox

[ndctl,v2,2/2] ndctl: add sector_size to 'ndctl list' output

Message ID 20180126205449.28693-1-ross.zwisler@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ross Zwisler Jan. 26, 2018, 8:54 p.m. UTC
It used to be that the only PMEM namespaces with a variable sector size
were ones with a BTT, but that has changed.  sector_size still doesn't make
sense for device DAX since we don't have a block I/O path.

If we don't have a specified sector size, as happens with namespaces of
devtype nd_namespace_io and older v1.1 namespace labels, we will display
the default sector size of 512.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
---
 util/json.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Comments

Dave Jiang Jan. 26, 2018, 8:56 p.m. UTC | #1
On 01/26/2018 01:54 PM, Ross Zwisler wrote:
> It used to be that the only PMEM namespaces with a variable sector size
> were ones with a BTT, but that has changed.  sector_size still doesn't make
> sense for device DAX since we don't have a block I/O path.
> 
> If we don't have a specified sector size, as happens with namespaces of
> devtype nd_namespace_io and older v1.1 namespace labels, we will display
> the default sector size of 512.
> 
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>   util/json.c | 23 ++++++++++++++++++-----
>   1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/util/json.c b/util/json.c
> index 95beaa2..647bf03 100644
> --- a/util/json.c
> +++ b/util/json.c
> @@ -718,11 +718,6 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
>   			goto err;
>   		json_object_object_add(jndns, "uuid", jobj);
>   
> -		jobj = json_object_new_int(ndctl_btt_get_sector_size(btt));
> -		if (!jobj)
> -			goto err;
> -		json_object_object_add(jndns, "sector_size", jobj);
> -
>   		bdev = ndctl_btt_get_block_device(btt);
>   	} else if (pfn) {
>   		ndctl_pfn_get_uuid(pfn, uuid);
> @@ -774,6 +769,24 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
>   	} else
>   		bdev = ndctl_namespace_get_block_device(ndns);
>   
> +	jobj = NULL;
> +	if (btt) {
> +		jobj = json_object_new_int(ndctl_btt_get_sector_size(btt));
> +		if (!jobj)
> +			goto err;
> +	} else if (!dax) {
> +		unsigned int sector_size = ndctl_namespace_get_sector_size(ndns);
> +
> +		if (!sector_size)
> +			sector_size = 512;
> +
> +		jobj = json_object_new_int(sector_size);
> +		if (!jobj)
> +			goto err;
> +	}
> +	if (jobj)
> +		json_object_object_add(jndns, "sector_size", jobj);
> +
>   	if (bdev && bdev[0]) {
>   		jobj = json_object_new_string(bdev);
>   		if (!jobj)
>
Dan Williams Jan. 26, 2018, 9 p.m. UTC | #2
On Fri, Jan 26, 2018 at 12:54 PM, Ross Zwisler
<ross.zwisler@linux.intel.com> wrote:
> It used to be that the only PMEM namespaces with a variable sector size
> were ones with a BTT, but that has changed.  sector_size still doesn't make
> sense for device DAX since we don't have a block I/O path.
>
> If we don't have a specified sector size, as happens with namespaces of
> devtype nd_namespace_io and older v1.1 namespace labels, we will display
> the default sector size of 512.
>
> Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
> ---
>  util/json.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/util/json.c b/util/json.c
> index 95beaa2..647bf03 100644
> --- a/util/json.c
> +++ b/util/json.c
> @@ -718,11 +718,6 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
>                         goto err;
>                 json_object_object_add(jndns, "uuid", jobj);
>
> -               jobj = json_object_new_int(ndctl_btt_get_sector_size(btt));
> -               if (!jobj)
> -                       goto err;
> -               json_object_object_add(jndns, "sector_size", jobj);
> -
>                 bdev = ndctl_btt_get_block_device(btt);
>         } else if (pfn) {
>                 ndctl_pfn_get_uuid(pfn, uuid);
> @@ -774,6 +769,24 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
>         } else
>                 bdev = ndctl_namespace_get_block_device(ndns);
>
> +       jobj = NULL;
> +       if (btt) {
> +               jobj = json_object_new_int(ndctl_btt_get_sector_size(btt));
> +               if (!jobj)
> +                       goto err;
> +       } else if (!dax) {
> +               unsigned int sector_size = ndctl_namespace_get_sector_size(ndns);
> +

I'd put a comment here that says on kernel's that do not export a
sector_size attribute, or if userspace fails to select a dynamic
sector_size, the kernel default size is 512.
diff mbox

Patch

diff --git a/util/json.c b/util/json.c
index 95beaa2..647bf03 100644
--- a/util/json.c
+++ b/util/json.c
@@ -718,11 +718,6 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 			goto err;
 		json_object_object_add(jndns, "uuid", jobj);
 
-		jobj = json_object_new_int(ndctl_btt_get_sector_size(btt));
-		if (!jobj)
-			goto err;
-		json_object_object_add(jndns, "sector_size", jobj);
-
 		bdev = ndctl_btt_get_block_device(btt);
 	} else if (pfn) {
 		ndctl_pfn_get_uuid(pfn, uuid);
@@ -774,6 +769,24 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 	} else
 		bdev = ndctl_namespace_get_block_device(ndns);
 
+	jobj = NULL;
+	if (btt) {
+		jobj = json_object_new_int(ndctl_btt_get_sector_size(btt));
+		if (!jobj)
+			goto err;
+	} else if (!dax) {
+		unsigned int sector_size = ndctl_namespace_get_sector_size(ndns);
+
+		if (!sector_size)
+			sector_size = 512;
+
+		jobj = json_object_new_int(sector_size);
+		if (!jobj)
+			goto err;
+	}
+	if (jobj)
+		json_object_object_add(jndns, "sector_size", jobj);
+
 	if (bdev && bdev[0]) {
 		jobj = json_object_new_string(bdev);
 		if (!jobj)