From patchwork Fri Aug 23 17:33:29 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: 13775615 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 D6C59C52D7C for ; Fri, 23 Aug 2024 17:34:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90FA0800B9; Fri, 23 Aug 2024 13:33:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 896E0800B4; Fri, 23 Aug 2024 13:33:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73800800B9; Fri, 23 Aug 2024 13:33:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 549B4800B4 for ; Fri, 23 Aug 2024 13:33:58 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A5A151C4045 for ; Fri, 23 Aug 2024 17:33:57 +0000 (UTC) X-FDA: 82484208114.19.AA4A5FD Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf28.hostedemail.com (Postfix) with ESMTP id 0360CC0028 for ; Fri, 23 Aug 2024 17:33:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=rgKiTFkM; spf=pass (imf28.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724434395; 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=kaq/p7WWGkDPfkYXS5iXH7ESr86fZs1bSaN+LK5hniQ=; b=HML6jMQtBdDhNs8IePo0I0Nxz1o8YUN0Dg5Oz2Z8IEluTwvzt6Ur0xDfbE1fIY20FsxZqN +bX7tWuu7/kIr3TZVwuZahyDZx1xrUT+WVSHT7kBw6CNGfSnDFww/wgBWpRgKk0jl6tVVG cGMpTqGCmkxOp6LaJSDQScbKTidb0DE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=rgKiTFkM; spf=pass (imf28.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724434395; a=rsa-sha256; cv=none; b=ZJruuLQ1epQWU4OSwuQ94ysMmm7zqwRJk9X6m2bN2/0aibhxc6LK6iz5NSdo8wdLCimrA3 r2emEj8ZmLn099FQ9Dz95/acxVuzStL8KXjsHby7r+Gw/QpmidZQKCXI4Bne+IK9m5BJHW dIBqwZzuYTRxn7rfeFyiX/0MZNtI8tE= 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=kaq/p7WWGkDPfkYXS5iXH7ESr86fZs1bSaN+LK5hniQ=; b=rgKiTFkMBobH15FQLLakWX0RAP BzP7Bp1kevVfr/cme/57GIHDALcfZ1lGwmnKxIOM8WrPIuby9AUXJoXDxgvGKgXGCC4Tg00Mn+AoA MRwGNdt7ymV7BBzymaAUEy+K4L/XWHkOfS2vHUhT01/y29VxGZB2kQzsZ+r0Rh2DWs1MtmEx5cINo m9Qwyn8bOOMGlztD8IvEGcPOaG9zZAZ3C88BD6FJiA0XbC5/Fn0JrT1l8HcxCWzaV/B1wKTyC6FHx QnbSrwG7cY3a8z8U1I/DStbyOAsUzfEDxqYSNaQfB7UIK6RD6zfcc6pgfwJgZUZndopllnDW7+VVS Znx9VXCg==; Received: from [179.118.186.198] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1shYAT-0048Ww-Do; Fri, 23 Aug 2024 19:33:45 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, krisman@kernel.org, Daniel Rosenberg , smcv@collabora.com, =?utf-8?q?Andr?= =?utf-8?q?=C3=A9_Almeida?= Subject: [PATCH 2/5] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Fri, 23 Aug 2024 14:33:29 -0300 Message-ID: <20240823173332.281211-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823173332.281211-1-andrealmeid@igalia.com> References: <20240823173332.281211-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 0360CC0028 X-Stat-Signature: dk6tq57um441godsownmxwuamz3g1xuj X-HE-Tag: 1724434435-427376 X-HE-Meta: U2FsdGVkX1/k2xQhJR1skDkz3qvVU4wZOGvCQV684l2vAszRNGp4PLWojMmZ8i1/QVsUuvFB8pyFZ0Pq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ked9yaCKdI2zfMoPulvydkijaUu4d70wroVAX61Uk7DbP15wHqNKwNAmmjo9oTNFegQ4pGg73mkF+Yr1Vf/Ru32LASnI8/JOCxDU6yGtsZkHsONkTKXXBOvT0jAklThzDnjBT7jmdBQj0FXwWsKd1gZo0O55wmqg== 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 --- include/linux/shmem_fs.h | 6 +++--- mm/shmem.c | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 1a1196b077a6..acec92564122 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 aa272c62f811..67b6ab580ca2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2617,9 +2617,26 @@ static int shmem_initxattrs(struct inode *, const struct xattr *, void *); * 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; + unsigned int i_flags = 0, old = inode->i_flags; + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + + if (fsflags & FS_CASEFOLD_FL) { + if (!sbinfo->casefold) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + + i_flags |= S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } if (fsflags & FS_NOATIME_FL) i_flags |= S_NOATIME; @@ -2630,10 +2647,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 +2699,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); @@ -3788,16 +3807,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;