Skip to contentSkip to conversation

tools/xl: Call init function for libxl defined datatypes

PATCH Superseded Uma Sharma 2 participants 2 messages Oct 17, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Uma Sharma

author
#0 lore raw

PATCH v2 1/1 tools/xl: Call init function for libxl defined datatypes

This patch calls init function for libxl_domain_sched_params before passing it as reference to sched_domain_get() function in tools/libxl/xl_cmdimpl.c
IDL generated libxl types should be used only after calling the init function even if the variable is simply being passed by reference as an output parameter to a libxl function

--
Changed since v1:
-Calling _init before using libxl_dominfo type and _dispose after using in function main_list

tools/libxl/xl_cmdimpl.c +8 -0
index c734f79..c16083b 100644
@@ -4354,6 +4354,7 @@ int main_list(int argc, char **argv)
         info_free = info;
     } else if (optind == argc-1) {
         uint32_t domid = find_domain(argv[optind]);
+	libxl_dominfo_init(&info_buf);
         rc = libxl_domain_info(ctx, &info_buf, domid);
         if (rc == ERROR_INVAL) {
             fprintf(stderr, "Error: Domain \'%s\' does not exist.\n",
@@ -4366,6 +4367,7 @@ int main_list(int argc, char **argv)
         }
         info = &info_buf;
         nb_domain = 1;
+	libxl_dominfo_dispose(&info_buf);
     } else {
         help("list");
         return 2;
@@ -5215,6 +5217,8 @@ static int sched_credit_domain_output(int domid)
         printf("%-33s %4s %6s %4s\n", "Name", "ID", "Weight", "Cap");
         return 0;
     }
+    
+    libxl_domain_sched_params_init(&scinfo);
     rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT, domid, &scinfo);
     if (rc)
         return rc;
@@ -5261,6 +5265,8 @@ static int sched_credit2_domain_output(
         printf("%-33s %4s %6s\n", "Name", "ID", "Weight");
         return 0;
     }
+    
+    libxl_domain_sched_params_init(&scinfo);
     rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT2, domid, &scinfo);
     if (rc)
         return rc;
@@ -5286,6 +5292,8 @@ static int sched_sedf_domain_output(
                "Slice", "Latency", "Extra", "Weight");
         return 0;
     }
+    
+    libxl_domain_sched_params_init(&scinfo);
     rc = sched_domain_get(LIBXL_SCHEDULER_SEDF, domid, &scinfo);
     if (rc)
         return rc;
#1 lore raw

Uma Sharma writes ("[OPW PATCH V2] tools/xl: Call init function for libxl defined datatypes"):

Quoted 6 lines

This patch calls init function for libxl_domain_sched_params before passing it as reference to sched_domain_get() function in tools/libxl/xl_cmdimpl.c
IDL generated libxl types should be used only after calling the init function even if the variable is simply being passed by reference as an output parameter to a libxl function

...

tools/libxl/xl_cmdimpl.c int main_list(int argc, char **argv) · line 4371

Quoted 12 lines
     } else if (optind == argc-1) {
         uint32_t domid = find_domain(argv[optind]);
tools/libxl/xl_cmdimpl.c +2 -0
+	libxl_dominfo_init(&info_buf);
         rc = libxl_domain_info(ctx, &info_buf, domid);
         if (rc == ERROR_INVAL) {
             fprintf(stderr, "Error: Domain \'%s\' does not exist.\n",
@@ -4366,6 +4367,7 @@ int main_list(int argc, char **argv)
         }
         info = &info_buf;
         nb_domain = 1;
+	libxl_dominfo_dispose(&info_buf);
     } else {

I'm not a huge fan of this ad-hoc at-the-call-site memory management. In libxl we generally try to initialise things where they are declared, and free them on all exit paths from the function.

So while this patch is OK, and I'm not nacking it, I'd like to suggest that future patches ought to use the other allocation-handling style.

For an example, see (for example) the handling of `tinfo' in libxl_nodemap_to_cpumap in libxl_utils.c.

Ian.