From nobody Sun May 19 16:58:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1622138326; cv=none; d=zohomail.com; s=zohoarc; b=FhNpa6dq+qjTMrRAnzCjxOCqukeVcjC8UDPjWBSzCUme71Z+BcDUqaxn33ShnJ6z/iE8Qv3pH3eoKQCxeOyXPxrH+SYcxk5a8xx8r42SCz2EBXmhuJSWZF4lDmu/rEZycn8BmwHeQUM3Dor9lwK6CJQ/S1B/JsPocVgUD5Ri6BA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622138326; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=y/GOcUShy5FjWgYDSfPOlFUsllk9Rf3WUCR1lrW76tY=; b=icvtR6oxXSbVlJhXsTVgP5X+TvceelISh1UcJ/RYCnjFP/P+iZgqi3yNMRiT1YpOIbAVwCR5rqTVOtqndPGz7Xcvw5ypjaF5xyDtV205ETUevTrbmEsJxPKAXq27R4yQvJ5rpuxSgLeZOascyZKmBN1ZBow7LuX/6G/CY+eG9hI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622138326615625.0904424155907; Thu, 27 May 2021 10:58:46 -0700 (PDT) Received: from localhost ([::1]:37536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmKHN-0004qI-2S for importer@patchew.org; Thu, 27 May 2021 13:58:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3d154cc9474cb0d5507d67211bd5e328ed2d7093@lizzy.crudebyte.com>) id 1lmKGQ-0003Gj-AE for qemu-devel@nongnu.org; Thu, 27 May 2021 13:57:46 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:51773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3d154cc9474cb0d5507d67211bd5e328ed2d7093@lizzy.crudebyte.com>) id 1lmKGO-0003MB-KH for qemu-devel@nongnu.org; Thu, 27 May 2021 13:57:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=y/GOcUShy5FjWgYDSfPOlFUsllk9Rf3WUCR1lrW76tY=; b=hcvuc eQOsRd4QCMK7bCEmi9uUkEjSamKlfBh0CEflFPmsotIFHUQcwZbAAJveJ3OuNszMt/JRe/jhdOWS1 lHmfDx9GKKq2csCR0xDRY+6hMoGwlesIF0CwNW6sNZohUCBRej5bKmQ4Wi5VbQGYNpGq0JaFMQMmM 5cXANaEXK2cQ9tSvyVbYCXk9niCzbKuA5fFSulN1lMZr76ZtOt7SH9cmK6N2YJyd2n5jDP5qkhIOs RpTrYIUzUnpSXyXSkQR+Lo6g3G72w53JC6wAKIO+dsrtB2N+yL1mBT53H7oQD+3QifOc0vbmXrOEP ArP1NA64pZXr5Q+llpyWSnaiklBtA==; Message-Id: <3d154cc9474cb0d5507d67211bd5e328ed2d7093.1622135592.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 27 May 2021 19:03:17 +0200 Subject: [PATCH 1/3] 9pfs: Twalk benchmark To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=91.194.90.13; envelope-from=3d154cc9474cb0d5507d67211bd5e328ed2d7093@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is not intentended to be merged, it just acts as performance A/B comparison benchmark for the subsequent patch. Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-test.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 41fed41de1..2cd9e427b4 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -20,6 +20,18 @@ #include "libqos/virtio-9p.h" #include "libqos/qgraph.h" =20 +/* + * to benchmark the real time (not CPU time) that elapsed between start of + * a request and arrival of its response + */ +static double wall_time(void) +{ + struct timeval t; + struct timezone tz; + gettimeofday(&t, &tz); + return t.tv_sec + t.tv_usec * 0.000001; +} + #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000) static QGuestAllocator *alloc; =20 @@ -646,12 +658,30 @@ static void fs_walk(void *obj, void *data, QGuestAllo= cator *t_alloc) } =20 do_attach(v9p); + const double start =3D wall_time(); req =3D v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0); + const double twalk =3D wall_time(); v9fs_req_wait_for_reply(req, NULL); + const double waitforreply =3D wall_time(); v9fs_rwalk(req, &nwqid, &wqid); + const double end =3D wall_time(); =20 g_assert_cmpint(nwqid, =3D=3D, P9_MAXWELEM); =20 + printf("\nTime client spent on sending Twalk: %fs\n\n", + twalk - start); + + printf("Time client spent for waiting for reply from server: %fs " + "[MOST IMPORTANT]\n", waitforreply - start); + printf("(This is the most important value, because it reflects the tim= e\n" + "the 9p server required to process and return the result of the= \n" + "Twalk request.)\n\n"); + + printf("Total client time: %fs\n", end - start); + + //printf("Details of response message data: R_readddir nentries=3D%d " + // "rbytes=3D%d\n", nentries, count); + for (i =3D 0; i < P9_MAXWELEM; i++) { g_free(wnames[i]); } --=20 2.20.1 From nobody Sun May 19 16:58:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1622138389; cv=none; d=zohomail.com; s=zohoarc; b=kOn/pVR+X+WyLsGN7c6KX9wfM8uoB6yxbc6QGeZC5sjSqKnwo6rOIM6WFHlejnFYeUpoILW98sDrxNlMYWw+4YVSqE3sOVvvpAV5H7YOcnafF5++Wx53xxaFnOdSzyGIKLofJU14JWgGjQv5y2CGm/+6F1qCpsX2S2WnrSe/lcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622138389; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=PPl6xgA7/vNQepFNtsupFT4wcQ/Kz0LGNru6apqgWaE=; b=loUqVhf/ddREjjcYCmrNEMQP4PBBpARrw0l2I0ga4+r1VjPyoWQ82JFA7Xazz2tVsL0Pzyt144lTFupZUeb9QE4DizfJZKX540hi7qizjsqtXZFP/WAEzlmL4C25yg2C1x28hod8KpIzXbStzSfUlTC5kkyGm3M+GwbM42tt+kw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622138389500353.8006566750654; Thu, 27 May 2021 10:59:49 -0700 (PDT) Received: from localhost ([::1]:40440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmKIO-0006lN-8B for importer@patchew.org; Thu, 27 May 2021 13:59:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmKHQ-0005PQ-Rs for qemu-devel@nongnu.org; Thu, 27 May 2021 13:58:50 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:48801) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lmKHP-00041N-9x for qemu-devel@nongnu.org; Thu, 27 May 2021 13:58:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=PPl6xgA7/vNQepFNtsupFT4wcQ/Kz0LGNru6apqgWaE=; b=JLqd8 BIqdTj65/DoljdYG3npHhpBUQk/n16LT1GyGJPR5d9OXj1sQcvIOuYeXG5HxIrMt4R0cGC2bYczRW aXXUCDS2TwO4dxut7VgBwsAJwMAV93qlD6d0yoT3b/RCgzlepejLIDUqoMffloopQX7LI1rHSuG/c 5q2RgOIkt1V2rpAf/hhqAy2tces/V659vV0zkkQVW3IJ1do01kx1UBcnuMLYX/2aagExfz30aMcqj Bo98KL9xzKc1keE/GZ2yT++LVzOcpaKpTb1wFIIiHihjY3aspfGglG7M0e8g0J3m7eVCvfg3YM4tH wAmoQIk+Qb2SlXCDDkCHOffeS9zBg==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 27 May 2021 19:04:11 +0200 Subject: [PATCH 2/3] 9pfs: capture root stat To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=91.194.90.13; envelope-from=e6a33f077cf0675f51bff979e976f8472cfe027d@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We already capture the QID of the exported 9p root path, i.e. to prevent client access outside the defined, exported filesystem's tree. This is currently checked by comparing the root QID with another FID's QID. The problem with the latter is that resolving a QID of any given 9p path can only be done on 9p server's main thread, that's because it might mutate the server's state if inode remapping is enabled. For that reason also capture the POSIX stat info of the root path for being able to identify on any (e.g. worker) thread whether an arbitrary given path is identical to the export root. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 10 +++++++++- hw/9pfs/9p.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 89aa07db78..825de1561d 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1400,6 +1400,7 @@ static void coroutine_fn v9fs_attach(void *opaque) size_t offset =3D 7; V9fsQID qid; ssize_t err; + struct stat stbuf; =20 v9fs_string_init(&uname); v9fs_string_init(&aname); @@ -1422,7 +1423,13 @@ static void coroutine_fn v9fs_attach(void *opaque) clunk_fid(s, fid); goto out; } - err =3D fid_to_qid(pdu, fidp, &qid); + err =3D v9fs_co_lstat(pdu, &fidp->path, &stbuf); + if (err < 0) { + err =3D -EINVAL; + clunk_fid(s, fid); + goto out; + } + err =3D stat_to_qid(pdu, &stbuf, &qid); if (err < 0) { err =3D -EINVAL; clunk_fid(s, fid); @@ -1455,6 +1462,7 @@ static void coroutine_fn v9fs_attach(void *opaque) err +=3D offset; =20 memcpy(&s->root_qid, &qid, sizeof(qid)); + memcpy(&s->root_st, &stbuf, sizeof(struct stat)); trace_v9fs_attach_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path); out: diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 00381591ff..6f0b4c78c0 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -356,6 +356,7 @@ struct V9fsState { Error *migration_blocker; V9fsConf fsconf; V9fsQID root_qid; + struct stat root_st; dev_t dev_id; struct qht qpd_table; struct qht qpp_table; --=20 2.20.1 From nobody Sun May 19 16:58:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1622138258; cv=none; d=zohomail.com; s=zohoarc; b=K3Wyoh9cZ2tnaxYs+V5y+enI9IUrPbWgH83Umiyoe0bJKi7O/FdnSEou0hQegl+FxWRk0Mc77nveU3e9hvWLXwY8kBqxyfONQ3gMIURs5zw4LyyMu2gv65OgN9MOQOsr0T2MVBJGNKYO0tSzhGL3L/9RJC4ul1rEPeWZMMH5T04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622138258; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=TDBLWrGlbK49ZkCBN6JkQF/18xIACpjhm2CQWGx+LIQ=; b=HF/AwPULH6DkdYiC+/AUkH6eIJX4RhVCmBGnaj9Iu1xj9LB2oN61Z3gcjrwG22PKFTtOr/Xp9ZWlF9CUTR3409k6GkIC6+8AaNWBwQldaGb7ixa+yGCKhr4zKlbLnMU43wqwvlHV6itAphtxY8WOloq6zrFLogKvEO//EKLVy0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622138258537467.0212491061685; Thu, 27 May 2021 10:57:38 -0700 (PDT) Received: from localhost ([::1]:33630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lmKGH-0002F8-7s for importer@patchew.org; Thu, 27 May 2021 13:57:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <364bc324ad4dfdb87cbbb75abb7dc09b561cda2f@lizzy.crudebyte.com>) id 1lmKFP-0000qo-Lr for qemu-devel@nongnu.org; Thu, 27 May 2021 13:56:43 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:53013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <364bc324ad4dfdb87cbbb75abb7dc09b561cda2f@lizzy.crudebyte.com>) id 1lmKFN-0002Xo-CT for qemu-devel@nongnu.org; Thu, 27 May 2021 13:56:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=TDBLWrGlbK49ZkCBN6JkQF/18xIACpjhm2CQWGx+LIQ=; b=FSlAp rNj78vSJ+sKKjK6MltK7BeUfYZ+wFapHReQdT18qBMGAjK7a3eeuwVO76cy5qCPOQKg55EhPf67SY USaknweRQkWAfmiocbD8qL94VYIGfTuUTNZK9jfRB2JukI83s3lN8hgv/80q5w9brS9t+67WrawZc Ygep3vA62ttEpIxCuMG5jGsJebPJKudab9ajnPp4Di9Ryb0oiEi7gwjkbNLAn/CF6sHppxYkj7woe iVChliNpQ211/G9ai1wJfSE1s9KMs5/U8aKzXA77b4QzGpNTWlDaqZ/sPJjSBXeIe/DGuVnrny1KT NZOiYfc+GygrqJHRPxP7F7CbEiKdw==; Message-Id: <364bc324ad4dfdb87cbbb75abb7dc09b561cda2f.1622135592.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 27 May 2021 19:05:43 +0200 Subject: [PATCH 3/3] 9pfs: reduce latency of Twalk To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=91.194.90.13; envelope-from=364bc324ad4dfdb87cbbb75abb7dc09b561cda2f@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As on the previous performance optimization on Treaddir handling; reduce the overall latency, i.e. overall time spent on processing a Twalk request by reducing the amount of thread hops between the 9p server's main thread and fs worker thread(s). In fact this patch even reduces the thread hops for Twalk handling to its theoritical minimum of exactly 2 thread hops: main thread -> fs worker thread -> main thread This is achieved by doing all the required fs driver tasks altogether in a single v9fs_co_run_in_worker({ ... }); code block. This patches also changes the way how an arbitrary path is identified to whether it equals the 9p export root. Previously QIDs were compared for this, which forces to be done on main thread for resolving individual path element QIDs. For that reason POSIX stat device number and inode number pairs are compared instead now. Accordingly, as 9p server's root_qid member variable is no longer used, nor are functions fid_to_qid() and not_same_qid(), hence drop them. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 118 +++++++++++++++++++++++++++++++++------------------ hw/9pfs/9p.h | 1 - 2 files changed, 76 insertions(+), 43 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 825de1561d..cc1b176eb5 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -971,23 +971,6 @@ static int stat_to_qid(V9fsPDU *pdu, const struct stat= *stbuf, V9fsQID *qidp) return 0; } =20 -static int coroutine_fn fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, - V9fsQID *qidp) -{ - struct stat stbuf; - int err; - - err =3D v9fs_co_lstat(pdu, &fidp->path, &stbuf); - if (err < 0) { - return err; - } - err =3D stat_to_qid(pdu, &stbuf, qidp); - if (err < 0) { - return err; - } - return 0; -} - V9fsPDU *pdu_alloc(V9fsState *s) { V9fsPDU *pdu =3D NULL; @@ -1461,7 +1444,6 @@ static void coroutine_fn v9fs_attach(void *opaque) } err +=3D offset; =20 - memcpy(&s->root_qid, &qid, sizeof(qid)); memcpy(&s->root_st, &stbuf, sizeof(struct stat)); trace_v9fs_attach_return(pdu->tag, pdu->id, qid.type, qid.version, qid.path); @@ -1713,12 +1695,9 @@ static bool name_is_illegal(const char *name) return !*name || strchr(name, '/') !=3D NULL; } =20 -static bool not_same_qid(const V9fsQID *qid1, const V9fsQID *qid2) +static bool same_stat_id(const struct stat *a, const struct stat *b) { - return - qid1->type !=3D qid2->type || - qid1->version !=3D qid2->version || - qid1->path !=3D qid2->path; + return a->st_dev =3D=3D b->st_dev && a->st_ino =3D=3D b->st_ino; } =20 static void coroutine_fn v9fs_walk(void *opaque) @@ -1726,9 +1705,9 @@ static void coroutine_fn v9fs_walk(void *opaque) int name_idx; V9fsQID *qids =3D NULL; int i, err =3D 0; - V9fsPath dpath, path; + V9fsPath dpath, path, *pathes =3D NULL; uint16_t nwnames; - struct stat stbuf; + struct stat stbuf, fidst, *stbufs =3D NULL; size_t offset =3D 7; int32_t fid, newfid; V9fsString *wnames =3D NULL; @@ -1754,6 +1733,8 @@ static void coroutine_fn v9fs_walk(void *opaque) if (nwnames) { wnames =3D g_new0(V9fsString, nwnames); qids =3D g_new0(V9fsQID, nwnames); + stbufs =3D g_new0(struct stat, nwnames); + pathes =3D g_new0(V9fsPath, nwnames); for (i =3D 0; i < nwnames; i++) { err =3D pdu_unmarshal(pdu, offset, "s", &wnames[i]); if (err < 0) { @@ -1774,35 +1755,85 @@ static void coroutine_fn v9fs_walk(void *opaque) =20 v9fs_path_init(&dpath); v9fs_path_init(&path); + /* + * Both dpath and path initially point to fidp. + * Needed to handle request with nwnames =3D=3D 0 + */ + v9fs_path_copy(&dpath, &fidp->path); + v9fs_path_copy(&path, &fidp->path); =20 - err =3D fid_to_qid(pdu, fidp, &qid); + /* + * To keep latency (i.e. overall execution time for processing this + * Twalk client request) as small as possible, run all the required fs + * driver code altogether inside the following block. + */ + v9fs_co_run_in_worker({ + if (v9fs_request_cancelled(pdu)) { + err =3D -EINTR; + break; + } + err =3D s->ops->lstat(&s->ctx, &dpath, &fidst); + if (err < 0) { + err =3D -errno; + break; + } + stbuf =3D fidst; + for (name_idx =3D 0; name_idx < nwnames; name_idx++) { + if (v9fs_request_cancelled(pdu)) { + err =3D -EINTR; + break; + } + if (!same_stat_id(&pdu->s->root_st, &stbuf) || + strcmp("..", wnames[name_idx].data)) + { + err =3D s->ops->name_to_path(&s->ctx, &dpath, + wnames[name_idx].data, &path); + if (err < 0) { + err =3D -errno; + break; + } + if (v9fs_request_cancelled(pdu)) { + err =3D -EINTR; + break; + } + err =3D s->ops->lstat(&s->ctx, &path, &stbuf); + if (err < 0) { + err =3D -errno; + break; + } + stbufs[name_idx] =3D stbuf; + v9fs_path_copy(&dpath, &path); + v9fs_path_copy(&pathes[name_idx], &path); + } + } + }); + /* + * Handle all the rest of this Twalk request on main thread ... + */ if (err < 0) { goto out; } =20 - /* - * Both dpath and path initially poin to fidp. - * Needed to handle request with nwnames =3D=3D 0 - */ + err =3D stat_to_qid(pdu, &fidst, &qid); + if (err < 0) { + goto out; + } + stbuf =3D fidst; + + /* reset dpath and path */ v9fs_path_copy(&dpath, &fidp->path); v9fs_path_copy(&path, &fidp->path); - for (name_idx =3D 0; name_idx < nwnames; name_idx++) { - if (not_same_qid(&pdu->s->root_qid, &qid) || - strcmp("..", wnames[name_idx].data)) { - err =3D v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].dat= a, - &path); - if (err < 0) { - goto out; - } =20 - err =3D v9fs_co_lstat(pdu, &path, &stbuf); - if (err < 0) { - goto out; - } + for (name_idx =3D 0; name_idx < nwnames; name_idx++) { + if (!same_stat_id(&pdu->s->root_st, &stbuf) || + strcmp("..", wnames[name_idx].data)) + { + stbuf =3D stbufs[name_idx]; err =3D stat_to_qid(pdu, &stbuf, &qid); if (err < 0) { goto out; } + v9fs_path_copy(&path, &pathes[name_idx]); v9fs_path_copy(&dpath, &path); } memcpy(&qids[name_idx], &qid, sizeof(qid)); @@ -1838,9 +1869,12 @@ out_nofid: if (nwnames && nwnames <=3D P9_MAXWELEM) { for (name_idx =3D 0; name_idx < nwnames; name_idx++) { v9fs_string_free(&wnames[name_idx]); + v9fs_path_free(&pathes[name_idx]); } g_free(wnames); g_free(qids); + g_free(stbufs); + g_free(pathes); } } =20 diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 6f0b4c78c0..1567b67841 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -355,7 +355,6 @@ struct V9fsState { int32_t root_fid; Error *migration_blocker; V9fsConf fsconf; - V9fsQID root_qid; struct stat root_st; dev_t dev_id; struct qht qpd_table; --=20 2.20.1