From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 01/14] file-posix: Use error API properly
Date: Mon, 12 Nov 2018 18:05:50 +0100 [thread overview]
Message-ID: <20181112170603.23986-2-kwolf@redhat.com> (raw)
In-Reply-To: <20181112170603.23986-1-kwolf@redhat.com>
From: Fam Zheng <famz@redhat.com>
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>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
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 0c1b81ce4b..074f0ce2b3 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_errno(errp, errno, "%s: stat failed", fname);
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:
@@ -818,7 +814,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:
@@ -828,7 +824,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;
}
@@ -905,10 +901,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) {
@@ -1788,7 +1782,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;
}
@@ -2276,7 +2270,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:
@@ -3141,9 +3135,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.19.1
next prev parent reply other threads:[~2018-11-12 17:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-12 17:05 [Qemu-devel] [PULL 00/14] Block layer patches Kevin Wolf
2018-11-12 17:05 ` Kevin Wolf [this message]
2018-11-12 17:05 ` [Qemu-devel] [PULL 02/14] blockdev: handle error on block latency histogram set error Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 03/14] blockdev: Consistently use snapshot_node_name in external_snapshot_prepare() Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 04/14] nvme: don't unref ctrl_mem when device unrealized Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 05/14] nvme: free cmbuf in nvme_exit Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 06/14] file-posix: Skip effectiveless OFD lock operations Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 07/14] file-posix: Drop s->lock_fd Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 08/14] tests: Add unit tests for image locking Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 09/14] block: Make more block drivers compile-time configurable Kevin Wolf
2018-11-12 17:05 ` [Qemu-devel] [PULL 10/14] job: Fix off-by-one assert checks for JobSTT and JobVerbTable Kevin Wolf
2018-11-12 17:06 ` [Qemu-devel] [PULL 11/14] block: Null pointer dereference in blk_root_get_parent_desc() Kevin Wolf
2018-11-12 17:06 ` [Qemu-devel] [PULL 12/14] qemu-img: assert block_job_get() does not return NULL in img_commit() Kevin Wolf
2018-11-12 17:06 ` [Qemu-devel] [PULL 13/14] block: Fix potential Null pointer dereferences in vvfat.c Kevin Wolf
2018-11-12 17:06 ` [Qemu-devel] [PULL 14/14] qcow2: Read outside array bounds in qcow2_pre_write_overlap_check() Kevin Wolf
2018-11-13 10:14 ` [Qemu-devel] [PULL 00/14] Block layer patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181112170603.23986-2-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).