From patchwork Thu Oct 10 19:39:43 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: 1995739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=ngCP2OSX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=pjb/=rg=vger.kernel.org=linux-ext4+bounces-4560-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPgG10FHJz1xsc for ; Fri, 11 Oct 2024 06:45:13 +1100 (AEDT) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XPgG018rHz4wnw for ; Fri, 11 Oct 2024 06:45:12 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4XPgG01550z4xNw; Fri, 11 Oct 2024 06:45:12 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45d1:ec00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1728589512; cv=pass; b=KXFNZetv1z8tSs9X3UxUaJkZkzUolxCdsHjCoSkg/m/QriGuua9lOK3Y5wZJbOBcyTVKKQKWE1PF/XpdM9lpXZy/7WYinO8fLh3vPND7oNugiLc5fWrDawIEiuX346b0Ovz0aCt8lPTuPAqmEfWANrieUvZ9LcUmjuleNKZ0wPTl5KHBeuSWJXk62SMM9KtI1d0KjKaaFxN32jO4UVOOab20pbqwZ+T3NkSAqenXHgSV3zMUsTj/ZkV8lb6Ztv3drSLCoRwFVo7nuzWXgTyAgqNkCyWCaw5Eio801DZZJJjKc3y0chTi4ICtQl0z4xoBB9dA2gGkiJPmHJzyImFInw== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1728589512; c=relaxed/relaxed; bh=zoE4RPJrEfLVHReDLgphj31bDW38mEz4OTwqDqkwzOs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KHf+e+a6IIrEQIKt/wDCnleVF3+g38H1B3IF6NKUQdByMLarQAnW9dhdC3HuF3ft17Rg5Ko83mMRI121r5jftYfwardFWCw9Djod2hokMVAF6Q3rorIHo4CxUnpM/EOQkC1gk4zI6h5xdU+/BKFSVSrXPpcUcy3P+oYH6ry6Xwc7BBtkO+i1qE9X8vQqOTBJ7m0v7QF7K8UuOejSFpUeSe7RUFvIkypE335AqSsPvF8OHC8GRWtuoiZ47YrLPdJ20Nd/PlzRgHnigGWVWz2xnhJ3in4r9u6kVtYtVH5kSyLK8Cn6OYEgmYcj/yP+UzRYGUzMI8pZ6iGQ7hIVeVBt/A== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=fail (p=none dis=none) header.from=igalia.com; dkim=fail (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=ngCP2OSX reason="signature verification failed"; dkim-atps=neutral; spf=pass (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4560-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=none dis=none) header.from=igalia.com Authentication-Results: gandalf.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=ngCP2OSX; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4560-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XPgFz507xz4wnw for ; Fri, 11 Oct 2024 06:45:11 +1100 (AEDT) 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 7F1C81C2498E for ; Thu, 10 Oct 2024 19:45:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEB3B1F12E4; Thu, 10 Oct 2024 19:41:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="ngCP2OSX" X-Original-To: linux-ext4@vger.kernel.org Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (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 D66251EF949; Thu, 10 Oct 2024 19:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589298; cv=none; b=fZipUbqKHeBT4rc07Hb/FHmzy7qEYLnJ4eoF1/jIZgkWKvVRGxKAy6vSPtP1U5BnOj/bPMcdzjOhfPVMnENOce6xRCw7aIeKK5l9r3STxDC7q9ch0RC6SR34hZ9zsadnh1oGDq/N9lH7NowForWBvCeYhqVyFYirpc2tLGjwFX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589298; c=relaxed/simple; bh=9cm/RLr8Rzh1vFGh5pv0TyUOuYayhYnzXjVb8aJOmYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D2oldi+B/MD+/wVqvPp70knXchTbvGzXqbsbTIidtC9YBu0bx5gWRm1uwpykE8mI5rr/4aEmZaJEXbo/bjYmPg7AGSS+s6gAZvxthvuTqII8kNQf2Fs3s55MEfFGT2uFzOuAa3D0fK6f7xN72AT1qpOXgEbRZXITlFHzJmiJlV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=ngCP2OSX; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: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=zoE4RPJrEfLVHReDLgphj31bDW38mEz4OTwqDqkwzOs=; b=ngCP2OSX3FyNez4PeGc6ilBYL2 VlvK0I+D6Vcx+oGjksNEOCAIhEsf2nmAeZ6yfNK0Xu7/OpLkbI9Ac8nl6cNsqLtwmiswOrnpbZ2gx qRLfHMUjuD1+lZ2yw3QPaZihs6cBD8JMFMVYgy6dvePodtMpof9Lx2cUBBFAsDX6KBRfeezxCmL5w S1dqfODKlVQn4QfZu47oIzYvKG0NwX/M1PCPVIyMbt4JPKJFsJcGhP1hNWgnn8Rnl5AfJcl1zk0uP s7whR7pHza136ZA/Y237m8Ul3amIqkqzFuST69DUr1vzeyb1T1+6Guvd38NpahdTd81nZP1a6LLnk Z7xNHMtg==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2U-007SHz-0k; Thu, 10 Oct 2024 21:41:34 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:43 -0300 Subject: [PATCH v6 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241010-tonyk-tmpfs-v6-8-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeid?= =?utf-8?q?a?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 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 515a9a6a3c6f82c55952d821887514217a6a00d1..018da28c01e7d71b8fb00bfb23c000248c8a83f4 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 935e824990799d927098fd88ebaba384a6284f42..1c130a7d58ff3a4f5f920374414f9e7a29347ed9 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;