[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/5] tools/xl: Rename printf_info()/list_domains_details() to dump_by_...()



Date: Thu, 17 Dec 2020 17:42:42 -0800

printf_info()/list_domains_details() had been serving fairly similar
purposes.  Increase their consistency (add file-handle and output_format
arguments to list_domains_details(), reorder arguments) and then rename
to better reflect their functionality.

Both were simply outputting full domain information.  As this is more of
a dump operation, "dump" is a better name.

Signed-off-by: Elliott Mitchell <ehem+xen@xxxxxxx>
---
 tools/xl/xl.h      | 11 ++++++++---
 tools/xl/xl_info.c | 29 +++++++++++++++++------------
 tools/xl/xl_misc.c |  2 +-
 3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index dcd77d1ec4..7fd33db800 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -308,13 +308,18 @@ typedef enum {
     DOMAIN_RESTART_SUSPENDED,    /* Domain suspended - keep looping */
 } domain_restart_type;
 
+extern void dump_by_config(enum output_format output_format,
+                           FILE *fh,
+                           const libxl_domain_config *d_config,
+                           int domid);
+extern void dump_by_dominfo_list(enum output_format output_format,
+                                 FILE *fh,
+                                 const libxl_dominfo info[],
+                                 int nb_domain);
 extern void printf_info_sexp(int domid, const libxl_domain_config *d_config, 
FILE *fh);
 extern void apply_global_affinity_masks(libxl_domain_type type,
                                         libxl_bitmap *vcpu_affinity_array,
                                         unsigned int size);
-void printf_info(enum output_format output_format,
-                 int domid,
-                 libxl_domain_config *d_config, FILE *fh);
 
 #define XL_GLOBAL_CONFIG XEN_CONFIG_DIR "/xl.conf"
 #define XL_LOCK_FILE XEN_LOCK_DIR "/xl"
diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c
index 9540384beb..46bba4bb54 100644
--- a/tools/xl/xl_info.c
+++ b/tools/xl/xl_info.c
@@ -144,9 +144,10 @@ out:
 }
 #endif
 
-void printf_info(enum output_format output_format,
-                 int domid,
-                 libxl_domain_config *d_config, FILE *fh)
+void dump_by_config(enum output_format output_format,
+                    FILE *fh,
+                    const libxl_domain_config *const d_config,
+                    int domid)
 {
     if (output_format == OUTPUT_FORMAT_SXP)
         return printf_info_sexp(domid, d_config, fh);
@@ -540,7 +541,10 @@ static void list_domains(bool verbose, bool context, bool 
claim, bool numa,
     libxl_physinfo_dispose(&physinfo);
 }
 
-static void list_domains_details(const libxl_dominfo *info, int nb_domain)
+void dump_by_dominfo_list(enum output_format output_format,
+                          FILE *fh,
+                          const libxl_dominfo info[],
+                          int nb_domain)
 {
     libxl_domain_config d_config;
 
@@ -556,11 +560,11 @@ static void list_domains_details(const libxl_dominfo 
*info, int nb_domain)
 #endif
 
 #ifdef HAVE_LIBJSONC
-    if (default_output_format == OUTPUT_FORMAT_JSON) {
+    if (output_format == OUTPUT_FORMAT_JSON) {
         jso = json_object_new_array();
     }
 #elif defined(HAVE_LIBYAJL)
-    if (default_output_format == OUTPUT_FORMAT_JSON) {
+    if (output_format == OUTPUT_FORMAT_JSON) {
         hand = libxl_yajl_gen_alloc(NULL);
         if (!hand) {
             fprintf(stderr, "unable to allocate JSON generator\n");
@@ -580,7 +584,7 @@ static void list_domains_details(const libxl_dominfo *info, 
int nb_domain)
                                                  &d_config, NULL);
         if (rc)
             continue;
-        if (default_output_format == OUTPUT_FORMAT_JSON) {
+        if (output_format == OUTPUT_FORMAT_JSON) {
 #ifdef HAVE_LIBJSONC
             json_object *jso_value;
             rc = printf_info_one_json(&jso_value, info[i].domid, &d_config);
@@ -590,7 +594,7 @@ static void list_domains_details(const libxl_dominfo *info, 
int nb_domain)
             s = printf_info_one_json(hand, info[i].domid, &d_config);
 #endif
         } else
-            printf_info_sexp(info[i].domid, &d_config, stdout);
+            printf_info_sexp(info[i].domid, &d_config, fh);
         libxl_domain_config_dispose(&d_config);
 #ifdef HAVE_LIBJSONC
         if (rc)
@@ -601,7 +605,7 @@ static void list_domains_details(const libxl_dominfo *info, 
int nb_domain)
 #endif
     }
 
-    if (default_output_format == OUTPUT_FORMAT_JSON) {
+    if (output_format == OUTPUT_FORMAT_JSON) {
 #ifdef HAVE_LIBJSONC
         buf = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PRETTY);
         if (!buf)
@@ -616,11 +620,12 @@ static void list_domains_details(const libxl_dominfo 
*info, int nb_domain)
             goto out;
 #endif
 
-        puts(buf);
+        fputs(buf, fh);
+        fputc('\n', fh);
     }
 
 out:
-    if (default_output_format == OUTPUT_FORMAT_JSON) {
+    if (output_format == OUTPUT_FORMAT_JSON) {
 #ifdef HAVE_LIBJSONC
         json_object_put(jso);
 #elif defined(HAVE_LIBYAJL)
@@ -701,7 +706,7 @@ int main_list(int argc, char **argv)
     }
 
     if (details)
-        list_domains_details(info, nb_domain);
+        dump_by_dominfo_list(default_output_format, stdout, info, nb_domain);
     else
         list_domains(verbose, context, false /* claim */, numa, cpupool,
                      info, nb_domain);
diff --git a/tools/xl/xl_misc.c b/tools/xl/xl_misc.c
index f0167e1603..bcf178762b 100644
--- a/tools/xl/xl_misc.c
+++ b/tools/xl/xl_misc.c
@@ -341,7 +341,7 @@ int main_config_update(int argc, char **argv)
     parse_config_data(filename, config_data, config_len, &d_config);
 
     if (debug || dryrun_only)
-        printf_info(default_output_format, -1, &d_config, stdout);
+        dump_by_config(default_output_format, stdout, &d_config, -1);
 
     if (!dryrun_only) {
         fprintf(stderr, "setting dom%u configuration\n", domid);
-- 
2.47.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.