From patchwork Mon Jan 25 11:44:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12043269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EB68C433E0 for ; Mon, 25 Jan 2021 11:46:50 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 00A6722D04 for ; Mon, 25 Jan 2021 11:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 00A6722D04 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l40KW-0000fm-U2 for qemu-devel@archiver.kernel.org; Mon, 25 Jan 2021 06:46:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l40Ii-0007lK-Gn for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:56 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:55173) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l40Ig-0007KN-9z for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:56 -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-328-zdsEo8jQM_OcsCptfPQiJQ-1; Mon, 25 Jan 2021 06:44:48 -0500 X-MC-Unique: zdsEo8jQM_OcsCptfPQiJQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19DDD801AB7; Mon, 25 Jan 2021 11:44:47 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06C1A5D9D7; Mon, 25 Jan 2021 11:44:45 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PULL 1/5] 9pfs/proxy: Check return value of proxy_marshal() Date: Mon, 25 Jan 2021 12:44:39 +0100 Message-Id: <20210125114443.933857-2-groug@kaod.org> In-Reply-To: <20210125114443.933857-1-groug@kaod.org> References: <20210125114443.933857-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 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: Peter Maydell , Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This should always successfully write exactly two 32-bit integers. Make it clear with an assert(), like v9fs_receive_status() and v9fs_receive_response() already do when unmarshalling the same header. Fixes: Coverity CID 1438968 Reviewed-by: Christian Schoenebeck Message-Id: <161035859647.1221144.4691749806675653934.stgit@bahia.lan> Signed-off-by: Greg Kurz --- hw/9pfs/9p-proxy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 6f598a0f111c..4aa4e0a3baa0 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -537,7 +537,8 @@ static int v9fs_request(V9fsProxy *proxy, int type, void *response, ...) } /* marshal the header details */ - proxy_marshal(iovec, 0, "dd", header.type, header.size); + retval = proxy_marshal(iovec, 0, "dd", header.type, header.size); + assert(retval == 4 * 2); header.size += PROXY_HDR_SZ; retval = qemu_write_full(proxy->sockfd, iovec->iov_base, header.size); From patchwork Mon Jan 25 11:44:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12043277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0300C433DB for ; Mon, 25 Jan 2021 11:49:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2ACC6216FD for ; Mon, 25 Jan 2021 11:49:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2ACC6216FD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l40NH-00044V-3v for qemu-devel@archiver.kernel.org; Mon, 25 Jan 2021 06:49:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l40Ij-0007lc-6v for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:57 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:20631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l40Ig-0007KY-GL for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:56 -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-501-NRf-jST9NBC8ds2bRiulcQ-1; Mon, 25 Jan 2021 06:44:49 -0500 X-MC-Unique: NRf-jST9NBC8ds2bRiulcQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8178A107ACF6; Mon, 25 Jan 2021 11:44:48 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83A9F5D9D7; Mon, 25 Jan 2021 11:44:47 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PULL 2/5] 9pfs: Convert V9fsFidState::clunked to bool Date: Mon, 25 Jan 2021 12:44:40 +0100 Message-Id: <20210125114443.933857-3-groug@kaod.org> In-Reply-To: <20210125114443.933857-1-groug@kaod.org> References: <20210125114443.933857-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 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: Peter Maydell , Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This can only be 0 or 1. Reviewed-by: Christian Schoenebeck Message-Id: <20210118142300.801516-2-groug@kaod.org> Signed-off-by: Greg Kurz --- 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 fid) } fidp = *fidpp; *fidpp = fidp->next; - fidp->clunked = 1; + fidp->clunked = true; return fidp; } @@ -544,7 +544,7 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu) /* Clunk fid */ s->fid_list = fidp->next; - fidp->clunked = 1; + fidp->clunked = true; 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; }; From patchwork Mon Jan 25 11:44:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12043279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE760C433E0 for ; Mon, 25 Jan 2021 11:52:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3C9F522D04 for ; Mon, 25 Jan 2021 11:52:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C9F522D04 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l40Pk-0006cO-6A for qemu-devel@archiver.kernel.org; Mon, 25 Jan 2021 06:52:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l40Ij-0007m5-L2 for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:57 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:57147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l40Ih-0007Lt-In for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:57 -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-559-w4Oy_cYJNjO4e4tmS3k1cQ-1; Mon, 25 Jan 2021 06:44:50 -0500 X-MC-Unique: w4Oy_cYJNjO4e4tmS3k1cQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAFC810054FF; Mon, 25 Jan 2021 11:44:49 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD1335D9D7; Mon, 25 Jan 2021 11:44:48 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PULL 3/5] 9pfs: Convert V9fsFidState::fid_list to QSIMPLEQ Date: Mon, 25 Jan 2021 12:44:41 +0100 Message-Id: <20210125114443.933857-4-groug@kaod.org> In-Reply-To: <20210125114443.933857-1-groug@kaod.org> References: <20210125114443.933857-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 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: Peter Maydell , Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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(). Reviewed-by: Christian Schoenebeck Message-Id: <20210118142300.801516-3-groug@kaod.org> Signed-off-by: Greg Kurz --- 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 = pdu->s; - for (f = s->fid_list; f; f = f->next) { + QSIMPLEQ_FOREACH(f, &s->fid_list, next) { BUG_ON(f->clunked); if (f->fid == fid) { /* @@ -295,7 +295,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) { V9fsFidState *f; - for (f = s->fid_list; f; f = f->next) { + QSIMPLEQ_FOREACH(f, &s->fid_list, next) { /* If fid is already there return NULL */ BUG_ON(f->clunked); if (f->fid == fid) { @@ -311,8 +311,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) * reclaim won't close the file descriptor */ f->flags |= FID_REFERENCED; - f->next = s->fid_list; - s->fid_list = f; + QSIMPLEQ_INSERT_HEAD(&s->fid_list, f, next); 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, V9fsFidState *fidp) static V9fsFidState *clunk_fid(V9fsState *s, int32_t fid) { - V9fsFidState **fidpp, *fidp; + V9fsFidState *fidp; - for (fidpp = &s->fid_list; *fidpp; fidpp = &(*fidpp)->next) { - if ((*fidpp)->fid == fid) { - break; + QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { + if (fidp->fid == fid) { + QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); + fidp->clunked = true; + return fidp; } } - if (*fidpp == NULL) { - return NULL; - } - fidp = *fidpp; - *fidpp = fidp->next; - fidp->clunked = true; - return fidp; + return NULL; } void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) @@ -423,7 +418,7 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) V9fsState *s = pdu->s; V9fsFidState *f, *reclaim_list = NULL; - for (f = s->fid_list; f; f = 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(V9fsPDU *pdu, V9fsPath *path) V9fsFidState *fidp; again: - for (fidp = s->fid_list; fidp; fidp = fidp->next) { + QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { if (fidp->path.size != path->size) { continue; } @@ -537,13 +532,13 @@ static void coroutine_fn virtfs_reset(V9fsPDU *pdu) V9fsFidState *fidp; /* Free all fids */ - while (s->fid_list) { + while (!QSIMPLEQ_EMPTY(&s->fid_list)) { /* Get fid */ - fidp = s->fid_list; + fidp = QSIMPLEQ_FIRST(&s->fid_list); fidp->ref++; /* Clunk fid */ - s->fid_list = fidp->next; + QSIMPLEQ_REMOVE(&s->fid_list, fidp, V9fsFidState, next); fidp->clunked = true; 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 = s->fid_list; tfidp; tfidp = 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 *pdu, V9fsPath *olddir, * Fixup fid's pointing to the old name to * start pointing to the new name */ - for (tfidp = s->fid_list; tfidp; tfidp = 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 V9fsTransport *t, s->ctx.fmode = fse->fmode; s->ctx.dmode = fse->dmode; - s->fid_list = NULL; + QSIMPLEQ_INIT(&s->fid_list); qemu_co_rwlock_init(&s->rename_lock); 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; }; @@ -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; From patchwork Mon Jan 25 11:44:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12043275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03D1EC433DB for ; Mon, 25 Jan 2021 11:49:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 86EEB216FD for ; Mon, 25 Jan 2021 11:49:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86EEB216FD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l40NE-0003ye-5Q for qemu-devel@archiver.kernel.org; Mon, 25 Jan 2021 06:49:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l40Ik-0007mn-0X for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:58 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:44483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l40Ih-0007Ki-RT for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:57 -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-575-ri_IcRTgObSuuFiUGTyXrw-1; Mon, 25 Jan 2021 06:44:52 -0500 X-MC-Unique: ri_IcRTgObSuuFiUGTyXrw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 289E71005513; Mon, 25 Jan 2021 11:44:51 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22ECB5D9D7; Mon, 25 Jan 2021 11:44:49 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PULL 4/5] 9pfs: Improve unreclaim loop Date: Mon, 25 Jan 2021 12:44:42 +0100 Message-Id: <20210125114443.933857-5-groug@kaod.org> In-Reply-To: <20210125114443.933857-1-groug@kaod.org> References: <20210125114443.933857-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.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: Peter Maydell , Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If a fid was actually re-opened 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 (i.e. the client opened a new handle on the path that is being unlinked). This is 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 to avoid the need to rewind. 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. Reviewed-by: Christian Schoenebeck Message-Id: <20210121181510.1459390-1-groug@kaod.org> Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index b65f320e6518..3864d014b43c 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -311,7 +311,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) * reclaim won't close the file descriptor */ f->flags |= FID_REFERENCED; - QSIMPLEQ_INSERT_HEAD(&s->fid_list, f, next); + QSIMPLEQ_INSERT_TAIL(&s->fid_list, f, next); v9fs_readdir_init(s->proto_version, &f->fs.dir); v9fs_readdir_init(s->proto_version, &f->fs_reclaim.dir); @@ -497,32 +497,50 @@ static int coroutine_fn v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path) { int err; V9fsState *s = pdu->s; - V9fsFidState *fidp; + V9fsFidState *fidp, *fidp_next; -again: - QSIMPLEQ_FOREACH(fidp, &s->fid_list, next) { - if (fidp->path.size != path->size) { - continue; - } - if (!memcmp(fidp->path.data, path->data, path->size)) { + fidp = QSIMPLEQ_FIRST(&s->fid_list); + if (!fidp) { + return 0; + } + + /* + * 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 = fidp_next) { + if (fidp->path.size == path->size && + !memcmp(fidp->path.data, path->data, path->size)) { /* Mark the fid non reclaimable. */ fidp->flags |= FID_NON_RECLAIMABLE; /* reopen the file/dir if already closed */ err = v9fs_reopen_fid(pdu, fidp); if (err < 0) { + put_fid(pdu, fidp); return err; } + } + + fidp_next = 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 during + * put_fid() below and v9fs_reopen_fid() in the next iteration. */ - if (err == 0) { - goto again; - } + fidp_next->ref++; } + + /* We're done with this fid */ + put_fid(pdu, fidp); } + return 0; } From patchwork Mon Jan 25 11:44:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 12043273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 705D4C433DB for ; Mon, 25 Jan 2021 11:47:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AD61622D04 for ; Mon, 25 Jan 2021 11:47:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD61622D04 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l40L9-0000vx-CY for qemu-devel@archiver.kernel.org; Mon, 25 Jan 2021 06:47:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l40Il-0007qx-Ll for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:59 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:25355) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l40Ik-0007N8-6T for qemu-devel@nongnu.org; Mon, 25 Jan 2021 06:44:59 -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-288-p1k5znL8Mn-seHq4hD6Bfg-1; Mon, 25 Jan 2021 06:44:53 -0500 X-MC-Unique: p1k5znL8Mn-seHq4hD6Bfg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7583610054FF; Mon, 25 Jan 2021 11:44:52 +0000 (UTC) Received: from bahia.redhat.com (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 749685D9D7; Mon, 25 Jan 2021 11:44:51 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PULL 5/5] 9pfs: Convert reclaim list to QSLIST Date: Mon, 25 Jan 2021 12:44:43 +0100 Message-Id: <20210125114443.933857-6-groug@kaod.org> In-Reply-To: <20210125114443.933857-1-groug@kaod.org> References: <20210125114443.933857-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 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: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) BAYES_00=-1.9, PDS_OTHER_BAD_TLD=1.999, 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: Peter Maydell , Christian Schoenebeck , Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use QSLIST instead of open-coding for a slightly improved readability. No behavioral change. Reviewed-by: Christian Schoenebeck Message-Id: <20210122143514.215780-1-groug@kaod.org> Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 17 ++++++++--------- hw/9pfs/9p.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 3864d014b43c..5a6e2c9d3d7f 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -416,7 +416,9 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) { int reclaim_count = 0; V9fsState *s = pdu->s; - V9fsFidState *f, *reclaim_list = NULL; + V9fsFidState *f; + QSLIST_HEAD(, V9fsFidState) reclaim_list = + QSLIST_HEAD_INITIALIZER(reclaim_list); QSIMPLEQ_FOREACH(f, &s->fid_list, next) { /* @@ -448,8 +450,7 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) * a clunk request won't free this fid */ f->ref++; - f->rclm_lst = reclaim_list; - reclaim_list = f; + QSLIST_INSERT_HEAD(&reclaim_list, f, reclaim_next); f->fs_reclaim.fd = f->fs.fd; f->fs.fd = -1; reclaim_count++; @@ -461,8 +462,7 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) * a clunk request won't free this fid */ f->ref++; - f->rclm_lst = reclaim_list; - reclaim_list = f; + QSLIST_INSERT_HEAD(&reclaim_list, f, reclaim_next); f->fs_reclaim.dir.stream = f->fs.dir.stream; f->fs.dir.stream = NULL; reclaim_count++; @@ -476,15 +476,14 @@ void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu) * Now close the fid in reclaim list. Free them if they * are already clunked. */ - while (reclaim_list) { - f = reclaim_list; - reclaim_list = f->rclm_lst; + while (!QSLIST_EMPTY(&reclaim_list)) { + f = QSLIST_FIRST(&reclaim_list); + QSLIST_REMOVE(&reclaim_list, f, V9fsFidState, reclaim_next); if (f->fid_type == P9_FID_FILE) { v9fs_co_close(pdu, &f->fs_reclaim); } else if (f->fid_type == P9_FID_DIR) { v9fs_co_closedir(pdu, &f->fs_reclaim); } - f->rclm_lst = NULL; /* * Now drop the fid reference, free it * if clunked. diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 85fb6930b0ca..00381591ffa2 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -281,7 +281,7 @@ struct V9fsFidState { int ref; bool clunked; QSIMPLEQ_ENTRY(V9fsFidState) next; - V9fsFidState *rclm_lst; + QSLIST_ENTRY(V9fsFidState) reclaim_next; }; typedef enum AffixType_t {