Patchwork [v2] block: output more error messages if failed to create temporary snapshot

login
register
mail settings
Submitter dunrong huang
Date Sept. 5, 2012, 9:55 a.m.
Message ID <1346838932-29658-1-git-send-email-riegamaths@gmail.com>
Download mbox | patch
Permalink /patch/181836/
State New
Headers show

Comments

dunrong huang - Sept. 5, 2012, 9:55 a.m.
From: Dunrong Huang <riegamaths@gmail.com>

If we failed to create temporary snapshot, the error message did not match
with the error, for example:

$ TMPDIR=/tmp/bad_path qemu-system-x86_64 -enable-kvm debian.qcow2 -snapshot
qemu-system-x86_64: -enable-kvm: could not open disk image /home/mathslinux/Images/debian.qcow2: No such file or directory

Indeed, the file which cant be created is /tmp/bad_path/vl.xxxxxx,  not
debian.qcow2. so the error message makes users feel confused.

Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
---
v1 -> v2:
   Output error message only if fd < 0
 block.c | 7 ++++++-
 1 个文件被修改,插入 6 行(+),删除 1 行(-)

Patch

diff --git a/block.c b/block.c
index 470bdcc..2dd0c5b 100644
--- a/block.c
+++ b/block.c
@@ -433,7 +433,12 @@  int get_tmp_filename(char *filename, int size)
         return -EOVERFLOW;
     }
     fd = mkstemp(filename);
-    if (fd < 0 || close(fd)) {
+    if (fd < 0) {
+        fprintf(stderr, "Could not create temporary snapshot in %s directory: "
+                "%s\n", tmpdir, strerror(errno));
+        return -errno;
+    }
+    if (close(fd) != 0) {
         return -errno;
     }
     return 0;