Thanks to visit codestin.com
Credit goes to github.com

Skip to content

New API: Replace btrfs-fsck with btrfs-scrub-full #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions daemon/btrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,47 @@ do_btrfs_scrub_resume (const char *path)
return 0;
}

/* Takes optional arguments, consult optargs_bitmask. */
int
do_btrfs_scrub_full (const char *path, int readonly)
{
const size_t MAX_ARGS = 64;
const char *argv[MAX_ARGS];
size_t i = 0;
CLEANUP_FREE char *path_buf = NULL;
CLEANUP_FREE char *out = NULL, *err = NULL;
int r;

path_buf = sysroot_path (path);
if (path_buf == NULL) {
reply_with_perror ("malloc");
return -1;
}

ADD_ARG (argv, i, "btrfs");
ADD_ARG (argv, i, "scrub");
ADD_ARG (argv, i, "start");
ADD_ARG (argv, i, "-B"); /* foreground */

/* Optional arguments. */
if ((optargs_bitmask & GUESTFS_BTRFS_SCRUB_FULL_READONLY_BITMASK) &&
readonly)
ADD_ARG (argv, i, "-r");

ADD_ARG (argv, i, path_buf);
ADD_ARG (argv, i, NULL);

r = commandvf (&out, &err,
COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
argv);
if (r == -1) {
reply_with_error ("%s: %s", path, err);
return -1;
}

return 0;
}

int
do_btrfs_balance_pause (const char *path)
{
Expand Down
3 changes: 3 additions & 0 deletions docs/guestfs-release-notes-1.56.pod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ New C<command_out> and C<sh_out> APIs which allow you to capture
output from guest commands that generate more output than the protocol
limit allows.

New C<btrfs_scrub_full> API which runs a full Btrfs scrub,
synchronously. It works more like fsck for other filesystems.

The C<fstrim> API has been modified to work around several issues in
upstream and RHEL 9 kernels related to XFS support (Eric Sandeen, Dave
Chinner).
Expand Down
29 changes: 15 additions & 14 deletions generator/actions_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7344,20 +7344,6 @@ If C<devices> is an empty list, this does nothing." };
Enable or disable the seeding feature of a device that contains
a btrfs filesystem." };

{ defaults with
name = "btrfs_fsck"; added = (1, 17, 43);
style = RErr, [String (Device, "device")], [OInt64 "superblock"; OBool "repair"];
optional = Some "btrfs";
tests = [
InitPartition, Always, TestRun (
[["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
["btrfs_fsck"; "/dev/sda1"; ""; ""]]), []
];
shortdesc = "check a btrfs filesystem";
longdesc = "\
Used to check a btrfs filesystem, C<device> is the device file where the
filesystem is stored." };

{ defaults with
name = "filesystem_available"; added = (1, 19, 5);
style = RBool "fsavail", [String (PlainString, "filesystem")], [];
Expand Down Expand Up @@ -9082,6 +9068,21 @@ Show the status of a running or paused balance on a btrfs filesystem." };
longdesc = "\
Show status of running or finished scrub on a btrfs filesystem." };

{ defaults with
name = "btrfs_scrub_full"; added = (1, 55, 12);
style = RErr, [String (Pathname, "path")], [OBool "readonly"];
optional = Some "btrfs"; camel_name = "BTRFSScrubFull";
tests = [
InitPartition, Always, TestRun (
[["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
["mount"; "/dev/sda1"; "/"];
["btrfs_scrub_full"; "/"; "false"]]), [];
];
shortdesc = "run a full scrub on a btrfs filesystem";
longdesc = "\
Run a full scrub on a btrfs filesystem and wait for it to finish.
If the filesystem has errors this will return an error." };

{ defaults with
name = "btrfstune_seeding"; added = (1, 29, 29);
style = RErr, [String (Device, "device"); Bool "seeding"], [];
Expand Down
15 changes: 15 additions & 0 deletions generator/actions_core_deprecated.ml
Original file line number Diff line number Diff line change
Expand Up @@ -927,4 +927,19 @@ This call does nothing and returns an error." };
longdesc = "\
This call does nothing and returns an error." };

{ defaults with
name = "btrfs_fsck"; added = (1, 17, 43);
style = RErr, [String (Device, "device")], [OInt64 "superblock"; OBool "repair"];
optional = Some "btrfs";
deprecated_by = Replaced_by "btrfs_scrub_full";
tests = [
InitPartition, Always, TestRun (
[["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
["btrfs_fsck"; "/dev/sda1"; ""; ""]]), []
];
shortdesc = "check a btrfs filesystem";
longdesc = "\
Used to check a btrfs filesystem, C<device> is the device file where the
filesystem is stored." };

]
1 change: 1 addition & 0 deletions generator/proc_nr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ let proc_nr = [
515, "findfs_partlabel";
516, "command_out";
517, "sh_out";
518, "btrfs_scrub_full";
]

(* End of list. If adding a new entry, add it at the end of the list
Expand Down
2 changes: 2 additions & 0 deletions gobject/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-btrfs_filesystem_resize.h \
include/guestfs-gobject/optargs-btrfs_fsck.h \
include/guestfs-gobject/optargs-btrfs_image.h \
include/guestfs-gobject/optargs-btrfs_scrub_full.h \
include/guestfs-gobject/optargs-btrfs_subvolume_create.h \
include/guestfs-gobject/optargs-btrfs_subvolume_snapshot.h \
include/guestfs-gobject/optargs-compress_device_out.h \
Expand Down Expand Up @@ -153,6 +154,7 @@ guestfs_gobject_sources= \
src/optargs-btrfs_filesystem_resize.c \
src/optargs-btrfs_fsck.c \
src/optargs-btrfs_image.c \
src/optargs-btrfs_scrub_full.c \
src/optargs-btrfs_subvolume_create.c \
src/optargs-btrfs_subvolume_snapshot.c \
src/optargs-compress_device_out.c \
Expand Down
2 changes: 1 addition & 1 deletion lib/MAX_PROC_NR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
517
518