Skip to content

Commit 2142b88

Browse files
Christoph Hellwigbrauner
authored andcommitted
block: call into the file system for ioctl BLKFLSBUF
BLKFLSBUF is a historic ioctl that is called on a file handle to a block device and syncs either the file system mounted on that block device if there is one, or otherwise the just the data on the block device. Replace the get_super based syncing with a holder operation to remove the last usage of get_super, and to also support syncing the file system if the block device is not the main block device stored in s_dev. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Message-Id: <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent d8530de commit 2142b88

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

block/bdev.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,22 +206,6 @@ int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend)
206206
}
207207
EXPORT_SYMBOL(sync_blockdev_range);
208208

209-
/*
210-
* Write out and wait upon all dirty data associated with this
211-
* device. Filesystem data as well as the underlying block
212-
* device. Takes the superblock lock.
213-
*/
214-
int fsync_bdev(struct block_device *bdev)
215-
{
216-
struct super_block *sb = get_super(bdev);
217-
if (sb) {
218-
int res = sync_filesystem(sb);
219-
drop_super(sb);
220-
return res;
221-
}
222-
return sync_blockdev(bdev);
223-
}
224-
225209
/**
226210
* freeze_bdev - lock a filesystem and force it into a consistent state
227211
* @bdev: blockdevice to lock

block/ioctl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,14 @@ static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
364364
{
365365
if (!capable(CAP_SYS_ADMIN))
366366
return -EACCES;
367-
fsync_bdev(bdev);
367+
368+
mutex_lock(&bdev->bd_holder_lock);
369+
if (bdev->bd_holder_ops && bdev->bd_holder_ops->sync)
370+
bdev->bd_holder_ops->sync(bdev);
371+
else
372+
sync_blockdev(bdev);
373+
mutex_unlock(&bdev->bd_holder_lock);
374+
368375
invalidate_bdev(bdev);
369376
return 0;
370377
}

fs/super.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,21 @@ static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)
12481248
up_read(&sb->s_umount);
12491249
}
12501250

1251+
static void fs_bdev_sync(struct block_device *bdev)
1252+
{
1253+
struct super_block *sb = bdev->bd_holder;
1254+
1255+
lockdep_assert_held(&bdev->bd_holder_lock);
1256+
1257+
if (!lock_active_super(sb))
1258+
return;
1259+
sync_filesystem(sb);
1260+
up_read(&sb->s_umount);
1261+
}
1262+
12511263
const struct blk_holder_ops fs_holder_ops = {
12521264
.mark_dead = fs_bdev_mark_dead,
1265+
.sync = fs_bdev_sync,
12531266
};
12541267
EXPORT_SYMBOL_GPL(fs_holder_ops);
12551268

include/linux/blkdev.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,11 @@ void blkdev_show(struct seq_file *seqf, off_t offset);
14621462

14631463
struct blk_holder_ops {
14641464
void (*mark_dead)(struct block_device *bdev, bool surprise);
1465+
1466+
/*
1467+
* Sync the file system mounted on the block device.
1468+
*/
1469+
void (*sync)(struct block_device *bdev);
14651470
};
14661471

14671472
extern const struct blk_holder_ops fs_holder_ops;
@@ -1524,8 +1529,6 @@ static inline int early_lookup_bdev(const char *pathname, dev_t *dev)
15241529
}
15251530
#endif /* CONFIG_BLOCK */
15261531

1527-
int fsync_bdev(struct block_device *bdev);
1528-
15291532
int freeze_bdev(struct block_device *bdev);
15301533
int thaw_bdev(struct block_device *bdev);
15311534

0 commit comments

Comments
 (0)