Blame SOURCES/0006-create-remove-stale-hba-only-dir.patch

ec3309
From f06103354394ffa86817696a37edb7ddd351bc10 Mon Sep 17 00:00:00 2001
ec3309
From: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
ec3309
Date: Fri, 9 Feb 2018 17:20:26 +0530
ec3309
Subject: [PATCH] create: remove stale hba-only dir
ec3309
ec3309
curretly if there exist any stale hba-only directories,
ec3309
ec3309
$ ls /sys/kernel/config/target/core/user_0/
ec3309
hba_info  hba_mode
ec3309
ec3309
Then backend creation fails,
ec3309
ec3309
$ targetcli /backstores/fileio create block file 1M
ec3309
This _Backstore already exists in configFS
ec3309
ec3309
We will have to restart target.service or restore the configuration
ec3309
again to clear the stale hba-only dirs.
ec3309
ec3309
This patch checks for hba directory before creating one,
ec3309
if it is already existing and found to be stale then removes it.
ec3309
ec3309
Thanks to "Maurizio Lombardi <mlombard@redhat.com>" for debugging along
ec3309
ec3309
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
ec3309
---
ec3309
 rtslib/node.py | 11 +++++++++--
ec3309
 1 file changed, 9 insertions(+), 2 deletions(-)
ec3309
ec3309
diff --git a/rtslib/node.py b/rtslib/node.py
ec3309
index c0092fc..1d77cd1 100644
ec3309
--- a/rtslib/node.py
ec3309
+++ b/rtslib/node.py
ec3309
@@ -52,9 +52,16 @@ class CFSNode(object):
ec3309
         '''
ec3309
         if mode not in ['any', 'lookup', 'create']:
ec3309
             raise RTSLibError("Invalid mode: %s" % mode)
ec3309
+
ec3309
         if self.exists and mode == 'create':
ec3309
-            raise RTSLibError("This %s already exists in configFS"
ec3309
-                              % self.__class__.__name__)
ec3309
+            # ensure that self.path is not stale hba-only dir
ec3309
+            if os.path.samefile(os.path.dirname(self.path), self.configfs_dir+'/core') \
ec3309
+               and not next(os.walk(self.path))[1]:
ec3309
+                os.rmdir(self.path)
ec3309
+            else:
ec3309
+               raise RTSLibError("This %s already exists in configFS"
ec3309
+                                 % self.__class__.__name__)
ec3309
+
ec3309
         elif not self.exists and mode == 'lookup':
ec3309
             raise RTSLibNotInCFS("No such %s in configfs: %s"
ec3309
                                  % (self.__class__.__name__, self.path))
ec3309
-- 
ec3309
1.8.3.1
ec3309