[sheepdog] [PATCH 2/2] farm: show progress bar for load/save operations
Liu Yuan
namei.unix at gmail.com
Wed Jul 17 07:49:08 CEST 2013
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
collie/farm/farm.c | 9 +++++++++
collie/farm/farm.h | 1 +
collie/farm/trunk.c | 8 ++++++++
3 files changed, 18 insertions(+)
diff --git a/collie/farm/farm.c b/collie/farm/farm.c
index d4aff48..a42ac47 100644
--- a/collie/farm/farm.c
+++ b/collie/farm/farm.c
@@ -255,15 +255,22 @@ error:
uatomic_set_true(&work_error);
}
+static void farm_show_progress(uint64_t done, uint64_t total)
+{
+ return show_progress(done, total, true);
+}
+
static void save_object_done(struct work *work)
{
struct snapshot_work *sw = container_of(work, struct snapshot_work,
work);
+ static uint64_t saved;
if (uatomic_is_true(&work_error))
goto out;
strbuf_add(sw->trunk_buf, &sw->entry, sizeof(struct trunk_entry));
+ farm_show_progress(uatomic_add_return(&saved, 1), object_tree_size());
out:
free(sw);
}
@@ -331,6 +338,7 @@ static void do_load_object(struct work *work)
void *buffer = NULL;
size_t size;
struct snapshot_work *sw;
+ static uint64_t loaded;
if (uatomic_is_true(&work_error))
return;
@@ -356,6 +364,7 @@ static void do_load_object(struct work *work)
pthread_rwlock_unlock(&vdi_list_lock);
}
+ farm_show_progress(uatomic_add_return(&loaded, 1), trunk_get_count());
free(buffer);
return;
error:
diff --git a/collie/farm/farm.h b/collie/farm/farm.h
index 0a25324..ba6f53e 100644
--- a/collie/farm/farm.h
+++ b/collie/farm/farm.h
@@ -55,6 +55,7 @@ int trunk_file_write(uint64_t nr_entries, struct trunk_entry *entries,
int for_each_entry_in_trunk(unsigned char *trunk_sha1,
int (*func)(struct trunk_entry *entry, void *data),
void *data);
+uint64_t trunk_get_count(void);
/* snap.c */
int snap_init(const char *path);
diff --git a/collie/farm/trunk.c b/collie/farm/trunk.c
index 4d39084..91f293e 100644
--- a/collie/farm/trunk.c
+++ b/collie/farm/trunk.c
@@ -28,6 +28,8 @@
#include "util.h"
#include "sheepdog_proto.h"
+static uint64_t total_count;
+
int trunk_file_write(uint64_t nr_entries, struct trunk_entry *entries,
unsigned char *trunk_sha1)
{
@@ -62,6 +64,7 @@ int for_each_entry_in_trunk(unsigned char *trunk_sha1,
if (!trunk)
goto out;
+ total_count = trunk->nr_entries;
entry = trunk->entries;
for (uint64_t i = 0; i < trunk->nr_entries; i++, entry++) {
if (func(entry, data) < 0)
@@ -74,3 +77,8 @@ out:
free(trunk);
return ret;
}
+
+uint64_t trunk_get_count(void)
+{
+ return total_count;
+}
--
1.7.9.5
More information about the sheepdog
mailing list