All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] file-posix: Use error API properly
@ 2018-10-31  5:39 Fam Zheng
  2018-10-31 14:51 ` Markus Armbruster
  2018-10-31 14:57 ` Eric Blake
  0 siblings, 2 replies; 6+ messages in thread
From: Fam Zheng @ 2018-10-31  5:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, qemu-block, armbru

Use error_report for situations that affect user operation (i.e.  we're
actually returning error), and warn_report/warn_report_err when some
less critical error happened but the user operation can still carry on.

For raw_normalize_devicepath, add Error parameter to propagate to
its callers.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>

---

v2: Add Error ** to raw_normalize_devicepath. [Markus]
    Use error_printf for splitting multi-sentence message. [Markus]
---
 block/file-posix.c | 39 ++++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 23 deletions(-)

diff --git a/block/file-posix.c b/block/file-posix.c
index 2da3a76355..b7f0316005 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -205,7 +205,7 @@ static int cdrom_reopen(BlockDriverState *bs);
 #endif
 
 #if defined(__NetBSD__)
-static int raw_normalize_devicepath(const char **filename)
+static int raw_normalize_devicepath(const char **filename, Error **errp)
 {
     static char namebuf[PATH_MAX];
     const char *dp, *fname;
@@ -214,8 +214,7 @@ static int raw_normalize_devicepath(const char **filename)
     fname = *filename;
     dp = strrchr(fname, '/');
     if (lstat(fname, &sb) < 0) {
-        fprintf(stderr, "%s: stat failed: %s\n",
-            fname, strerror(errno));
+        error_setg(errp, "%s: stat failed: %s", fname, strerror(errno));
         return -errno;
     }
 
@@ -229,14 +228,13 @@ static int raw_normalize_devicepath(const char **filename)
         snprintf(namebuf, PATH_MAX, "%.*s/r%s",
             (int)(dp - fname), fname, dp + 1);
     }
-    fprintf(stderr, "%s is a block device", fname);
     *filename = namebuf;
-    fprintf(stderr, ", using %s\n", *filename);
+    warn_report("%s is a block device, using %s", fname, *filename);
 
     return 0;
 }
 #else
-static int raw_normalize_devicepath(const char **filename)
+static int raw_normalize_devicepath(const char **filename, Error **errp)
 {
     return 0;
 }
@@ -461,9 +459,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
 
     filename = qemu_opt_get(opts, "filename");
 
-    ret = raw_normalize_devicepath(&filename);
+    ret = raw_normalize_devicepath(&filename, errp);
     if (ret != 0) {
-        error_setg_errno(errp, -ret, "Could not normalize device path");
         goto fail;
     }
 
@@ -492,11 +489,10 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
     case ON_OFF_AUTO_ON:
         s->use_lock = true;
         if (!qemu_has_ofd_lock()) {
-            fprintf(stderr,
-                    "File lock requested but OFD locking syscall is "
-                    "unavailable, falling back to POSIX file locks.\n"
-                    "Due to the implementation, locks can be lost "
-                    "unexpectedly.\n");
+            warn_report("File lock requested but OFD locking syscall is "
+                        "unavailable, falling back to POSIX file locks");
+            error_printf("Due to the implementation, locks can be lost "
+                         "unexpectedly.\n");
         }
         break;
     case ON_OFF_AUTO_OFF:
@@ -805,7 +801,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
             /* Theoretically the above call only unlocks bytes and it cannot
              * fail. Something weird happened, report it.
              */
-            error_report_err(local_err);
+            warn_report_err(local_err);
         }
         break;
     case RAW_PL_COMMIT:
@@ -815,7 +811,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
             /* Theoretically the above call only unlocks bytes and it cannot
              * fail. Something weird happened, report it.
              */
-            error_report_err(local_err);
+            warn_report_err(local_err);
         }
         break;
     }
@@ -892,10 +888,8 @@ static int raw_reopen_prepare(BDRVReopenState *state,
     /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */
     if (rs->fd == -1) {
         const char *normalized_filename = state->bs->filename;
-        ret = raw_normalize_devicepath(&normalized_filename);
-        if (ret < 0) {
-            error_setg_errno(errp, -ret, "Could not normalize device path");
-        } else {
+        ret = raw_normalize_devicepath(&normalized_filename, errp);
+        if (ret >= 0) {
             assert(!(rs->open_flags & O_CREAT));
             rs->fd = qemu_open(normalized_filename, rs->open_flags);
             if (rs->fd == -1) {
@@ -1775,7 +1769,7 @@ static int aio_worker(void *arg)
         ret = handle_aiocb_truncate(aiocb);
         break;
     default:
-        fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type);
+        error_report("invalid aio request (0x%x)", aiocb->aio_type);
         ret = -EINVAL;
         break;
     }
@@ -2263,7 +2257,7 @@ out_unlock:
          * not mean the whole creation operation has failed.  So
          * report it the user for their convenience, but do not report
          * it to the caller. */
-        error_report_err(local_err);
+        warn_report_err(local_err);
     }
 
 out_close:
@@ -3128,9 +3122,8 @@ static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts *opts
 
     (void)has_prefix;
 
-    ret = raw_normalize_devicepath(&filename);
+    ret = raw_normalize_devicepath(&filename, errp);
     if (ret < 0) {
-        error_setg_errno(errp, -ret, "Could not normalize device path");
         return ret;
     }
 
-- 
2.17.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2] file-posix: Use error API properly
  2018-10-31  5:39 [Qemu-devel] [PATCH v2] file-posix: Use error API properly Fam Zheng
@ 2018-10-31 14:51 ` Markus Armbruster
  2018-11-01  6:27   ` Fam Zheng
  2018-10-31 14:57 ` Eric Blake
  1 sibling, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2018-10-31 14:51 UTC (permalink / raw)
  To: Fam Zheng; +Cc: qemu-devel, Kevin Wolf, armbru, qemu-block, Max Reitz

Fam Zheng <famz@redhat.com> writes:

> Use error_report for situations that affect user operation (i.e.  we're
> actually returning error), and warn_report/warn_report_err when some
> less critical error happened but the user operation can still carry on.
>
> For raw_normalize_devicepath, add Error parameter to propagate to
> its callers.
>
> Suggested-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>

Kevin, if you'd prefer this to go through my tree, let me know.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2] file-posix: Use error API properly
  2018-10-31  5:39 [Qemu-devel] [PATCH v2] file-posix: Use error API properly Fam Zheng
  2018-10-31 14:51 ` Markus Armbruster
@ 2018-10-31 14:57 ` Eric Blake
  2018-10-31 16:05   ` Philippe Mathieu-Daudé
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Blake @ 2018-10-31 14:57 UTC (permalink / raw)
  To: Fam Zheng, qemu-devel; +Cc: Kevin Wolf, armbru, qemu-block, Max Reitz

On 10/31/18 12:39 AM, Fam Zheng wrote:
> Use error_report for situations that affect user operation (i.e.  we're
> actually returning error), and warn_report/warn_report_err when some
> less critical error happened but the user operation can still carry on.
> 
> For raw_normalize_devicepath, add Error parameter to propagate to
> its callers.
> 
> Suggested-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> 

> @@ -214,8 +214,7 @@ static int raw_normalize_devicepath(const char **filename)
>       fname = *filename;
>       dp = strrchr(fname, '/');
>       if (lstat(fname, &sb) < 0) {
> -        fprintf(stderr, "%s: stat failed: %s\n",
> -            fname, strerror(errno));
> +        error_setg(errp, "%s: stat failed: %s", fname, strerror(errno));
>           return -errno;

error_setg_errno() is nicer here.  In fact, should we have a Coverity 
script that looks for error_setg(... strerror())?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2] file-posix: Use error API properly
  2018-10-31 14:57 ` Eric Blake
@ 2018-10-31 16:05   ` Philippe Mathieu-Daudé
  2018-10-31 16:53     ` Eric Blake
  0 siblings, 1 reply; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-10-31 16:05 UTC (permalink / raw)
  To: Eric Blake, Fam Zheng, qemu-devel
  Cc: Kevin Wolf, armbru, qemu-block, Max Reitz

On 31/10/18 15:57, Eric Blake wrote:
> On 10/31/18 12:39 AM, Fam Zheng wrote:
...
>> -        fprintf(stderr, "%s: stat failed: %s\n",
>> -            fname, strerror(errno));
>> +        error_setg(errp, "%s: stat failed: %s", fname, strerror(errno));
>>           return -errno;
> 
> error_setg_errno() is nicer here.  In fact, should we have a Coverity 
> script that looks for error_setg(... strerror())?
> 

Coverity -> Coccinelle?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2] file-posix: Use error API properly
  2018-10-31 16:05   ` Philippe Mathieu-Daudé
@ 2018-10-31 16:53     ` Eric Blake
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2018-10-31 16:53 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Fam Zheng, qemu-devel
  Cc: Kevin Wolf, armbru, qemu-block, Max Reitz

On 10/31/18 11:05 AM, Philippe Mathieu-Daudé wrote:
> On 31/10/18 15:57, Eric Blake wrote:
>> On 10/31/18 12:39 AM, Fam Zheng wrote:
> ...
>>> -        fprintf(stderr, "%s: stat failed: %s\n",
>>> -            fname, strerror(errno));
>>> +        error_setg(errp, "%s: stat failed: %s", fname, 
>>> strerror(errno));
>>>           return -errno;
>>
>> error_setg_errno() is nicer here.  In fact, should we have a Coverity 
>> script that looks for error_setg(... strerror())?
>>
> 
> Coverity -> Coccinelle?

Yes. (Is it okay if I begin my defense with: They both start with "Co"?)

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2] file-posix: Use error API properly
  2018-10-31 14:51 ` Markus Armbruster
@ 2018-11-01  6:27   ` Fam Zheng
  0 siblings, 0 replies; 6+ messages in thread
From: Fam Zheng @ 2018-11-01  6:27 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, Kevin Wolf, qemu-block, Max Reitz

On Wed, 10/31 15:51, Markus Armbruster wrote:
> Fam Zheng <famz@redhat.com> writes:
> 
> > Use error_report for situations that affect user operation (i.e.  we're
> > actually returning error), and warn_report/warn_report_err when some
> > less critical error happened but the user operation can still carry on.
> >
> > For raw_normalize_devicepath, add Error parameter to propagate to
> > its callers.
> >
> > Suggested-by: Markus Armbruster <armbru@redhat.com>
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> 
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> 
> Kevin, if you'd prefer this to go through my tree, let me know.

Thanks for the review. I'll respin and use error_setg_errno as suggested by
Eric, if it's okay.

Fam

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-11-01  6:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31  5:39 [Qemu-devel] [PATCH v2] file-posix: Use error API properly Fam Zheng
2018-10-31 14:51 ` Markus Armbruster
2018-11-01  6:27   ` Fam Zheng
2018-10-31 14:57 ` Eric Blake
2018-10-31 16:05   ` Philippe Mathieu-Daudé
2018-10-31 16:53     ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.