From patchwork Wed Oct 2 23:44:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 13820561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C79BCF8547 for ; Wed, 2 Oct 2024 23:45:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0E306B04E7; Wed, 2 Oct 2024 19:45:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBEAE6B04EF; Wed, 2 Oct 2024 19:45:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5FB96B04F0; Wed, 2 Oct 2024 19:45:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8065C6B04E7 for ; Wed, 2 Oct 2024 19:45:43 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2EFA7140BD8 for ; Wed, 2 Oct 2024 23:45:43 +0000 (UTC) X-FDA: 82630296966.11.01554AB Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf07.hostedemail.com (Postfix) with ESMTP id 8784B4000A for ; Wed, 2 Oct 2024 23:45:41 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=S3porjiK; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf07.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727912599; h=from:from:sender: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:dkim-signature; bh=QytpkEJz2P1dJL+CmfxoJi8346LIRFv339Bsa+p1XKQ=; b=eXDh8v7/S00Cr1HDUGhC6hztTE+xDz3fnYEsk33ih6KiqMxrgnGZKaM2o59RqqPocNNjEG jOR+WpMj8Sv1TROGH9OBxS8ffq/KMzavDPDctW+WG0yZx6HsvXfTyQ8c9GvqYd0kX7dlrV Ts6S6yU4JpJN6DH0h8dQRV8zj5rZSGo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727912599; a=rsa-sha256; cv=none; b=C5jEaf9dm6qs4iaVZiYVNPshtPDtSm03rebfCSgHcL+8JE6krb+lxloE0kwzsr1MjY/nSu 84CWY1vJ7Go0/R7kQBnRcMF78DER72ESvgzG9P2bC9dkRKMRu4uF5s/l5eaK2dh7C5W6Pf +5lZCp0+pG1bo7/IYJpgKKmga2QW5FU= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=S3porjiK; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf07.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=QytpkEJz2P1dJL+CmfxoJi8346LIRFv339Bsa+p1XKQ=; b=S3porjiKB8j1yc1P13gIqYyX/u 7PmSf6enyYqUSXaev5M2yurMA9//3IHYmZFL5hQ8Tl+aU1b5nDWsh6QW0POaCoR4JQTLD+jPpIE5I VfJYHblM+8f7loAVsR0hBj6degYp9N+sBHcRgqVXTChMkEOYB8stu7o5x0uZwfti8kRtYo8P5hOgM eLQrWem3+Rh9e+YodNjfn+z7wVKQc7DDFggSevcgRQ1moW8XNTc/dhyCYkyGFlOyZLiHSKJR15j6v 0xMZOcXyrKWkkB6VaAFCxvLVOS0ug0/gRrBnlnlOz9XlKAt/lIpekWGhqHK0geEG5g80+EXaDABwB wEyThyVQ==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw92D-0045tc-FT; Thu, 03 Oct 2024 01:45:33 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?utf-8?q?An?= =?utf-8?q?dr=C3=A9_Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Wed, 2 Oct 2024 20:44:42 -0300 Message-ID: <20241002234444.398367-9-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8784B4000A X-Stat-Signature: npriq3brgi6p6im437ubz7jzku91fcmp X-Rspam-User: X-HE-Tag: 1727912741-590733 X-HE-Meta: U2FsdGVkX1+9iQ3qr9RdA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B7zyZBtL+t1X7l4H4dFwAwr6o46IkAaZ8rrJZ5GPMSaLPw9++uScNeL+0GedJdWOyAMWer8Enq16GHlZ5nIGJLVDIH9k6fviD73JvV/dqz36diDRzZMr4qPT7DWjOxi66s7GaHe0oXF9wqHLBYTW/UklyUuAveJWXSdBCw1MCgDROMAbYx9MPkneNnu1n4ZIRgHI31h+lMheycarWCtsyIVHK58rMOTC4MexkukRIb0EH524slDZmEhix7I2rnjzBe0nSGrgUkv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enable setting flag FS_CASEFOLD_FL for tmpfs directories, when tmpfs is mounted with casefold support. A special check is need for this flag, since it can't be set for non-empty directories. Signed-off-by: André Almeida Reviewed-by: Gabriel Krisman Bertazi --- Changes from v2: - Fixed bug when adding a non-casefold flag in a non-empty dir --- include/linux/shmem_fs.h | 6 ++-- mm/shmem.c | 70 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 515a9a6a3c6f..018da28c01e7 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -42,10 +42,10 @@ struct shmem_inode_info { struct inode vfs_inode; }; -#define SHMEM_FL_USER_VISIBLE FS_FL_USER_VISIBLE +#define SHMEM_FL_USER_VISIBLE (FS_FL_USER_VISIBLE | FS_CASEFOLD_FL) #define SHMEM_FL_USER_MODIFIABLE \ - (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL) -#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) + (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) +#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) struct shmem_quota_limits { qsize_t usrquota_bhardlimit; /* Default user quota block hard limit */ diff --git a/mm/shmem.c b/mm/shmem.c index 3c8c7b34632a..f07b446b3c98 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2760,13 +2760,62 @@ static int shmem_file_open(struct inode *inode, struct file *file) #ifdef CONFIG_TMPFS_XATTR static int shmem_initxattrs(struct inode *, const struct xattr *, void *); +#if IS_ENABLED(CONFIG_UNICODE) +/* + * shmem_inode_casefold_flags - Deal with casefold file attribute flag + * + * The casefold file attribute needs some special checks. I can just be added to + * an empty dir, and can't be removed from a non-empty dir. + */ +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fsflags, + struct dentry *dentry, unsigned int *i_flags) +{ + unsigned int old = inode->i_flags; + struct super_block *sb = inode->i_sb; + + if (fsflags & FS_CASEFOLD_FL) { + if (!(old & S_CASEFOLD)) { + if (!sb->s_encoding) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + *i_flags = *i_flags | S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + return 0; +} +#else +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fsflags, + struct dentry *dentry, unsigned int *i_flags) +{ + if (fsflags & FS_CASEFOLD_FL) + return -EOPNOTSUPP; + + return 0; +} +#endif + /* * chattr's fsflags are unrelated to extended attributes, * but tmpfs has chosen to enable them under the same config option. */ -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) +static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry) { unsigned int i_flags = 0; + int ret; + + ret = shmem_inode_casefold_flags(inode, fsflags, dentry, &i_flags); + if (ret) + return ret; if (fsflags & FS_NOATIME_FL) i_flags |= S_NOATIME; @@ -2777,10 +2826,12 @@ static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) /* * But FS_NODUMP_FL does not require any action in i_flags. */ - inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE); + inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE | S_CASEFOLD); + + return 0; } #else -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) +static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry) { } #define shmem_initxattrs NULL @@ -2827,7 +2878,7 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, info->fsflags = (dir == NULL) ? 0 : SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; if (info->fsflags) - shmem_set_inode_flags(inode, info->fsflags); + shmem_set_inode_flags(inode, info->fsflags, NULL); INIT_LIST_HEAD(&info->shrinklist); INIT_LIST_HEAD(&info->swaplist); simple_xattrs_init(&info->xattrs); @@ -3934,16 +3985,23 @@ static int shmem_fileattr_set(struct mnt_idmap *idmap, { struct inode *inode = d_inode(dentry); struct shmem_inode_info *info = SHMEM_I(inode); + int ret, flags; if (fileattr_has_fsx(fa)) return -EOPNOTSUPP; if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE) return -EOPNOTSUPP; - info->fsflags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | + flags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | (fa->flags & SHMEM_FL_USER_MODIFIABLE); - shmem_set_inode_flags(inode, info->fsflags); + ret = shmem_set_inode_flags(inode, flags, dentry); + + if (ret) + return ret; + + info->fsflags = flags; + inode_set_ctime_current(inode); inode_inc_iversion(inode); return 0;