Linux-NVME Archive on lore.kernel.org
 help / color / Atom feed
From: Tony Asleson <tasleson@redhat.com>
To: linux-nvme@lists.infradead.org
Subject: [PATCH v2 2/7] nvmetcli: Improve IOError handling on restore
Date: Thu, 26 Mar 2020 13:07:45 -0500
Message-ID: <20200326180750.469346-3-tasleson@redhat.com> (raw)
In-Reply-To: <20200326180750.469346-1-tasleson@redhat.com>

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

  parent reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200326180750.469346-3-tasleson@redhat.com \
    --to=tasleson@redhat.com \
    --cc=linux-nvme@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-NVME Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvme/0 linux-nvme/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvme linux-nvme/ https://lore.kernel.org/linux-nvme \
		linux-nvme@lists.infradead.org
	public-inbox-index linux-nvme

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-nvme


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git