anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone
4a01d4
zero_info_block: skip seed devices
4a01d4
4a01d4
BZ: 
4a01d4
Brew: 
4a01d4
4a01d4
commit fb13dfb8d84c4f0a749665c8f07179450b199f3e
4a01d4
Author: Jeff Moyer <jmoyer@redhat.com>
4a01d4
Date:   Tue Feb 9 16:51:53 2021 -0500
4a01d4
4a01d4
    zero_info_block: skip seed devices
4a01d4
    
4a01d4
    Currently, ndctl destroy-namespace -f all will output errors of the
4a01d4
    form:
4a01d4
    
4a01d4
      Error: destroy namespace: namespace0.0 failed to enable for zeroing, continuing
4a01d4
    
4a01d4
    for any zero-sized namespace.  That particular namespace looks like this:
4a01d4
    
4a01d4
      {
4a01d4
        "dev":"namespace0.0",
4a01d4
        "mode":"raw",
4a01d4
        "size":0,
4a01d4
        "uuid":"00000000-0000-0000-0000-000000000000",
4a01d4
        "sector_size":512,
4a01d4
        "state":"disabled"
4a01d4
      }
4a01d4
    
4a01d4
    This patch skips over namespaces with size=0 when zeroing out info
4a01d4
    blocks.
4a01d4
    
4a01d4
    Fixes: 46654c2d60b70 ("ndctl/namespace: Always zero info-blocks")
4a01d4
    Reported-by: Zhang Yi <yizhan@redhat.com>
4a01d4
    Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
4a01d4
    Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
4a01d4
    Link: https://lore.kernel.org/r/x49r1lohpty.fsf@segfault.boston.devel.redhat.com
4a01d4
4a01d4
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
4a01d4
index 1feb74d..1e8a2cd 100644
4a01d4
--- a/ndctl/namespace.c
4a01d4
+++ b/ndctl/namespace.c
4a01d4
@@ -1052,6 +1052,9 @@ static int zero_info_block(struct ndctl_namespace *ndns)
4a01d4
 	void *buf = NULL, *read_buf = NULL;
4a01d4
 	char path[50];
4a01d4
 
4a01d4
+	if (ndctl_namespace_get_size(ndns) == 0)
4a01d4
+		return 1;
4a01d4
+
4a01d4
 	ndctl_namespace_set_raw_mode(ndns, 1);
4a01d4
 	rc = ndctl_namespace_enable(ndns);
4a01d4
 	if (rc < 0) {