linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] nvmetcli: Misc. corrections
@ 2020-03-20 20:39 Tony Asleson
  2020-03-20 20:39 ` [PATCH 1/6] README: Update URL for configshell-fb Tony Asleson
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Tony Asleson @ 2020-03-20 20:39 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.

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(-)

-- 
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] 12+ messages in thread

* [PATCH 1/6] README: Update URL for configshell-fb
  2020-03-20 20:39 [PATCH 0/6] nvmetcli: Misc. corrections Tony Asleson
@ 2020-03-20 20:39 ` Tony Asleson
  2020-03-21  0:47   ` Chaitanya Kulkarni
  2020-03-20 20:39 ` [PATCH 2/6] nvmetcli: Improve IOError handling on restore Tony Asleson
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Tony Asleson @ 2020-03-20 20:39 UTC (permalink / raw)
  To: linux-nvme

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] 12+ messages in thread

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

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.

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

diff --git a/nvmetcli b/nvmetcli
index 3d8c16e..5553721 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,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):
-- 
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] 12+ messages in thread

* [PATCH 3/6] nvme.py: Explicit close is redundant
  2020-03-20 20:39 [PATCH 0/6] nvmetcli: Misc. corrections Tony Asleson
  2020-03-20 20:39 ` [PATCH 1/6] README: Update URL for configshell-fb Tony Asleson
  2020-03-20 20:39 ` [PATCH 2/6] nvmetcli: Improve IOError handling on restore Tony Asleson
@ 2020-03-20 20:39 ` Tony Asleson
  2020-03-21  1:06   ` Chaitanya Kulkarni
  2020-03-20 20:39 ` [PATCH 4/6] nvme.py: Sync the containing directory Tony Asleson
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ messages in thread
From: Tony Asleson @ 2020-03-20 20:39 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] 12+ messages in thread

* [PATCH 4/6] nvme.py: Sync the containing directory
  2020-03-20 20:39 [PATCH 0/6] nvmetcli: Misc. corrections Tony Asleson
                   ` (2 preceding siblings ...)
  2020-03-20 20:39 ` [PATCH 3/6] nvme.py: Explicit close is redundant Tony Asleson
@ 2020-03-20 20:39 ` Tony Asleson
  2020-03-20 20:39 ` [PATCH 5/6] nvme.py: Make modprobe work for kmod lib too Tony Asleson
  2020-03-20 20:39 ` [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase Tony Asleson
  5 siblings, 0 replies; 12+ messages in thread
From: Tony Asleson @ 2020-03-20 20:39 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] 12+ messages in thread

* [PATCH 5/6] nvme.py: Make modprobe work for kmod lib too
  2020-03-20 20:39 [PATCH 0/6] nvmetcli: Misc. corrections Tony Asleson
                   ` (3 preceding siblings ...)
  2020-03-20 20:39 ` [PATCH 4/6] nvme.py: Sync the containing directory Tony Asleson
@ 2020-03-20 20:39 ` Tony Asleson
  2020-03-20 20:39 ` [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase Tony Asleson
  5 siblings, 0 replies; 12+ messages in thread
From: Tony Asleson @ 2020-03-20 20:39 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] 12+ messages in thread

* [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase
  2020-03-20 20:39 [PATCH 0/6] nvmetcli: Misc. corrections Tony Asleson
                   ` (4 preceding siblings ...)
  2020-03-20 20:39 ` [PATCH 5/6] nvme.py: Make modprobe work for kmod lib too Tony Asleson
@ 2020-03-20 20:39 ` Tony Asleson
  2020-03-21  1:12   ` Chaitanya Kulkarni
  5 siblings, 1 reply; 12+ messages in thread
From: Tony Asleson @ 2020-03-20 20:39 UTC (permalink / raw)
  To: linux-nvme

This exists for both py2 & py3.

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] 12+ messages in thread

* Re: [PATCH 1/6] README: Update URL for configshell-fb
  2020-03-20 20:39 ` [PATCH 1/6] README: Update URL for configshell-fb Tony Asleson
@ 2020-03-21  0:47   ` Chaitanya Kulkarni
  2020-03-21  2:49     ` Tony Asleson
  0 siblings, 1 reply; 12+ messages in thread
From: Chaitanya Kulkarni @ 2020-03-21  0:47 UTC (permalink / raw)
  To: Tony Asleson, linux-nvme

On 03/20/2020 01:42 PM, Tony Asleson wrote:
>   Installation
>   ------------
>   Please install the configshell-fb package from
> -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.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

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

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

* Re: [PATCH 3/6] nvme.py: Explicit close is redundant
  2020-03-20 20:39 ` [PATCH 3/6] nvme.py: Explicit close is redundant Tony Asleson
@ 2020-03-21  1:06   ` Chaitanya Kulkarni
  0 siblings, 0 replies; 12+ messages in thread
From: Chaitanya Kulkarni @ 2020-03-21  1:06 UTC (permalink / raw)
  To: Tony Asleson, linux-nvme

On 03/20/2020 01:43 PM, Tony Asleson wrote:
> 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>
Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

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

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

* Re: [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase
  2020-03-20 20:39 ` [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase Tony Asleson
@ 2020-03-21  1:12   ` Chaitanya Kulkarni
  2020-03-21  2:34     ` Tony Asleson
  0 siblings, 1 reply; 12+ messages in thread
From: Chaitanya Kulkarni @ 2020-03-21  1:12 UTC (permalink / raw)
  To: Tony Asleson, linux-nvme

On 03/20/2020 01:42 PM, Tony Asleson wrote:
> This exists for both py2 & py3.
>
> Signed-off-by: Tony Asleson<tasleson@redhat.com>

Can commit message be more descriptive here ?

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

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

* Re: [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase
  2020-03-21  1:12   ` Chaitanya Kulkarni
@ 2020-03-21  2:34     ` Tony Asleson
  0 siblings, 0 replies; 12+ messages in thread
From: Tony Asleson @ 2020-03-21  2:34 UTC (permalink / raw)
  To: linux-nvme

On 3/20/20 8:12 PM, Chaitanya Kulkarni wrote:
> On 03/20/2020 01:42 PM, Tony Asleson wrote:
>> This exists for both py2 & py3.
>>
>> Signed-off-by: Tony Asleson<tasleson@redhat.com>
> 
> 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
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH 1/6] README: Update URL for configshell-fb
  2020-03-21  0:47   ` Chaitanya Kulkarni
@ 2020-03-21  2:49     ` Tony Asleson
  0 siblings, 0 replies; 12+ messages in thread
From: Tony Asleson @ 2020-03-21  2:49 UTC (permalink / raw)
  To: Chaitanya Kulkarni, linux-nvme

On 3/20/20 7:47 PM, Chaitanya Kulkarni wrote:
> On 03/20/2020 01:42 PM, Tony Asleson wrote:
>>   Installation
>>   ------------
>>   Please install the configshell-fb package from
>> -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
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, other threads:[~2020-03-21  2:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20 20:39 [PATCH 0/6] nvmetcli: Misc. corrections Tony Asleson
2020-03-20 20:39 ` [PATCH 1/6] README: Update URL for configshell-fb Tony Asleson
2020-03-21  0:47   ` Chaitanya Kulkarni
2020-03-21  2:49     ` Tony Asleson
2020-03-20 20:39 ` [PATCH 2/6] nvmetcli: Improve IOError handling on restore Tony Asleson
2020-03-20 20:39 ` [PATCH 3/6] nvme.py: Explicit close is redundant Tony Asleson
2020-03-21  1:06   ` Chaitanya Kulkarni
2020-03-20 20:39 ` [PATCH 4/6] nvme.py: Sync the containing directory Tony Asleson
2020-03-20 20:39 ` [PATCH 5/6] nvme.py: Make modprobe work for kmod lib too Tony Asleson
2020-03-20 20:39 ` [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase Tony Asleson
2020-03-21  1:12   ` Chaitanya Kulkarni
2020-03-21  2:34     ` Tony Asleson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).