Skip to content

Commit bfecc40

Browse files
yhrcmaiolino
authored andcommitted
xfs: allow ro mounts if rtdev or logdev are read-only
Allow read-only mounts on rtdevs and logdevs that are marked as read-only and make sure those mounts can't be remounted read-write. Use the sb_open_mode helper to make sure that we don't try to open devices with write access enabled for read-only mounts. Signed-off-by: Hans Holmberg <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Carlos Maiolino <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 5088aad commit bfecc40

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

fs/xfs/xfs_super.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,11 @@ xfs_blkdev_get(
380380
struct file **bdev_filep)
381381
{
382382
int error = 0;
383+
blk_mode_t mode;
383384

384-
*bdev_filep = bdev_file_open_by_path(name,
385-
BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
386-
mp->m_super, &fs_holder_ops);
385+
mode = sb_open_mode(mp->m_super->s_flags);
386+
*bdev_filep = bdev_file_open_by_path(name, mode,
387+
mp->m_super, &fs_holder_ops);
387388
if (IS_ERR(*bdev_filep)) {
388389
error = PTR_ERR(*bdev_filep);
389390
*bdev_filep = NULL;
@@ -1969,6 +1970,20 @@ xfs_remount_rw(
19691970
struct xfs_sb *sbp = &mp->m_sb;
19701971
int error;
19711972

1973+
if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp &&
1974+
bdev_read_only(mp->m_logdev_targp->bt_bdev)) {
1975+
xfs_warn(mp,
1976+
"ro->rw transition prohibited by read-only logdev");
1977+
return -EACCES;
1978+
}
1979+
1980+
if (mp->m_rtdev_targp &&
1981+
bdev_read_only(mp->m_rtdev_targp->bt_bdev)) {
1982+
xfs_warn(mp,
1983+
"ro->rw transition prohibited by read-only rtdev");
1984+
return -EACCES;
1985+
}
1986+
19721987
if (xfs_has_norecovery(mp)) {
19731988
xfs_warn(mp,
19741989
"ro->rw transition prohibited on norecovery mount");

0 commit comments

Comments
 (0)