From nobody Sun May 5 22:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610979953; cv=none; d=zohomail.com; s=zohoarc; b=N9c5lSYIpDOJ7mYJIjQJykeSHlGJXxqwT5HJXnG4lEfpFxdC4ppFk1eAGaa2+sf5c7kVVS+4dLpQTnw0E/YWqeSq/xgAyLgE2rdYxO7rsKKHNEFEv3Fi70Uj4ZXUwBa8PD7qxCnoxopWGQVVULY/UNwL+cz2NdtPzkOrdg8+KaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610979953; h=Content-Type: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=kC6y0wnIICZZQkWiPWsUvQ0OPeZhWQjflQZ4md/F2vc=; b=ETcHBn+oeYopoQ4m/IL2SGpVjtQJH9uN952pXyWrykp2FedZ5pEBPidwLe99eHNfytw7/QAclE+ePJQr5ft+Mj45Ugl5jOBErI6EhAWD5hg0pA9yZIPxV9o6Sx2504QUUyomenpBlYLw29wmmMbPscUZBmUtH+3wLZ/YpjJZdu4= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610979953193988.775444821787; Mon, 18 Jan 2021 06:25:53 -0800 (PST) Received: from localhost ([::1]:33644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1VTc-0004Th-3r for importer@patchew.org; Mon, 18 Jan 2021 09:25:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1VR1-00026H-N4 for qemu-devel@nongnu.org; Mon, 18 Jan 2021 09:23:13 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:59286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1VR0-00021J-Ae for qemu-devel@nongnu.org; Mon, 18 Jan 2021 09:23:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-fAHfTI_hOyGCPcgwI0cYHg-1; Mon, 18 Jan 2021 09:23:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10AB68144E3; Mon, 18 Jan 2021 14:23:04 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2717260861; Mon, 18 Jan 2021 14:23:02 +0000 (UTC) X-MC-Unique: fAHfTI_hOyGCPcgwI0cYHg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 1/3] 9pfs: Convert V9fsFidState::clunked to bool Date: Mon, 18 Jan 2021 15:22:58 +0100 Message-Id: <20210118142300.801516-2-groug@kaod.org> In-Reply-To: <20210118142300.801516-1-groug@kaod.org> References: <20210118142300.801516-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable 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: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: , Cc: Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This can only be 0 or 1. Signed-off-by: Greg Kurz Reviewed-by: Christian Schoenebeck --- hw/9pfs/9p.c | 4 ++-- hw/9pfs/9p.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 6026b51a1c04..37c3379b7462 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -413,7 +413,7 @@ static V9fsFidState *clunk_fid(V9fsState *s, int32_t fi= d) } fidp =3D *fidpp; *fidpp =3D fidp->next; - fidp->clunked =3D 1; + fidp->clunked =3D true; return fidp; } =20 @@ -544,7 +544,7 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu) =20 /* Clunk fid */ s->fid_list =3D fidp->next; - fidp->clunked =3D 1; + fidp->clunked =3D true; =20 put_fid(pdu, fidp); } diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 32df81f360ea..93656323d1d7 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -279,7 +279,7 @@ struct V9fsFidState { int open_flags; uid_t uid; int ref; - int clunked; + bool clunked; V9fsFidState *next; V9fsFidState *rclm_lst; }; --=20 2.26.2 From nobody Sun May 5 22:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610980035; cv=none; d=zohomail.com; s=zohoarc; b=Vaqh1e2YTn7Gcjtem/ynP9yHlUlk7c0yb3039Ombg4FAIhNjViDmOfFjGPonTBQXliLUENWGBBYUUPTsXsJpu252ZiRgHCeRkXS4ZDvU0nNCz8Vz6rt4jxSF+FI0rr5O7vQjG2BEwtvxOD6jhOAO8vUihM6ntBQ6E/squFqCFNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610980035; h=Content-Type: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=5x03uzOBRF7rRu7vaZbRee3g1qdtMZjl2uilVxy/2bo=; b=cbJQy+kjiAVjeImeAlke9x5+C+yUThijT8/TZKqcAcqREHZNQSNatBD2IHSb2qqj+CK37qPBsBplIan3dtw4pm7t4X/j5asQ/f6fyDto0fWYNbrf7NSxkMy7m2ZDjp6AbmxLM7ztXOiJubvBgdt5xIZs+JphcKlELLUzIKTWqJc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1610980035325834.8516618455229; Mon, 18 Jan 2021 06:27:15 -0800 (PST) Received: from localhost ([::1]:36410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1VUw-0005hL-BI for importer@patchew.org; Mon, 18 Jan 2021 09:27:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1VR5-00026Y-GH for qemu-devel@nongnu.org; Mon, 18 Jan 2021 09:23:17 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:51399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1VR3-00022k-9U for qemu-devel@nongnu.org; Mon, 18 Jan 2021 09:23:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-L5Wz6pcjNH2vDZpJ36OAlg-1; Mon, 18 Jan 2021 09:23:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38BB6180A09E; Mon, 18 Jan 2021 14:23:05 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C7BB60622; Mon, 18 Jan 2021 14:23:04 +0000 (UTC) X-MC-Unique: L5Wz6pcjNH2vDZpJ36OAlg-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 2/3] 9pfs: Convert V9fsFidState::fid_list to QSIMPLEQ Date: Mon, 18 Jan 2021 15:22:59 +0100 Message-Id: <20210118142300.801516-3-groug@kaod.org> In-Reply-To: <20210118142300.801516-1-groug@kaod.org> References: <20210118142300.801516-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable 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: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: , Cc: Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The fid_list is currently open-coded. This doesn't seem to serve any purpose that cannot be met with QEMU's generic lists. Let's go for a QSIMPLEQ : this will allow to add new fids at the end of the list and to improve the logic in v9fs_mark_fids_unreclaim(). Signed-off-by: Greg Kurz Reviewed-by: Christian Schoenebeck --- hw/9pfs/9p.c | 41 ++++++++++++++++++----------------------- hw/9pfs/9p.h | 4 ++-- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 37c3379b7462..b65f320e6518 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -260,7 +260,7 @@ static V9fsFidState *coroutine_fn get_fid(V9fsPDU *pdu,= int32_t fid) V9fsFidState *f; V9fsState *s =3D pdu->s; =20 - for (f =3D s->fid_list; f; f =3D f->next) { + QSIMPLEQ_FOREACH(f, &s->fid_list, next) { BUG_ON(f->clunked); if (f->fid =3D=3D fid) { /* @@ -295,7 +295,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fi= d) { V9fsFidState *f; =20 - for (f =3D s->fid_list; f; f =3D f->next) { + QSIMPLEQ_FOREACH(f, &s->fid_list, next) { /* If fid is already there return NULL */ BUG_ON(f->clunked); if (f->fid =3D=3D fid) { @@ -311,8 +311,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fi= d) * reclaim won't close the file descriptor */ f->flags |=3D FID_REFERENCED; - f->next =3D s->fid_list; - s->fid_list =3D f; + QSIMPLEQ_INSERT_HEAD(&s->fid_list, f, next); =20 v9fs_readdir_init(s->proto_version, &f->fs.dir); v9fs_readdir_init(s->proto_version, &f->fs_reclaim.dir); @@ -401,20 +400,16 @@ static int coroutine_fn put_fid(V9fsPDU *pdu, V9fsFid= State *fidp) =20 static V9fsFidState *clunk_fid(V9fsState *s, int32_t fid) { - V9fsFidState **fidpp, *fidp; + V9fsFidState *fidp; =20 - for (fidpp =3D &s->fid_list; *fidpp; fidpp =3D &(*fidpp)->next) { - if ((*fidpp)->fid =3D=3D fid) { - break; + QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { + if (fidp->fid =3D=3D fid) { + QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); + fidp->clunked =3D true; + return fidp; } } - if (*fidpp =3D=3D NULL) { - return NULL; - } - fidp =3D *fidpp; - *fidpp =3D fidp->next; - fidp->clunked =3D true; - return fidp; + return NULL; } =20 void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) @@ -423,7 +418,7 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) V9fsState *s =3D pdu->s; V9fsFidState *f, *reclaim_list =3D NULL; =20 - for (f =3D s->fid_list; f; f =3D f->next) { + QSIMPLEQ_FOREACH(f, &s->fid_list, next) { /* * Unlink fids cannot be reclaimed. Check * for them and skip them. Also skip fids @@ -505,7 +500,7 @@ static int coroutine_fn v9fs_mark_fids_unreclaim(V9fsPD= U *pdu, V9fsPath *path) V9fsFidState *fidp; =20 again: - for (fidp =3D s->fid_list; fidp; fidp =3D fidp->next) { + QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { if (fidp->path.size !=3D path->size) { continue; } @@ -537,13 +532,13 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu) V9fsFidState *fidp; =20 /* Free all fids */ - while (s->fid_list) { + while (!QSIMPLEQ_EMPTY(&s->fid_list)) { /* Get fid */ - fidp =3D s->fid_list; + fidp =3D QSIMPLEQ_FIRST(&s->fid_list); fidp->ref++; =20 /* Clunk fid */ - s->fid_list =3D fidp->next; + QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); fidp->clunked =3D true; =20 put_fid(pdu, fidp); @@ -3121,7 +3116,7 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU = *pdu, V9fsFidState *fidp, * Fixup fid's pointing to the old name to * start pointing to the new name */ - for (tfidp =3D s->fid_list; tfidp; tfidp =3D tfidp->next) { + QSIMPLEQ_FOREACH(tfidp, &s->fid_list, next) { if (v9fs_path_is_ancestor(&fidp->path, &tfidp->path)) { /* replace the name */ v9fs_fix_path(&tfidp->path, &new_path, strlen(fidp->path.data)= ); @@ -3215,7 +3210,7 @@ static int coroutine_fn v9fs_fix_fid_paths(V9fsPDU *p= du, V9fsPath *olddir, * Fixup fid's pointing to the old name to * start pointing to the new name */ - for (tfidp =3D s->fid_list; tfidp; tfidp =3D tfidp->next) { + QSIMPLEQ_FOREACH(tfidp, &s->fid_list, next) { if (v9fs_path_is_ancestor(&oldpath, &tfidp->path)) { /* replace the name */ v9fs_fix_path(&tfidp->path, &newpath, strlen(oldpath.data)); @@ -4081,7 +4076,7 @@ int v9fs_device_realize_common(V9fsState *s, const V9= fsTransport *t, s->ctx.fmode =3D fse->fmode; s->ctx.dmode =3D fse->dmode; =20 - s->fid_list =3D NULL; + QSIMPLEQ_INIT(&s->fid_list); qemu_co_rwlock_init(&s->rename_lock); =20 if (s->ops->init(&s->ctx, errp) < 0) { diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 93656323d1d7..85fb6930b0ca 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -280,7 +280,7 @@ struct V9fsFidState { uid_t uid; int ref; bool clunked; - V9fsFidState *next; + QSIMPLEQ_ENTRY(V9fsFidState) next; V9fsFidState *rclm_lst; }; =20 @@ -339,7 +339,7 @@ typedef struct { struct V9fsState { QLIST_HEAD(, V9fsPDU) free_list; QLIST_HEAD(, V9fsPDU) active_list; - V9fsFidState *fid_list; + QSIMPLEQ_HEAD(, V9fsFidState) fid_list; FileOperations *ops; FsContext ctx; char *tag; --=20 2.26.2 From nobody Sun May 5 22:05:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610979870; cv=none; d=zohomail.com; s=zohoarc; b=OtYsik/5H3g/PShKIZTuoes9FaW2HA3ledgZJ6VtcMxrFTc6MHh6PrE9Za838sT/kZHPY/0zejAacHpqOadOCGlOyRAiwHOXJifIGJ+nR/Niw8Hems1ANKsa8ytL3bwRt1RORqyprMYEco8dc9svlKN2ioLsKvqGvPf3pTIs+Ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610979870; h=Content-Type: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=RZD2M4SQYnAqTEV8QBoQAQGPNQL+Ia0n9fchsPMOSNM=; b=UI96kxuD3QuEJgcGeFVNGv8I3XKEabDodLD/mTl6hOns1GCoB10spRWwIONMaqE66cL4c5SKdmzrAwJz9mcAK3OUcZdhJHmU8mHo5rardN8eykf0yVWeHFjVcLL06NcJnel6p+G5ZvJqg3j61cfqrDxqFahgnxrqg31iusV/FtU= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161097987045094.99761584939188; Mon, 18 Jan 2021 06:24:30 -0800 (PST) Received: from localhost ([::1]:58968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1VSH-0003Jb-65 for importer@patchew.org; Mon, 18 Jan 2021 09:24:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1VR5-00026d-GV for qemu-devel@nongnu.org; Mon, 18 Jan 2021 09:23:17 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:30430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1VR3-00022p-9w for qemu-devel@nongnu.org; Mon, 18 Jan 2021 09:23:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-513-957IcdytNSmYhtzcJ_wsyA-1; Mon, 18 Jan 2021 09:23:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BE3B801817; Mon, 18 Jan 2021 14:23:06 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8373660CC4; Mon, 18 Jan 2021 14:23:05 +0000 (UTC) X-MC-Unique: 957IcdytNSmYhtzcJ_wsyA-1 From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 3/3] 9pfs: Improve unreclaim loop Date: Mon, 18 Jan 2021 15:23:00 +0100 Message-Id: <20210118142300.801516-4-groug@kaod.org> In-Reply-To: <20210118142300.801516-1-groug@kaod.org> References: <20210118142300.801516-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: quoted-printable 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: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no 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: , Cc: Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If a fid was actually re-open by v9fs_reopen_fid(), we re-traverse the fid list from the head in case some other request created a fid that needs to be marked unreclaimable as well (ie. the client open a new handle on the path that is being unlinked). This is a suboptimal since most if not all fids that require it have likely been taken care of already. This is mostly the result of new fids being added to the head of the list. Since the list is now a QSIMPLEQ, add new fids at the end instead. Take a reference on the fid to ensure it doesn't go away during v9fs_reopen_fid() and that it can be safely passed to QSIMPLEQ_NEXT() afterwards. Since the associated put_fid() can also yield, same is done with the next fid. So the logic here is to get a reference on a fid and only put it back during the next iteration after we could get a reference on the next fid. Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index b65f320e6518..b0ab5cf61c1f 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -311,7 +311,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fi= d) * reclaim won't close the file descriptor */ f->flags |=3D FID_REFERENCED; - QSIMPLEQ_INSERT_HEAD(&s->fid_list, f, next); + QSIMPLEQ_INSERT_TAIL(&s->fid_list, f, next); =20 v9fs_readdir_init(s->proto_version, &f->fs.dir); v9fs_readdir_init(s->proto_version, &f->fs_reclaim.dir); @@ -497,32 +497,48 @@ static int coroutine_fn v9fs_mark_fids_unreclaim(V9fs= PDU *pdu, V9fsPath *path) { int err; V9fsState *s =3D pdu->s; - V9fsFidState *fidp; + V9fsFidState *fidp, *fidp_next; =20 -again: - QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { - if (fidp->path.size !=3D path->size) { - continue; - } - if (!memcmp(fidp->path.data, path->data, path->size)) { + fidp =3D QSIMPLEQ_FIRST(&s->fid_list); + assert(fidp); + + /* + * v9fs_reopen_fid() can yield : a reference on the fid must be held + * to ensure its pointer remains valid and we can safely pass it to + * QSIMPLEQ_NEXT(). The corresponding put_fid() can also yield so + * we must keep a reference on the next fid as well. So the logic here + * is to get a reference on a fid and only put it back during the next + * iteration after we could get a reference on the next fid. Start with + * the first one. + */ + for (fidp->ref++; fidp; fidp =3D fidp_next) { + if (fidp->path.size =3D=3D path->size && + !memcmp(fidp->path.data, path->data, path->size)) { /* Mark the fid non reclaimable. */ fidp->flags |=3D FID_NON_RECLAIMABLE; =20 /* reopen the file/dir if already closed */ err =3D v9fs_reopen_fid(pdu, fidp); if (err < 0) { + put_fid(pdu, fidp); return err; } + } + + fidp_next =3D QSIMPLEQ_NEXT(fidp, next); + + if (fidp_next) { /* - * Go back to head of fid list because - * the list could have got updated when - * switched to the worker thread + * Ensure the next fid survives a potential clunk request duri= ng + * put_fid() below and v9fs_reopen_fid() in the next iteration. */ - if (err =3D=3D 0) { - goto again; - } + fidp_next->ref++; } + + /* We're done with this fid */ + put_fid(pdu, fidp); } + return 0; } =20 --=20 2.26.2