btrfs-progs: tune: factor out seeding to own file

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2023-01-18 15:48:21 +01:00
parent f66478b961
commit b380d972e2
4 changed files with 88 additions and 42 deletions

View File

@ -234,7 +234,7 @@ convert_objects = convert/main.o convert/common.o convert/source-fs.o \
mkfs/common.o
mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
image_objects = image/main.o image/sanitize.o
tune_objects = tune/main.o
tune_objects = tune/main.o tune/seeding.o
all_objects = $(objects) $(cmds_objects) $(libbtrfs_objects) $(convert_objects) \
$(mkfs_objects) $(image_objects) $(tune_objects) $(libbtrfsutil_objects)

View File

@ -41,51 +41,12 @@
#include "common/string-utils.h"
#include "common/help.h"
#include "common/box.h"
#include "tune/tune.h"
#include "ioctl.h"
static char *device;
static int force = 0;
static int update_seeding_flag(struct btrfs_root *root, int set_flag)
{
struct btrfs_trans_handle *trans;
struct btrfs_super_block *disk_super;
u64 super_flags;
int ret;
disk_super = root->fs_info->super_copy;
super_flags = btrfs_super_flags(disk_super);
if (set_flag) {
if (super_flags & BTRFS_SUPER_FLAG_SEEDING) {
if (force)
return 0;
else
warning("seeding flag is already set on %s",
device);
return 1;
}
if (btrfs_super_log_root(disk_super)) {
error("filesystem with dirty log detected, not setting seed flag");
return 1;
}
super_flags |= BTRFS_SUPER_FLAG_SEEDING;
} else {
if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {
warning("seeding flag is not set on %s", device);
return 1;
}
super_flags &= ~BTRFS_SUPER_FLAG_SEEDING;
warning("seeding flag cleared on %s", device);
}
trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans));
btrfs_set_super_flags(disk_super, super_flags);
ret = btrfs_commit_transaction(trans, root);
return ret;
}
/*
* Return 0 for no unfinished fsid change.
* Return >0 for unfinished fsid change, and restore unfinished fsid/
@ -1111,7 +1072,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])
}
}
ret = update_seeding_flag(root, seeding_value);
ret = update_seeding_flag(root, device, seeding_value, force);
if (!ret)
success++;
total++;

61
tune/seeding.c Normal file
View File

@ -0,0 +1,61 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License v2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*/
#include "kerncompat.h"
#include "kernel-shared/ctree.h"
#include "kernel-shared/transaction.h"
#include "common/messages.h"
int update_seeding_flag(struct btrfs_root *root, const char *device, int set_flag, int force)
{
struct btrfs_trans_handle *trans;
struct btrfs_super_block *disk_super;
u64 super_flags;
int ret;
disk_super = root->fs_info->super_copy;
super_flags = btrfs_super_flags(disk_super);
if (set_flag) {
if (super_flags & BTRFS_SUPER_FLAG_SEEDING) {
if (force)
return 0;
else
warning("seeding flag is already set on %s",
device);
return 1;
}
if (btrfs_super_log_root(disk_super)) {
error("filesystem with dirty log detected, not setting seed flag");
return 1;
}
super_flags |= BTRFS_SUPER_FLAG_SEEDING;
} else {
if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) {
warning("seeding flag is not set on %s", device);
return 1;
}
super_flags &= ~BTRFS_SUPER_FLAG_SEEDING;
warning("seeding flag cleared on %s", device);
}
trans = btrfs_start_transaction(root, 1);
BUG_ON(IS_ERR(trans));
btrfs_set_super_flags(disk_super, super_flags);
ret = btrfs_commit_transaction(trans, root);
return ret;
}

24
tune/tune.h Normal file
View File

@ -0,0 +1,24 @@
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License v2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 021110-1307, USA.
*/
#ifndef __BTRFS_TUNE_H__
#define __BTRFS_TUNE_H__
struct btrfs_root;
int update_seeding_flag(struct btrfs_root *root, const char *device, int set_flag, int force);
#endif