Skip to content

Commit

Permalink
Subvolume.vala: (btrfs) Wait for async file operations to complete.
Browse files Browse the repository at this point in the history
With quotas disabled, available space wasn't being updated
consistently when removing old snapshots.

With quotas enabled, no time was allowed after committing to
delete a subvolume before attempting to remove its corresponding
qgroup, resulting in an error and requiring the user to delete the
snapshot twice.

Use the return codes from subvolume-sync and quota-rescan commands
to control the pace during a delete operation. This allows qgroup-
destroy to succeed and keeps the 'available space' value in the
main window in sync with the current filesystem state.

Unfortunately, as a result of this, snapshot deletion may take
longer to complete even with quotas disabled.

ref: #291
  • Loading branch information
mtwebster committed Feb 7, 2025
1 parent 36429af commit 33f9e7a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Core/Subvolume.vala
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,23 @@ public class Subvolume : GLib.Object{
return false;
}

log_debug("Waiting on btrfs to finish deleting...");
while (exec_sync("btrfs subvolume sync %s".printf(mount_path), out std_out, out std_err) != 0) {
log_debug("Still waiting for btrfs to finish deleting... %s".printf(std_err));
sleep(1000);
}

log_msg("%s: %s (Id:%ld)\n".printf(_("Deleted subvolume"), name, id));

if (App.btrfs_qgroups_enabled) {
if ((id > 0) && (repo != null)){

log_debug("Rescanning quotas...");
while (exec_sync("btrfs quota rescan %s".printf(mount_path), out std_out, out std_err) != 0) {
log_debug("Still rescanning quotas... %s".printf(std_err));
sleep(1000);
}

log_msg("%s: 0/%ld".printf(_("Destroying qgroup"), id));

cmd = "btrfs qgroup destroy 0/%ld '%s'".printf(id, repo.mount_paths[name]);
Expand All @@ -179,6 +192,19 @@ public class Subvolume : GLib.Object{
}

log_msg("%s: 0/%ld\n".printf(_("Destroyed qgroup"), id));

log_debug("Rescanning quotas (post)...");
while (exec_sync("btrfs quota rescan %s".printf(mount_path), out std_out, out std_err) != 0) {
log_debug("Still rescanning quotas (post)... %s".printf(std_err));
sleep(1000);
}

log_debug("Final sync (post)...");
while (exec_sync("btrfs subvolume sync %s".printf(mount_path), out std_out, out std_err) != 0) {
log_debug("Still syncing (post)... %s".printf(std_err));
sleep(1000);
}

}
}

Expand Down

0 comments on commit 33f9e7a

Please sign in to comment.