debuggers.hg

changeset 22044:2f1f35359317

Make blktap support optional.
Enable it by default on Linux, disable it on non-Linux.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Christoph Egger <Christoph.Egger@amd.com>
date Mon Aug 16 17:04:31 2010 +0100 (2010-08-16)
parents def814437d42
children cd5b4135fe03
files tools/Rules.mk tools/libxl/Makefile tools/libxl/libxl.c tools/libxl/libxl_blktap2.c tools/libxl/libxl_internal.h tools/libxl/libxl_noblktap2.c
line diff
     1.1 --- a/tools/Rules.mk	Mon Aug 16 13:39:19 2010 +0100
     1.2 +++ b/tools/Rules.mk	Mon Aug 16 17:04:31 2010 +0100
     1.3 @@ -26,8 +26,19 @@ LDLIBS_libxenguest = -L$(XEN_LIBXC) -lxe
     1.4  CFLAGS_libxenstore = -I$(XEN_XENSTORE) $(CFLAGS_include)
     1.5  LDLIBS_libxenstore = -L$(XEN_XENSTORE) -lxenstore
     1.6  
     1.7 +ifeq ($(CONFIG_Linux),y)
     1.8 +LIBXL_BLKTAP = y
     1.9 +else
    1.10 +LIBXL_BLKTAP = n
    1.11 +endif
    1.12 +
    1.13 +ifeq ($(LIBXL_BLKTAP),y)
    1.14  CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_include)
    1.15  LDLIBS_libblktapctl = -L$(XEN_BLKTAP2)/control -lblktapctl
    1.16 +else
    1.17 +CFLAGS_libblktapctl =
    1.18 +LDLIBS_libblktapctl =
    1.19 +endif
    1.20  
    1.21  X11_LDPATH = -L/usr/X11R6/$(LIBLEAFDIR)
    1.22  
     2.1 --- a/tools/libxl/Makefile	Mon Aug 16 13:39:19 2010 +0100
     2.2 +++ b/tools/libxl/Makefile	Mon Aug 16 17:04:31 2010 +0100
     2.3 @@ -18,6 +18,12 @@ CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_
     2.4  LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(UTIL_LIBS)
     2.5  
     2.6  LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o
     2.7 +ifeq ($(LIBXL_BLKTAP),y)
     2.8 +LIBXL_OBJS-y += libxl_blktap2.o
     2.9 +else
    2.10 +LIBXL_OBJS-y += libxl_noblktap2.o
    2.11 +endif
    2.12 +
    2.13  LIBXL_OBJS = flexarray.o libxl.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
    2.14  
    2.15  AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
     3.1 --- a/tools/libxl/libxl.c	Mon Aug 16 13:39:19 2010 +0100
     3.2 +++ b/tools/libxl/libxl.c	Mon Aug 16 17:04:31 2010 +0100
     3.3 @@ -36,7 +36,6 @@
     3.4  #include "libxl_utils.h"
     3.5  #include "libxl_internal.h"
     3.6  #include "flexarray.h"
     3.7 -#include "tap-ctl.h"
     3.8  
     3.9  #define PAGE_TO_MEMKB(pages) ((pages) * 4)
    3.10  
    3.11 @@ -1715,27 +1714,6 @@ int libxl_confirm_device_model_startup(l
    3.12  
    3.13  /******************************************************************************/
    3.14  
    3.15 -static char *get_blktap2_device(libxl_gc *gc,
    3.16 -				const char *name, const char *type)
    3.17 -{
    3.18 -    int minor = tap_ctl_find_minor(type, name);
    3.19 -    if (minor < 0)
    3.20 -        return NULL;
    3.21 -    return libxl_sprintf(gc, "/dev/xen/blktap-2/tapdev%d", minor);
    3.22 -}
    3.23 -
    3.24 -static char *make_blktap2_device(libxl_gc *gc,
    3.25 -				 const char *name, const char *type)
    3.26 -{
    3.27 -    char *params, *devname = NULL;
    3.28 -    int err;
    3.29 -    params = libxl_sprintf(gc, "%s:%s", type, name);
    3.30 -    err = tap_ctl_create(params, &devname);
    3.31 -    if (!err)
    3.32 -        libxl_ptr_add(gc, devname);
    3.33 -    return err ? NULL : devname;
    3.34 -}
    3.35 -
    3.36  int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
    3.37  {
    3.38      libxl_gc gc = LIBXL_INIT_GC(ctx);
    3.39 @@ -1790,14 +1768,13 @@ int libxl_device_disk_add(libxl_ctx *ctx
    3.40          case PHYSTYPE_FILE:
    3.41              /* let's pretend is tap:aio for the moment */
    3.42              disk->phystype = PHYSTYPE_AIO;
    3.43 -        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: {
    3.44 -            const char *msg;
    3.45 -            if (!tap_ctl_check(&msg)) {
    3.46 -                const char *type = device_disk_string_of_phystype(disk->phystype);
    3.47 -                char *dev;
    3.48 -                dev = get_blktap2_device(&gc, disk->physpath, type);
    3.49 -                if (!dev)
    3.50 -                    dev = make_blktap2_device(&gc, disk->physpath, type);
    3.51 +        case PHYSTYPE_AIO:
    3.52 +        case PHYSTYPE_QCOW:
    3.53 +        case PHYSTYPE_QCOW2:
    3.54 +        case PHYSTYPE_VHD:
    3.55 +            if (libxl_blktap_enabled(&gc)) {
    3.56 +                const char *dev = libxl_blktap_devpath(&gc,
    3.57 +                                               disk->physpath, disk->phystype);
    3.58                  if (!dev) {
    3.59                      rc = ERROR_FAIL;
    3.60                      goto out_free;
    3.61 @@ -1820,7 +1797,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
    3.62  
    3.63              device.backend_kind = DEVICE_TAP;
    3.64              break;
    3.65 -        }
    3.66 +
    3.67          default:
    3.68              XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", disk->phystype);
    3.69              rc = ERROR_INVAL;
    3.70 @@ -1892,7 +1869,8 @@ int libxl_device_disk_del(libxl_ctx *ctx
    3.71  char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk)
    3.72  {
    3.73      libxl_gc gc = LIBXL_INIT_GC(ctx);
    3.74 -    char *dev = NULL, *ret;
    3.75 +    const char *dev = NULL;
    3.76 +    char *ret;
    3.77      int phystype = disk->phystype;
    3.78      switch (phystype) {
    3.79          case PHYSTYPE_PHY: {
    3.80 @@ -1903,16 +1881,14 @@ char * libxl_device_disk_local_attach(li
    3.81          case PHYSTYPE_FILE:
    3.82              /* let's pretend is tap:aio for the moment */
    3.83              phystype = PHYSTYPE_AIO;
    3.84 -        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: {
    3.85 -            const char *msg;
    3.86 -            if (!tap_ctl_check(&msg)) {
    3.87 -                const char *type = device_disk_string_of_phystype(phystype);
    3.88 -                dev = get_blktap2_device(&gc, disk->physpath, type);
    3.89 -                if (!dev)
    3.90 -                    dev = make_blktap2_device(&gc, disk->physpath, type);
    3.91 -            }
    3.92 +        case PHYSTYPE_AIO:
    3.93 +        case PHYSTYPE_QCOW:
    3.94 +        case PHYSTYPE_QCOW2:
    3.95 +        case PHYSTYPE_VHD:
    3.96 +            if (libxl_blktap_enabled(&gc))
    3.97 +                dev = libxl_blktap_devpath(&gc, disk->physpath, phystype);
    3.98              break;
    3.99 -        }
   3.100 +
   3.101          default:
   3.102              XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", phystype);
   3.103              break;
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/libxl/libxl_blktap2.c	Mon Aug 16 17:04:31 2010 +0100
     4.3 @@ -0,0 +1,51 @@
     4.4 +/*
     4.5 + * Copyright (C) 2010      Advanced Micro Devices
     4.6 + * Author Christoph Egger <Christoph.Egger@amd.com>
     4.7 + *
     4.8 + * This program is free software; you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU Lesser General Public License as published
    4.10 + * by the Free Software Foundation; version 2.1 only.
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU Lesser General Public License for more details.
    4.16 + */
    4.17 +
    4.18 +#include "libxl.h"
    4.19 +#include "libxl_osdeps.h"
    4.20 +#include "libxl_internal.h"
    4.21 +
    4.22 +#include "tap-ctl.h"
    4.23 +
    4.24 +int libxl_blktap_enabled(libxl_gc *gc)
    4.25 +{
    4.26 +    const char *msg;
    4.27 +    return !tap_ctl_check(&msg);
    4.28 +}
    4.29 +
    4.30 +const char *libxl_blktap_devpath(libxl_gc *gc,
    4.31 +                                 const char *disk,
    4.32 +                                 libxl_disk_phystype phystype)
    4.33 +{
    4.34 +    const char *type;
    4.35 +    char *params, *devname;
    4.36 +    int minor, err;
    4.37 +
    4.38 +    type = device_disk_string_of_phystype(phystype);
    4.39 +    minor = tap_ctl_find_minor(type, disk);
    4.40 +    if (minor >= 0) {
    4.41 +        devname = libxl_sprintf(gc, "/dev/xen/blktap-2/tapdev%d", minor);
    4.42 +        if (devname)
    4.43 +            return devname;
    4.44 +    }
    4.45 +
    4.46 +    params = libxl_sprintf(gc, "%s:%s", type, disk);
    4.47 +    err = tap_ctl_create(params, &devname);
    4.48 +    if (!err) {
    4.49 +        libxl_ptr_add(gc, devname);
    4.50 +        return devname;
    4.51 +    }
    4.52 +
    4.53 +    return NULL;
    4.54 +}
     5.1 --- a/tools/libxl/libxl_internal.h	Mon Aug 16 13:39:19 2010 +0100
     5.2 +++ b/tools/libxl/libxl_internal.h	Mon Aug 16 17:04:31 2010 +0100
     5.3 @@ -248,4 +248,23 @@ struct libxl_device_model_starting {
     5.4  _hidden char *_libxl_domid_to_name(libxl_gc *gc, uint32_t domid);
     5.5  _hidden char *_libxl_poolid_to_name(libxl_gc *gc, uint32_t poolid);
     5.6  
     5.7 +/*
     5.8 + * blktap2 support
     5.9 + */
    5.10 +
    5.11 +/* libxl_blktap_enabled:
    5.12 + *    return true if blktap/blktap2 support is available.
    5.13 + */
    5.14 +int libxl_blktap_enabled(libxl_gc *gc);
    5.15 +
    5.16 +/* libxl_blktap_devpath:
    5.17 + *    Argument: path and disk image as specified in config file.
    5.18 + *      The type specifies whether this is aio, qcow, qcow2, etc.
    5.19 + *    returns device path xenstore wants to have. returns NULL
    5.20 + *      if no device corresponds to the disk.
    5.21 + */
    5.22 +const char *libxl_blktap_devpath(libxl_gc *gc,
    5.23 +                                 const char *disk,
    5.24 +                                 libxl_disk_phystype phystype);
    5.25 +
    5.26  #endif
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxl/libxl_noblktap2.c	Mon Aug 16 17:04:31 2010 +0100
     6.3 @@ -0,0 +1,29 @@
     6.4 +/*
     6.5 + * Copyright (C) 2010      Advanced Micro Devices
     6.6 + * Author Christoph Egger <Christoph.Egger@amd.com>
     6.7 + *
     6.8 + * This program is free software; you can redistribute it and/or modify
     6.9 + * it under the terms of the GNU Lesser General Public License as published
    6.10 + * by the Free Software Foundation; version 2.1 only.
    6.11 + *
    6.12 + * This program is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU Lesser General Public License for more details.
    6.16 + */
    6.17 +
    6.18 +#include "libxl.h"
    6.19 +#include "libxl_osdeps.h"
    6.20 +#include "libxl_internal.h"
    6.21 +
    6.22 +int libxl_blktap_enabled(libxl_gc *gc)
    6.23 +{
    6.24 +    return 0;
    6.25 +}
    6.26 +
    6.27 +const char *libxl_blktap_devpath(libxl_gc *gc,
    6.28 +                                 const char *disk,
    6.29 +                                 libxl_disk_phystype phystype)
    6.30 +{
    6.31 +    return NULL;
    6.32 +}