[PATCH] xfs: allow ro mounts if rtdev or logdev are read-only

Hans Holmberg posted 1 patch 9 months, 2 weeks ago
There is a newer version of this series
fs/xfs/xfs_super.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
[PATCH] xfs: allow ro mounts if rtdev or logdev are read-only
Posted by Hans Holmberg 9 months, 2 weeks ago
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.

Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
---

I will post a couple of xfstests to add coverage for these cases.

 fs/xfs/xfs_super.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index b2dd0c0bf509..d7ac1654bc80 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -380,10 +380,14 @@ xfs_blkdev_get(
 	struct file		**bdev_filep)
 {
 	int			error = 0;
+	blk_mode_t		mode;
 
-	*bdev_filep = bdev_file_open_by_path(name,
-		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
-		mp->m_super, &fs_holder_ops);
+	mode = BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES;
+	if (!xfs_is_readonly(mp))
+		mode |= BLK_OPEN_WRITE;
+
+	*bdev_filep = bdev_file_open_by_path(name, mode,
+			mp->m_super, &fs_holder_ops);
 	if (IS_ERR(*bdev_filep)) {
 		error = PTR_ERR(*bdev_filep);
 		*bdev_filep = NULL;
@@ -1969,6 +1973,20 @@ xfs_remount_rw(
 	struct xfs_sb		*sbp = &mp->m_sb;
 	int error;
 
+	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp &&
+	    bdev_read_only(mp->m_logdev_targp->bt_bdev)) {
+		xfs_warn(mp,
+			"ro->rw transition prohibited by read-only logdev");
+		return -EACCES;
+	}
+
+	if (mp->m_rtdev_targp &&
+	    bdev_read_only(mp->m_rtdev_targp->bt_bdev)) {
+		xfs_warn(mp,
+			"ro->rw transition prohibited by read-only rtdev");
+		return -EACCES;
+	}
+
 	if (xfs_has_norecovery(mp)) {
 		xfs_warn(mp,
 			"ro->rw transition prohibited on norecovery mount");
-- 
2.34.1
Re: [PATCH] xfs: allow ro mounts if rtdev or logdev are read-only
Posted by Darrick J. Wong 9 months, 2 weeks ago
On Fri, Apr 25, 2025 at 08:52:53AM +0000, Hans Holmberg wrote:
> 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.

If the log device is readonly, does that mean the filesystem gets
mounted norecovery too?  Your test might want to check that a dirty log
is not recovered even if the filesystem mounts.

--D

> Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
> ---
> 
> I will post a couple of xfstests to add coverage for these cases.
> 
>  fs/xfs/xfs_super.c | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index b2dd0c0bf509..d7ac1654bc80 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -380,10 +380,14 @@ xfs_blkdev_get(
>  	struct file		**bdev_filep)
>  {
>  	int			error = 0;
> +	blk_mode_t		mode;
>  
> -	*bdev_filep = bdev_file_open_by_path(name,
> -		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
> -		mp->m_super, &fs_holder_ops);
> +	mode = BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES;
> +	if (!xfs_is_readonly(mp))
> +		mode |= BLK_OPEN_WRITE;
> +
> +	*bdev_filep = bdev_file_open_by_path(name, mode,
> +			mp->m_super, &fs_holder_ops);
>  	if (IS_ERR(*bdev_filep)) {
>  		error = PTR_ERR(*bdev_filep);
>  		*bdev_filep = NULL;
> @@ -1969,6 +1973,20 @@ xfs_remount_rw(
>  	struct xfs_sb		*sbp = &mp->m_sb;
>  	int error;
>  
> +	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp &&
> +	    bdev_read_only(mp->m_logdev_targp->bt_bdev)) {
> +		xfs_warn(mp,
> +			"ro->rw transition prohibited by read-only logdev");
> +		return -EACCES;
> +	}
> +
> +	if (mp->m_rtdev_targp &&
> +	    bdev_read_only(mp->m_rtdev_targp->bt_bdev)) {
> +		xfs_warn(mp,
> +			"ro->rw transition prohibited by read-only rtdev");
> +		return -EACCES;
> +	}
> +
>  	if (xfs_has_norecovery(mp)) {
>  		xfs_warn(mp,
>  			"ro->rw transition prohibited on norecovery mount");
> -- 
> 2.34.1
>
Re: [PATCH] xfs: allow ro mounts if rtdev or logdev are read-only
Posted by Hans Holmberg 9 months, 2 weeks ago
On 25/04/2025 16:54, Darrick J. Wong wrote:
> On Fri, Apr 25, 2025 at 08:52:53AM +0000, Hans Holmberg wrote:
>> 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.
> 
> If the log device is readonly, does that mean the filesystem gets
> mounted norecovery too?  Your test might want to check that a dirty log
> is not recovered even if the filesystem mounts.
> 

Read only-mounts do not mean that norecovery is set, but xfs will fail
to mount if recovery is needed and the logdev/rtdev/.. is read-only.
To mount in this state, the user needs to pass in norecovery.



> --D
> 
>> Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
>> ---
>>
>> I will post a couple of xfstests to add coverage for these cases.
>>
>>  fs/xfs/xfs_super.c | 24 +++++++++++++++++++++---
>>  1 file changed, 21 insertions(+), 3 deletions(-)
>>
>> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
>> index b2dd0c0bf509..d7ac1654bc80 100644
>> --- a/fs/xfs/xfs_super.c
>> +++ b/fs/xfs/xfs_super.c
>> @@ -380,10 +380,14 @@ xfs_blkdev_get(
>>  	struct file		**bdev_filep)
>>  {
>>  	int			error = 0;
>> +	blk_mode_t		mode;
>>  
>> -	*bdev_filep = bdev_file_open_by_path(name,
>> -		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
>> -		mp->m_super, &fs_holder_ops);
>> +	mode = BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES;
>> +	if (!xfs_is_readonly(mp))
>> +		mode |= BLK_OPEN_WRITE;
>> +
>> +	*bdev_filep = bdev_file_open_by_path(name, mode,
>> +			mp->m_super, &fs_holder_ops);
>>  	if (IS_ERR(*bdev_filep)) {
>>  		error = PTR_ERR(*bdev_filep);
>>  		*bdev_filep = NULL;
>> @@ -1969,6 +1973,20 @@ xfs_remount_rw(
>>  	struct xfs_sb		*sbp = &mp->m_sb;
>>  	int error;
>>  
>> +	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp &&
>> +	    bdev_read_only(mp->m_logdev_targp->bt_bdev)) {
>> +		xfs_warn(mp,
>> +			"ro->rw transition prohibited by read-only logdev");
>> +		return -EACCES;
>> +	}
>> +
>> +	if (mp->m_rtdev_targp &&
>> +	    bdev_read_only(mp->m_rtdev_targp->bt_bdev)) {
>> +		xfs_warn(mp,
>> +			"ro->rw transition prohibited by read-only rtdev");
>> +		return -EACCES;
>> +	}
>> +
>>  	if (xfs_has_norecovery(mp)) {
>>  		xfs_warn(mp,
>>  			"ro->rw transition prohibited on norecovery mount");
>> -- 
>> 2.34.1
>>
> 
> 


Re: [PATCH] xfs: allow ro mounts if rtdev or logdev are read-only
Posted by hch 9 months, 2 weeks ago
On Fri, Apr 25, 2025 at 08:52:53AM +0000, Hans Holmberg wrote:
> 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.
> 
> Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>