zoned fixes
Hi all,
this is a small set of zoned fixes, one reported by Dan through smatch, and reported and draft fixed by Darrick, and a little cleanup I noticed while going through the report from Dan.
PATCH 1/3 xfs: fix a missing unlock in xfs_growfs_data
The newly added check for the internal RT device needs to unlock m_growlock just like all ther other error cases.
--- fs/xfs/xfs_fsops.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/xfs/xfs_fsops.c +5 -3
@@ -301,7 +301,7 @@ xfs_growfs_data(struct xfs_mount *mp, struct xfs_growfs_data *in) { - int error = 0; + int error;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
@@ -309,8 +309,10 @@ xfs_growfs_data(return -EWOULDBLOCK ;/* we can't grow the data section when an internal RT section exists */ -if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) -return -EINVAL ; +if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) { + error = -EINVAL ; + goto out_error; + }/* update imaxpct separately to the physical grow of the filesystem */ if (in->imaxpct != mp->m_sb.sb_imax_pct) {
Signature · 1 line
2.45.2
Re: [PATCH 1/3] xfs: fix a missing unlock in xfs_growfs_data
Quoted 6 lines · Christoph Hellwig
The newly added check for the internal RT device needs to unlock
m_growlockjust like all ther other error cases.Fixes bdc03eb5f98f ("xfs: allow internal RT devices for zoned mode")Reported-by Dan Carpenter <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>
Quoted 33 lines
--- fs/xfs/xfs_fsops.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)fs/xfs/xfs_fsops.c +5
-4@@ -301,7 +301,7 @@ xfs_growfs_data(struct xfs_mount *mp, struct xfs_growfs_data *in) { - int error = 0; + int error;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;@@ -309,8 +309,10 @@ xfs_growfs_data(return -EWOULDBLOCK ;/* we can't grow the data section when an internal RT section exists */ -if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) -return -EINVAL ; +if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) { + error = -EINVAL ; + goto out_error; + }/* update imaxpct separately to the physical grow of the filesystem */ if (in->imaxpct != mp->m_sb.sb_imax_pct) { --2.45.2
Re: [PATCH 1/3] xfs: fix a missing unlock in xfs_growfs_data
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
The newly added check for the internal RT device needs to unlock
m_growlockjust like all ther other error cases.
Applied to for-next, thanks!
[1/3] xfs: fix a missing unlock in xfs_growfs_data
commit: beba9487138151c17dec17105364b35935f21562
[2/3] xfs: don't increment m_generation for all errors in xfs_growfs_data
commit: 9ec3f7977a32f2045ef14445f165bcd96e596344
[3/3] xfs: don't wake zone space waiters without m_zone_info
commit: f56f73ebf8bb13d72b93e490c1f175a0a2c836f2Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>
PATCH 2/3 xfs: don't increment m_generation for all errors in xfs_growfs_data
In reply to Christoph Hellwigxfs_growfs_data needs to increment m_generation as soon as the primary superblock has been updated. As the update of the secondary superblocks was part of xfs_growfs_data_private that mean the incremented had to be done unconditionally once that was called. Later, commit 83a7f86e39ff ("xfs: separate secondary sb update in growfs") split the secondary superblock update into a separate helper, so now the increment on error can be limited to failed calls to xfs_update_secondary_sbs.
--- fs/xfs/xfs_fsops.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/xfs_fsops.c +6 -7
@@ -311,20 +311,20 @@ xfs_growfs_data(/* we can't grow the data section when an internal RT section exists */ if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) { error = -EINVAL ; - goto out_error; + goto out_unlock; }/* update imaxpct separately to the physical grow of the filesystem */ if (in->imaxpct != mp->m_sb.sb_imax_pct) { error =xfs_growfs_imaxpct (mp, in->imaxpct);if (error) - goto out_error; + goto out_unlock; }if (in->newblocks != mp->m_sb.sb_dblocks) { error =xfs_growfs_data_private (mp, in);if (error) - goto out_error; + goto out_unlock; }/* Post growfs calculations needed to reflect new state in operations */
@@ -338,13 +338,12 @@ xfs_growfs_data(/* Update secondary superblocks now the physical grow has completed */ error =xfs_update_secondary_sbs (mp); -out_error:/* -* Increment the generation unconditionally, the error could be from -* updating the secondary superblocks, in which case the new size -* is live already. +* Increment the generation unconditionally, after trying to update the +* secondary superblocks, as the new size is live already at this point. */ mp->m_generation++; +out_unlock:mutex_unlock (&mp->m_growlock);return error; }
Signature · 1 line
2.45.2
Re: [PATCH 2/3] xfs: don't increment m_generation for all errors in xfs_growfs_data
Quoted 9 lines · Christoph Hellwig
xfs_growfs_dataneeds to incrementm_generationas soon as the primary superblock has been updated. As the update of the secondary superblocks was part ofxfs_growfs_data_privatethat mean the incremented had to be done unconditionally once that was called. Later, commit83a7f86e39ff("xfs: separate secondary sb update in growfs") split the secondary superblock update into a separate helper, so now the increment on error can be limited to failed calls toxfs_update_secondary_sbs.Signed-off-by Christoph Hellwig <[email protected]>
Quoted 53 lines
--- fs/xfs/xfs_fsops.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)fs/xfs/xfs_fsops.c +6
-8@@ -311,20 +311,20 @@ xfs_growfs_data(/* we can't grow the data section when an internal RT section exists */ if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) { error = -EINVAL ; - goto out_error; + goto out_unlock; }/* update imaxpct separately to the physical grow of the filesystem */ if (in->imaxpct != mp->m_sb.sb_imax_pct) { error =xfs_growfs_imaxpct (mp, in->imaxpct);if (error) - goto out_error; + goto out_unlock; }if (in->newblocks != mp->m_sb.sb_dblocks) { error =xfs_growfs_data_private (mp, in);if (error) - goto out_error; + goto out_unlock; }/* Post growfs calculations needed to reflect new state in operations */ @@ -338,13 +338,12 @@ xfs_growfs_data(/* Update secondary superblocks now the physical grow has completed */ error =xfs_update_secondary_sbs (mp); -out_error:/* -* Increment the generation unconditionally, the error could be from -* updating the secondary superblocks, in which case the new size -* is live already. +* Increment the generation unconditionally, after trying to update the +* secondary superblocks, as the new size is live already at this point. */ mp->m_generation++; +out_unlock:mutex_unlock (&mp->m_growlock);return error; } --2.45.2
PATCH 3/3 xfs: don't wake zone space waiters without m_zone_info
In reply to Christoph HellwigFrom: "Darrick J. Wong" <[email protected]>
xfs_zoned_wake_all checks SB_ACTIVE to make sure it does the right thing when a shutdown happens during unmount, but it fails to account for the log recovery special case that sets SB_ACTIVE temporarily. Add a NULL check to cover both cases.
--- fs/xfs/xfs_zone_alloc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +12 -3
@@ -853,13 +853,22 @@ xfs_zone_alloc_and_submit(bio_io_error (&ioend->io_bio); } +/* +* Wake up all threads waiting for a zoned space allocation when the file system +* is shut down. +*/ void xfs_zoned_wake_all (struct xfs_mount *mp) { -if (!(mp->m_super->s_flags &SB_ACTIVE )) -return ;/* can happen during log recovery */ -wake_up_all (&mp->m_zone_info->zi_zone_wait); +/* +* Don't wake up if there is no m_zone_info. This is complicated by the +* fact that unmount can't atomically clear m_zone_info and thus we need +* to check SB_ACTIVE for that, but mount temporarily enables SB_ACTIVE +* during log recovery so we can't entirely rely on that either. +*/ +if ((mp->m_super->s_flags &SB_ACTIVE ) && mp->m_zone_info) +wake_up_all (&mp->m_zone_info->zi_zone_wait); }/*
Signature · 1 line
2.45.2
Re: [PATCH 3/3] xfs: don't wake zone space waiters without m_zone_info
Quoted 34 lines · Christoph Hellwig
From: "Darrick J. Wong" <[email protected]>
xfs_zoned_wake_allchecksSB_ACTIVEto make sure it does the right thing when a shutdown happens during unmount, but it fails to account for the log recovery special case that setsSB_ACTIVEtemporarily. Add a NULL check to cover both cases.Signed-off-by Darrick J. Wong <[email protected]>[hch: added a commit log and comment]Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_zone_alloc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)fs/xfs/xfs_zone_alloc.c +5
-3@@ -853,13 +853,22 @@ xfs_zone_alloc_and_submit(bio_io_error (&ioend->io_bio); } +/* +* Wake up all threads waiting for a zoned space allocation when the file system +* is shut down. +*/ void xfs_zoned_wake_all (struct xfs_mount *mp) { -if (!(mp->m_super->s_flags &SB_ACTIVE )) -return ;/* can happen during log recovery */ -wake_up_all (&mp->m_zone_info->zi_zone_wait); +/*
fs/xfs/xfs_zone_alloc.c xfs_zone_alloc_and_submit( · line 874
Quoted 10 lines
fs/xfs/xfs_zone_alloc.c +7
-0+* Don't wake up if there is no m_zone_info. This is complicated by the +* fact that unmount can't atomically clear m_zone_info and thus we need +* to check SB_ACTIVE for that, but mount temporarily enables SB_ACTIVE +* during log recovery so we can't entirely rely on that either. +*/ +if ((mp->m_super->s_flags &SB_ACTIVE ) && mp->m_zone_info) +wake_up_all (&mp->m_zone_info->zi_zone_wait); }/*
Looks good,
Re: [PATCH 3/3] xfs: don't wake zone space waiters without m_zone_info
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
From: "Darrick J. Wong" <[email protected]>
xfs_zoned_wake_allchecksSB_ACTIVEto make sure it does the right thing when a shutdown happens during unmount, but it fails to account for the log recovery special case that setsSB_ACTIVEtemporarily. Add a NULL check to cover both cases.Signed-off-by Darrick J. Wong <[email protected]>[hch: added a commit log and comment]Signed-off-by Christoph Hellwig <[email protected]>
Quoted 37 lines
--- fs/xfs/xfs_zone_alloc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)fs/xfs/xfs_zone_alloc.c +12
-4@@ -853,13 +853,22 @@ xfs_zone_alloc_and_submit(bio_io_error (&ioend->io_bio); } +/* +* Wake up all threads waiting for a zoned space allocation when the file system +* is shut down. +*/ void xfs_zoned_wake_all (struct xfs_mount *mp) { -if (!(mp->m_super->s_flags &SB_ACTIVE )) -return ;/* can happen during log recovery */ -wake_up_all (&mp->m_zone_info->zi_zone_wait); +/* +* Don't wake up if there is no m_zone_info. This is complicated by the +* fact that unmount can't atomically clear m_zone_info and thus we need +* to check SB_ACTIVE for that, but mount temporarily enables SB_ACTIVE +* during log recovery so we can't entirely rely on that either. +*/ +if ((mp->m_super->s_flags &SB_ACTIVE ) && mp->m_zone_info) +wake_up_all (&mp->m_zone_info->zi_zone_wait); }/* -- 2.45.2