xfs: Move ASSERTion location in xfs_rtcopy_summary()
PATCH 1/1 xfs: Move ASSERTion location in xfs_rtcopy_summary()
We should ASSERT on a variable before using it, so that we don't end up using an illegal value.
--- fs/xfs/xfs_rtalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_rtalloc.c +1 -1
@@ -112,6 +112,7 @@ xfs_rtcopy_summary( error =xfs_rtget_summary (oargs, log, bbno, &sum);if (error) goto out; +ASSERT (sum >=0 );if (sum ==0 )continue ; error =xfs_rtmodify_summary (oargs, log, bbno, -sum);
@@ -120,7 +121,6 @@ xfs_rtcopy_summary( error =xfs_rtmodify_summary (nargs, log, bbno, sum);if (error) goto out; -ASSERT (sum >0 ); } } error =0 ;
Signature · 1 line
2.43.5
Quoted 2 lines · Nirjhar Roy (IBM)
We should ASSERT on a variable before using it, so that we don't end up using an illegal value.
Assertions don't necessarily kill the kernel so ... do you want to bail out?
if (sum < 0) {
ASSERT(sum >= 0);
return -EFSCORRUPTED;
}
if (sum == 0)
continue;--D
Quoted 29 lines
Signed-off-by Nirjhar Roy (IBM) <[email protected]>--- fs/xfs/xfs_rtalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/xfs/xfs_rtalloc.c +1
-1@@ -112,6 +112,7 @@ xfs_rtcopy_summary( error =xfs_rtget_summary (oargs, log, bbno, &sum);if (error) goto out; +ASSERT (sum >=0 );if (sum ==0 )continue ; error =xfs_rtmodify_summary (oargs, log, bbno, -sum);@@ -120,7 +121,6 @@ xfs_rtcopy_summary( error =xfs_rtmodify_summary (nargs, log, bbno, sum);if (error) goto out; -ASSERT (sum >0 ); } } error =0 ;Signature · 1 line
2.43.5
Quoted 5 lines · Darrick J. Wong
Quoted 2 lines · Nirjhar Roy (IBM)
We should ASSERT on a variable before using it, so that we don't end up using an illegal value.
Assertions don't necessarily kill the kernel so ... do you want to bail out?
Okay, I wasn't aware of this. Thank you for pointing this out.
Quoted 5 lines
if (sum < 0) {
ASSERT(sum >= 0);
return -EFSCORRUPTED;
}Yeah, this makes sense - this will prevent further code to get executed. Also, does an XFS_IS_CORRUPT() look good above, i.e,
if (XFS_IS_CORRUPT(oargs->mp, sum < 0)) {
return -EFSCORRUPTED;
}
If not, can you please give me some guidelines as to when to use XFS_IS_CORRUPT()?
--NR
Quoted 34 lines
if (sum == 0) continue;--D
Quoted 29 lines
Signed-off-by Nirjhar Roy (IBM) <[email protected]>--- fs/xfs/xfs_rtalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/xfs/xfs_rtalloc.c +1
-1@@ -112,6 +112,7 @@ xfs_rtcopy_summary( error =xfs_rtget_summary (oargs, log, bbno, &sum);if (error) goto out; +ASSERT (sum >=0 );if (sum ==0 )continue ; error =xfs_rtmodify_summary (oargs, log, bbno, -sum);@@ -120,7 +121,6 @@ xfs_rtcopy_summary( error =xfs_rtmodify_summary (nargs, log, bbno, sum);if (error) goto out; -ASSERT (sum >0 ); } } error =0 ;Signature · 1 line
2.43.5
Signature · 3 lines
Nirjhar Roy Linux Kernel Developer IBM, Bangalore