tools/libxl: Fix blktap2 NetBSD build and also revert broken change
authorChristoph Egger <Christoph.Egger@amd.com>
Fri, 23 Jul 2010 15:46:59 +0000 (16:46 +0100)
committerChristoph Egger <Christoph.Egger@amd.com>
Fri, 23 Jul 2010 15:46:59 +0000 (16:46 +0100)
Fix e76befc7fe2d which broke the build.
Also revert 24277e3237ca which was broken.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/Makefile
tools/libxl/libxl.c
tools/libxl/libxl_device.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_linux.c [new file with mode: 0644]
tools/libxl/libxl_netbsd.c [new file with mode: 0644]
tools/libxl/libxl_osdeps.h

index 68b4fc9167d5b7ab600e1d60d5c03f5df6d8435f..4d57764223ca67a068111161ff74d0140dbc43d3 100644 (file)
@@ -18,6 +18,8 @@ CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFL
 LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) $(LDFLAGS_libblktapctl) $(UTIL_LIBS)
 
 LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o
+LIBXL_OBJS-$(CONFIG_Linux) += libxl_linux.o
+LIBXL_OBJS-$(CONFIG_NetBSD) += libxl_netbsd.o
 LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
 
 AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
@@ -85,7 +87,7 @@ xl_cmdimpl.o: xl_cmdimpl.c
 xl_cmdtable.o: xl_cmdtable.c
        $(CC) $(CFLAGS) -c xl_cmdtable.c
 
-$(CLIENTS): xl.o xl_cmdimpl.o xl_cmdtable.o libxl_paths.o libxl_bootloader.o libxlutil.so libxenlight.so
+$(CLIENTS): xl.o xl_cmdimpl.o xl_cmdtable.o libxlutil.so libxenlight.so
        $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 .PHONY: install
index 05a140b94a212a9c1d6355977026a38c39c49fb8..192a02bf8a97db333dc5818325f5432dd7e4af3c 100644 (file)
@@ -34,7 +34,6 @@
 #include "libxl_utils.h"
 #include "libxl_internal.h"
 #include "flexarray.h"
-#include "tap-ctl.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 
@@ -1345,27 +1344,6 @@ int libxl_confirm_device_model_startup(struct libxl_ctx *ctx,
 
 /******************************************************************************/
 
-static char *get_blktap2_device(struct libxl_ctx *ctx,
-                               const char *name, const char *type)
-{
-    int minor = tap_ctl_find_minor(type, name);
-    if (minor < 0)
-        return NULL;
-    return libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", minor);
-}
-
-static char *make_blktap2_device(struct libxl_ctx *ctx,
-                                const char *name, const char *type)
-{
-    char *params, *devname = NULL;
-    int err;
-    params = libxl_sprintf(ctx, "%s:%s", type, name);
-    err = tap_ctl_create(params, &devname);
-    if (!err)
-        libxl_ptr_add(ctx, devname);
-    return err ? NULL : devname;
-}
-
 int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
 {
     flexarray_t *front;
@@ -1414,14 +1392,13 @@ int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_di
         case PHYSTYPE_FILE:
             /* let's pretend is tap:aio for the moment */
             disk->phystype = PHYSTYPE_AIO;
-        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: {
-            const char *msg;
-            if (!tap_ctl_check(&msg)) {
-                const char *type = device_disk_string_of_phystype(disk->phystype);
-                char *dev;
-                dev = get_blktap2_device(ctx, disk->physpath, type);
-                if (!dev)
-                    dev = make_blktap2_device(ctx, disk->physpath, type);
+        case PHYSTYPE_AIO:
+        case PHYSTYPE_QCOW:
+        case PHYSTYPE_QCOW2:
+        case PHYSTYPE_VHD:
+            if (libxl_blktap_enabled(ctx)) {
+                const char *dev = libxl_blktap_devpath(ctx,
+                                               disk->physpath, disk->phystype);
                 if (!dev)
                     return -1;
                 flexarray_set(back, boffset++, "tapdisk-params");
@@ -1442,7 +1419,7 @@ int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_di
 
             device.backend_kind = DEVICE_TAP;
             break;
-        }
+
         default:
             XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", disk->phystype);
             return ERROR_INVAL;
@@ -1506,7 +1483,7 @@ int libxl_device_disk_del(struct libxl_ctx *ctx,
 
 const char * libxl_device_disk_local_attach(struct libxl_ctx *ctx, libxl_device_disk *disk)
 {
-    char *dev = NULL;
+    const char *dev = NULL;
     int phystype = disk->phystype;
     switch (phystype) {
         case PHYSTYPE_PHY: {
@@ -1517,16 +1494,14 @@ const char * libxl_device_disk_local_attach(struct libxl_ctx *ctx, libxl_device_
         case PHYSTYPE_FILE:
             /* let's pretend is tap:aio for the moment */
             phystype = PHYSTYPE_AIO;
-        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: {
-            const char *msg;
-            if (!tap_ctl_check(&msg)) {
-                const char *type = device_disk_string_of_phystype(phystype);
-                dev = get_blktap2_device(ctx, disk->physpath, type);
-                if (!dev)
-                    dev = make_blktap2_device(ctx, disk->physpath, type);
-            }
+        case PHYSTYPE_AIO:
+        case PHYSTYPE_QCOW:
+        case PHYSTYPE_QCOW2:
+        case PHYSTYPE_VHD:
+            if (libxl_blktap_enabled(ctx))
+                dev = libxl_blktap_devpath(ctx, disk->physpath, phystype);
             break;
-        }
+
         default:
             XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", phystype);
             break;
index 89c92db592d3cd14002009965eec6a32220e5b79..677b4c80583142c91201fb395b599bc63dbfd9be 100644 (file)
@@ -132,7 +132,7 @@ char *device_disk_backend_type_of_phystype(libxl_disk_phystype phystype)
     }
 }
 
-int device_physdisk_major_minor(char *physpath, int *major, int *minor)
+int device_physdisk_major_minor(const char *physpath, int *major, int *minor)
 {
     struct stat buf;
     if (stat(physpath, &buf) < 0)
index 10d45c70e6df69916506755122364b2de6850d4a..05b637b0d69c8f6fd83216898440925f6c3e800d 100644 (file)
@@ -149,7 +149,7 @@ void libxl__userdata_destroyall(struct libxl_ctx *ctx, uint32_t domid);
 char *device_disk_backend_type_of_phystype(libxl_disk_phystype phystype);
 char *device_disk_string_of_phystype(libxl_disk_phystype phystype);
 
-int device_physdisk_major_minor(char *physpath, int *major, int *minor);
+int device_physdisk_major_minor(const char *physpath, int *major, int *minor);
 int device_disk_dev_number(char *virtpath);
 
 int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device,
diff --git a/tools/libxl/libxl_linux.c b/tools/libxl/libxl_linux.c
new file mode 100644 (file)
index 0000000..369cabd
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010      Advanced Micro Devices
+ * Author Christoph Egger <Christoph.Egger@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl.h"
+#include "libxl_osdeps.h"
+
+#include "tap-ctl.h"
+
+int libxl_blktap_enabled(struct libxl_ctx *ctx)
+{
+    const char *msg;
+    return !tap_ctl_check(&msg);
+}
+
+const char *libxl_blktap_devpath(struct libxl_ctx *ctx,
+                                 const char *disk,
+                                 libxl_disk_phystype phystype)
+{
+    const char *type, *devname;
+    char *params;
+    int minor, err;
+
+    type = device_disk_string_of_type(phystype);
+    minor = tap_ctl_find_minor(type, disk);
+    if (minor >= 0) {
+        devname = libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", minor);
+        if (devname)
+            return devname;
+    }
+
+    params = libxl_sprintf(ctx, "%s:%s", type, disk);
+    err = tap_ctl_create(params, &devname);
+    if (!err) {
+        libxl_ptr_add(ctx, devname);
+        return devname;
+    }
+
+    return NULL;
+}
diff --git a/tools/libxl/libxl_netbsd.c b/tools/libxl/libxl_netbsd.c
new file mode 100644 (file)
index 0000000..6cbfd40
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2010      Advanced Micro Devices
+ * Author Christoph Egger <Christoph.Egger@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl.h"
+#include "libxl_osdeps.h"
+
+int libxl_blktap_enabled(struct libxl_ctx *ctx)
+{
+    return 0;
+}
+
+const char *libxl_blktap_devpath(struct libxl_ctx *ctx,
+                                 const char *disk,
+                                 libxl_disk_phystype phystype)
+{
+    return NULL;
+}
index fc453c3553c4f81a09ea6e018fc639f5fe5d7352..0dd22d89d47bd424cb8bc6d89e1c9499c840f4ed 100644 (file)
@@ -23,6 +23,8 @@
 
 #define _GNU_SOURCE
 
+#include <libxl_internal.h>
+
 #ifdef NEED_OWN_ASPRINTF
 #include <stdarg.h>
 
@@ -30,4 +32,23 @@ int asprintf(char **buffer, char *fmt, ...);
 int vasprintf(char **buffer, const char *fmt, va_list ap);
 #endif /*NEED_OWN_ASPRINTF*/
 
+/*
+ * blktap2 support
+ */
+
+/* libxl_blktap_enabled:
+ *    return true if blktap/blktap2 support is available.
+ */
+int libxl_blktap_enabled(struct libxl_ctx *ctx);
+
+/* libxl_blktap_devpath:
+ *    Argument: path and disk image as specified in config file.
+ *      The type specifies whether this is aio, qcow, qcow2, etc.
+ *    returns device path xenstore wants to have. returns NULL
+ *      if no device corresponds to the disk.
+ */
+const char *libxl_blktap_devpath(struct libxl_ctx *ctx,
+                                 const char *disk,
+                                 libxl_disk_phystype phystype);
+
 #endif