From patchwork Thu Sep 5 19:02:50 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: 13792879 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 47758CE7A81 for ; Thu, 5 Sep 2024 19:03:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7C956B0098; Thu, 5 Sep 2024 15:03:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2D3A6B0099; Thu, 5 Sep 2024 15:03:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA7326B009A; Thu, 5 Sep 2024 15:03:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9862A6B0098 for ; Thu, 5 Sep 2024 15:03:48 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9A80EA0A50 for ; Thu, 5 Sep 2024 19:03:47 +0000 (UTC) X-FDA: 82531608894.18.5452D0A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf05.hostedemail.com (Postfix) with ESMTP id E375C100010 for ; Thu, 5 Sep 2024 19:03:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="qRDe7y/i"; spf=pass (imf05.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725562929; 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=4vz8LJ8AGqtE46pXkxH06G/62SH6tsoXVW4UBJQz500=; b=USEFW9539DW/qOKU3MfEJpYCuhmceOKKkqjsJWA+4Yw/9FDOzStxKOyiDM44/MvAF3UOTR YkGRzrnhY7aZ401YD7Vb8rguBYuzRSJ/73XxvEN8ZhGTD9/fDR/WH+x76mVTmZU58LMX2a MIz66+oZpQY+MRXUm/7V+/3q6ZGpipU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725562929; a=rsa-sha256; cv=none; b=lzhDntZ5zV+MWJEbR+xsyS09W/h3nbmq9wbiYfkO72e+I4PX6Yv8yC5vSCNIojw90NE06l vCj9n3KwUh0wX9pyHojPHTsqkbL3VzOTNiuoMsPWIzl55H1Jbft9yr0Pa5fZZzRQy6fspH dI6EPXLP9oPDqIes3r/mksWZN5Dg2zI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="qRDe7y/i"; spf=pass (imf05.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=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=4vz8LJ8AGqtE46pXkxH06G/62SH6tsoXVW4UBJQz500=; b=qRDe7y/i3zJwIWrkmkWIlGSNG5 S8C/1KxCMXfvhhaAOkFX3VUMNClSZ9JflAyBEbAWNSt9LmkJunrXCJ38rnWCAI3AkrbzWvxFUbSmB dHaJKveIWlR4idWLWfU0B9NTBUxH4379FDaEvV3v7uNz0wht/K27+ttfz58v1GqRiMoerG5SLowVh 2Wlb+UhmxHeg+a0y9R4Nl1yT88f2AMWWVvksy2TJIWcOGGJoACJFsCmryE2FYHLXXx3FCuhhgCmVu KwLcBzQYqqKsXEV0Iuq84EY4KvQCcptkJ3q51oL+h/r4r4PaXqN95AQ9xJTeNPd/cAMDFK1FuCN4t 5nN+1DJw==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1smHla-00A6Ho-Is; Thu, 05 Sep 2024 21:03:38 +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?= Subject: [PATCH v3 7/9] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Thu, 5 Sep 2024 16:02:50 -0300 Message-ID: <20240905190252.461639-8-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240905190252.461639-1-andrealmeid@igalia.com> References: <20240905190252.461639-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E375C100010 X-Stat-Signature: 1hs1mmb6s5ot8y1p6sfdyefr9cwcbie7 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725563025-920541 X-HE-Meta: U2FsdGVkX1+BCrW6XQNk1IARTI4xq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SADG9XqVS9aEERzMvWfHBbJt9BnwgZsOxtruSu7C7D4uOQDlwhkgiUwDjMtta6NjuAsVMVV+srmV/KXJiaDZzVNFYE/kG0OoBZ0KValy/KRT6J0XYgPqzxMyZwfFjcjkE56v0fA0S3IcsvWrYkNRkRMy5E78vui0+uyB8F2xLL/X0gjYcT5Kwn+5wBgDw9iooEb2e7xPGERJVzkjvDN8m6MBQG1a5kVvVOPBmRprN+7gDJQqiuS95gaA2zKRf+zhMHoI0uPG7O3gFNvHXwNISC5PDxHMQKc16z 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 --- 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 1d06b1e5408a..8367ca2b99d9 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 6b61fc5dc0b1..d38977fb2097 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2613,13 +2613,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; @@ -2630,10 +2679,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 @@ -2680,7 +2731,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); @@ -3789,16 +3840,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;