Misc. corrections
v2 cover Misc. corrections
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(-)
Signature · 7 lines
2.25.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v2 1/7 README: Update URL for configshell-fb
The github repository was moved. There is a github redirect, so this change is not strictly required.
--- 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
PATCH v2 2/7 nvmetcli: Improve IOError handling on restore
In reply to Tony AslesonNot 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.
--- nvmetcli | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
nvmetcli +15 -4
@@ -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()
Signature · 7 lines
2.25.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v2 3/7 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
PATCH v2 4/7 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 v2 5/7 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 v2 6/7 test_nvmet.py: test_invalid_input fails for py3
In reply to Tony AslesonWhen 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, 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
Python 2 does ref.
https://docs.python.org/2/library/string.html
Both have "string.ascii_lowercase" so lets leverage that to support both.
--- 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
PATCH v2 7/7 nvmetcli: Report save name correctly
In reply to Tony AslesonWhen 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
--- nvmet/__init__.py | 3 ++- nvmetcli | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-)
nvmet/__init__.py +2 -1
@@ -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
nvmetcli +3 -0
@@ -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)
Signature · 7 lines
2.25.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Thanks Tony,
I've applied all your patches.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme