libxc/progress: Extend the progress interface
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 24 Jul 2014 12:05:27 +0000 (13:05 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 5 May 2015 13:29:45 +0000 (14:29 +0100)
Progress information is logged via a different logger to regular libxc log
messages, and currently can only express a range.  However, not everything
which needs reporting as progress comes with a range.  Extend the interface to
allow reporting of a single statement.

The programming interface now looks like:
  xc_set_progress_prefix()
    set the prefix string to be used
  xc_report_progress_single()
    report a single action
  xc_report_progress_step()
    report $X of $Y

The new programming interface is implemented in a compatible way with the
existing caller interface (by reporting a single action as "0 of 0").

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Campbell <Ian.Campbell@citrix.com>
tools/libxc/xc_domain_restore.c
tools/libxc/xc_domain_save.c
tools/libxc/xc_private.c
tools/libxc/xc_private.h
tools/libxc/xtl_core.c

index f9dfd2d0f839c8d8e554a2e8b7f8afe72d2d839d..2ba639066b7737b47fef6aa51999b22b2b6c6bd6 100644 (file)
@@ -1622,7 +1622,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
         goto out;
     }
 
-    xc_report_progress_start(xch, "Reloading memory pages", dinfo->p2m_size);
+    xc_set_progress_prefix(xch, "Reloading memory pages");
+    xc_report_progress_step(xch, 0, dinfo->p2m_size);
 
     /*
      * Now simply read each saved frame into its new machine frame.
index 59323b82a047c4c737a804b51d3e3074e78ce3c4..a71442e0c6fef18e57ea833c4c569d6c6804efcd 100644 (file)
@@ -1131,7 +1131,8 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
                  "Saving memory: iter %d (last sent %u skipped %u)",
                  iter, sent_this_iter, skip_this_iter);
 
-        xc_report_progress_start(xch, reportbuf, dinfo->p2m_size);
+        xc_set_progress_prefix(xch, reportbuf);
+        xc_report_progress_step(xch, 0, dinfo->p2m_size);
 
         iter++;
         sent_this_iter = 0;
index 83ead5e3b29f59c1baa8c7dcfd3416fb4880e6c3..2ffebd9775511d2bd7ecfebd96a426d5ed450547 100644 (file)
@@ -388,18 +388,26 @@ void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code, const cha
     va_end(args);
 }
 
-void xc_report_progress_start(xc_interface *xch, const char *doing,
-                              unsigned long total) {
+const char *xc_set_progress_prefix(xc_interface *xch, const char *doing)
+{
+    const char *old = xch->currently_progress_reporting;
+
     xch->currently_progress_reporting = doing;
-    xtl_progress(xch->error_handler, "xc", xch->currently_progress_reporting,
-                 0, total);
+    return old;
+}
+
+void xc_report_progress_single(xc_interface *xch, const char *doing)
+{
+    assert(doing);
+    xtl_progress(xch->error_handler, "xc", doing, 0, 0);
 }
 
 void xc_report_progress_step(xc_interface *xch,
-                             unsigned long done, unsigned long total) {
+                             unsigned long done, unsigned long total)
+{
     assert(xch->currently_progress_reporting);
-    xtl_progress(xch->error_handler, "xc", xch->currently_progress_reporting,
-                 done, total);
+    xtl_progress(xch->error_handler, "xc",
+                 xch->currently_progress_reporting, done, total);
 }
 
 int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom,
index b45b079759443e3724f9c1f87442660e397d9d73..247a4089a66da438105c83b4b36924e494915e34 100644 (file)
@@ -133,8 +133,8 @@ void xc_report(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
                int code, const char *fmt, ...)
      __attribute__((format(printf,5,6)));
 
-void xc_report_progress_start(xc_interface *xch, const char *doing,
-                              unsigned long total);
+const char *xc_set_progress_prefix(xc_interface *xch, const char *doing);
+void xc_report_progress_single(xc_interface *xch, const char *doing);
 void xc_report_progress_step(xc_interface *xch,
                              unsigned long done, unsigned long total);
 
index 326b97ea6f4b735bbd3a55b4e355ea3bb415a91f..73add923df8ff6f572a90f11f79e9b7710516e52 100644 (file)
@@ -66,13 +66,14 @@ void xtl_log(struct xentoollog_logger *logger,
 void xtl_progress(struct xentoollog_logger *logger,
                   const char *context, const char *doing_what,
                   unsigned long done, unsigned long total) {
-    int percent;
+    int percent = 0;
 
     if (!logger->progress) return;
 
-    percent = (total < LONG_MAX/100)
-        ? (done * 100) / total
-        : done / ((total + 99) / 100);
+    if ( total )
+        percent = (total < LONG_MAX/100)
+            ? (done * 100) / total
+            : done / ((total + 99) / 100);
 
     logger->progress(logger, context, doing_what, percent, done, total);
 }