All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] Misc. corrections
@ 2020-03-26 18:07 Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 1/7] README: Update URL for configshell-fb Tony Asleson
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

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

v2:
* Updated commit msg for README
* nvmetcli: Revert to exiting non-zero for 'errors' present
* Updated commit msg for test_nvmet.py change
* Added new commit for reporting restore file name correctly

Tony Asleson (7):
  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: test_invalid_input fails for py3
  nvmetcli: Report save name correctly

 README              |  2 +-
 nvmet/__init__.py   |  3 ++-
 nvmet/nvme.py       | 17 +++++++++++++++--
 nvmet/test_nvmet.py |  2 +-
 nvmetcli            | 22 ++++++++++++++++++----
 5 files changed, 37 insertions(+), 9 deletions(-)

-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/7] README: Update URL for configshell-fb
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 2/7] nvmetcli: Improve IOError handling on restore Tony Asleson
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

The github repository was moved. There is a github redirect,
so this change is not strictly required.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 README | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README b/README
index c8717e8..5a4ecd1 100644
--- a/README
+++ b/README
@@ -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.
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/7] nvmetcli: Improve IOError handling on restore
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 1/7] README: Update URL for configshell-fb Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 3/7] nvme.py: Explicit close is redundant Tony Asleson
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

Not all IOErrors are caused by specifying 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.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 nvmetcli | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/nvmetcli b/nvmetcli
index 3d8c16e..a646232 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -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,16 +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)
 
+    # These errors are non-fatal
     for error in errors:
         print(error)
 
+    sys.exit(0)
+
 
 def clear(unused):
     nvme.Root().clear_existing()
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/7] nvme.py: Explicit close is redundant
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 1/7] README: Update URL for configshell-fb Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 2/7] nvmetcli: Improve IOError handling on restore Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 4/7] nvme.py: Sync the containing directory Tony Asleson
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

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

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 nvmet/nvme.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/nvmet/nvme.py b/nvmet/nvme.py
index 0647ddc..55c3930 100644
--- a/nvmet/nvme.py
+++ b/nvmet/nvme.py
@@ -302,7 +302,6 @@ class Root(CFSNode):
             f.write("\n")
             f.flush()
             os.fsync(f.fileno())
-            f.close()
 
         os.rename(savefile + ".temp", savefile)
 
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/7] nvme.py: Sync the containing directory
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
                   ` (2 preceding siblings ...)
  2020-03-26 18:07 ` [PATCH v2 3/7] nvme.py: Explicit close is redundant Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 5/7] nvme.py: Make modprobe work for kmod lib too Tony Asleson
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

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/

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 nvmet/nvme.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/nvmet/nvme.py b/nvmet/nvme.py
index 55c3930..4817124 100644
--- a/nvmet/nvme.py
+++ b/nvmet/nvme.py
@@ -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.
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/7] nvme.py: Make modprobe work for kmod lib too
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
                   ` (3 preceding siblings ...)
  2020-03-26 18:07 ` [PATCH v2 4/7] nvme.py: Sync the containing directory Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 6/7] test_nvmet.py: test_invalid_input fails for py3 Tony Asleson
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

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

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 nvmet/nvme.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/nvmet/nvme.py b/nvmet/nvme.py
index 4817124..089bafb 100644
--- a/nvmet/nvme.py
+++ b/nvmet/nvme.py
@@ -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()
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/7] test_nvmet.py: test_invalid_input fails for py3
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
                   ` (4 preceding siblings ...)
  2020-03-26 18:07 ` [PATCH v2 5/7] nvme.py: Make modprobe work for kmod lib too Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-03-26 18:07 ` [PATCH v2 7/7] nvmetcli: Report save name correctly Tony Asleson
  2020-04-01  9:03 ` [PATCH v2 0/7] Misc. corrections Christoph Hellwig
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

When you run 'make test' 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

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

Both have "string.ascii_lowercase" so lets leverage that to
support both.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 nvmet/test_nvmet.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nvmet/test_nvmet.py b/nvmet/test_nvmet.py
index 5caa546..aae4a86 100644
--- a/nvmet/test_nvmet.py
+++ b/nvmet/test_nvmet.py
@@ -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')
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 7/7] nvmetcli: Report save name correctly
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
                   ` (5 preceding siblings ...)
  2020-03-26 18:07 ` [PATCH v2 6/7] test_nvmet.py: test_invalid_input fails for py3 Tony Asleson
@ 2020-03-26 18:07 ` Tony Asleson
  2020-04-01  9:03 ` [PATCH v2 0/7] Misc. corrections Christoph Hellwig
  7 siblings, 0 replies; 9+ messages in thread
From: Tony Asleson @ 2020-03-26 18:07 UTC (permalink / raw)
  To: linux-nvme

When a user simply does 'nvmetcli restore' without
specifying a file name the default is used.  However, if the
restore fails you end up with the error message:

Error processing config file at None, error [Errno 1] Operation not
permitted: '/sys/kernel/config/nvmet/ports/0/ana_groups/1', exiting

Correct file name if None in error path.

Error processing config file at /etc/nvmet/config.json, error \
[Errno 1] Operation not permitted: \
'/sys/kernel/config/nvmet/ports/1/ana_groups/1', exiting

Signed-off-by: Tony Asleson <tasleson@redhat.com>
---
 nvmet/__init__.py | 3 ++-
 nvmetcli          | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/nvmet/__init__.py b/nvmet/__init__.py
index ca05de4..cf172bd 100644
--- a/nvmet/__init__.py
+++ b/nvmet/__init__.py
@@ -1 +1,2 @@
-from .nvme import Root, Subsystem, Namespace, Port, Host, Referral, ANAGroup
+from .nvme import Root, Subsystem, Namespace, Port, Host, Referral, ANAGroup,\
+    DEFAULT_SAVE_FILE
diff --git a/nvmetcli b/nvmetcli
index a646232..8ee8590 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -680,6 +680,9 @@ def restore(from_file):
     try:
         errors = nvme.Root().restore_from_file(from_file)
     except IOError as e:
+        if not from_file:
+            from_file = nvme.DEFAULT_SAVE_FILE
+
         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)
-- 
2.25.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/7] Misc. corrections
  2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
                   ` (6 preceding siblings ...)
  2020-03-26 18:07 ` [PATCH v2 7/7] nvmetcli: Report save name correctly Tony Asleson
@ 2020-04-01  9:03 ` Christoph Hellwig
  7 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2020-04-01  9:03 UTC (permalink / raw)
  To: Tony Asleson; +Cc: linux-nvme

Thanks Tony,

I've applied all your patches.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-04-01  9:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26 18:07 [PATCH v2 0/7] Misc. corrections Tony Asleson
2020-03-26 18:07 ` [PATCH v2 1/7] README: Update URL for configshell-fb Tony Asleson
2020-03-26 18:07 ` [PATCH v2 2/7] nvmetcli: Improve IOError handling on restore Tony Asleson
2020-03-26 18:07 ` [PATCH v2 3/7] nvme.py: Explicit close is redundant Tony Asleson
2020-03-26 18:07 ` [PATCH v2 4/7] nvme.py: Sync the containing directory Tony Asleson
2020-03-26 18:07 ` [PATCH v2 5/7] nvme.py: Make modprobe work for kmod lib too Tony Asleson
2020-03-26 18:07 ` [PATCH v2 6/7] test_nvmet.py: test_invalid_input fails for py3 Tony Asleson
2020-03-26 18:07 ` [PATCH v2 7/7] nvmetcli: Report save name correctly Tony Asleson
2020-04-01  9:03 ` [PATCH v2 0/7] Misc. corrections Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.