From nobody Tue Oct 28 12:17:37 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513606856470336.196607900112; Mon, 18 Dec 2017 06:20:56 -0800 (PST) Received: from localhost ([::1]:39702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQwHk-0002cK-B1 for importer@patchew.org; Mon, 18 Dec 2017 09:20:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQwDS-0007kH-7u for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:16:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQwDK-0001z3-Nf for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:16:26 -0500 Received: from 3.mo1.mail-out.ovh.net ([46.105.60.232]:42862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQwDK-0001wo-AX for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:16:18 -0500 Received: from player691.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id CA9F2B27B9 for ; Mon, 18 Dec 2017 15:16:16 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player691.ha.ovh.net (Postfix) with ESMTPA id ACB6926009D; Mon, 18 Dec 2017 15:16:15 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 15:16:15 +0100 Message-ID: <151360657561.21833.11192135359551870162.stgit@bahia.lan> In-Reply-To: <151360656934.21833.11316709584569537205.stgit@bahia.lan> References: <151360656934.21833.11316709584569537205.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 14821346375621843264 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtuddrgedtgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.60.232 Subject: [Qemu-devel] [PATCH 1/2] fsdev: improve error handling of backend opts parsing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 This patch changes some error messages in the backend opts parsing code and convert backends to propagate QEMU Error objects instead of calling error_report(). Signed-off-by: Greg Kurz --- fsdev/file-op-9p.h | 2 +- fsdev/qemu-fsdev.c | 4 +++- hw/9pfs/9p-handle.c | 3 ++- hw/9pfs/9p-local.c | 34 ++++++++++++++++++++-------------- hw/9pfs/9p-proxy.c | 17 ++++++++++++++--- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 474c79d003f6..74b7b677c21d 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -105,7 +105,7 @@ void cred_init(FsCred *); =20 struct FileOperations { - int (*parse_opts)(QemuOpts *, struct FsDriverEntry *); + int (*parse_opts)(QemuOpts *, struct FsDriverEntry *, Error **errp); int (*init)(struct FsContext *); void (*cleanup)(struct FsContext *); int (*lstat)(FsContext *, V9fsPath *, struct stat *); diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 266e442b871a..941e3096574e 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -37,6 +37,7 @@ int qemu_fsdev_add(QemuOpts *opts) const char *fsdriver =3D qemu_opt_get(opts, "fsdriver"); const char *writeout =3D qemu_opt_get(opts, "writeout"); bool ro =3D qemu_opt_get_bool(opts, "readonly", 0); + Error *local_err =3D NULL; =20 if (!fsdev_id) { error_report("fsdev: No id specified"); @@ -74,7 +75,8 @@ int qemu_fsdev_add(QemuOpts *opts) } =20 if (fsle->fse.ops->parse_opts) { - if (fsle->fse.ops->parse_opts(opts, &fsle->fse)) { + if (fsle->fse.ops->parse_opts(opts, &fsle->fse, &local_err)) { + error_report_err(local_err); g_free(fsle->fse.fsdev_id); g_free(fsle); return -1; diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 9875f1894cc5..9eab01b10582 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -652,7 +652,8 @@ static void handle_cleanup(FsContext *ctx) g_free(data); } =20 -static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) +static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse, + Error **errp) { const char *sec_model =3D qemu_opt_get(opts, "security_model"); const char *path =3D qemu_opt_get(opts, "path"); diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index e51af87309c6..676d60e1a8ef 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1459,16 +1459,22 @@ static void local_cleanup(FsContext *ctx) g_free(data); } =20 -static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) +static void error_append_security_model_hint(Error **errp) +{ + error_append_hint(errp, "Valid options are: security_model=3D" + "[passthrough|mapped-xattr|mapped-file|none]\n"); +} + +static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse, + Error **errp) { const char *sec_model =3D qemu_opt_get(opts, "security_model"); const char *path =3D qemu_opt_get(opts, "path"); - Error *err =3D NULL; + Error *local_err =3D NULL; =20 if (!sec_model) { - error_report("Security model not specified, local fs needs securit= y model"); - error_printf("valid options are:" - "\tsecurity_model=3D[passthrough|mapped-xattr|mapped-= file|none]\n"); + error_setg(errp, "security_model property not set"); + error_append_security_model_hint(errp); return -1; } =20 @@ -1482,20 +1488,20 @@ static int local_parse_opts(QemuOpts *opts, struct = FsDriverEntry *fse) } else if (!strcmp(sec_model, "mapped-file")) { fse->export_flags |=3D V9FS_SM_MAPPED_FILE; } else { - error_report("Invalid security model %s specified", sec_model); - error_printf("valid options are:" - "\t[passthrough|mapped-xattr|mapped-file|none]\n"); + error_setg(errp, "invalid security_model property '%s'", sec_model= ); + error_append_security_model_hint(errp); return -1; } =20 if (!path) { - error_report("fsdev: No path specified"); + error_setg(errp, "path property not set"); return -1; } =20 - fsdev_throttle_parse_opts(opts, &fse->fst, &err); - if (err) { - error_reportf_err(err, "Throttle configuration is not valid: "); + fsdev_throttle_parse_opts(opts, &fse->fst, &local_err); + if (local_err) { + error_propagate(errp, local_err); + error_prepend(errp, "invalid throttle configuration: "); return -1; } =20 @@ -1507,11 +1513,11 @@ static int local_parse_opts(QemuOpts *opts, struct = FsDriverEntry *fse) qemu_opt_get_number(opts, "dmode", SM_LOCAL_DIR_MODE_BITS) & 0= 777; } else { if (qemu_opt_find(opts, "fmode")) { - error_report("fmode is only valid for mapped 9p modes"); + error_setg(errp, "fmode is only valid for mapped security mode= s"); return -1; } if (qemu_opt_find(opts, "dmode")) { - error_report("dmode is only valid for mapped 9p modes"); + error_setg(errp, "dmode is only valid for mapped security mode= s"); return -1; } } diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 28b20a7c3dfa..186fe1d5a8eb 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -1111,17 +1111,28 @@ static int connect_namedsocket(const char *path) return sockfd; } =20 -static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs) +static void error_append_socket_sockfd_hint(Error **errp) +{ + error_append_hint(errp, "Either specify socket=3D/some/path where /som= e/path" + " points to a listening AF_UNIX socket or sock_fd=3D= fd" + " where fd is a file descriptor to a connected AF_UN= IX" + " socket\n"); +} + +static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs, + Error **errp) { const char *socket =3D qemu_opt_get(opts, "socket"); const char *sock_fd =3D qemu_opt_get(opts, "sock_fd"); =20 if (!socket && !sock_fd) { - error_report("Must specify either socket or sock_fd"); + error_setg(errp, "both socket and sock_fd properties are missing"); + error_append_socket_sockfd_hint(errp); return -1; } if (socket && sock_fd) { - error_report("Both socket and sock_fd options specified"); + error_setg(errp, "both socket and sock_fd properties are set"); + error_append_socket_sockfd_hint(errp); return -1; } if (socket) { From nobody Tue Oct 28 12:17:37 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151360683199242.16779980939839; Mon, 18 Dec 2017 06:20:31 -0800 (PST) Received: from localhost ([::1]:39661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQwHN-0002Gk-UB for importer@patchew.org; Mon, 18 Dec 2017 09:20:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQwDY-0007p7-Px for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:16:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQwDS-00026I-LA for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:16:32 -0500 Received: from 2.mo1.mail-out.ovh.net ([178.32.119.250]:38807) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQwDS-00025M-Bi for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:16:26 -0500 Received: from player691.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id E8E25B27DF for ; Mon, 18 Dec 2017 15:16:22 +0100 (CET) Received: from bahia.lan (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player691.ha.ovh.net (Postfix) with ESMTPA id D7EA326009D; Mon, 18 Dec 2017 15:16:21 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 15:16:21 +0100 Message-ID: <151360658178.21833.10761644150673770398.stgit@bahia.lan> In-Reply-To: <151360656934.21833.11316709584569537205.stgit@bahia.lan> References: <151360656934.21833.11316709584569537205.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 14823035226197498176 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtuddrgedtgdeifecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 178.32.119.250 Subject: [Qemu-devel] [PATCH 2/2] fsdev: improve error handling of backend init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 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 --- 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 74b7b677c21d..ac7113cfc712 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -106,7 +106,7 @@ void cred_init(FsCred *); struct FileOperations { int (*parse_opts)(QemuOpts *, struct FsDriverEntry *, Error **errp); - int (*init)(struct FsContext *); + int (*init)(struct FsContext *, Error **errp); void (*cleanup)(struct 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 9eab01b10582..86b7de1187b5 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -604,7 +604,7 @@ static int handle_ioc_getversion(FsContext *ctx, V9fsPa= th *path, #endif } =20 -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 676d60e1a8ef..b1d546447ed8 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1400,13 +1400,14 @@ static int local_ioc_getversion(FsContext *ctx, V9f= sPath *path, #endif } =20 -static int local_init(FsContext *ctx) +static int local_init(FsContext *ctx, Error **errp) { struct statfs stbuf; LocalData *data =3D g_malloc(sizeof(*data)); =20 data->mountfd =3D open(ctx->fs_root, O_DIRECTORY | O_RDONLY); if (data->mountfd =3D=3D -1) { + error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root); goto err; } =20 diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 186fe1d5a8eb..ead2df221e4d 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; } =20 -static int connect_namedsocket(const char *path) +static int connect_namedsocket(const char *path, Error **errp) { int sockfd, size; struct sockaddr_un helper; =20 if (strlen(path) >=3D sizeof(helper.sun_path)) { - error_report("Socket name too long"); + error_setg(errp, "socket name too long"); return -1; } sockfd =3D 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 =3D AF_UNIX; size =3D 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; } @@ -1145,17 +1145,17 @@ static int proxy_parse_opts(QemuOpts *opts, struct = FsDriverEntry *fs, return 0; } =20 -static int proxy_init(FsContext *ctx) +static int proxy_init(FsContext *ctx, Error **errp) { V9fsProxy *proxy =3D g_malloc(sizeof(V9fsProxy)); int sock_id; =20 if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { - sock_id =3D connect_namedsocket(ctx->fs_root); + sock_id =3D connect_namedsocket(ctx->fs_root, errp); } else { sock_id =3D 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; } =20 -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 52d46632fe15..73cb3e1646ac 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3544,9 +3544,9 @@ int v9fs_device_realize_common(V9fsState *s, Error **= errp) s->fid_list =3D NULL; qemu_co_rwlock_init(&s->rename_lock); =20 - 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_ro= ot); + if (s->ops->init(&s->ctx, errp) < 0) { + error_prepend(errp, "cannot initialize fsdev '%s': ", + s->fsconf.fsdev_id); goto out; } =20