Skip to contentSkip to conversation

Scrub resume regression

DISCUSSION Graham Cobb 7 participants 10 messages Jan 15, 2020 – Jan 17, 2020 Btrfs file system

lore
Share & tools
lore

Graham Cobb

author Reviewed-by David Sterba
#0 lore raw

OK, I have bisected the problem with scrub resume being broken by the scrub ioctl ABI being changed.

The bad commit is:

Fail
06fe39ab15a6a47d4979460fcc17d33b1d72ccf9 is the first bad commit commit 06fe39ab15a6a47d4979460fcc17d33b1d72ccf9

Author: Filipe Manana <[email protected]>
Date:   Fri Dec 14 19:50:17 2018 +0000

Btrfs: do not overwrite scrub error with fault error in scrub ioctl

If scrub returned an error and then the copy_to_user() call did not succeed, we would overwrite the error returned by scrub with -EFAULT. Fix that by calling copy_to_user() only if btrfs_scrub_dev() returned success.

 fs/btrfs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

bisect run success

It is important that scrub always returns the stats, even when it returns an error. This is critical for cancel, as that is how cancel/resume works, but it should also apply in case of other errors so that the user can see how much of the scrub was done before the fatal error.

I am not sure in which kernel release this commit appeared but as this breaks the "scrub resume" command completely, I think the fix for this needs to be backported and may want to be considered by distro kernel maintainers.

I will reply later with the simple reproducer program I created for the bisection in case it is useful for testing.

#1 lore raw
Quoted 32 lines · Graham Cobb

OK, I have bisected the problem with scrub resume being broken by the scrub ioctl ABI being changed.

The bad commit is:

Fail
06fe39ab15a6a47d4979460fcc17d33b1d72ccf9 is the first bad commit commit 06fe39ab15a6a47d4979460fcc17d33b1d72ccf9

Author: Filipe Manana <[email protected]>
Date:   Fri Dec 14 19:50:17 2018 +0000

Btrfs: do not overwrite scrub error with fault error in scrub ioctl

If scrub returned an error and then the copy_to_user() call did not succeed, we would overwrite the error returned by scrub with -EFAULT. Fix that by calling copy_to_user() only if btrfs_scrub_dev() returned success.

 fs/btrfs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

bisect run success

It is important that scrub always returns the stats, even when it returns an error. This is critical for cancel, as that is how cancel/resume works, but it should also apply in case of other errors so that the user can see how much of the scrub was done before the fatal error.

Quoted 7 lines

I am not sure in which kernel release this commit appeared but as this breaks the "scrub resume" command completely, I think the fix for this needs to be backported and may want to be considered by distro kernel maintainers.

I will reply later with the simple reproducer program I created for the bisection in case it is useful for testing.

No need to, it is simple to understand why it happens and the not copying that stats in error case was not intentional.

Try this:

fs/btrfs/ioctl.c +0 -0
index 3a4bd5cd67fa..611dfe8cdbb1 100644
@@ -4253,8 +4253,10 @@ static long btrfs_ioctl_scrub(struct file

*file, void __user *arg)

                              &sa->progress, sa->flags & BTRFS_SCRUB_READONLY,
                              0);

- if (ret == 0 && copy_to_user(arg, sa, sizeof(*sa)))
- ret = -EFAULT;
+ if (copy_to_user(arg, sa, sizeof(*sa))) {
+ if (!ret)
+ ret = -EFAULT;
+ }

        if (!(sa->flags & BTRFS_SCRUB_READONLY))
                mnt_drop_write_file(file);

I'll later send a patch with a changelog to the list. Thanks.

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#2 lore raw
Quoted 4 lines · Filipe Manana
Quoted 3 lines · Graham Cobb

OK, I have bisected the problem with scrub resume being broken by the scrub ioctl ABI being changed.

[snip]

Quoted 22 lines

Try this:

fs/btrfs/ioctl.c +4 -2
index 3a4bd5cd67fa..611dfe8cdbb1 100644
@@ -4253,8 +4253,10 @@ static long btrfs_ioctl_scrub(struct file
 *file, void __user *arg)
                              &sa->progress, sa->flags & BTRFS_SCRUB_READONLY,
                              0);
 
-       if (ret == 0 && copy_to_user(arg, sa, sizeof(*sa)))
-               ret = -EFAULT;
+       if (copy_to_user(arg, sa, sizeof(*sa))) {
+               if (!ret)
+                       ret = -EFAULT;
+       }
 
        if (!(sa->flags & BTRFS_SCRUB_READONLY))
                mnt_drop_write_file(file);
Quoted 2 lines

I'll later send a patch with a changelog to the list. Thanks.

Thanks Filipe. I have tested that the patch builds and works with my reproducer on a 5.4 kernel.

Later I will build a distro kernel with the patch and try my monthly scrub-with-interruptions script. That will take a day or two.

#3 lore raw
In reply to Graham Cobb
Quoted 2 lines · Graham Cobb

OK, I have bisected the problem with scrub resume being broken by the scrub ioctl ABI being changed.

Thanks for the bisecting, I'll forward the fix to 5.5-rc so it can be picked by stable trees. The regression has been there since 5.1, which at the moment is only for 5.4.x.

Quoted 8 lines

The bad commit is:

06fe39ab15a6a47d4979460fcc17d33b1d72ccf9 is the first bad commit commit 06fe39ab15a6a47d4979460fcc17d33b1d72ccf9

Author: Filipe Manana <[email protected]>
Date:   Fri Dec 14 19:50:17 2018 +0000

Btrfs: do not overwrite scrub error with fault error in scrub ioctl

[...]

Quoted 4 lines

It is important that scrub always returns the stats, even when it returns an error. This is critical for cancel, as that is how cancel/resume works, but it should also apply in case of other errors so that the user can see how much of the scrub was done before the fatal error.

That's something we need to document in code and perhaps in the manual pages too.

#4 lore raw
Quoted 7 lines · David Sterba
Quoted 4 lines

It is important that scrub always returns the stats, even when it returns an error. This is critical for cancel, as that is how cancel/resume works, but it should also apply in case of other errors so that the user can see how much of the scrub was done before the fatal error.

That's something we need to document in code and perhaps in the manual pages too.

Isn't the real problem that cancel does not actually mean cancel, but rather also implies "..and maybe continue"? IMHO cancel should cancel (and say how much work was performed), while the intention to resume should be called e.g. "pause". This makes the behaviour clear and prevents accidental semantic overlap.

-h

#5 lore raw
Quoted 6 lines

Isn't the real problem that cancel does not actually mean cancel, but rather also implies "..and maybe continue"? IMHO cancel should cancel (and say how much work was performed), while the intention to resume should be called e.g. "pause". This makes the behaviour clear and prevents accidental semantic overlap.

IMHO a better choice of wording might also be "interrupt" and "abort", but maybe that's just being pedantic (cancel could then stay in place for backwards compatibility). In any case the current man page for btrfs-progs makes it somewhat clear what's supposed to happen and my confusion was mostly caused by the bug.

BTW: Thanks to everyone who helped tracking down the cause of this bug. Haven't had a chance to test the proposed patch yet, but am looking forward to schedule large scrubs across multiple nights.

#6 lore raw
In reply to Holger Hoffstätte
Quoted 6 lines · Holger Hoffstätte
Quoted 5 lines · David Sterba
Quoted 4 lines

It is important that scrub always returns the stats, even when it returns an error. This is critical for cancel, as that is how cancel/resume works, but it should also apply in case of other errors so that the user can see how much of the scrub was done before the fatal error.

Quoted 8 lines
Quoted 2 lines

That's something we need to document in code and perhaps in the manual pages too.

Isn't the real problem that cancel does not actually mean cancel, but rather also implies "..and maybe continue"? IMHO cancel should cancel (and say how much work was performed), while the intention to resume should be called e.g. "pause". This makes the behaviour clear and prevents accidental semantic overlap.

We can add 'pause', but for backward compatibility, cancel has to stay as is. I personally think that saving the last position after cancel is not a big deal. With 'pause' it will be less confusing for users and will have also parity with balance commands.

start - pause - resume
start - cancel

One difference is that cancelling balance will also delete the state (stored inside the filesystem metadata). If scrub start follows cancel, the state is reset at the beginning. I'm not sure if adding an extra option eg. 'scrub cancel --reset' is worth.

#7 lore raw
Quoted 21 lines · David Sterba
Quoted 6 lines · Holger Hoffstätte
Quoted 5 lines · David Sterba
Quoted 4 lines

It is important that scrub always returns the stats, even when it returns an error. This is critical for cancel, as that is how cancel/resume works, but it should also apply in case of other errors so that the user can see how much of the scrub was done before the fatal error.

Quoted 8 lines
Quoted 2 lines

That's something we need to document in code and perhaps in the manual pages too.

Isn't the real problem that cancel does not actually mean cancel, but rather also implies "..and maybe continue"? IMHO cancel should cancel (and say how much work was performed), while the intention to resume should be called e.g. "pause". This makes the behaviour clear and prevents accidental semantic overlap.

We can add 'pause', but for backward compatibility, cancel has to stay as is. I personally think that saving the last position after cancel is not a big deal. With 'pause' it will be less confusing for users and will have also parity with balance commands.

Quoted 7 lines

start - pause - resume
start - cancel

One difference is that cancelling balance will also delete the state (stored inside the filesystem metadata). If scrub start follows cancel, the state is reset at the beginning. I'm not sure if adding an extra option eg. 'scrub cancel --reset' is worth.

Currently 'scrub cancel' doesn't reset the state, so existing scripts will be broken if 'cancel' is not exactly the same as 'pause'. I have such scripts, they call 'cancel' and 'resume' blindly according to load or maintenance window boundaries, and they leave it to btrfs userspace to sort out whether any new work should be done.

#8 lore raw

It's no one's fault, it's just confusing. :P

Cancel word origin means more than stop, implies resetting state, to obliterate or invalidate.

Pause and stop word origin suggests they're interchangeable, but in practice with digital audio and video consumer gear, stop has come to mean a kind of cancel. (I'm gonna ignore tape.) Where a start from a stop will start at the very beginning. Whereas pause saves state and unpause means resume.

Lightweight change, add new command stop, which saves state, and cancel is an alias for backward compatibility. No other change.

Moderate change:
start = alias resume
stop = alias cancel
i.e. a stop then start does the same thing as a cancel then resume, unless new command 'reset' is used
reset = stops, and resets state to the beginning

Heavier change that's linguistically sane, but breaks expectations of today's cancel:
pause and unpause (alias resume), and start and stop (alias cancel). The former is stateful, and the latter is stateless.

But this problem should be looked at by i18n folks before changing anything.

---
Chris Murphy

#9 lore raw
Quoted 5 lines · Chris Murphy

It's no one's fault, it's just confusing. :P

Cancel word origin means more than stop, implies resetting state, to obliterate or invalidate.

Quoted 8 lines

Pause and stop word origin suggests they're interchangeable, but in practice with digital audio and video consumer gear, stop has come to mean a kind of cancel. (I'm gonna ignore tape.) Where a start from a stop will start at the very beginning. Whereas pause saves state and unpause means resume.

Lightweight change, add new command stop, which saves state, and cancel is an alias for backward compatibility. No other change.

That seems fairly pointless.

Quoted 2 lines

Moderate change:
start = alias resume

start and resume do different things today. The distinction is important as the "saved state" after a cancel stays around until the next scrub starts (it could be months old).

Quoted 4 lines

stop = alias cancel
i.e. a stop then start does the same thing as a cancel then resume, unless new command 'reset' is used
reset = stops, and resets state to the beginning

That really isn't useful. It is much more useful to be able to decide whether to use the saved state at start time than it is to decide whether to save state at stop time. To build on Zygo's example, I might have a script which pauses the scrub when the system load goes up and then decides whether to resume it or restart from scratch depending on how long it has been paused for. Also, the saved state can be inspected while the scrub is paused to allow the operator to estimate how long it might take to complete.

Quoted 4 lines

Heavier change that's linguistically sane, but breaks expectations of today's cancel:
pause and unpause (alias resume), and start and stop (alias cancel). The former is stateful, and the latter is stateless.

Changing the meaning of the current start, resume, or cancel commands isn't an option - these are built into user scripts.