static void test_ratelimit_below(void) { int i; RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10); for (i = 0; i < 10; i++) assert_se(ratelimit_below(&ratelimit)); assert_se(!ratelimit_below(&ratelimit)); sleep(1); for (i = 0; i < 10; i++) assert_se(ratelimit_below(&ratelimit)); RATELIMIT_INIT(ratelimit, 0, 10); for (i = 0; i < 10000; i++) assert_se(ratelimit_below(&ratelimit)); }
static void raw_export_report_progress(RawExport *e) { unsigned percent; assert(e); if (e->written_uncompressed >= (uint64_t) e->st.st_size) percent = 100; else percent = (unsigned) ((e->written_uncompressed * UINT64_C(100)) / (uint64_t) e->st.st_size); if (percent == e->last_percent) return; if (!ratelimit_below(&e->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); log_info("Exported %u%%.", percent); e->last_percent = percent; }
static void raw_import_report_progress(RawImport *i) { unsigned percent; assert(i); /* We have no size information, unless the source is a regular file */ if (!S_ISREG(i->st.st_mode)) return; if (i->written_compressed >= (uint64_t) i->st.st_size) percent = 100; else percent = (unsigned) ((i->written_compressed * UINT64_C(100)) / (uint64_t) i->st.st_size); if (percent == i->last_percent) return; if (!ratelimit_below(&i->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); log_info("Imported %u%%.", percent); i->last_percent = percent; }
static void tar_export_report_progress(TarExport *e) { unsigned percent; assert(e); /* Do we have any quota info? If not, we don't know anything about the progress */ if (e->quota_referenced == (uint64_t) -1) return; if (e->written_uncompressed >= e->quota_referenced) percent = 100; else percent = (unsigned) ((e->written_uncompressed * UINT64_C(100)) / e->quota_referenced); if (percent == e->last_percent) return; if (!ratelimit_below(&e->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); log_info("Exported %u%%.", percent); e->last_percent = percent; }