From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A7C2C6FA83 for ; Tue, 27 Sep 2022 18:07:35 +0000 (UTC) Received: from localhost ([::1]:54974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odDqT-000462-2i for qemu-devel@archiver.kernel.org; Tue, 27 Sep 2022 12:54:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odCIb-00087e-Lm; Tue, 27 Sep 2022 11:15:05 -0400 Received: from sosiego.soundray.org ([116.203.207.114]:52162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odCIZ-0001Si-QU; Tue, 27 Sep 2022 11:15:05 -0400 From: Linus Heckemann DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sphalerite.org; s=sosiego; t=1664291699; bh=mmoSWSPony/OOcRS26GkOGGpwYFoZXbHHGHNNYxjq9g=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=RLg4ZgPFqLBridZr/wCm+pDvE+UnZdhOQGlPLVPYuaQpkFTlF74mGsZNVGC7Ptt61 h4Jfc/HTgLPCBR5F/v0zS7TOeIFo46l6HGnx1QQl9MOILiMDVWSbGBIfL97PXui/Hh DNvOSyGjKyw/kUCIhL7S+KLnSKFXMUD5nONqVoIM= To: Christian Schoenebeck , qemu-devel@nongnu.org Cc: Qemu-block , Greg Kurz , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Subject: Re: [PATCH v5] 9pfs: use GHashTable for fid table In-Reply-To: <20220927142503.1694674-1-git@sphalerite.org> References: <20220927142503.1694674-1-git@sphalerite.org> Date: Tue, 27 Sep 2022 17:14:57 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=116.203.207.114; envelope-from=git@sphalerite.org; helo=sosiego.soundray.org 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_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Linus Heckemann writes: > static void coroutine_fn virtfs_reset(V9fsPDU *pdu) > { > V9fsState *s = pdu->s; > V9fsFidState *fidp; > + GList *freeing; > + /* Get a list of all the values (fid states) in the table, which we then... */ > + g_autoptr(GList) fids = g_hash_table_get_values(s->fids); > > - /* Free all fids */ > - while (!QSIMPLEQ_EMPTY(&s->fid_list)) { > - /* Get fid */ > - fidp = QSIMPLEQ_FIRST(&s->fid_list); > - fidp->ref++; > + /* ... remove from the table, taking over ownership. */ > + g_hash_table_steal_all(s->fids); > > - /* Clunk fid */ > - QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); > + /* > + * This allows us to release our references to them asynchronously without > + * iterating over the hash table and risking iterator invalidation > + * through concurrent modifications. > + */ > + for (freeing = fids; freeing; freeing = freeing->next) { > + fidp = freeing->data; > + fidp->ref++; > fidp->clunked = true; > - > put_fid(pdu, fidp); > } > } I'm not sure if this implementation is correct. I'm concerned that it may result in dangling references, but haven't been able to find a client that will send the TVERSION request on a connection that's already been used in other ways, as opposed to when the connection is first established. I suspect this will be very rare in general, so it might be good to have a test case somewhere.