From nobody Tue Oct 28 04:17:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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 1515201369113866.8783615571459; Fri, 5 Jan 2018 17:16:09 -0800 (PST) Received: from localhost ([::1]:39632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXd5h-0005fj-1F for importer@patchew.org; Fri, 05 Jan 2018 20:16:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eXcy6-0007Ef-V0 for qemu-devel@nongnu.org; Fri, 05 Jan 2018 20:08:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eXcy3-0006Lp-A4 for qemu-devel@nongnu.org; Fri, 05 Jan 2018 20:08:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45674 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eXcy3-0006K5-1P for qemu-devel@nongnu.org; Fri, 05 Jan 2018 20:08:11 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w0614Zd1007286 for ; Fri, 5 Jan 2018 20:08:08 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fak5jabm1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 05 Jan 2018 20:08:07 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 6 Jan 2018 01:08:06 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 6 Jan 2018 01:08:04 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w061834f64487654; Sat, 6 Jan 2018 01:08:03 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D140442045; Sat, 6 Jan 2018 01:01:45 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BEB9942041; Sat, 6 Jan 2018 01:01:45 +0000 (GMT) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Sat, 6 Jan 2018 01:01:45 +0000 (GMT) Received: from bahia.lan (icon-9-164-172-212.megacenter.de.ibm.com [9.164.172.212]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 14FA22202BB; Sat, 6 Jan 2018 02:08:03 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Sat, 6 Jan 2018 02:07:38 +0100 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180106010739.18201-1-groug@kaod.org> References: <20180106010739.18201-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 18010601-0040-0000-0000-00000401255E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18010601-0041-0000-0000-0000260472B4 Message-Id: <20180106010739.18201-12-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-05_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=13 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801060011 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 11/12] 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: Peter Maydell , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 | 2 +- hw/9pfs/9p-local.c | 33 +++++++++++++++++++-------------- hw/9pfs/9p-proxy.c | 16 +++++++++++++--- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 63d19a6dcd0e..e7f9e1872129 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -103,7 +103,7 @@ void cred_init(FsCred *); =20 struct FileOperations { - int (*parse_opts)(QemuOpts *, FsDriverEntry *); + int (*parse_opts)(QemuOpts *, FsDriverEntry *, Error **errp); int (*init)(FsContext *); void (*cleanup)(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 26ac90fc5ce3..e50941075bda 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -652,7 +652,7 @@ static void handle_cleanup(FsContext *ctx) g_free(data); } =20 -static int handle_parse_opts(QemuOpts *opts, FsDriverEntry *fse) +static int handle_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **e= rrp) { 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 155834db28e1..e1a4b844a527 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1459,16 +1459,21 @@ static void local_cleanup(FsContext *ctx) g_free(data); } =20 -static int local_parse_opts(QemuOpts *opts, 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, FsDriverEntry *fse, Error **er= rp) { 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 +1487,20 @@ static int local_parse_opts(QemuOpts *opts, FsDrive= rEntry *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 +1512,11 @@ static int local_parse_opts(QemuOpts *opts, FsDrive= rEntry *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 652940726e72..f6fb7a408fd1 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -1111,17 +1111,27 @@ static int connect_namedsocket(const char *path) return sockfd; } =20 -static int proxy_parse_opts(QemuOpts *opts, 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, FsDriverEntry *fs, Error **err= p) { 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) { --=20 2.13.6