From: Greg Kurz <groug@kaod.org>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>, Greg Kurz <groug@kaod.org>
Subject: [Qemu-devel] [PULL 12/14] fsdev: improve error handling of backend init
Date: Mon, 8 Jan 2018 15:28:29 +0100 [thread overview]
Message-ID: <20180108142831.6638-13-groug@kaod.org> (raw)
In-Reply-To: <20180108142831.6638-1-groug@kaod.org>
This patch changes some error messages in the backend init code and
convert backends to propagate QEMU Error objects instead of calling
error_report().
One notable improvement is that the local backend now provides a more
detailed error report when it fails to open the shared directory.
Signed-off-by: Greg Kurz <groug@kaod.org>
---
fsdev/file-op-9p.h | 2 +-
hw/9pfs/9p-handle.c | 2 +-
hw/9pfs/9p-local.c | 3 ++-
hw/9pfs/9p-proxy.c | 14 +++++++-------
hw/9pfs/9p-synth.c | 2 +-
hw/9pfs/9p.c | 6 +++---
6 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index b6d4eaffe32b..3fa062b39f1b 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -104,7 +104,7 @@ void cred_init(FsCred *);
struct FileOperations
{
int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp);
- int (*init)(FsContext *);
+ int (*init)(FsContext *, Error **errp);
void (*cleanup)(FsContext *);
int (*lstat)(FsContext *, V9fsPath *, struct stat *);
ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t);
diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c
index e50941075bda..c5adfe6f3a96 100644
--- a/hw/9pfs/9p-handle.c
+++ b/hw/9pfs/9p-handle.c
@@ -604,7 +604,7 @@ static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
#endif
}
-static int handle_init(FsContext *ctx)
+static int handle_init(FsContext *ctx, Error **errp)
{
int ret, mnt_id;
struct statfs stbuf;
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index e1a4b844a527..b25c185ff030 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -1400,13 +1400,14 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
#endif
}
-static int local_init(FsContext *ctx)
+static int local_init(FsContext *ctx, Error **errp)
{
struct statfs stbuf;
LocalData *data = g_malloc(sizeof(*data));
data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY);
if (data->mountfd == -1) {
+ error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root);
goto err;
}
diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index f6fb7a408fd1..f030c6a42844 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -1083,25 +1083,25 @@ static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path,
return err;
}
-static int connect_namedsocket(const char *path)
+static int connect_namedsocket(const char *path, Error **errp)
{
int sockfd, size;
struct sockaddr_un helper;
if (strlen(path) >= sizeof(helper.sun_path)) {
- error_report("Socket name too long");
+ error_setg(errp, "socket name too long");
return -1;
}
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd < 0) {
- error_report("Failed to create socket: %s", strerror(errno));
+ error_setg_errno(errp, errno, "failed to create client socket");
return -1;
}
strcpy(helper.sun_path, path);
helper.sun_family = AF_UNIX;
size = strlen(helper.sun_path) + sizeof(helper.sun_family);
if (connect(sockfd, (struct sockaddr *)&helper, size) < 0) {
- error_report("Failed to connect to %s: %s", path, strerror(errno));
+ error_setg_errno(errp, errno, "failed to connect to '%s'", path);
close(sockfd);
return -1;
}
@@ -1144,17 +1144,17 @@ static int proxy_parse_opts(QemuOpts *opts, FsDriverEntry *fs, Error **errp)
return 0;
}
-static int proxy_init(FsContext *ctx)
+static int proxy_init(FsContext *ctx, Error **errp)
{
V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy));
int sock_id;
if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
- sock_id = connect_namedsocket(ctx->fs_root);
+ sock_id = connect_namedsocket(ctx->fs_root, errp);
} else {
sock_id = atoi(ctx->fs_root);
if (sock_id < 0) {
- error_report("Socket descriptor not initialized");
+ error_setg(errp, "socket descriptor not initialized");
}
}
if (sock_id < 0) {
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index df0a8de08aed..8f255e91c00f 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -514,7 +514,7 @@ static int synth_unlinkat(FsContext *ctx, V9fsPath *dir,
return -1;
}
-static int synth_init(FsContext *ctx)
+static int synth_init(FsContext *ctx, Error **errp)
{
QLIST_INIT(&synth_root.child);
qemu_mutex_init(&synth_mutex);
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 1e4ebbe57687..909a61139405 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3542,9 +3542,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **errp)
s->fid_list = NULL;
qemu_co_rwlock_init(&s->rename_lock);
- if (s->ops->init(&s->ctx) < 0) {
- error_setg(errp, "9pfs Failed to initialize fs-driver with id:%s"
- " and export path:%s", s->fsconf.fsdev_id, s->ctx.fs_root);
+ if (s->ops->init(&s->ctx, errp) < 0) {
+ error_prepend(errp, "cannot initialize fsdev '%s': ",
+ s->fsconf.fsdev_id);
goto out;
}
--
2.13.6
next prev parent reply other threads:[~2018-01-08 14:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-08 14:28 [Qemu-devel] [PULL 00/14] 9p patches for 2.12 20180108 Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 01/14] virtio-9p: move unrealize/realize after virtio_9p_transport definition Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 02/14] 9pfs: fix XattrOperations typedef Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 03/14] fsdev: fix some type definitions Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 04/14] 9pfs: " Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 05/14] 9pfs: handle: fix type definition Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 06/14] 9pfs: fix type in *_parse_opts declarations Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 07/14] 9pfs: fix error path in pdu_submit() Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 08/14] 9pfs: make pdu_marshal() and pdu_unmarshal() static functions Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 09/14] tests: virtio-9p: fix ISR dependence Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 10/14] tests: virtio-9p: set DRIVER_OK before using the device Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 11/14] fsdev: improve error handling of backend opts parsing Greg Kurz
2018-01-08 14:28 ` Greg Kurz [this message]
2018-01-08 14:28 ` [Qemu-devel] [PULL 13/14] 9pfs: deprecate handle backend Greg Kurz
2018-01-08 14:28 ` [Qemu-devel] [PULL 14/14] MAINTAINERS: Drop Aneesh as 9pfs maintainer Greg Kurz
2018-01-09 9:47 ` [Qemu-devel] [PULL 00/14] 9p patches for 2.12 20180108 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=20180108142831.6638-13-groug@kaod.org \
--to=groug@kaod.org \
--cc=peter.maydell@linaro.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).