From: Hongbo Li <lihongbo22@huawei.com>
To: <viro@zeniv.linux.org.uk>, <brauner@kernel.org>, <jack@suse.cz>,
<tytso@mit.edu>, <adilger.kernel@dilger.ca>
Cc: <lczerner@redhat.com>, <cmaiolino@redhat.com>,
<linux-fsdevel@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<yi.zhang@huawei.com>, <lihongbo22@huawei.com>
Subject: [PATCH v2 1/4] fs: add blockdev parser for filesystem mount option.
Date: Mon, 27 May 2024 15:58:51 +0800 [thread overview]
Message-ID: <20240527075854.1260981-2-lihongbo22@huawei.com> (raw)
In-Reply-To: <20240527075854.1260981-1-lihongbo22@huawei.com>
`fsparam_bdev` uses `fs_param_is_blockdev` to parse the option, but it
is currently empty. Filesystems like ext4 use the `fsparam_bdev` to
parse `journal_path` into the block device. This general logic should
be moved to the vfs layer, not the specific filesystem. Therefore, we
implement block device parser in `fs_param_is_blockdev`. And the logic
is similar with `fs_lookup_param`.
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
---
fs/fs_parser.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)
diff --git a/fs/fs_parser.c b/fs/fs_parser.c
index a4d6ca0b8971..2aa208cf2027 100644
--- a/fs/fs_parser.c
+++ b/fs/fs_parser.c
@@ -311,7 +311,56 @@ EXPORT_SYMBOL(fs_param_is_fd);
int fs_param_is_blockdev(struct p_log *log, const struct fs_parameter_spec *p,
struct fs_parameter *param, struct fs_parse_result *result)
{
- return 0;
+ int ret;
+ int dfd;
+ struct filename *f;
+ struct inode *dev_inode;
+ struct path path;
+ bool put_f;
+
+ switch (param->type) {
+ case fs_value_is_string:
+ if (!*param->string) {
+ if (p->flags & fs_param_can_be_empty)
+ return 0;
+ return fs_param_bad_value(log, param);
+ }
+ f = getname_kernel(param->string);
+ if (IS_ERR(f))
+ return fs_param_bad_value(log, param);
+ dfd = AT_FDCWD;
+ put_f = true;
+ break;
+ case fs_value_is_filename:
+ f = param->name;
+ dfd = param->dirfd;
+ put_f = false;
+ break;
+ default:
+ return fs_param_bad_value(log, param);
+ }
+
+ ret = filename_lookup(dfd, f, LOOKUP_FOLLOW, &path, NULL);
+ if (ret < 0) {
+ error_plog(log, "%s: Lookup failure for '%s'", param->key, f->name);
+ goto out_putname;
+ }
+
+ dev_inode = d_backing_inode(path.dentry);
+ if (!S_ISBLK(dev_inode->i_mode)) {
+ error_plog(log, "%s: Non-blockdev passed as '%s'", param->key, f->name);
+ ret = -1;
+ goto out_putpath;
+ }
+ result->uint_32 = new_encode_dev(dev_inode->i_rdev);
+
+out_putpath:
+ path_put(&path);
+out_putname:
+ if (put_f)
+ putname(f);
+
+ return (ret < 0) ? fs_param_bad_value(log, param) : 0;
}
EXPORT_SYMBOL(fs_param_is_blockdev);
--
2.34.1
next prev parent reply other threads:[~2024-05-27 7:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 7:58 [PATCH v2 0/4] enhance the path resolution capability in fs_parser Hongbo Li
2024-05-27 7:58 ` Hongbo Li [this message]
2024-05-27 7:58 ` [PATCH v2 2/4] fs: add path parser for filesystem mount option Hongbo Li
2024-05-27 14:32 ` Christian Brauner
2024-05-27 16:26 ` Christoph Hellwig
2024-05-27 7:58 ` [PATCH v2 3/4] fs: ext4: support relative path for `journal_path` in " Hongbo Li
2024-05-27 15:39 ` Christian Brauner
2024-05-27 7:58 ` [PATCH v2 4/4] fs: remove fs_lookup_param and its description Hongbo Li
2024-05-27 15:08 ` [PATCH v2 0/4] enhance the path resolution capability in fs_parser Christian Brauner
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=20240527075854.1260981-2-lihongbo22@huawei.com \
--to=lihongbo22@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=brauner@kernel.org \
--cc=cmaiolino@redhat.com \
--cc=jack@suse.cz \
--cc=lczerner@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
--cc=yi.zhang@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox