@@ -1373,6 +1373,50 @@ int get_tree_keyed(struct fs_context *fc,
1373
1373
}
1374
1374
EXPORT_SYMBOL (get_tree_keyed );
1375
1375
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
+
1376
1420
#ifdef CONFIG_BLOCK
1377
1421
/*
1378
1422
* Lock a super block that the callers holds a reference to.
@@ -1431,23 +1475,6 @@ const struct blk_holder_ops fs_holder_ops = {
1431
1475
};
1432
1476
EXPORT_SYMBOL_GPL (fs_holder_ops );
1433
1477
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
-
1451
1478
int setup_bdev_super (struct super_block * sb , int sb_flags ,
1452
1479
struct fs_context * fc )
1453
1480
{
@@ -1525,8 +1552,7 @@ int get_tree_bdev(struct fs_context *fc,
1525
1552
}
1526
1553
1527
1554
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 );
1530
1556
if (IS_ERR (s ))
1531
1557
return PTR_ERR (s );
1532
1558
0 commit comments