Blame SOURCES/kvm-file-posix-Use-error-API-properly.patch

7711c0
From a36c6beb5f5a2a02f805bcbf6303e3c6ab908c95 Mon Sep 17 00:00:00 2001
7711c0
From: Kevin Wolf <kwolf@redhat.com>
7711c0
Date: Fri, 15 Mar 2019 18:10:05 +0100
7711c0
Subject: [PATCH 009/163] file-posix: Use error API properly
7711c0
7711c0
RH-Author: Kevin Wolf <kwolf@redhat.com>
7711c0
Message-id: <20190315181010.14964-10-kwolf@redhat.com>
7711c0
Patchwork-id: 84886
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 09/14] file-posix: Use error API properly
7711c0
Bugzilla: 1685989
7711c0
RH-Acked-by: John Snow <jsnow@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Fam Zheng <famz@redhat.com>
7711c0
7711c0
Use error_report for situations that affect user operation (i.e.  we're
7711c0
actually returning error), and warn_report/warn_report_err when some
7711c0
less critical error happened but the user operation can still carry on.
7711c0
7711c0
For raw_normalize_devicepath, add Error parameter to propagate to
7711c0
its callers.
7711c0
7711c0
Suggested-by: Markus Armbruster <armbru@redhat.com>
7711c0
Signed-off-by: Fam Zheng <famz@redhat.com>
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
(cherry picked from commit db0754df88e3ca4797539c1edbde596d871b64b6)
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/file-posix.c | 39 ++++++++++++++++-----------------------
7711c0
 1 file changed, 16 insertions(+), 23 deletions(-)
7711c0
7711c0
diff --git a/block/file-posix.c b/block/file-posix.c
7711c0
index deecf58..419781c 100644
7711c0
--- a/block/file-posix.c
7711c0
+++ b/block/file-posix.c
7711c0
@@ -207,7 +207,7 @@ static int cdrom_reopen(BlockDriverState *bs);
7711c0
 #endif
7711c0
 
7711c0
 #if defined(__NetBSD__)
7711c0
-static int raw_normalize_devicepath(const char **filename)
7711c0
+static int raw_normalize_devicepath(const char **filename, Error **errp)
7711c0
 {
7711c0
     static char namebuf[PATH_MAX];
7711c0
     const char *dp, *fname;
7711c0
@@ -216,8 +216,7 @@ static int raw_normalize_devicepath(const char **filename)
7711c0
     fname = *filename;
7711c0
     dp = strrchr(fname, '/');
7711c0
     if (lstat(fname, &sb) < 0) {
7711c0
-        fprintf(stderr, "%s: stat failed: %s\n",
7711c0
-            fname, strerror(errno));
7711c0
+        error_setg_errno(errp, errno, "%s: stat failed", fname);
7711c0
         return -errno;
7711c0
     }
7711c0
 
7711c0
@@ -231,14 +230,13 @@ static int raw_normalize_devicepath(const char **filename)
7711c0
         snprintf(namebuf, PATH_MAX, "%.*s/r%s",
7711c0
             (int)(dp - fname), fname, dp + 1);
7711c0
     }
7711c0
-    fprintf(stderr, "%s is a block device", fname);
7711c0
     *filename = namebuf;
7711c0
-    fprintf(stderr, ", using %s\n", *filename);
7711c0
+    warn_report("%s is a block device, using %s", fname, *filename);
7711c0
 
7711c0
     return 0;
7711c0
 }
7711c0
 #else
7711c0
-static int raw_normalize_devicepath(const char **filename)
7711c0
+static int raw_normalize_devicepath(const char **filename, Error **errp)
7711c0
 {
7711c0
     return 0;
7711c0
 }
7711c0
@@ -458,9 +456,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
7711c0
 
7711c0
     filename = qemu_opt_get(opts, "filename");
7711c0
 
7711c0
-    ret = raw_normalize_devicepath(&filename);
7711c0
+    ret = raw_normalize_devicepath(&filename, errp);
7711c0
     if (ret != 0) {
7711c0
-        error_setg_errno(errp, -ret, "Could not normalize device path");
7711c0
         goto fail;
7711c0
     }
7711c0
 
7711c0
@@ -489,11 +486,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
7711c0
     case ON_OFF_AUTO_ON:
7711c0
         s->use_lock = true;
7711c0
         if (!qemu_has_ofd_lock()) {
7711c0
-            fprintf(stderr,
7711c0
-                    "File lock requested but OFD locking syscall is "
7711c0
-                    "unavailable, falling back to POSIX file locks.\n"
7711c0
-                    "Due to the implementation, locks can be lost "
7711c0
-                    "unexpectedly.\n");
7711c0
+            warn_report("File lock requested but OFD locking syscall is "
7711c0
+                        "unavailable, falling back to POSIX file locks");
7711c0
+            error_printf("Due to the implementation, locks can be lost "
7711c0
+                         "unexpectedly.\n");
7711c0
         }
7711c0
         break;
7711c0
     case ON_OFF_AUTO_OFF:
7711c0
@@ -821,7 +817,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
7711c0
             /* Theoretically the above call only unlocks bytes and it cannot
7711c0
              * fail. Something weird happened, report it.
7711c0
              */
7711c0
-            error_report_err(local_err);
7711c0
+            warn_report_err(local_err);
7711c0
         }
7711c0
         break;
7711c0
     case RAW_PL_COMMIT:
7711c0
@@ -831,7 +827,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
7711c0
             /* Theoretically the above call only unlocks bytes and it cannot
7711c0
              * fail. Something weird happened, report it.
7711c0
              */
7711c0
-            error_report_err(local_err);
7711c0
+            warn_report_err(local_err);
7711c0
         }
7711c0
         break;
7711c0
     }
7711c0
@@ -891,10 +887,8 @@ static int raw_reopen_prepare(BDRVReopenState *state,
7711c0
     /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */
7711c0
     if (rs->fd == -1) {
7711c0
         const char *normalized_filename = state->bs->filename;
7711c0
-        ret = raw_normalize_devicepath(&normalized_filename);
7711c0
-        if (ret < 0) {
7711c0
-            error_setg_errno(errp, -ret, "Could not normalize device path");
7711c0
-        } else {
7711c0
+        ret = raw_normalize_devicepath(&normalized_filename, errp);
7711c0
+        if (ret >= 0) {
7711c0
             assert(!(rs->open_flags & O_CREAT));
7711c0
             rs->fd = qemu_open(normalized_filename, rs->open_flags);
7711c0
             if (rs->fd == -1) {
7711c0
@@ -1742,7 +1736,7 @@ static int aio_worker(void *arg)
7711c0
         ret = handle_aiocb_truncate(aiocb);
7711c0
         break;
7711c0
     default:
7711c0
-        fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
7711c0
+        error_report("invalid aio request (0x%x)", aiocb->aio_type);
7711c0
         ret = -EINVAL;
7711c0
         break;
7711c0
     }
7711c0
@@ -2233,7 +2227,7 @@ out_unlock:
7711c0
          * not mean the whole creation operation has failed.  So
7711c0
          * report it the user for their convenience, but do not report
7711c0
          * it to the caller. */
7711c0
-        error_report_err(local_err);
7711c0
+        warn_report_err(local_err);
7711c0
     }
7711c0
 
7711c0
 out_close:
7711c0
@@ -2986,9 +2980,8 @@ static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts *opts
7711c0
 
7711c0
     (void)has_prefix;
7711c0
 
7711c0
-    ret = raw_normalize_devicepath(&filename);
7711c0
+    ret = raw_normalize_devicepath(&filename, errp);
7711c0
     if (ret < 0) {
7711c0
-        error_setg_errno(errp, -ret, "Could not normalize device path");
7711c0
         return ret;
7711c0
     }
7711c0
 
7711c0
-- 
7711c0
1.8.3.1
7711c0