Skip to contentSkip to conversation

raw-posix: Better error return values for hdev_create

PATCH Applied Kevin Wolf 3 participants 3 messages Mar 12, 2010 – Mar 27, 2010 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 raw-posix: Better error return values for hdev_create

Now that we output an error message according to the returned error code in qemu-img, let's return the real error codes. "Input/output error" for everything isn't helpful.

---
 block/raw-posix.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
block/raw-posix.c +3 -3
index 716c15c..f07d730 100644
@@ -1009,12 +1009,12 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
 
     fd = open(filename, O_WRONLY | O_BINARY);
     if (fd < 0)
-        return -EIO;
+        return -errno;
 
     if (fstat(fd, &stat_buf) < 0)
-        ret = -EIO;
+        ret = -errno;
     else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode))
-        ret = -EIO;
+        ret = -ENODEV;
     else if (lseek(fd, 0, SEEK_END) < total_size * 512)
         ret = -ENOSPC;
 
Signature · 1 line
1.6.6.1
#2 lore raw
In reply to Kevin Wolf
Quoted 5 lines · Kevin Wolf

Now that we output an error message according to the returned error code in qemu-img, let's return the real error codes. "Input/output error" for everything isn't helpful.

Thanks, applied.

Quoted 30 lines
---
 block/raw-posix.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
block/raw-posix.c +3 -3
index 716c15c..f07d730 100644
@@ -1009,12 +1009,12 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
 
     fd = open(filename, O_WRONLY | O_BINARY);
     if (fd < 0)
-        return -EIO;
+        return -errno;
 
     if (fstat(fd, &stat_buf) < 0)
-        ret = -EIO;
+        ret = -errno;
     else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode))
-        ret = -EIO;
+        ret = -ENODEV;
     else if (lseek(fd, 0, SEEK_END) < total_size * 512)
         ret = -ENOSPC;
 
Signature · 1 line
1.6.6.1
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net