Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp5140rdh; Tue, 6 Feb 2024 16:53:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcHlAKtBQo0ANZbRP8nxj2N9+KZhvyZjLI/9LtdxM9ZQhmzLN497nYDBf/17M3OuhAB+o3/Qhmhct8kjHU3uLAqluBdPYO68ngsV0Oxg== X-Google-Smtp-Source: AGHT+IEgyf9OJpwliRKUOzYp4t+vXeLj4K50Ho4urzVeYZ/W7r9+2M3X0YrFRHhPfD0YNuv9KrtH X-Received: by 2002:a05:6214:19e2:b0:68c:746f:734b with SMTP id q2-20020a05621419e200b0068c746f734bmr5370818qvc.26.1707267195188; Tue, 06 Feb 2024 16:53:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707267195; cv=pass; d=google.com; s=arc-20160816; b=Wfd/hpb6WHfwZz1aAetBLMSv3TuDGhqY++CNDTQiqb+fFd4C8ULY0qPrwpQsVsoLj1 DEyIATn6Qzv6J+fxMKnJTv468rszZC7wM6vx6qKJTgqOxSpfTkV9CKn4f39b0nYl9nmi EXVEb95BLozQxqrqfi48wXjdIgDCXxlWGOKtT7TChR2OQRsW5Csv6C9sM57/sTdKlajl TcGAln1ZgtVg+vx6vQGCd8IieL3XNAmq6mQW8Fo2LgfFDNP4e99tfYOr5/4YabD1JZhm 4PVrOS03/iMElLN5gmdrlKwUv7c9+63Njpu5wQgZnfB8OUS3XKocODA3uWykwbWaQ/mm 7jTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=xKJg4xDRPfxrmB09U1/OU0Wyf/oKOvuGfaF8SQKeioU=; fh=ZBnDvsAa9BmhSOPmaRGWUPe6UKRo7JmRUADO5iaOvIQ=; b=Fv6lHWRCF/3Q1tQe6wjaSL1pVqqCiO9mJ41UH8MhJHoueffyckc/bcU7IIhuDozhVj 5VhkS9zruekxzA52rFtwmm67d9+ZAN+5grYRfbgeD96YlyBr1u2kt0lg7dCLab2mkmlP Ge+q/E01ZqkzyG22dHUyX2DF8KUWeSbzkvOPjHQkFTuS+hvE+t2X92x6EEHvZeeeqq0n RiEyqO2f4DDcrRakTu2WvNoj6z9iJmShjZgOrRtbO3l0hoqZMUF0XwM1GgpTuAzjugNU YysSpvXyeAK8d8E4LlFxQq1Zm95U/51FvIutWUbHZmzf4QfttmicDdiyry80qvh069lo S8bA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qwUJ5DxY; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-55773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55773-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCVNxk0sTHFng1ucNFaFai7C2ddHnCyrjK5p3ZYM5WHUpG/aGCnM06prsKKMh//EJlB+KtbCIKHCjCl8FRCsHz6XCrDMSTYnUJmEJ9AYPw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j2-20020a0ceb02000000b0068cb0d93942si108094qvp.410.2024.02.06.16.53.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 16:53:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=qwUJ5DxY; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-55773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55773-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EC7B71C2468A for ; Wed, 7 Feb 2024 00:53:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39007F9EA; Wed, 7 Feb 2024 00:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qwUJ5DxY" Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 1884EEED0 for ; Wed, 7 Feb 2024 00:53:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707267185; cv=none; b=ed7z5HdPpoZbW6RTNpLOcIba2yQRtYr8V584c1TYYacCKAEv2VkIc/mJwHEDpg/j82HLSn+8HcH5x9hZWVxbmIrOWr/qWT4ls5G6eMUSPv8DgIOpZgm2WZXsbiCytkVY/vaMxVJSD1EsOnU4DOfoYpr0iOWYqiFjUYtH/C/6R1k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707267185; c=relaxed/simple; bh=i6MOU3XAf6ORd9eWxLKeFNLmu+/lfcJD3ylRSkOkZfM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WMJb/W0cz+2WnCRKdW/LrYDJOMf1LfcFceqxPSb0zId8tKcYnezSZm2ICqvIlmh9au3c/tt1vg6St/NiEReHl1KcromUTyrNym1LZwvZpf501NrDtXyBFtkicNq7k5TxvasVj/N6V2pjBkweCv2fRPJNT7nVEQRLIenbTjvKcsE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qwUJ5DxY; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Tue, 6 Feb 2024 19:52:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707267180; 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: in-reply-to:in-reply-to:references:references; bh=xKJg4xDRPfxrmB09U1/OU0Wyf/oKOvuGfaF8SQKeioU=; b=qwUJ5DxYqSpZfutGhz4IjFVNbMmbJchD6Xs8Goyj2c0dLJns/fAD5iKCCBuY8a9hdE1fGY 8ryIbZSG0MPPd2VNf2H1DfRcEiDZbW/9ZBOoMuV/bqGAMGTci4/8NEUkRj3RHvGIOvX7w4 G8C0D31mwXazZukzt/DJD7ET04zq/rk= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Dave Chinner Cc: brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner , "Darrick J. Wong" , Theodore Ts'o , Josef Bacik Subject: Re: [PATCH v2 5/7] fs: FS_IOC_GETSYSFSNAME Message-ID: References: <20240206201858.952303-1-kent.overstreet@linux.dev> <20240206201858.952303-6-kent.overstreet@linux.dev> 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: X-Migadu-Flow: FLOW_OUT On Wed, Feb 07, 2024 at 09:26:40AM +1100, Dave Chinner wrote: > On Tue, Feb 06, 2024 at 03:18:53PM -0500, Kent Overstreet wrote: > > Add a new ioctl for getting the sysfs name of a filesystem - the path > > under /sys/fs. > > > > This is going to let us standardize exporting data from sysfs across > > filesystems, e.g. time stats. > > > > The returned path will always be of the form "$FSTYP/$SYSFS_IDENTIFIER", > > where the sysfs identifier may be a UUID (for bcachefs) or a device name > > (xfs). > > > > Cc: Christian Brauner > > Cc: Jan Kara > > Cc: Dave Chinner > > Cc: "Darrick J. Wong" > > Cc: Theodore Ts'o > > Cc: Josef Bacik > > Signed-off-by: Kent Overstreet > > --- > > fs/ioctl.c | 17 +++++++++++++++++ > > include/linux/fs.h | 1 + > > include/uapi/linux/fs.h | 10 ++++++++++ > > 3 files changed, 28 insertions(+) > > > > diff --git a/fs/ioctl.c b/fs/ioctl.c > > index 046c30294a82..7c37765bd04e 100644 > > --- a/fs/ioctl.c > > +++ b/fs/ioctl.c > > @@ -776,6 +776,20 @@ static int ioctl_getfsuuid(struct file *file, void __user *argp) > > return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0; > > } > > > > +static int ioctl_get_fs_sysfs_path(struct file *file, void __user *argp) > > +{ > > + struct super_block *sb = file_inode(file)->i_sb; > > + > > + if (!strlen(sb->s_sysfs_name)) > > + return -ENOIOCTLCMD; > > This relies on the kernel developers getting string termination > right and not overflowing buffers. > > We can do better, I think, and I suspect that starts with a > super_set_sysfs_name() helper.... I don't think that's needed here; a standard snprintf() ensures that the buffer is null terminated, even if the result overflowed. > > + struct fssysfspath u = {}; > > Variable names that look like the cat just walked over the keyboard > are difficult to read. Please use some separators here! > > Also, same comment as previous about mixing code and declarations. > > > + > > + snprintf(u.name, sizeof(u.name), "%s/%s", sb->s_type->name, sb->s_sysfs_name); > > What happens if the combined path overflows the fssysfspath > buffer? It won't; s_sysfs_name is going to be either a UUID or a short device name. It can't be a longer device name (like we show in /proc/mounts) - here that would lead to ambiguouty. > > + char s_sysfs_name[UUID_STRING_LEN + 1]; > > Can we just kstrdup() the sysfs name and keep a {ptr, len} pair > in the sb for this? Then we can treat them as an opaque identifier > that isn't actually a string, and we don't have to make up some > arbitrary maximum name size, either. What if we went in a different direction - take your previous suggestion to have a helper for setting the name, and then enforce through the API that the only valid identifiers are a UUID or a short device name. super_set_sysfs_identifier_uuid(sb); super_set_sysfs_identifier_device(sb); then we can enforce that the identifier comes from either sb->s_uuid or sb->s_dev. I'll have to check existing filesystems before we commit to that, though. > > > unsigned int s_max_links; > > > > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > > index 16a6ecadfd8d..c0f7bd4b6350 100644 > > --- a/include/uapi/linux/fs.h > > +++ b/include/uapi/linux/fs.h > > @@ -77,6 +77,10 @@ struct fsuuid2 { > > __u8 uuid[16]; > > }; > > > > +struct fssysfspath { > > + __u8 name[128]; > > +}; > > Undocumented magic number in a UAPI. Why was this chosen? In this case, I think the magic number is fine - though it could use a comment; since it only needs to be used in one place giving it a name is a bit pointless. As to why it was chosen - 64 is the next power of two size up from the length of a uuid string length, and 64 should fit any UUID + filesystem name. So took that and doubled it. > IMO, we shouldn't be returning strings that require the the kernel > to place NULLs correctly and for the caller to detect said NULLs to > determine their length, so something like: > > struct fs_sysfs_path { > __u32 name_len; > __u8 name[NAME_MAX]; > }; > > Seems better to me... I suppose modern languages are getting away from the whole nul-terminated string thing, heh