Skip to contentSkip to conversation

nvmetcli: Misc. corrections

PATCH Superseded Tony Asleson 2 participants 12 messages Mar 20, 2020 – Mar 21, 2020 NVMe

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover nvmetcli: Misc. corrections

While trying to experiment with nvmetcli I've run into a few issues. Some changes that I believe are beneficial.

Tony Asleson (6):
README: Update URL for configshell-fb
nvmetcli: Improve IOError handling on restore
nvme.py: Explicit close is redundant
nvme.py: Sync the containing directory
nvme.py: Make modprobe work for kmod lib too
test_nvmet.py: Use string.ascii_lowercase

 README              |  2 +-
 nvmet/nvme.py       | 17 +++++++++++++++--
 nvmet/test_nvmet.py |  2 +-
 nvmetcli            | 24 ++++++++++++++++++------
 4 files changed, 35 insertions(+), 10 deletions(-)
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#1 lore raw

PATCH 1/6 README: Update URL for configshell-fb

---
 README | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
README +1 -1
index c8717e8..5a4ecd1 100644
@@ -7,7 +7,7 @@ to save, restore or clear the current NVMe target configuration.
 Installation
 ------------
 Please install the configshell-fb package from
-https://github.com/agrover/configshell-fb first.
+https://github.com/open-iscsi/configshell-fb first.
 
 nvmetcli can be run directly from the source directory or installed
 using setup.py.
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] README: Update URL for configshell-fb

README to save, restore or clear the current NVMe target configuration. · line 10

Quoted 5 lines · Tony Asleson

Installation
------------
Please install the configshell-fb package from

README +1 -1
-https://github.com/agrover/configshell-fb first.
+https://github.com/open-iscsi/configshell-fb first.

The link is not broken yet. The agrover is now redirected to the open-iscsi automatically by the github, so do we need this ?

Anyways, looks good.

_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#3 lore raw

Re: [PATCH 1/6] README: Update URL for configshell-fb

Quoted 9 lines · Chaitanya Kulkarni

README to save, restore or clear the current NVMe target configuration. · line 10

Quoted 5 lines · Tony Asleson

Installation
------------
Please install the configshell-fb package from

README +1 -1
-https://github.com/agrover/configshell-fb first.
+https://github.com/open-iscsi/configshell-fb first.

The link is not broken yet. The agrover is now redirected to the open-iscsi automatically by the github, so do we need this ?

Technically at the moment the link is getting redirected to the correct location, it's not broken "yet".

However, I think it's better that a user ends up where the link shows instead of them wondering why they put one thing in their URL and ended up at a different one.

_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#4 lore raw

PATCH 2/6 nvmetcli: Improve IOError handling on restore

In reply to Tony Asleson

Not all IOErrors are caused by specifing a missing configuration file. When the file is present, dump the error exception text too, so the user has a better idea what is wrong.

---
 nvmetcli | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
nvmetcli +18 -6
index 3d8c16e..5553721 100755
@@ -24,6 +24,7 @@ import os
 import sys
 import configshell_fb as configshell
 import nvmet as nvme
+import errno
 from string import hexdigits
 import uuid
 
@@ -674,15 +675,26 @@ def save(to_file):
 
 
 def restore(from_file):
+    errors = None
+
     try:
         errors = nvme.Root().restore_from_file(from_file)
-    except IOError:
-        # Not an error if the restore file is not present
-        print("No saved config file at %s, ok, exiting" % from_file)
-    sys.exit(0)
+    except IOError as e:
+        if e.errno == errno.ENOENT:
+            # Not an error if the restore file is not present
+            print("No saved config file at %s, ok, exiting" % from_file)
+            sys.exit(0)
+        else:
+            print("Error processing config file at %s, error %s, exiting" %
+                  (from_file, str(e)))
+            sys.exit(1)
 
-    for error in errors:
-        print(error)
+    if errors:
+        for error in errors:
+            print(error)
+        sys.exit(1)
+
+    sys.exit(0)
 
 
 def clear(unused):
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#5 lore raw

PATCH 3/6 nvme.py: Explicit close is redundant

In reply to Tony Asleson

One of the benefits of using 'with' statement for open files is the close is going to be called regardless of what happens.

---
 nvmet/nvme.py | 1 -
 1 file changed, 1 deletion(-)
nvmet/nvme.py +0 -1
index 0647ddc..55c3930 100644
@@ -302,7 +302,6 @@ class Root(CFSNode):
             f.write("\n")
             f.flush()
             os.fsync(f.fileno())
-            f.close()
 
         os.rename(savefile + ".temp", savefile)
 
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] nvme.py: Explicit close is redundant

Quoted 4 lines · Tony Asleson

One of the benefits of using 'with' statement for open files is the close is going to be called regardless of what happens.

Looks good.

_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#7 lore raw

PATCH 4/6 nvme.py: Sync the containing directory

In reply to Tony Asleson

It's apparent that some thought went into making sure the config file makes it atomically to the fs. However, one thing is missing which is doing a fsync on the containing directory of the config file.

See: https://lwn.net/Articles/457667/

---
 nvmet/nvme.py | 9 +++++++++
 1 file changed, 9 insertions(+)
nvmet/nvme.py +9 -0
index 55c3930..4817124 100644
@@ -305,6 +305,15 @@ class Root(CFSNode):
 
         os.rename(savefile + ".temp", savefile)
 
+        # Sync the containing directory too
+        dir_fd = None
+        try:
+            dir_fd = os.open(savefile_dir, os.O_RDONLY)
+            os.fsync(dir_fd)
+        finally:
+            if dir_fd:
+                os.close(dir_fd)
+
     def clear_existing(self):
         '''
         Remove entire current configuration.
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#8 lore raw

PATCH 5/6 nvme.py: Make modprobe work for kmod lib too

In reply to Tony Asleson

The python library 'kmod' is included with libkmod, lets try to use that if the user isn't utilizing kmodpy.

---
 nvmet/nvme.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
nvmet/nvme.py +6 -1
index 4817124..089bafb 100644
@@ -253,7 +253,12 @@ class Root(CFSNode):
             except kmod.KmodError:
                 pass
         except ImportError:
-            pass
+            # Try the ctypes library included with the libkmod itself.
+            try:
+                import kmod
+                kmod.Kmod().modprobe(modname)
+            except Exception as e:
+                pass
 
     def _list_subsystems(self):
         self._check_self()
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#9 lore raw

PATCH 6/6 test_nvmet.py: Use string.ascii_lowercase

In reply to Tony Asleson

This exists for both py2 & py3.

---
 nvmet/test_nvmet.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nvmet/test_nvmet.py +1 -1
index 5caa546..aae4a86 100644
@@ -391,7 +391,7 @@ class TestNvmet(unittest.TestCase):
                           nqn='/', mode='create')
 
         for l in [ 257, 512, 1024, 2048 ]:
-            toolong = ''.join(random.choice(string.lowercase)
+            toolong = ''.join(random.choice(string.ascii_lowercase)
                               for i in range(l))
             self.assertRaises(nvme.CFSError, nvme.Subsystem,
                               nqn=toolong, mode='create')
Signature · 7 lines
2.25.1


_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
#11 lore raw

Re: [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase

Quoted 6 lines · Chaitanya Kulkarni
Quoted 3 lines · Tony Asleson

This exists for both py2 & py3.

Can commit message be more descriptive here ?

Sure, how about

test_nvmet.py: test_invalid_input fails on python 3

When you run attempt to run 'make test' on a system using python 3 the unit test test_invalid_input fails with:

Traceback (most recent call last):
File "/someuser/projects/nvmetcli/nvmet/test_nvmet.py", line 395, in
test_invalid_input
for i in range(l))
File "/someuser/projects/nvmetcli/nvmet/test_nvmet.py", line 395, in
<genexpr>
for i in range(l))
AttributeError: module 'string' has no attribute 'lowercase'

Python 3 does not have 'string.lowercase' ref.
https://docs.python.org/3/library/string.html

Both python 2 and python 3 have "string.ascii_lowercase". Use it instead so that the code works for both python 2 and python 3.

ref. https://docs.python.org/2/library/string.html

_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme