From nobody Mon Feb 9 12:29:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1562161420; cv=none; d=zoho.com; s=zohoarc; b=fLxFtO+fFN2krT3sfIBUimuCA4dWWgH7A0YggA2/GXWL3hC6/wQAWgFH63G0sGLJytMgTIE0vJOkTauV7FBWYzRvaMrapLeCA7XPMZMbMEqAvfUnv8tC4gZYHDeg03PenrS+rSpEL0W5QVqQAaetykVgA/1AZPt8c4GLd47Zq1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562161420; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=7NerczuoUN1ym39db6oag5kHDDInUVirFYx6rVdpx/o=; b=ZytFijOn1wGIg/9KmLuIkGYazV7AchTbFCQqdtouARgO1uP0APOy04c4nR8ti2s6DDmz/QST3IdxAygjQwS9NIvNuhsK/3tkkHmab7n9nWssBCGBx+N+2clOhNdmefVtdooWC7W53DUCurlN+bpZi7TjR8Oi8IYM7xmVQvxzOKU= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562161420545984.3764538587308; Wed, 3 Jul 2019 06:43:40 -0700 (PDT) Received: from localhost ([::1]:36144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hifXv-0000oN-L3 for importer@patchew.org; Wed, 03 Jul 2019 09:43:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44254) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hifWX-0000A4-R4 for qemu-devel@nongnu.org; Wed, 03 Jul 2019 09:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hifWW-0004K7-Et for qemu-devel@nongnu.org; Wed, 03 Jul 2019 09:42:13 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:53921) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hifWW-0003dg-8A for qemu-devel@nongnu.org; Wed, 03 Jul 2019 09:42:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Subject:Date:Cc:To:From:References:In-Reply-To: Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7NerczuoUN1ym39db6oag5kHDDInUVirFYx6rVdpx/o=; b=XCVU8L+PvTUNXhMywVoxX4Yy4 9HTyNmR5g4tYlCdnw8Bru5202w566mZPkKInOm9iLR1ZO0ip8kL8d8JmJh67VCLdp9pzttUGMRb26 vl+L+DHY+zWOCjI2xZSOqqomelMrA9+YN2E3xYs+crnZ8l6gOFc586+kWvTi5rl/pqYvdfG2yrOT7 EPYztBBRdN6q2J3BmlA40kBBrmbfDnZmVJ+1308SvpCH1I3HDVQWmEgCl5/p/y6vVniGrbepPj29C KW1dHKr3mwOqvuxmNe53FuOvvLFTX3GUhv5qxvakdCd9cfhjeVfA8quHXwE3r9leFy28GUc/SUJpm N5lVrRiwQ==; Message-Id: In-Reply-To: References: To: qemu-devel@nongnu.org Date: Wed, 3 Jul 2019 13:17:37 +0200 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 91.194.90.13 Subject: [Qemu-devel] [PATCH v5 4/5] 9p: stat_to_qid: implement slow path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Christian Schoenebeck via Qemu-devel Reply-To: Christian Schoenebeck Cc: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= , Greg Kurz , Antonios Motakis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" stat_to_qid attempts via qid_path_prefixmap to map unique files (which are identified by 64 bit inode nr and 32 bit device id) to a 64 QID path value. However this implementation makes some assumptions about inode number generation on the host. If qid_path_prefixmap fails, we still have 48 bits available in the QID path to fall back to a less memory efficient full mapping. Signed-off-by: Antonios Motakis [CS: - Rebased to master head. - Updated hash calls to new xxhash API. - Removed unnecessary parantheses in qpf_lookup_func(). - Removed unnecessary g_malloc0() result checks. - Log error message when running out of prefixes in qid_path_fullmap(). - Log error message about potential degraded performance in qid_path_prefixmap(). - Fixed typo in comment. ] Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--= ---- hw/9pfs/9p.h | 9 ++++++++ 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 39c6c2a894..549e279462 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -579,23 +579,73 @@ static uint32_t qpp_hash(QppEntry e) return qemu_xxhash7(e.ino_prefix, e.dev, 0, 0, 0); } =20 +static uint32_t qpf_hash(QpfEntry e) +{ + return qemu_xxhash7(e.ino, e.dev, 0, 0, 0); +} + static bool qpp_lookup_func(const void *obj, const void *userp) { const QppEntry *e1 =3D obj, *e2 =3D userp; return e1->dev =3D=3D e2->dev && e1->ino_prefix =3D=3D e2->ino_prefix; } =20 -static void qpp_table_remove(void *p, uint32_t h, void *up) +static bool qpf_lookup_func(const void *obj, const void *userp) +{ + const QpfEntry *e1 =3D obj, *e2 =3D userp; + return e1->dev =3D=3D e2->dev && e1->ino =3D=3D e2->ino; +} + +static void qp_table_remove(void *p, uint32_t h, void *up) { g_free(p); } =20 -static void qpp_table_destroy(struct qht *ht) +static void qp_table_destroy(struct qht *ht) { - qht_iter(ht, qpp_table_remove, NULL); + qht_iter(ht, qp_table_remove, NULL); qht_destroy(ht); } =20 +static int qid_path_fullmap(V9fsPDU *pdu, const struct stat *stbuf, + uint64_t *path) +{ + QpfEntry lookup =3D { + .dev =3D stbuf->st_dev, + .ino =3D stbuf->st_ino + }, *val; + uint32_t hash =3D qpf_hash(lookup); + + /* most users won't need the fullmap, so init the table lazily */ + if (!pdu->s->qpf_table.map) { + qht_init(&pdu->s->qpf_table, qpf_lookup_func, 1 << 16, QHT_MODE_AU= TO_RESIZE); + } + + val =3D qht_lookup(&pdu->s->qpf_table, &lookup, hash); + + if (!val) { + if (pdu->s->qp_fullpath_next =3D=3D 0) { + /* no more files can be mapped :'( */ + error_report_once( + "9p: No more prefixes available for remapping inodes from " + "host to guest." + ); + return -ENFILE; + } + + val =3D g_malloc0(sizeof(QppEntry)); + *val =3D lookup; + + /* new unique inode and device combo */ + val->path =3D pdu->s->qp_fullpath_next++; + pdu->s->qp_fullpath_next &=3D QPATH_INO_MASK; + qht_insert(&pdu->s->qpf_table, val, hash, NULL); + } + + *path =3D val->path; + return 0; +} + /* stat_to_qid needs to map inode number (64 bits) and device id (32 bits) * to a unique QID path (64 bits). To avoid having to map and keep track * of up to 2^64 objects, we map only the 16 highest bits of the inode plus @@ -621,8 +671,7 @@ static int qid_path_prefixmap(V9fsPDU *pdu, const struc= t stat *stbuf, if (pdu->s->qp_prefix_next =3D=3D 0) { /* we ran out of prefixes */ error_report_once( - "9p: No more prefixes available for remapping inodes from " - "host to guest." + "9p: Potential degraded performance of inode remapping" ); return -ENFILE; } @@ -647,6 +696,10 @@ static int stat_to_qid(V9fsPDU *pdu, const struct stat= *stbuf, V9fsQID *qidp) if (pdu->s->ctx.export_flags & V9FS_REMAP_INODES) { /* map inode+device to qid path (fast path) */ err =3D qid_path_prefixmap(pdu, stbuf, &qidp->path); + if (err =3D=3D -ENFILE) { + /* fast path didn't work, fall back to full map */ + err =3D qid_path_fullmap(pdu, stbuf, &qidp->path); + } if (err) { return err; } @@ -3827,6 +3880,7 @@ int v9fs_device_realize_common(V9fsState *s, const V9= fsTransport *t, /* QID path hash table. 1 entry ought to be enough for anybody ;) */ qht_init(&s->qpp_table, qpp_lookup_func, 1, QHT_MODE_AUTO_RESIZE); s->qp_prefix_next =3D 1; /* reserve 0 to detect overflow */ + s->qp_fullpath_next =3D 1; =20 s->ctx.fst =3D &fse->fst; fsdev_throttle_init(s->ctx.fst); @@ -3841,7 +3895,8 @@ out: } g_free(s->tag); g_free(s->ctx.fs_root); - qpp_table_destroy(&s->qpp_table); + qp_table_destroy(&s->qpp_table); + qp_table_destroy(&s->qpf_table); v9fs_path_free(&path); } return rc; @@ -3854,7 +3909,8 @@ void v9fs_device_unrealize_common(V9fsState *s, Error= **errp) } fsdev_throttle_cleanup(s->ctx.fst); g_free(s->tag); - qpp_table_destroy(&s->qpp_table); + qp_table_destroy(&s->qpp_table); + qp_table_destroy(&s->qpf_table); g_free(s->ctx.fs_root); } =20 diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index a283b0193e..f044a88a41 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -245,6 +245,13 @@ typedef struct { uint16_t qp_prefix; } QppEntry; =20 +/* QID path full entry, as above */ +typedef struct { + dev_t dev; + ino_t ino; + uint64_t path; +} QpfEntry; + struct V9fsState { QLIST_HEAD(, V9fsPDU) free_list; @@ -269,7 +276,9 @@ struct V9fsState ino_t root_ino; dev_t dev_id; struct qht qpp_table; + struct qht qpf_table; uint16_t qp_prefix_next; + uint64_t qp_fullpath_next; }; =20 /* 9p2000.L open flags */ --=20 2.11.0