diff mbox

[ndctl] ndctl: hide null uuids

Message ID 152700595304.1878.15402579458295755554.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams May 22, 2018, 4:19 p.m. UTC
Clean up the namespace listing to hide the 'raw_uuid' field when it is
zero.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/json.c |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Verma, Vishal L May 23, 2018, 5:45 p.m. UTC | #1
On Tue, 2018-05-22 at 09:19 -0700, Dan Williams wrote:
> Clean up the namespace listing to hide the 'raw_uuid' field when it is
> zero.
> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  util/json.c |   19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)

Looks good, applied.

> 
> diff --git a/util/json.c b/util/json.c
> index 1772177a8abd..c606e1cdf770 100644
> --- a/util/json.c
> +++ b/util/json.c
> @@ -652,10 +652,12 @@ static struct json_object
> *util_dax_badblocks_to_json(struct ndctl_dax *dax,
>  
>  static struct json_object *util_raw_uuid(struct ndctl_namespace *ndns)
>  {
> -	uuid_t raw_uuid;
>  	char buf[40];
> +	uuid_t raw_uuid;
>  
>  	ndctl_namespace_get_uuid(ndns, raw_uuid);
> +	if (uuid_is_null(raw_uuid))
> +		return NULL;
>  	uuid_unparse(raw_uuid, buf);
>  	return json_object_new_string(buf);
>  }
> @@ -734,9 +736,8 @@ struct json_object *util_namespace_to_json(struct
> ndctl_namespace *ndns,
>  		json_object_object_add(jndns, "uuid", jobj);
>  
>  		jobj = util_raw_uuid(ndns);
> -		if (!jobj)
> -			goto err;
> -		json_object_object_add(jndns, "raw_uuid", jobj);
> +		if (jobj)
> +			json_object_object_add(jndns, "raw_uuid", jobj);
>  		bdev = ndctl_btt_get_block_device(btt);
>  	} else if (pfn) {
>  		ndctl_pfn_get_uuid(pfn, uuid);
> @@ -746,9 +747,8 @@ struct json_object *util_namespace_to_json(struct
> ndctl_namespace *ndns,
>  			goto err;
>  		json_object_object_add(jndns, "uuid", jobj);
>  		jobj = util_raw_uuid(ndns);
> -		if (!jobj)
> -			goto err;
> -		json_object_object_add(jndns, "raw_uuid", jobj);
> +		if (jobj)
> +			json_object_object_add(jndns, "raw_uuid", jobj);
>  		bdev = ndctl_pfn_get_block_device(pfn);
>  	} else if (dax) {
>  		struct daxctl_region *dax_region;
> @@ -761,9 +761,8 @@ struct json_object *util_namespace_to_json(struct
> ndctl_namespace *ndns,
>  			goto err;
>  		json_object_object_add(jndns, "uuid", jobj);
>  		jobj = util_raw_uuid(ndns);
> -		if (!jobj)
> -			goto err;
> -		json_object_object_add(jndns, "raw_uuid", jobj);
> +		if (jobj)
> +			json_object_object_add(jndns, "raw_uuid", jobj);
>  		if ((flags & UTIL_JSON_DAX) && dax_region) {
>  			jobj = util_daxctl_region_to_json(dax_region,
> NULL,
>  					flags);
>
diff mbox

Patch

diff --git a/util/json.c b/util/json.c
index 1772177a8abd..c606e1cdf770 100644
--- a/util/json.c
+++ b/util/json.c
@@ -652,10 +652,12 @@  static struct json_object *util_dax_badblocks_to_json(struct ndctl_dax *dax,
 
 static struct json_object *util_raw_uuid(struct ndctl_namespace *ndns)
 {
-	uuid_t raw_uuid;
 	char buf[40];
+	uuid_t raw_uuid;
 
 	ndctl_namespace_get_uuid(ndns, raw_uuid);
+	if (uuid_is_null(raw_uuid))
+		return NULL;
 	uuid_unparse(raw_uuid, buf);
 	return json_object_new_string(buf);
 }
@@ -734,9 +736,8 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 		json_object_object_add(jndns, "uuid", jobj);
 
 		jobj = util_raw_uuid(ndns);
-		if (!jobj)
-			goto err;
-		json_object_object_add(jndns, "raw_uuid", jobj);
+		if (jobj)
+			json_object_object_add(jndns, "raw_uuid", jobj);
 		bdev = ndctl_btt_get_block_device(btt);
 	} else if (pfn) {
 		ndctl_pfn_get_uuid(pfn, uuid);
@@ -746,9 +747,8 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 			goto err;
 		json_object_object_add(jndns, "uuid", jobj);
 		jobj = util_raw_uuid(ndns);
-		if (!jobj)
-			goto err;
-		json_object_object_add(jndns, "raw_uuid", jobj);
+		if (jobj)
+			json_object_object_add(jndns, "raw_uuid", jobj);
 		bdev = ndctl_pfn_get_block_device(pfn);
 	} else if (dax) {
 		struct daxctl_region *dax_region;
@@ -761,9 +761,8 @@  struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 			goto err;
 		json_object_object_add(jndns, "uuid", jobj);
 		jobj = util_raw_uuid(ndns);
-		if (!jobj)
-			goto err;
-		json_object_object_add(jndns, "raw_uuid", jobj);
+		if (jobj)
+			json_object_object_add(jndns, "raw_uuid", jobj);
 		if ((flags & UTIL_JSON_DAX) && dax_region) {
 			jobj = util_daxctl_region_to_json(dax_region, NULL,
 					flags);