mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-24 15:12:47 +00:00
btrfs-progs: convert: use task for progress indication of metadata creation
Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
cd08bdfd98
commit
48e06b7fa4
@ -29,6 +29,8 @@ Roll back to ext2fs.
|
||||
set filesystem label during conversion.
|
||||
-L::
|
||||
use label from the converted filesystem.
|
||||
-p::
|
||||
Show progress of conversion.
|
||||
|
||||
EXIT STATUS
|
||||
-----------
|
||||
|
4
Makefile
4
Makefile
@ -10,7 +10,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
|
||||
root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
|
||||
extent-cache.o extent_io.o volumes.o utils.o repair.o \
|
||||
qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
|
||||
ulist.o qgroup-verify.o backref.o string-table.o
|
||||
ulist.o qgroup-verify.o backref.o string-table.o task-utils.o
|
||||
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
|
||||
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
|
||||
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
|
||||
@ -26,7 +26,7 @@ TESTS = fsck-tests.sh convert-tests.sh
|
||||
INSTALL = install
|
||||
prefix ?= /usr/local
|
||||
bindir = $(prefix)/bin
|
||||
lib_LIBS = -luuid -lblkid -lm -lz -llzo2 -L.
|
||||
lib_LIBS = -luuid -lblkid -lm -lz -llzo2 -L. -pthread
|
||||
libdir ?= $(prefix)/lib
|
||||
incdir = $(prefix)/include/btrfs
|
||||
LIBS = $(lib_LIBS) $(libs_static)
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "transaction.h"
|
||||
#include "crc32c.h"
|
||||
#include "utils.h"
|
||||
#include "task-utils.h"
|
||||
#include <ext2fs/ext2_fs.h>
|
||||
#include <ext2fs/ext2fs.h>
|
||||
#include <ext2fs/ext2_ext_attr.h>
|
||||
@ -45,6 +46,41 @@
|
||||
#define INO_OFFSET (BTRFS_FIRST_FREE_OBJECTID - EXT2_ROOT_INO)
|
||||
#define EXT2_IMAGE_SUBVOL_OBJECTID BTRFS_FIRST_FREE_OBJECTID
|
||||
|
||||
struct task_ctx {
|
||||
uint32_t max_copy_inodes;
|
||||
uint32_t cur_copy_inodes;
|
||||
struct task_info *info;
|
||||
};
|
||||
|
||||
static void *print_copied_inodes(void *p)
|
||||
{
|
||||
struct task_ctx *priv = p;
|
||||
const char work_indicator[] = { '.', 'o', 'O', 'o' };
|
||||
uint32_t count = 0;
|
||||
|
||||
task_period_start(priv->info, 1000 /* 1s */);
|
||||
while (1) {
|
||||
count++;
|
||||
printf("copy inodes [%c] [%10d/%10d]\r",
|
||||
work_indicator[count % 4], priv->cur_copy_inodes,
|
||||
priv->max_copy_inodes);
|
||||
fflush(stdout);
|
||||
task_period_wait(priv->info);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int after_copied_inodes(void *p)
|
||||
{
|
||||
struct task_ctx *priv = p;
|
||||
|
||||
printf("\n");
|
||||
task_period_stop(priv->info);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open Ext2fs in readonly mode, read block allocation bitmap and
|
||||
* inode bitmap into memory.
|
||||
@ -1036,7 +1072,7 @@ fail:
|
||||
* scan ext2's inode bitmap and copy all used inodes.
|
||||
*/
|
||||
static int copy_inodes(struct btrfs_root *root, ext2_filsys ext2_fs,
|
||||
int datacsum, int packing, int noxattr)
|
||||
int datacsum, int packing, int noxattr, struct task_ctx *p)
|
||||
{
|
||||
int ret;
|
||||
errcode_t err;
|
||||
@ -1068,6 +1104,7 @@ static int copy_inodes(struct btrfs_root *root, ext2_filsys ext2_fs,
|
||||
objectid, ext2_fs, ext2_ino,
|
||||
&ext2_inode, datacsum, packing,
|
||||
noxattr);
|
||||
p->cur_copy_inodes++;
|
||||
if (ret)
|
||||
return ret;
|
||||
if (trans->blocks_used >= 4096) {
|
||||
@ -2197,7 +2234,7 @@ err:
|
||||
}
|
||||
|
||||
static int do_convert(const char *devname, int datacsum, int packing, int noxattr,
|
||||
int copylabel, const char *fslabel)
|
||||
int copylabel, const char *fslabel, int progress)
|
||||
{
|
||||
int i, ret;
|
||||
int fd = -1;
|
||||
@ -2208,6 +2245,7 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt
|
||||
ext2_filsys ext2_fs;
|
||||
struct btrfs_root *root;
|
||||
struct btrfs_root *ext2_root;
|
||||
struct task_ctx ctx;
|
||||
|
||||
ret = open_ext2fs(devname, &ext2_fs);
|
||||
if (ret) {
|
||||
@ -2275,11 +2313,23 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt
|
||||
goto fail;
|
||||
}
|
||||
printf("creating btrfs metadata.\n");
|
||||
ret = copy_inodes(root, ext2_fs, datacsum, packing, noxattr);
|
||||
ctx.max_copy_inodes = (ext2_fs->super->s_inodes_count
|
||||
- ext2_fs->super->s_free_inodes_count);
|
||||
ctx.cur_copy_inodes = 0;
|
||||
|
||||
if (progress) {
|
||||
ctx.info = task_init(print_copied_inodes, after_copied_inodes, &ctx);
|
||||
task_start(ctx.info);
|
||||
}
|
||||
ret = copy_inodes(root, ext2_fs, datacsum, packing, noxattr, &ctx);
|
||||
if (ret) {
|
||||
fprintf(stderr, "error during copy_inodes %d\n", ret);
|
||||
goto fail;
|
||||
}
|
||||
if (progress) {
|
||||
task_stop(ctx.info);
|
||||
task_deinit(ctx.info);
|
||||
}
|
||||
printf("creating ext2fs image file.\n");
|
||||
ext2_root = link_subvol(root, "ext2_saved", EXT2_IMAGE_SUBVOL_OBJECTID);
|
||||
if (!ext2_root) {
|
||||
@ -2703,6 +2753,7 @@ static void print_usage(void)
|
||||
printf("\t-r roll back to ext2fs\n");
|
||||
printf("\t-l LABEL set filesystem label\n");
|
||||
printf("\t-L use label from converted fs\n");
|
||||
printf("\t-p show converting progress\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -2714,11 +2765,12 @@ int main(int argc, char *argv[])
|
||||
int rollback = 0;
|
||||
int copylabel = 0;
|
||||
int usage_error = 0;
|
||||
int progress = 0;
|
||||
char *file;
|
||||
char *fslabel = NULL;
|
||||
|
||||
while(1) {
|
||||
int c = getopt(argc, argv, "dinrl:L");
|
||||
int c = getopt(argc, argv, "dinrl:Lp");
|
||||
if (c < 0)
|
||||
break;
|
||||
switch(c) {
|
||||
@ -2747,6 +2799,9 @@ int main(int argc, char *argv[])
|
||||
case 'L':
|
||||
copylabel = 1;
|
||||
break;
|
||||
case 'p':
|
||||
progress = 1;
|
||||
break;
|
||||
default:
|
||||
print_usage();
|
||||
return 1;
|
||||
@ -2784,7 +2839,7 @@ int main(int argc, char *argv[])
|
||||
if (rollback) {
|
||||
ret = do_rollback(file);
|
||||
} else {
|
||||
ret = do_convert(file, datacsum, packing, noxattr, copylabel, fslabel);
|
||||
ret = do_convert(file, datacsum, packing, noxattr, copylabel, fslabel, progress);
|
||||
}
|
||||
if (ret)
|
||||
return 1;
|
||||
|
@ -115,10 +115,8 @@ void task_period_wait(struct task_info *info)
|
||||
return;
|
||||
|
||||
ret = read(info->periodic.timer_fd, &missed, sizeof (missed));
|
||||
if (ret == -1) {
|
||||
perror("read timer");
|
||||
if (ret == -1)
|
||||
return;
|
||||
}
|
||||
|
||||
if (missed > 0)
|
||||
info->periodic.wakeups_missed += (missed - 1);
|
||||
|
Loading…
Reference in New Issue
Block a user