Skip to contentSkip to conversation

: Introduce libxl_domain_create()

RFC PATCH In review Gianni Tedesco 2 participants 3 messages Dec 21, 2010

lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 : Introduce libxl_domain_create()

This patch incorporates previous suggestions:
- use LIBXL namespace for ACTION_* enum
- use callbacks for console attach
- split to two functions / remove 'flags' parameter
- don't call exit() from libxl
- catch strdup() error in console struct init
- put dm_info inside domain_info struct

Not done:
- internalise old domain create functions
- idl bindings

So not sure where to take this from here, could do a series with:
1. IDL changes
2. updated version of this patch
3. re-base of my python patch-queue

More comments?

tools/libxl/Makefile +2 -2
diff -r 1f0f3b6d6ced tools/libxl/Makefile
@@ -20,7 +20,7 @@ ifeq ($(CONFIG_Linux),y)
 LIBS += -luuid
 endif
 
-LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o
+LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o flexarray.o
 ifeq ($(LIBXL_BLKTAP),y)
 LIBXL_OBJS-y += libxl_blktap2.o
 else
@@ -29,7 +29,7 @@ endif
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o
 LIBXL_OBJS-$(CONFIG_IA64) += libxl_nocpuid.o
 
-LIBXL_OBJS = flexarray.o libxl.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y)
+LIBXL_OBJS = libxl.o libxl_create.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o libxl_utils.o $(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o
 
 AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
tools/libxl/libxl.h +36 -0
diff -r 1f0f3b6d6ced tools/libxl/libxl.h
@@ -246,6 +246,38 @@ enum {
 
 #define LIBXL_VERSION 0
 
+enum action_on_shutdown {
+    LIBXL_ACTION_DESTROY,
+
+    LIBXL_ACTION_RESTART,
+    LIBXL_ACTION_RESTART_RENAME,
+
+    LIBXL_ACTION_PRESERVE,
+
+    LIBXL_ACTION_COREDUMP_DESTROY,
+    LIBXL_ACTION_COREDUMP_RESTART,
+};
+
+typedef struct {
+    libxl_domain_create_info c_info;
+    libxl_domain_build_info b_info;
+    libxl_device_model_info dm_info;
+
+    int num_disks, num_vifs, num_vif2s, num_pcidevs, num_vfbs, num_vkbs;
+
+    libxl_device_disk *disks;
+    libxl_device_nic *vifs;
+    libxl_device_net2 *vif2s;
+    libxl_device_pci *pcidevs;
+    libxl_device_vfb *vfbs;
+    libxl_device_vkb *vkbs;
+
+    enum action_on_shutdown on_poweroff;
+    enum action_on_shutdown on_reboot;
+    enum action_on_shutdown on_watchdog;
+    enum action_on_shutdown on_crash;
+} libxl_domain_config;
+
 /* context functions */
 int libxl_ctx_init(libxl_ctx *ctx, int version, xentoollog_logger*);
 int libxl_ctx_free(libxl_ctx *ctx);
@@ -253,6 +285,10 @@ int libxl_ctx_set_log(libxl_ctx *ctx, xe
 int libxl_ctx_postfork(libxl_ctx *ctx);
 
 /* domain related functions */
+typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv);
+int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid);
+int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd);
+void libxl_domain_config_destroy(libxl_domain_config *d_config);
 int libxl_domain_make(libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
 int libxl_domain_build(libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
 int libxl_domain_restore(libxl_ctx *ctx, libxl_domain_build_info *info,
tools/libxl/libxl_create.c new file +229 -0

229 lines not on this page · raw message

tools/libxl/xl_cmdimpl.c +73 -251

468 lines not on this page · raw message

#1 lore raw

Only minor comments.

tools/libxl/libxl.h enum { · line 249

Quoted 5 lines · Gianni Tedesco
tools/libxl/libxl.h +1 -0
@@ -246,6 +246,38 @@ enum {
 
 #define LIBXL_VERSION 0
 
+enum action_on_shutdown {

Namespace.

Quoted 10 lines
tools/libxl/libxl.h +10 -0
+    LIBXL_ACTION_DESTROY,
+
+    LIBXL_ACTION_RESTART,
+    LIBXL_ACTION_RESTART_RENAME,
+
+    LIBXL_ACTION_PRESERVE,
+
+    LIBXL_ACTION_COREDUMP_DESTROY,
+    LIBXL_ACTION_COREDUMP_RESTART,
+};

[...]

tools/libxl/libxl_create.c line 36

Quoted 8 lines
tools/libxl/libxl_create.c new file +8 -0
+#define MUST( call ) ({                                                 \
+        int must_rc = (call);                                           \
+        if (must_rc < 0) {                                              \
+            fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n",       \
+                    __FILE__,__LINE__, must_rc, #call);                 \
+            goto error_out;                                             \
+        }                                                               \
+    })

I don't think the two callsites of this macro justify the obfuscation of having a goto in a macro, just open code it.

tools/libxl/xl_cmdimpl.c start: · line 1523

Quoted 4 lines
tools/libxl/xl_cmdimpl.c +4 -0
+
+    if ( dom_info->console_autoconnect ) {
+        cb = autoconnect_console;
+    }else{
       } else {
Quoted 1 line

+ }else{

Some of the indentation looks weird. Could be my mail client or perhaps you are mixing spaces and tabs or something?

Ian.

#2 lore raw
Quoted 10 lines · Ian Campbell

Only minor comments.

tools/libxl/libxl.h enum { · line 249

Quoted 5 lines · Gianni Tedesco
tools/libxl/libxl.h +1 -0
@@ -246,6 +246,38 @@ enum {
 
 #define LIBXL_VERSION 0
 
+enum action_on_shutdown {

Namespace.

Ah, thanks, missed that.

Quoted 20 lines
Quoted 10 lines
tools/libxl/libxl.h +10 -0
+    LIBXL_ACTION_DESTROY,
+
+    LIBXL_ACTION_RESTART,
+    LIBXL_ACTION_RESTART_RENAME,
+
+    LIBXL_ACTION_PRESERVE,
+
+    LIBXL_ACTION_COREDUMP_DESTROY,
+    LIBXL_ACTION_COREDUMP_RESTART,
+};

[...]

tools/libxl/libxl_create.c line 36

Quoted 8 lines
tools/libxl/libxl_create.c new file +8 -0
+#define MUST( call ) ({                                                 \
+        int must_rc = (call);                                           \
+        if (must_rc < 0) {                                              \
+            fprintf(stderr,"xl: fatal error: %s:%d, rc=%d: %s\n",       \
+                    __FILE__,__LINE__, must_rc, #call);                 \
+            goto error_out;                                             \
+        }                                                               \
+    })
Quoted 2 lines

I don't think the two callsites of this macro justify the obfuscation of having a goto in a macro, just open code it.

Yes, you're right.

Quoted 11 lines

tools/libxl/xl_cmdimpl.c start: · line 1523

Quoted 4 lines
tools/libxl/xl_cmdimpl.c +4 -0
+
+    if ( dom_info->console_autoconnect ) {
+        cb = autoconnect_console;
+    }else{
       } else {
Quoted 1 line

+ }else{

Some of the indentation looks weird. Could be my mail client or perhaps you are mixing spaces and tabs or something?

Don't think so, seems fine to me. There was something else I was working on that was all already tabs but I don't think it's anything I touched here.

Quoted 1 line

Ian.

Thanks

Gianni