All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.com>
To: "André Almeida" <andrealmeid@collabora.com>
Cc: Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	smcv@collabora.com, kernel@collabora.com, linux-mm@kvack.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Daniel Rosenberg <drosen@google.com>
Subject: Re: [RFC PATCH 2/4] mm: shmem: Support case-insensitive file name lookups
Date: Tue, 23 Mar 2021 16:18:43 -0400	[thread overview]
Message-ID: <877dlxd3oc.fsf@collabora.com> (raw)
In-Reply-To: <20210323195941.69720-3-andrealmeid@collabora.com> (=?utf-8?Q?=22Andr=C3=A9?= Almeida"'s message of "Tue, 23 Mar 2021 16:59:39 -0300")

André Almeida <andrealmeid@collabora.com> writes:

> This patch implements the support for case-insensitive file name lookups
> in tmpfs, based on the encoding passed in the mount options.

Thanks for doing this.

>  
> +#ifdef CONFIG_UNICODE
> +static const struct dentry_operations casefold_dentry_ops = {
> +	.d_hash = generic_ci_d_hash,
> +	.d_compare = generic_ci_d_compare,
> +};
> +#endif

Why not reuse struct generic_ci_dentry_ops ?

> +
>  /*
>   * shmem_file_setup pre-accounts the whole fixed size of a VM object,
>   * for shared memory and for shared anonymous (/dev/zero) mappings
> @@ -2859,8 +2869,18 @@ shmem_mknod(struct user_namespace *mnt_userns, struct inode *dir,
>  	struct inode *inode;
>  	int error = -ENOSPC;
>  
> +#ifdef CONFIG_UNICODE
> +	struct super_block *sb = dir->i_sb;
> +
> +	if (sb_has_strict_encoding(sb) && IS_CASEFOLDED(dir) &&
> +	    sb->s_encoding && utf8_validate(sb->s_encoding, &dentry->d_name))
> +		return -EINVAL;
> +#endif
> +
>  	inode = shmem_get_inode(dir->i_sb, dir, mode, dev, VM_NORESERVE);
>  	if (inode) {
> +		inode->i_flags |= dir->i_flags;
> +
>  		error = simple_acl_create(dir, inode);
>  		if (error)
>  			goto out_iput;
> @@ -2870,6 +2890,9 @@ shmem_mknod(struct user_namespace *mnt_userns, struct inode *dir,
>  		if (error && error != -EOPNOTSUPP)
>  			goto out_iput;
>  
> +		if (IS_CASEFOLDED(dir))
> +			d_add(dentry, NULL);
> +
>  		error = 0;
>  		dir->i_size += BOGO_DIRENT_SIZE;
>  		dir->i_ctime = dir->i_mtime = current_time(dir);
> @@ -2925,6 +2948,19 @@ static int shmem_create(struct user_namespace *mnt_userns, struct inode *dir,
>  	return shmem_mknod(&init_user_ns, dir, dentry, mode | S_IFREG, 0);
>  }
>  
> +static struct dentry *shmem_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
> +{
> +	if (dentry->d_name.len > NAME_MAX)
> +		return ERR_PTR(-ENAMETOOLONG);
> +
> +	if (IS_CASEFOLDED(dir))
> +		return NULL;

I think this deserves a comment explaining why it is necessary.

> +
> +	d_add(dentry, NULL);
> +
> +	return NULL;
> +}
> +
>  /*
>   * Link a file..
>   */
> @@ -2946,6 +2982,9 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr
>  			goto out;
>  	}
>  
> +	if (IS_CASEFOLDED(dir))
> +		d_add(dentry, NULL);
> +
>  	dir->i_size += BOGO_DIRENT_SIZE;
>  	inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
>  	inc_nlink(inode);
> @@ -2967,6 +3006,10 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry)
>  	inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode);
>  	drop_nlink(inode);
>  	dput(dentry);	/* Undo the count from "create" - this does all the work */
> +
> +	if (IS_CASEFOLDED(dir))
> +		d_invalidate(dentry);
> +
>  	return 0;
>  }
>  
> @@ -3128,6 +3171,8 @@ static int shmem_symlink(struct user_namespace *mnt_userns, struct inode *dir,
>  	}
>  	dir->i_size += BOGO_DIRENT_SIZE;
>  	dir->i_ctime = dir->i_mtime = current_time(dir);
> +	if (IS_CASEFOLDED(dir))
> +		d_add(dentry, NULL);
>  	d_instantiate(dentry, inode);
>  	dget(dentry);
>  	return 0;
> @@ -3364,6 +3409,8 @@ enum shmem_param {
>  	Opt_uid,
>  	Opt_inode32,
>  	Opt_inode64,
> +	Opt_casefold,
> +	Opt_cf_strict,
>  };
>  
>  static const struct constant_table shmem_param_enums_huge[] = {
> @@ -3385,6 +3432,8 @@ const struct fs_parameter_spec shmem_fs_parameters[] = {
>  	fsparam_u32   ("uid",		Opt_uid),
>  	fsparam_flag  ("inode32",	Opt_inode32),
>  	fsparam_flag  ("inode64",	Opt_inode64),
> +	fsparam_string("casefold",	Opt_casefold),
> +	fsparam_flag  ("cf_strict",	Opt_cf_strict),
>  	{}
>  };
>  
> @@ -3392,9 +3441,11 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
>  {
>  	struct shmem_options *ctx = fc->fs_private;
>  	struct fs_parse_result result;
> +	struct unicode_map *encoding;
>  	unsigned long long size;
> +	char version[10];
>  	char *rest;
> -	int opt;
> +	int opt, ret;
>  
>  	opt = fs_parse(fc, shmem_fs_parameters, param, &result);
>  	if (opt < 0)
> @@ -3468,6 +3519,23 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
>  		ctx->full_inums = true;
>  		ctx->seen |= SHMEM_SEEN_INUMS;
>  		break;
> +	case Opt_casefold:
> +		if (strncmp(param->string, "utf8-", 5))
> +			return invalfc(fc, "Only utf8 encondings are supported");
> +		ret = strscpy(version, param->string + 5, sizeof(version));

Ugh.  Now we are doing two strscpy for the parse api (in unicode_load).
Can change the unicode_load api to reuse it?

thanks,

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2021-03-23 20:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 19:59 [RFC PATCH 0/4] mm: shmem: Add case-insensitive support for tmpfs André Almeida
2021-03-23 19:59 ` [RFC PATCH 1/4] Revert "libfs: unexport generic_ci_d_compare() and generic_ci_d_hash()" André Almeida
2021-03-23 20:15   ` Matthew Wilcox
2021-03-24 20:09     ` André Almeida
2021-03-23 19:59 ` [RFC PATCH 2/4] mm: shmem: Support case-insensitive file name lookups André Almeida
2021-03-23 20:18   ` Gabriel Krisman Bertazi [this message]
2021-03-23 20:18     ` Gabriel Krisman Bertazi
2021-03-24 20:17     ` André Almeida
2021-03-23 23:19   ` Al Viro
2021-03-24 20:44     ` André Almeida
2021-03-23 19:59 ` [RFC PATCH 3/4] mm: shmem: Add IOCTL support for tmpfs André Almeida
2021-03-23 22:15   ` Gabriel Krisman Bertazi
2021-03-23 22:15     ` Gabriel Krisman Bertazi
2021-03-23 19:59 ` [RFC PATCH 4/4] docs: tmpfs: Add casefold options André Almeida
2021-03-23 21:58   ` Randy Dunlap
2021-03-25 14:27     ` André Almeida
2021-03-23 22:19   ` Gabriel Krisman Bertazi
2021-03-23 22:19     ` Gabriel Krisman Bertazi
2021-03-24 20:47     ` André Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877dlxd3oc.fsf@collabora.com \
    --to=krisman@collabora.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrealmeid@collabora.com \
    --cc=drosen@google.com \
    --cc=hughd@google.com \
    --cc=kernel@collabora.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=smcv@collabora.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.