Skip to content

Commit 69881be

Browse files
committed
fs: export sget_dev()
They will be used for mtd devices as well. Acked-by: Richard Weinberger <richard@nod.at> Reviewed-by: Jan Kara <jack@suse.cz> Message-Id: <20230829-vfs-super-mtd-v1-1-fecb572e5df3@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent b97d64c commit 69881be

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

fs/super.c

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,50 @@ int get_tree_keyed(struct fs_context *fc,
13731373
}
13741374
EXPORT_SYMBOL(get_tree_keyed);
13751375

1376+
static int set_bdev_super(struct super_block *s, void *data)
1377+
{
1378+
s->s_dev = *(dev_t *)data;
1379+
return 0;
1380+
}
1381+
1382+
static int super_s_dev_set(struct super_block *s, struct fs_context *fc)
1383+
{
1384+
return set_bdev_super(s, fc->sget_key);
1385+
}
1386+
1387+
static int super_s_dev_test(struct super_block *s, struct fs_context *fc)
1388+
{
1389+
return !(s->s_iflags & SB_I_RETIRED) &&
1390+
s->s_dev == *(dev_t *)fc->sget_key;
1391+
}
1392+
1393+
/**
1394+
* sget_dev - Find or create a superblock by device number
1395+
* @fc: Filesystem context.
1396+
* @dev: device number
1397+
*
1398+
* Find or create a superblock using the provided device number that
1399+
* will be stored in fc->sget_key.
1400+
*
1401+
* If an extant superblock is matched, then that will be returned with
1402+
* an elevated reference count that the caller must transfer or discard.
1403+
*
1404+
* If no match is made, a new superblock will be allocated and basic
1405+
* initialisation will be performed (s_type, s_fs_info, s_id, s_dev will
1406+
* be set). The superblock will be published and it will be returned in
1407+
* a partially constructed state with SB_BORN and SB_ACTIVE as yet
1408+
* unset.
1409+
*
1410+
* Return: an existing or newly created superblock on success, an error
1411+
* pointer on failure.
1412+
*/
1413+
struct super_block *sget_dev(struct fs_context *fc, dev_t dev)
1414+
{
1415+
fc->sget_key = &dev;
1416+
return sget_fc(fc, super_s_dev_test, super_s_dev_set);
1417+
}
1418+
EXPORT_SYMBOL(sget_dev);
1419+
13761420
#ifdef CONFIG_BLOCK
13771421
/*
13781422
* Lock a super block that the callers holds a reference to.
@@ -1431,23 +1475,6 @@ const struct blk_holder_ops fs_holder_ops = {
14311475
};
14321476
EXPORT_SYMBOL_GPL(fs_holder_ops);
14331477

1434-
static int set_bdev_super(struct super_block *s, void *data)
1435-
{
1436-
s->s_dev = *(dev_t *)data;
1437-
return 0;
1438-
}
1439-
1440-
static int set_bdev_super_fc(struct super_block *s, struct fs_context *fc)
1441-
{
1442-
return set_bdev_super(s, fc->sget_key);
1443-
}
1444-
1445-
static int test_bdev_super_fc(struct super_block *s, struct fs_context *fc)
1446-
{
1447-
return !(s->s_iflags & SB_I_RETIRED) &&
1448-
s->s_dev == *(dev_t *)fc->sget_key;
1449-
}
1450-
14511478
int setup_bdev_super(struct super_block *sb, int sb_flags,
14521479
struct fs_context *fc)
14531480
{
@@ -1525,8 +1552,7 @@ int get_tree_bdev(struct fs_context *fc,
15251552
}
15261553

15271554
fc->sb_flags |= SB_NOSEC;
1528-
fc->sget_key = &dev;
1529-
s = sget_fc(fc, test_bdev_super_fc, set_bdev_super_fc);
1555+
s = sget_dev(fc, dev);
15301556
if (IS_ERR(s))
15311557
return PTR_ERR(s);
15321558

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,7 @@ struct super_block *sget(struct file_system_type *type,
23972397
int (*test)(struct super_block *,void *),
23982398
int (*set)(struct super_block *,void *),
23992399
int flags, void *data);
2400+
struct super_block *sget_dev(struct fs_context *fc, dev_t dev);
24002401

24012402
/* Alas, no aliases. Too much hassle with bringing module.h everywhere */
24022403
#define fops_get(fops) \

0 commit comments

Comments
 (0)