]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: scrub: keep the progress socket of a background scrub topics/scrub-progress-socket
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 30 Oct 2026 05:04:01 +0000 (01:04 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fri, 30 Oct 2026 05:04:01 +0000 (01:04 -0400)
A background scrub start creates and binds the progress socket, then
forks.  The child scrubs and answers on the socket, but the parent
leaves through the common exit path, which closes the socket and
removes it from the file system.  Nothing can connect to the child
after that: "btrfs scrub status" falls back to the status file, which
is written every 5 seconds, and the check for a running scrub in
another "btrfs scrub start -f" does not see the background scrub.

Close the parent's copy of the socket without removing it.  The child
removes it when the scrub is finished.

Fixes: 4ba165318745 ("btrfs-progs: scrub userland implementation")
Assisted-by: Claude:claude-opus-5-5
cmds/scrub.c

index 1843856bd210973d1fd4d2693114ba4ded079eb3..c286b20dfc9efc03d7337969f5187d681c5f1bc8 100644 (file)
@@ -1567,6 +1567,17 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
                        /* The child scrubs and restores the old limits. */
                        for (i = 0; i < fi_args.num_devices; ++i)
                                sp[i].limit_changed = false;
+
+                       /*
+                        * The child serves the progress socket and removes it
+                        * when the scrub is finished.  Close the parent's copy
+                        * without removing it, or nothing can connect to the
+                        * child.
+                        */
+                       if (prg_fd > -1) {
+                               close(prg_fd);
+                               prg_fd = -1;
+                       }
                        scrub_handle_sigint_parent();
                        pr_default("scrub %s on %s, fsid %s (pid=%d)\n",
                                   n_start ? "started" : "resumed",