nvmetcli: Misc. corrections
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
PATCH 1/6 README: Update URL for configshell-fb
--- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
README +1 -1
@@ -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
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 fromREADME +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
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 fromREADME +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
PATCH 2/6 nvmetcli: Improve IOError handling on restore
In reply to Tony AslesonNot 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
@@ -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
PATCH 3/6 nvme.py: Explicit close is redundant
In reply to Tony AslesonOne 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
@@ -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
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.
Signed-off-by Tony Asleson<[email protected]>
Looks good.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 4/6 nvme.py: Sync the containing directory
In reply to Tony AslesonIt'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
@@ -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
PATCH 5/6 nvme.py: Make modprobe work for kmod lib too
In reply to Tony AslesonThe 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
@@ -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
PATCH 6/6 test_nvmet.py: Use string.ascii_lowercase
In reply to Tony AslesonThis exists for both py2 & py3.
--- nvmet/test_nvmet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nvmet/test_nvmet.py +1 -1
@@ -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
Re: [PATCH 6/6] test_nvmet.py: Use string.ascii_lowercase
Quoted 3 lines · Tony Asleson
This exists for both py2 & py3.
Signed-off-by Tony Asleson<[email protected]>
Can commit message be more descriptive here ?
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
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.
Signed-off-by Tony Asleson<[email protected]>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, intest_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