From nobody Wed Nov 12 13:33:00 2025 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; 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=1570713959; cv=none; d=zoho.com; s=zohoarc; b=jzPNqATQ/pyrU/8f594GLrVoyEkpVXJV9sausSv4+R5tVbq+oRgWAcLNITci4slFQe8UgZBqxUSEQ17SRg2YwoU7YZ9YmdP6HMgFREccps7BdsCS6ISzLpBMXsqlyLsDh2dapoTXSkwM6SoUhXeR2fC+TgOXaOs0qr9BkjlvQbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570713959; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LuNFDhPOZoILE4ZyeDJJpuccxRXL5ULnox4JrShjxPU=; b=YAHG0Y0f03yHnE1sMR4Ssv8jv9ue6iC6wmpWdlczN5+7ZfToazw0j1Ldcq4hQhLkUO6QJ82mxyx06oDKCKv3Ph4o6qY7u8sUK7YPKVqnzYFt6Y5V6keBSkzIBgtDAwbN/rVuMONaCjFlSSE8gkp0gwVTF5xgojPcK0PN05wqc9c= ARC-Authentication-Results: i=1; mx.zoho.com; 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 157071395929183.6008203379049; Thu, 10 Oct 2019 06:25:59 -0700 (PDT) Received: from localhost ([::1]:39480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIYS5-0003RO-NJ for importer@patchew.org; Thu, 10 Oct 2019 09:25:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIYKq-000287-Ei for qemu-devel@nongnu.org; Thu, 10 Oct 2019 09:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIYKo-0002wb-Ge for qemu-devel@nongnu.org; Thu, 10 Oct 2019 09:18:28 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:61076 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 1iIYKo-0002uO-Aq for qemu-devel@nongnu.org; Thu, 10 Oct 2019 09:18:26 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9ADHfJL042586 for ; Thu, 10 Oct 2019 09:18:20 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2vj52y0xy6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 Oct 2019 09:18:20 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Oct 2019 14:18:18 +0100 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 10 Oct 2019 14:18:15 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9ADIFQn43712812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 10 Oct 2019 13:18:15 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE0AAAE057; Thu, 10 Oct 2019 13:18:14 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1A46AE04D; Thu, 10 Oct 2019 13:18:14 +0000 (GMT) Received: from smtp.tls.ibm.com (unknown [9.101.4.1]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 10 Oct 2019 13:18:14 +0000 (GMT) Received: from bahia.tls.ibm.com (bahia.tls.ibm.com [9.101.4.41]) by smtp.tls.ibm.com (Postfix) with ESMTP id 87444220208; Thu, 10 Oct 2019 15:18:14 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PULL v2 6/8] 9p: stat_to_qid: implement slow path Date: Thu, 10 Oct 2019 15:18:07 +0200 X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191010131809.1284004-1-groug@kaod.org> References: <20191010131809.1284004-1-groug@kaod.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 x-cbid: 19101013-0012-0000-0000-00000356E0CA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19101013-0013-0000-0000-00002191E9EC Message-Id: <20191010131809.1284004-7-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-10-10_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=580 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910100125 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 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: , Cc: Peter Maydell , Christian Schoenebeck , Greg Kurz , Antonios Motakis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Antonios Motakis 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 https://github.com/gkurz/qemu/commits/9p-next (SHA1 7fc4c49e91). - 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 warning message about potential degraded performance in qid_path_prefixmap(). - Wrapped qpf_table initialization to dedicated qpf_table_init() function. - Fixed typo in comment. ] Signed-off-by: Christian Schoenebeck Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++----- hw/9pfs/9p.h | 9 +++++++ 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 8eb89c5c7d3f..d9be2d45d3e4 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -579,23 +579,34 @@ 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) { if (!ht || !ht->map) { return; } - qht_iter(ht, qpp_table_remove, NULL); + qht_iter(ht, qp_table_remove, NULL); qht_destroy(ht); } =20 @@ -604,6 +615,50 @@ static void qpp_table_init(struct qht *ht) qht_init(ht, qpp_lookup_func, 1, QHT_MODE_AUTO_RESIZE); } =20 +static void qpf_table_init(struct qht *ht) +{ + qht_init(ht, qpf_lookup_func, 1 << 16, QHT_MODE_AUTO_RESIZE); +} + +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) { + qpf_table_init(&pdu->s->qpf_table); + } + + 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 @@ -629,9 +684,8 @@ static int qid_path_prefixmap(V9fsPDU *pdu, const struc= t stat *stbuf, if (!val) { 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." + warn_report_once( + "9p: Potential degraded performance of inode remapping" ); return -ENFILE; } @@ -656,6 +710,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; } @@ -3820,6 +3878,7 @@ int v9fs_device_realize_common(V9fsState *s, const V9= fsTransport *t, =20 qpp_table_init(&s->qpp_table); 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); @@ -3842,7 +3901,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 7262fe80aa02..35a362c0d797 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; @@ -268,7 +275,9 @@ struct V9fsState V9fsQID root_qid; 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.21.0