copy: calculate bytes per second while copying, and pass to progress info

Also, show it in import-fs/repart.
This commit is contained in:
Lennart Poettering
2025-09-17 19:48:08 +01:00
committed by Luca Boccassi
parent e566236fc1
commit acd4943528
5 changed files with 42 additions and 16 deletions
+7 -3
View File
@@ -45,6 +45,7 @@ typedef struct ProgressInfo {
uint64_t size;
bool started;
bool logged_incomplete;
uint64_t bps;
} ProgressInfo;
static void progress_info_free(ProgressInfo *p) {
@@ -72,8 +73,10 @@ static void progress_show(ProgressInfo *p) {
if (p->size == 0)
log_info("Copying tree, currently at '%s'...", p->path);
else
else if (p->bps == UINT64_MAX)
log_info("Copying tree, currently at '%s' (@%s)...", p->path, FORMAT_BYTES(p->size));
else
log_info("Copying tree, currently at '%s' (@%s, %s/s)...", p->path, FORMAT_BYTES(p->size), FORMAT_BYTES(p->bps));
}
static int progress_path(const char *path, const struct stat *st, void *userdata) {
@@ -90,12 +93,13 @@ static int progress_path(const char *path, const struct stat *st, void *userdata
return 0;
}
static int progress_bytes(uint64_t nbytes, void *userdata) {
static int progress_bytes(uint64_t nbytes, uint64_t bps, void *userdata) {
ProgressInfo *p = ASSERT_PTR(userdata);
assert(p->size != UINT64_MAX);
p->size += nbytes;
p->bps = bps;
progress_show(p);
return 0;
@@ -103,7 +107,7 @@ static int progress_bytes(uint64_t nbytes, void *userdata) {
static int import_fs(int argc, char *argv[], void *userdata) {
_cleanup_(rm_rf_subvolume_and_freep) char *temp_path = NULL;
_cleanup_(progress_info_free) ProgressInfo progress = {};
_cleanup_(progress_info_free) ProgressInfo progress = { .bps = UINT64_MAX };
_cleanup_free_ char *l = NULL, *final_path = NULL;
const char *path = NULL, *local = NULL, *dest = NULL;
_cleanup_close_ int open_fd = -EBADF;