From nobody Fri Apr 19 04:19:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623335232033323.3855724107699; Thu, 10 Jun 2021 07:27:12 -0700 (PDT) Received: from localhost ([::1]:60052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrLeI-0003Jx-U1 for importer2@patchew.org; Thu, 10 Jun 2021 10:27:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrLdS-0002SU-EG for qemu-devel@nongnu.org; Thu, 10 Jun 2021 10:26:18 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:43811) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrLdM-0004nQ-6d for qemu-devel@nongnu.org; Thu, 10 Jun 2021 10:26:14 -0400 Received: by mail-pl1-x62b.google.com with SMTP id v12so1101962plo.10 for ; Thu, 10 Jun 2021 07:26:10 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.229]) by smtp.gmail.com with ESMTPSA id b14sm2903322pgl.52.2021.06.10.07.26.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jun 2021 07:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=di2Bc1dMXaIWwytWrNJ6VH6k4Sm+c/u0WhK1IYB5KBI=; b=g/b4dJnjmu45IB3EwVUgsTx/PEueA4JduRxDAXsPu2qYNwY9gc4AGIxGobiZJXtw9y oNd3ZKKNhsW5ZVFqUGShGgisUrxVL25jWSFQMHq0UFaF0IQonpaW8iNqnKcO/EqhWPFa 2y/RJPMDU1uHUpL6hoF0pDqIqtAa6xvfkJ/WxNOVcQaTx3qoi6AeJAAOUYJncyw+hRRC MFWZ1auGOumdbiCAzx2/8g1TdzYeg3sLCxnX2E9iPLVWMXg7iAQ26bP0WX9/RVsYzx08 02x0e6Ixr+/jH0KnDQGq25MwTI6IgCglyWMD/obf+Ze3ov/5yAitQCV9b9wKVMhoO7J2 OxAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=di2Bc1dMXaIWwytWrNJ6VH6k4Sm+c/u0WhK1IYB5KBI=; b=BwYETrFKMitcf2GfKMkg/RW2wvUgpkFCRLUYIlL8br7I6VhbQkh+SUQu/bk3YsWo6i RRdwIPnkIv7MqHWJRXmW9iuOJZoPastaQMVFgzYdLorYR5LanXviPqeHECeLJtev1DkZ 6uFRrS6SyqVA4jTDEwN03zj81jQczYsFbiILN9b4ysRDSKBmjhL3tkGBbImdP9CpsE8Q abwXrm5h/mQgIywxi/2hPWWFTqehuvH4llfKsZKCAI5n4iEwlvRQRCiMfmTL6ncGkewM CZqroT7+k51TsitHofE7CMlXG27KcPaj486HDdb5pvrkpi12zkrPnEL5dvfmoU+Qs/8+ qaWQ== X-Gm-Message-State: AOAM533foMTaJBd8wFQ9C6uV7k3kMrjBSkjtQa4eIycWpErq7+MxCE/H bC9Bjq/MVzBMrgzb9IrBC6DB3g== X-Google-Smtp-Source: ABdhPJyOWtgXq5XnNrKZ+Tz+XCle8Tpw/23H4todCSYF0Y4gakhIF99hK3LNrVoBWUZ2e2MMXzPMSQ== X-Received: by 2002:a17:90b:1d89:: with SMTP id pf9mr3595364pjb.26.1623335168962; Thu, 10 Jun 2021 07:26:08 -0700 (PDT) From: Jiachen Zhang To: "Dr. David Alan Gilbert" , Stefan Hajnoczi , virtio-fs@redhat.com Subject: [PATCH] virtiofsd: Avoid increasing nlookup when calling lookup_name Date: Thu, 10 Jun 2021 22:25:49 +0800 Message-Id: <20210610142549.33220-1-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=zhangjiachen.jaycee@bytedance.com; helo=mail-pl1-x62b.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiachen Zhang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 9257e514d861afa7 introduced lookup_name(), which will calls lo_find(), to increase the refcount of the inodes used in lo_rename, lo_rmdir, and lo_unlink. However, as lo_find() increases both refcount and nlookup, and the three functions do not need to increase nlookup, unref_inode_lolocked() is called later in the three function to decrease nlookup by one. This commit adds a increase_nlookup flag to lo_find(), it is set to false when called from lookup_name(). This way we can make the behavior more clear, and also makes it easier to maintain nlookup crash consistency if we are introducing crash recovery feature in the future. Signed-off-by: Jiachen Zhang --- tools/virtiofsd/passthrough_ll.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 49c21fd855..3e7c2f6b9d 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -219,7 +219,7 @@ static struct { static __thread bool cap_loaded =3D 0; =20 static struct lo_inode *lo_find(struct lo_data *lo, struct stat *st, - uint64_t mnt_id); + uint64_t mnt_id, bool increase_nlookup); static int xattr_map_client(const struct lo_data *lo, const char *client_n= ame, char **out_name); =20 @@ -880,7 +880,7 @@ out_err: } =20 static struct lo_inode *lo_find(struct lo_data *lo, struct stat *st, - uint64_t mnt_id) + uint64_t mnt_id, bool increase_nlookup) { struct lo_inode *p; struct lo_key key =3D { @@ -893,7 +893,9 @@ static struct lo_inode *lo_find(struct lo_data *lo, str= uct stat *st, p =3D g_hash_table_lookup(lo->inodes, &key); if (p) { assert(p->nlookup > 0); - p->nlookup++; + if (increase_nlookup) { + p->nlookup++; + } g_atomic_int_inc(&p->refcount); } pthread_mutex_unlock(&lo->mutex); @@ -1023,7 +1025,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t pa= rent, const char *name, e->attr_flags |=3D FUSE_ATTR_SUBMOUNT; } =20 - inode =3D lo_find(lo, &e->attr, mnt_id); + inode =3D lo_find(lo, &e->attr, mnt_id, true); if (inode) { close(newfd); } else { @@ -1316,7 +1318,7 @@ out_err: fuse_reply_err(req, saverr); } =20 -/* Increments nlookup and caller must release refcount using lo_inode_put(= ) */ +/* Caller must release refcount using lo_inode_put() */ static struct lo_inode *lookup_name(fuse_req_t req, fuse_ino_t parent, const char *name) { @@ -1336,7 +1338,7 @@ static struct lo_inode *lookup_name(fuse_req_t req, f= use_ino_t parent, return NULL; } =20 - return lo_find(lo, &attr, mnt_id); + return lo_find(lo, &attr, mnt_id, false); } =20 static void lo_rmdir(fuse_req_t req, fuse_ino_t parent, const char *name) @@ -1364,7 +1366,6 @@ static void lo_rmdir(fuse_req_t req, fuse_ino_t paren= t, const char *name) res =3D unlinkat(lo_fd(req, parent), name, AT_REMOVEDIR); =20 fuse_reply_err(req, res =3D=3D -1 ? errno : 0); - unref_inode_lolocked(lo, inode, 1); lo_inode_put(lo, &inode); } =20 @@ -1423,8 +1424,6 @@ static void lo_rename(fuse_req_t req, fuse_ino_t pare= nt, const char *name, =20 fuse_reply_err(req, res =3D=3D -1 ? errno : 0); out: - unref_inode_lolocked(lo, oldinode, 1); - unref_inode_lolocked(lo, newinode, 1); lo_inode_put(lo, &oldinode); lo_inode_put(lo, &newinode); lo_inode_put(lo, &parent_inode); @@ -1456,7 +1455,6 @@ static void lo_unlink(fuse_req_t req, fuse_ino_t pare= nt, const char *name) res =3D unlinkat(lo_fd(req, parent), name, 0); =20 fuse_reply_err(req, res =3D=3D -1 ? errno : 0); - unref_inode_lolocked(lo, inode, 1); lo_inode_put(lo, &inode); } =20 --=20 2.20.1