From nobody Mon Feb 9 20:46:03 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612451131; cv=none; d=zohomail.com; s=zohoarc; b=G7v+7MuxL4OBWZbeFWRtT1o5wmrSkWryQ1kNAfNsG0kpgth66fClEoGlr5L2RN0PbtxU5i3ZuWYkSdO5oD3SqjYvVnHcQ0vRmg+tusJg8n/XueBPDYvRgwW8zS9a7SFfblgeUDflW0TWTF9HqA0OI5qPTANY37Wlkgo48HQ67z0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612451131; 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=TDEce3OIkshhfGWpJ6O1gNUvo+qNj3ylTwkmaF9ii04=; b=KWLZEwrV/TKEsw5qs9XbzFHSjQW0RVhPl8U0QgfNqBcZKjbUgGCjlusoMLwoKxkFWeXcO1rb2YLeRWJ3/RDML7quGRaKfUb9/LOh6P6pnSixDAavmYeDWZUSTkrVI5XD54rXJPTm/KexWh5jZ3ItRzbyY/57S5utMw7Fen+hOns= ARC-Authentication-Results: i=1; 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+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none 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 1612451131043367.00275298821134; Thu, 4 Feb 2021 07:05:31 -0800 (PST) Received: from localhost ([::1]:55012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7gCE-0004n2-3l for importer@patchew.org; Thu, 04 Feb 2021 10:05:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7g9o-000356-2C for qemu-devel@nongnu.org; Thu, 04 Feb 2021 10:02:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30350) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l7g9i-0002dU-8Y for qemu-devel@nongnu.org; Thu, 04 Feb 2021 10:02:55 -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-129-uY0QrSEKMQaDapBfBHJUag-1; Thu, 04 Feb 2021 10:02:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8736107ACE6; Thu, 4 Feb 2021 15:02:46 +0000 (UTC) Received: from localhost (ovpn-115-89.ams2.redhat.com [10.36.115.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CF0160BE2; Thu, 4 Feb 2021 15:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612450969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDEce3OIkshhfGWpJ6O1gNUvo+qNj3ylTwkmaF9ii04=; b=cTvHzeP5x7xKcFDaPDbja34W2hzekuCnP16iYvhHYkuogTiDt8ay0gF9UufC7nILl4wskS +71LyaWtmEiePA158lUfdDuFGYHEOv9QYX3tKF/8GkxQIHzV0gVFND/FW2LxrjQ+LQsKqm FxhpavdPzaLn7BOopxFfr3FJZJLtar4= X-MC-Unique: uY0QrSEKMQaDapBfBHJUag-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH v5 2/3] virtiofsd: optionally return inode pointer from lo_do_lookup() Date: Thu, 4 Feb 2021 15:02:07 +0000 Message-Id: <20210204150208.367837-3-stefanha@redhat.com> In-Reply-To: <20210204150208.367837-1-stefanha@redhat.com> References: <20210204150208.367837-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: mszeredi@redhat.com, Daniel Berrange , slp@redhat.com, Greg Kurz , P J P , virtio-fs@redhat.com, vgoyal@redhat.com, Stefan Hajnoczi , Laszlo Ersek , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" lo_do_lookup() finds an existing inode or allocates a new one. It increments nlookup so that the inode stays alive until the client releases it. Existing callers don't need the struct lo_inode so the function doesn't return it. Extend the function to optionally return the inode. The next commit will need it. Signed-off-by: Stefan Hajnoczi Reviewed-by: Greg Kurz --- tools/virtiofsd/passthrough_ll.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index f14fa5124d..aa35fc6ba5 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -831,11 +831,13 @@ static int do_statx(struct lo_data *lo, int dirfd, co= nst char *pathname, } =20 /* - * Increments nlookup and caller must release refcount using - * lo_inode_put(&parent). + * Increments nlookup on the inode on success. unref_inode_lolocked() must= be + * called eventually to decrement nlookup again. If inodep is non-NULL, the + * inode pointer is stored and the caller must call lo_inode_put(). */ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *nam= e, - struct fuse_entry_param *e) + struct fuse_entry_param *e, + struct lo_inode **inodep) { int newfd; int res; @@ -845,6 +847,10 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t par= ent, const char *name, struct lo_inode *inode =3D NULL; struct lo_inode *dir =3D lo_inode(req, parent); =20 + if (inodep) { + *inodep =3D NULL; + } + /* * name_to_handle_at() and open_by_handle_at() can reach here with fuse * mount point in guest, but we don't have its inode info in the @@ -913,7 +919,14 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t par= ent, const char *name, pthread_mutex_unlock(&lo->mutex); } e->ino =3D inode->fuse_ino; - lo_inode_put(lo, &inode); + + /* Transfer ownership of inode pointer to caller or drop it */ + if (inodep) { + *inodep =3D inode; + } else { + lo_inode_put(lo, &inode); + } + lo_inode_put(lo, &dir); =20 fuse_log(FUSE_LOG_DEBUG, " %lli/%s -> %lli\n", (unsigned long long)pa= rent, @@ -948,7 +961,7 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent= , const char *name) return; } =20 - err =3D lo_do_lookup(req, parent, name, &e); + err =3D lo_do_lookup(req, parent, name, &e, NULL); if (err) { fuse_reply_err(req, err); } else { @@ -1056,7 +1069,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino= _t parent, goto out; } =20 - saverr =3D lo_do_lookup(req, parent, name, &e); + saverr =3D lo_do_lookup(req, parent, name, &e, NULL); if (saverr) { goto out; } @@ -1534,7 +1547,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t = ino, size_t size, =20 if (plus) { if (!is_dot_or_dotdot(name)) { - err =3D lo_do_lookup(req, ino, name, &e); + err =3D lo_do_lookup(req, ino, name, &e, NULL); if (err) { goto error; } @@ -1732,7 +1745,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t pare= nt, const char *name, } =20 fi->fh =3D fh; - err =3D lo_do_lookup(req, parent, name, &e); + err =3D lo_do_lookup(req, parent, name, &e, NULL); } if (lo->cache =3D=3D CACHE_NONE) { fi->direct_io =3D 1; --=20 2.29.2