Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7510647rdb; Wed, 3 Jan 2024 20:40:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzvv+JAMBSqf+M/wz/iG3788yQfUkuBJtUoH/WGFxykk4bhQhhwXX6GyIczPdzImFxDx7c X-Received: by 2002:a05:6358:2812:b0:170:d74a:3aca with SMTP id k18-20020a056358281200b00170d74a3acamr20087rwb.63.1704343218975; Wed, 03 Jan 2024 20:40:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704343218; cv=none; d=google.com; s=arc-20160816; b=fvj2IYciVYjGcxSxZFVB9q4HQTPCohRVZNGoPX5HZrsV+5Y4VSp66p6LrqrlAa+2TK yQYCydkGUmzLAGuGejct2xBAc1uLyRSNT+zN7Tcfch/CtgV9mz8zE+uQgTw/TACRB5sK GAdvjldfbXdOEvntOe8s1vPpVXl/t6F0/DqB+4zpkmnXkWhHGR/a6bIFl5F0EW1i72Iw 2BI3Ll9m5bfFE+XQDFViwjF0jNjeiBPKV6DshLgJBGWrspNbKB7m4LfdSZ5w6ixVf331 /rmFYXJAllEKjYo5EWswxEYSNrRph1v0sM1o0zIgBW9O5KbpuQbahelxizlNCTyL6NZr SdgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=CtSYda2UUwOgNnyx2mXQ6hEwTW/gnpzF7k6u3XOdM2A=; fh=LVijBhQIFqKzwXXSERkvN96JucKU5xZhL1iTTTVYrKA=; b=rvhaHlAR39eYYhrdHegA67noqQT1fR06vO0WhEfhQbAdEfN3mv+tb3ycmZishqA0U7 PInmGrksRrQXhkYEBj4MJhTmHOrmsEFf9SI/el3aAaAHLwFZ67IbtTKoOKS6Og/S26qD OHWQMMmxlDUEGvi8Oh4tIXwMwgZpKUZO8hQ83lcApgH5Ne7v5oF09lSRglTmOKhvfEqD LFy+hcY2QP4z4jd8KpeBn8F5dgBeYbJxu0ZseuNMCpkqqnQjdZm4FTZ9nqMIDsv/h6la KegIzAmnv2z9vFuI03YCchQ1Gu0rtEZsx1qXfMtDPzqhUwheIZ4ENzoJyPNoaHUmycdY 8WkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=B9UarvKk; spf=pass (google.com: domain of linux-kernel+bounces-16244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q23-20020a631f57000000b005ce0b9846a2si18396251pgm.384.2024.01.03.20.40.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 20:40:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=B9UarvKk; spf=pass (google.com: domain of linux-kernel+bounces-16244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B8722286E0C for ; Thu, 4 Jan 2024 04:40:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEE8C14F6E; Thu, 4 Jan 2024 04:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="B9UarvKk" X-Original-To: linux-kernel@vger.kernel.org Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 804BA18647; Thu, 4 Jan 2024 04:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=CtSYda2UUwOgNnyx2mXQ6hEwTW/gnpzF7k6u3XOdM2A=; b=B9UarvKkJb0/RMb4ElWH1LPDW+ FR4n8bnbBClsSfL/lHmedGb6lDwATNVK3VPkzyXqD03DK22dCSflvnUy9hyADdYh4eQio6AeAkuhz Qt2WEJzoXloqD/DyW80hgQ5cU1QoMaWK2WkQiewuSv1sGDJfbYijLqwFHcdYgO6SkxWwXL2qLrlBS hGKFDVI70EB70wozcIznC18+3lp+M1xaLuXXhGr2JJCUVfTUFFs5RSZFHVRmUwpn2XoxF+m3VaskT DZ8rWkcbeKr42lr+Jn5SRabRthucua4FZ9OyTtlmDkCLnIO0Ucm9fueYZqDyHWCUYnI938KePinpr Yy6DSGyQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1rLFWD-001EqY-1X; Thu, 04 Jan 2024 04:39:45 +0000 Date: Thu, 4 Jan 2024 04:39:45 +0000 From: Al Viro To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , Linus Torvalds , Christian Brauner , linux-fsdevel@vger.kernel.org, Greg Kroah-Hartman Subject: Re: [PATCH] tracefs/eventfs: Use root and instance inodes as default ownership Message-ID: <20240104043945.GQ1674809@ZenIV> References: <20240103203246.115732ec@gandalf.local.home> <20240104014837.GO1674809@ZenIV> <20240103212506.41432d12@gandalf.local.home> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240103212506.41432d12@gandalf.local.home> Sender: Al Viro On Wed, Jan 03, 2024 at 09:25:06PM -0500, Steven Rostedt wrote: > On Thu, 4 Jan 2024 01:48:37 +0000 > Al Viro wrote: > > > On Wed, Jan 03, 2024 at 08:32:46PM -0500, Steven Rostedt wrote: > > > > > + /* Get the tracefs root from the parent */ > > > + inode = d_inode(dentry->d_parent); > > > + inode = d_inode(inode->i_sb->s_root); > > > > That makes no sense. First of all, for any positive dentry we have > > dentry->d_sb == dentry->d_inode->i_sb. And it's the same for all > > dentries on given superblock. So what's the point of that dance? > > If you want the root inode, just go for d_inode(dentry->d_sb->s_root) > > and be done with that... > > That was more of thinking that the dentry and dentry->d_parent are > different. As dentry is part of eventfs and dentry->d_parent is part of > tracefs. ??? >Currently they both have the same superblock so yeah, I could just > write it that way too and it would work. But in my head, I was thinking > that they behave differently and maybe one day eventfs would get its own > superblock which would not work. ->d_parent *always* points to the same filesystem; if you get an (automounted?) mountpoint there, ->d_parent simply won't work - it will point to dentry itself. > To explain this better: > > /sys/kernel/tracing/ is the parent of /sys/kernel/tracing/events > > But everything but "events" in /sys/kernel/tracing/* is part of tracefs. > Everything in /sys/kernel/tracing/events is part of eventfs. > > That was my thought process. But as both tracefs and eventfs still use > tracefs_get_inode(), it would work as you state. > > I'll update that, as I don't foresee that eventfs will become its own file > system. There is no way to get to underlying mountpoint by dentry - simply because the same fs instance can be mounted in any number of places. A crude overview of taxonomy: file_system_type: what filesystem instances belong to. Not quite the same thing as fs driver (one driver can provide several of those). Usually it's 1-to-1, but that's not required (e.g. NFS vs NFSv4, or ext[234], or...). super_block: individual filesystem instance. Hosts dentry tree (connected or several disconnected parts - think NFSv4 or the state while trying to get a dentry by fhandle, etc.). dentry: object in a filesystem's directory tree(s). Always belongs to specific filesystem instance - that relationship never changes. Tree structure (and names) _within_ _filesystem_ belong on that level. ->d_parent is part of that tree structure; never NULL, root of a (sub)tree has it pointing to itself. Might be negative, might refer to a filesystem object (file, directory, symlink, etc.). inode: filesystem object (file, directory, etc.). Always belongs to specific filesystem instance. Non-directory inodes might have any number of dentry instances (aliases) refering to it; a directory one - no more than one. Filesystem object contents belongs here; multiple hardlinks have different dentries and the same inode. Of course, filesystem type in question might have no such thing as multiple hardlinks - that's up to filesystem. In general there is no way to find (or enumerate) such links; e.g. a local filesystem might have an extra hardlink somewhere we had never looked at and there won't be any dentries for such hardlinks and no way to get them short of doing the full search of the entire tree. The situation with e.g. NFS client is even worse, obviously. mount: in a sense, mount to super_block is what dentry is to inode. It provides a view of (sub)tree hosted in given filesystem instance. The same filesystem may have any number of mounts, refering to its subtrees (possibly the same subtree for each, possibly all different - up to the callers of mount(2)). They form mount tree(s) - that's where the notions related to "this mounted on top of that" belong. Note that they can be moved around - with no telling the filesystem about that happening. Again, there's no such thing as "the mountpoint of given filesystem instance" - it might be mounted in any number of places at the same time. Specific mount - sure, no problem, except that it can move around. namespace: mount tree. Unlike everything prior, this one is a part of process state - same as descriptor table, mappings, etc. file: opened IO channel. It does refer to specific mount and specific dentry (and thus filesystem instance and an inode on it). Current IO position lives here, so does any per-open(2) state. descriptor table: mapping from numbers to IO channels (opened files). Again, a part of process state. dup() creates a new entry, with reference to the same file as the old one; multiple open() of the same pathname will each yield a separate opened file. _Some_ state belongs here (close-on-exec, mostly). Note that there's no such thing as "the descriptor of this file" - not even "the user-supplied number that had been used to get the file we are currently reading from", since that number might be refering to something entirely different right after we'd resolved it to opened file and that happens *without* disrupting the operation.