Skip to contentSkip to conversation

block: Make block error codes consistent

PATCH In review Wensheng Tang 2 participants 2 messages May 12, 2019 – May 13, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Make block error codes consistent

(The last email does not include signed-off-by line. Please ignoreit)

We should keep the error handling consistent. ENOMEDIUM is more meaningful than ENOENT a when driver cannot be loaded.

---
 block.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
block.c +3 -3
index 5c2c6aa..6685be7 100644
@@ -770,7 +770,7 @@ static int find_image_format(BlockBackend *file, const char *filename,
     if (!drv) {
         error_setg(errp, "Could not determine image format: No compatible "
                    "driver found");
-        ret = -ENOENT;
+        ret = -ENOMEDIUM;
     }
     *pdrv = drv;
     return ret;
@@ -1619,7 +1619,7 @@ static int bdrv_fill_options(QDict **options, const char *filename,
         drv = bdrv_find_format(drvname);
         if (!drv) {
             error_setg(errp, "Unknown driver '%s'", drvname);
-            return -ENOENT;
+            return -ENOMEDIUM;
         }
         /* If the user has explicitly specified the driver, this choice should
          * override the BDRV_O_PROTOCOL flag */
@@ -1655,7 +1655,7 @@ static int bdrv_fill_options(QDict **options, const char *filename,
         if (filename) {
             drv = bdrv_find_protocol(filename, parse_filename, errp);
             if (!drv) {
-                return -EINVAL;
+                return -ENOMEDIUM;
             }
 
             drvname = drv->format_name;
Signature · 1 line
2.20.1 (Apple Git-117)
#1 lore raw
Quoted 4 lines · Wensheng Tang

(The last email does not include signed-off-by line. Please ignoreit)

We should keep the error handling consistent. ENOMEDIUM is more meaningful than ENOENT a when driver cannot be loaded.

Consistent with what?

Why is it more meaningful?

I might argue that any one of ENODEV, EINVAL, ENOSYS, ENOTSUP, or EPROTONOSUPPORT might be more meaningful than ENOENT or ENOMEDIUM, but it depends on what people expect and why.

Quoted 37 lines
---
 block.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
block.c +3 -3
index 5c2c6aa..6685be7 100644
@@ -770,7 +770,7 @@ static int find_image_format(BlockBackend *file, const char *filename,
     if (!drv) {
         error_setg(errp, "Could not determine image format: No compatible "
                    "driver found");
-        ret = -ENOENT;
+        ret = -ENOMEDIUM;
     }
     *pdrv = drv;
     return ret;
@@ -1619,7 +1619,7 @@ static int bdrv_fill_options(QDict **options, const char *filename,
         drv = bdrv_find_format(drvname);
         if (!drv) {
             error_setg(errp, "Unknown driver '%s'", drvname);
-            return -ENOENT;
+            return -ENOMEDIUM;
         }
         /* If the user has explicitly specified the driver, this choice should
          * override the BDRV_O_PROTOCOL flag */
@@ -1655,7 +1655,7 @@ static int bdrv_fill_options(QDict **options, const char *filename,
         if (filename) {
             drv = bdrv_find_protocol(filename, parse_filename, errp);
             if (!drv) {
-                return -EINVAL;
+                return -ENOMEDIUM;
             }
 
             drvname = drv->format_name;