+Thu Oct 16 17:02:00 CEST 2008 Chris Lalancette <clalance@redhat.com>
+ * Add support for detecting the partition table type when scanning
+ iSCSI volumes. This is implemented in the
+ virStorageBackendUpdateVolInfoFD function, so all future callers will
+ automatically benefit. This is a somewhat large patch because the
+ conversion of the virStorageBackendPartTableTypeToString necessitated
+ a change to the formatToString and formatFromString function pointers,
+ which caused fallout in other places in the storage stuff. The good
+ news is that most of these callers are now converted over to the
+ VIR_ENUM_IMPL, which means a lot of redundant code is now gone.
+
Thu Oct 16 15:41:00 CEST 2008 Chris Lalancette <clalance@redhat.com>
* Compiling with -Werror showed a possible use before initialization
in src/qemu_driver.c. Make sure to initialize the origdisk ptr to
#include "storage_backend_fs.h"
#endif
+VIR_ENUM_IMPL(virStorageBackendPartTable,
+ VIR_STORAGE_POOL_DISK_LAST,
+ "unknown", "dos", "dvh", "gpt",
+ "mac", "bsd", "pc98", "sun", "lvm2");
+
static virStorageBackendPtr backends[] = {
#if WITH_STORAGE_DIR
&virStorageBackendDirectory,
return ret;
}
+static struct diskType const disk_types[] = {
+ { VIR_STORAGE_POOL_DISK_LVM2, 0x218, 8, 0x31303020324D564CULL },
+ { VIR_STORAGE_POOL_DISK_GPT, 0x200, 8, 0x5452415020494645ULL },
+ { VIR_STORAGE_POOL_DISK_DVH, 0x0, 4, 0x41A9E50BULL },
+ { VIR_STORAGE_POOL_DISK_MAC, 0x0, 2, 0x5245ULL },
+ { VIR_STORAGE_POOL_DISK_BSD, 0x40, 4, 0x82564557ULL },
+ { VIR_STORAGE_POOL_DISK_SUN, 0x1fc, 2, 0xBEDAULL },
+ /*
+ * NOTE: pc98 is funky; the actual signature is 0x55AA (just like dos), so
+ * we can't use that. At the moment I'm relying on the "dummy" IPL
+ * bootloader data that comes from parted. Luckily, the chances of running
+ * into a pc98 machine running libvirt are approximately nil.
+ */
+ /*{ 0x1fe, 2, 0xAA55UL },*/
+ { VIR_STORAGE_POOL_DISK_PC98, 0x0, 8, 0x314C5049000000CBULL },
+ /*
+ * NOTE: the order is important here; some other disk types (like GPT and
+ * and PC98) also have 0x55AA at this offset. For that reason, the DOS
+ * one must be the last one.
+ */
+ { VIR_STORAGE_POOL_DISK_DOS, 0x1fe, 2, 0xAA55ULL },
+ { -1, 0x0, 0, 0x0ULL },
+};
+
int
virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
virStorageVolDefPtr vol,
if (withCapacity) vol->capacity = end;
}
+ /* make sure to set the target format "unknown" to begin with */
+ vol->target.format = VIR_STORAGE_POOL_DISK_UNKNOWN;
+
+ if (S_ISBLK(sb.st_mode)) {
+ off_t start;
+ int i;
+ unsigned char buffer[1024];
+ ssize_t bytes;
+
+ start = lseek(fd, 0, SEEK_SET);
+ if (start < 0) {
+ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("cannot seek to beginning of file '%s':%s"),
+ vol->target.path, strerror(errno));
+ return -1;
+ }
+ bytes = saferead(fd, buffer, sizeof(buffer));
+ if (bytes < 0) {
+ virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("cannot read beginning of file '%s':%s"),
+ vol->target.path, strerror(errno));
+ return -1;
+ }
+
+ for (i = 0; disk_types[i].part_table_type != -1; i++) {
+ if (disk_types[i].offset + disk_types[i].length > bytes)
+ continue;
+ if (memcmp(buffer+disk_types[i].offset, &disk_types[i].magic,
+ disk_types[i].length) == 0) {
+ vol->target.format = disk_types[i].part_table_type;
+ break;
+ }
+ }
+ }
+
vol->target.perms.mode = sb.st_mode;
vol->target.perms.uid = sb.st_uid;
vol->target.perms.gid = sb.st_gid;
#include <libvirt/libvirt.h>
#include "storage_conf.h"
+#include "util.h"
-typedef const char *(*virStorageVolFormatToString)(virConnectPtr conn,
- int format);
-typedef int (*virStorageVolFormatFromString)(virConnectPtr conn,
- const char *format);
-
-typedef const char *(*virStoragePoolFormatToString)(virConnectPtr conn,
- int format);
-typedef int (*virStoragePoolFormatFromString)(virConnectPtr conn,
- const char *format);
+typedef const char *(*virStorageVolFormatToString)(int format);
+typedef int (*virStorageVolFormatFromString)(const char *format);
+typedef const char *(*virStoragePoolFormatToString)(int format);
+typedef int (*virStoragePoolFormatFromString)(const char *format);
typedef struct _virStorageBackendVolOptions virStorageBackendVolOptions;
typedef virStorageBackendVolOptions *virStorageBackendVolOptionsPtr;
VIR_STORAGE_BACKEND_POOL_SOURCE_NAME = (1<<4),
};
+enum partTableType {
+ VIR_STORAGE_POOL_DISK_UNKNOWN = 0,
+ VIR_STORAGE_POOL_DISK_DOS = 1,
+ VIR_STORAGE_POOL_DISK_DVH,
+ VIR_STORAGE_POOL_DISK_GPT,
+ VIR_STORAGE_POOL_DISK_MAC,
+ VIR_STORAGE_POOL_DISK_BSD,
+ VIR_STORAGE_POOL_DISK_PC98,
+ VIR_STORAGE_POOL_DISK_SUN,
+ VIR_STORAGE_POOL_DISK_LVM2,
+ VIR_STORAGE_POOL_DISK_LAST,
+};
+
+struct diskType {
+ enum partTableType part_table_type;
+ unsigned short offset;
+ unsigned short length;
+ unsigned long long magic;
+};
+VIR_ENUM_DECL(virStorageBackendPartTable);
+
typedef struct _virStorageBackendPoolOptions virStorageBackendPoolOptions;
typedef virStorageBackendPoolOptions *virStorageBackendPoolOptionsPtr;
struct _virStorageBackendPoolOptions {
#include "util.h"
#include "memory.h"
-enum {
- VIR_STORAGE_POOL_DISK_DOS = 0,
- VIR_STORAGE_POOL_DISK_DVH,
- VIR_STORAGE_POOL_DISK_GPT,
- VIR_STORAGE_POOL_DISK_MAC,
- VIR_STORAGE_POOL_DISK_BSD,
- VIR_STORAGE_POOL_DISK_PC98,
- VIR_STORAGE_POOL_DISK_SUN,
-};
-
/*
* XXX these are basically partition types.
*
VIR_STORAGE_VOL_DISK_LINUX_LVM,
VIR_STORAGE_VOL_DISK_LINUX_RAID,
VIR_STORAGE_VOL_DISK_EXTENDED,
+ VIR_STORAGE_VOL_DISK_LAST,
};
+VIR_ENUM_DECL(virStorageBackendDiskVol);
+VIR_ENUM_IMPL(virStorageBackendDiskVol,
+ VIR_STORAGE_VOL_DISK_LAST,
+ "none", "linux", "fat16",
+ "fat32", "linux-swap",
+ "linux-lvm", "linux-raid",
+ "extended");
#define PARTHELPER BINDIR "/libvirt_parthelper"
-static int
-virStorageBackendDiskPoolFormatFromString(virConnectPtr conn,
- const char *format) {
- if (format == NULL)
- return VIR_STORAGE_POOL_DISK_DOS;
-
- if (STREQ(format, "dos"))
- return VIR_STORAGE_POOL_DISK_DOS;
- if (STREQ(format, "dvh"))
- return VIR_STORAGE_POOL_DISK_DVH;
- if (STREQ(format, "gpt"))
- return VIR_STORAGE_POOL_DISK_GPT;
- if (STREQ(format, "mac"))
- return VIR_STORAGE_POOL_DISK_MAC;
- if (STREQ(format, "bsd"))
- return VIR_STORAGE_POOL_DISK_BSD;
- if (STREQ(format, "pc98"))
- return VIR_STORAGE_POOL_DISK_PC98;
- if (STREQ(format, "sun"))
- return VIR_STORAGE_POOL_DISK_SUN;
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported pool format %s"), format);
- return -1;
-}
-
-static const char *
-virStorageBackendDiskPoolFormatToString(virConnectPtr conn,
- int format) {
- switch (format) {
- case VIR_STORAGE_POOL_DISK_DOS:
- return "dos";
- case VIR_STORAGE_POOL_DISK_DVH:
- return "dvh";
- case VIR_STORAGE_POOL_DISK_GPT:
- return "gpt";
- case VIR_STORAGE_POOL_DISK_MAC:
- return "mac";
- case VIR_STORAGE_POOL_DISK_BSD:
- return "bsd";
- case VIR_STORAGE_POOL_DISK_PC98:
- return "pc98";
- case VIR_STORAGE_POOL_DISK_SUN:
- return "sun";
- }
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported pool format %d"), format);
- return NULL;
-}
-
-static int
-virStorageBackendDiskVolFormatFromString(virConnectPtr conn,
- const char *format) {
- if (format == NULL)
- return VIR_STORAGE_VOL_DISK_NONE;
-
- if (STREQ(format, "none"))
- return VIR_STORAGE_VOL_DISK_NONE;
- if (STREQ(format, "linux"))
- return VIR_STORAGE_VOL_DISK_LINUX;
- if (STREQ(format, "fat16"))
- return VIR_STORAGE_VOL_DISK_FAT16;
- if (STREQ(format, "fat32"))
- return VIR_STORAGE_VOL_DISK_FAT32;
- if (STREQ(format, "linux-swap"))
- return VIR_STORAGE_VOL_DISK_LINUX_SWAP;
- if (STREQ(format, "linux-lvm"))
- return VIR_STORAGE_VOL_DISK_LINUX_LVM;
- if (STREQ(format, "linux-raid"))
- return VIR_STORAGE_VOL_DISK_LINUX_RAID;
- if (STREQ(format, "extended"))
- return VIR_STORAGE_VOL_DISK_EXTENDED;
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %s"), format);
- return -1;
-}
-
-static const char *
-virStorageBackendDiskVolFormatToString(virConnectPtr conn,
- int format) {
- switch (format) {
- case VIR_STORAGE_VOL_DISK_NONE:
- return "none";
- case VIR_STORAGE_VOL_DISK_LINUX:
- return "linux";
- case VIR_STORAGE_VOL_DISK_FAT16:
- return "fat16";
- case VIR_STORAGE_VOL_DISK_FAT32:
- return "fat32";
- case VIR_STORAGE_VOL_DISK_LINUX_SWAP:
- return "linux-swap";
- case VIR_STORAGE_VOL_DISK_LINUX_LVM:
- return "linux-lvm";
- case VIR_STORAGE_VOL_DISK_LINUX_RAID:
- return "linux-raid";
- case VIR_STORAGE_VOL_DISK_EXTENDED:
- return "extended";
- }
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %d"), format);
- return NULL;
-}
-
static int
virStorageBackendDiskMakeDataVol(virConnectPtr conn,
virStoragePoolObjPtr pool,
"mklabel",
"--script",
((pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) ? "msdos" :
- virStorageBackendDiskPoolFormatToString(conn,
- pool->def->source.format)),
+ virStorageBackendPartTableTypeToString(pool->def->source.format)),
NULL,
};
.poolOptions = {
.flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE),
- .formatFromString = virStorageBackendDiskPoolFormatFromString,
- .formatToString = virStorageBackendDiskPoolFormatToString,
+ .formatFromString = virStorageBackendPartTableTypeFromString,
+ .formatToString = virStorageBackendPartTableTypeToString,
},
.volOptions = {
- .formatFromString = virStorageBackendDiskVolFormatFromString,
- .formatToString = virStorageBackendDiskVolFormatToString,
+ .formatFromString = virStorageBackendDiskVolTypeFromString,
+ .formatToString = virStorageBackendDiskVolTypeToString,
},
.volType = VIR_STORAGE_VOL_BLOCK,
VIR_STORAGE_POOL_FS_VFAT,
VIR_STORAGE_POOL_FS_HFSPLUS,
VIR_STORAGE_POOL_FS_XFS,
+ VIR_STORAGE_POOL_FS_LAST,
};
+VIR_ENUM_DECL(virStorageBackendFileSystemPool);
+VIR_ENUM_IMPL(virStorageBackendFileSystemPool,
+ VIR_STORAGE_POOL_FS_LAST,
+ "auto", "ext2", "ext3",
+ "ext4", "ufs", "iso9660", "udf",
+ "gfs", "gfs2", "vfat", "hfs+", "xfs");
enum {
VIR_STORAGE_POOL_NETFS_AUTO = 0,
VIR_STORAGE_POOL_NETFS_NFS,
+ VIR_STORAGE_POOL_NETFS_LAST,
};
-
+VIR_ENUM_DECL(virStorageBackendFileSystemNetPool);
+VIR_ENUM_IMPL(virStorageBackendFileSystemNetPool,
+ VIR_STORAGE_POOL_NETFS_LAST,
+ "auto", "nfs");
enum {
- VIR_STORAGE_VOL_RAW,
+ VIR_STORAGE_VOL_RAW = 0,
VIR_STORAGE_VOL_DIR,
VIR_STORAGE_VOL_BOCHS,
VIR_STORAGE_VOL_CLOOP,
VIR_STORAGE_VOL_QCOW2,
VIR_STORAGE_VOL_VMDK,
VIR_STORAGE_VOL_VPC,
+ VIR_STORAGE_VOL_LAST,
};
+VIR_ENUM_DECL(virStorageBackendFileSystemVol);
+VIR_ENUM_IMPL(virStorageBackendFileSystemVol,
+ VIR_STORAGE_VOL_LAST,
+ "raw", "dir", "bochs",
+ "cloop", "cow", "dmg", "iso",
+ "qcow", "qcow2", "vmdk", "vpc");
/* Either 'magic' or 'extension' *must* be provided */
struct FileTypeInfo {
-static int
-virStorageBackendFileSystemVolFormatFromString(virConnectPtr conn,
- const char *format) {
- if (format == NULL)
- return VIR_STORAGE_VOL_RAW;
-
- if (STREQ(format, "raw"))
- return VIR_STORAGE_VOL_RAW;
- if (STREQ(format, "dir"))
- return VIR_STORAGE_VOL_DIR;
- if (STREQ(format, "bochs"))
- return VIR_STORAGE_VOL_BOCHS;
- if (STREQ(format, "cow"))
- return VIR_STORAGE_VOL_COW;
- if (STREQ(format, "cloop"))
- return VIR_STORAGE_VOL_CLOOP;
- if (STREQ(format, "dmg"))
- return VIR_STORAGE_VOL_DMG;
- if (STREQ(format, "iso"))
- return VIR_STORAGE_VOL_ISO;
- if (STREQ(format, "qcow"))
- return VIR_STORAGE_VOL_QCOW;
- if (STREQ(format, "qcow2"))
- return VIR_STORAGE_VOL_QCOW2;
- if (STREQ(format, "vmdk"))
- return VIR_STORAGE_VOL_VMDK;
- if (STREQ(format, "vpc"))
- return VIR_STORAGE_VOL_VPC;
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %s"), format);
- return -1;
-}
-
-static const char *
-virStorageBackendFileSystemVolFormatToString(virConnectPtr conn,
- int format) {
- switch (format) {
- case VIR_STORAGE_VOL_RAW:
- return "raw";
- case VIR_STORAGE_VOL_DIR:
- return "dir";
- case VIR_STORAGE_VOL_BOCHS:
- return "bochs";
- case VIR_STORAGE_VOL_CLOOP:
- return "cloop";
- case VIR_STORAGE_VOL_COW:
- return "cow";
- case VIR_STORAGE_VOL_DMG:
- return "dmg";
- case VIR_STORAGE_VOL_ISO:
- return "iso";
- case VIR_STORAGE_VOL_QCOW:
- return "qcow";
- case VIR_STORAGE_VOL_QCOW2:
- return "qcow2";
- case VIR_STORAGE_VOL_VMDK:
- return "vmdk";
- case VIR_STORAGE_VOL_VPC:
- return "vpc";
- }
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %d"), format);
- return NULL;
-}
-
-
-static int
-virStorageBackendFileSystemPoolFormatFromString(virConnectPtr conn,
- const char *format) {
- if (format == NULL)
- return VIR_STORAGE_POOL_FS_AUTO;
-
- if (STREQ(format, "auto"))
- return VIR_STORAGE_POOL_FS_AUTO;
- if (STREQ(format, "ext2"))
- return VIR_STORAGE_POOL_FS_EXT2;
- if (STREQ(format, "ext3"))
- return VIR_STORAGE_POOL_FS_EXT3;
- if (STREQ(format, "ext4"))
- return VIR_STORAGE_POOL_FS_EXT4;
- if (STREQ(format, "ufs"))
- return VIR_STORAGE_POOL_FS_UFS;
- if (STREQ(format, "iso9660"))
- return VIR_STORAGE_POOL_FS_ISO;
- if (STREQ(format, "udf"))
- return VIR_STORAGE_POOL_FS_UDF;
- if (STREQ(format, "gfs"))
- return VIR_STORAGE_POOL_FS_GFS;
- if (STREQ(format, "gfs2"))
- return VIR_STORAGE_POOL_FS_GFS2;
- if (STREQ(format, "vfat"))
- return VIR_STORAGE_POOL_FS_VFAT;
- if (STREQ(format, "hfs+"))
- return VIR_STORAGE_POOL_FS_HFSPLUS;
- if (STREQ(format, "xfs"))
- return VIR_STORAGE_POOL_FS_XFS;
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %s"), format);
- return -1;
-}
-
-static const char *
-virStorageBackendFileSystemPoolFormatToString(virConnectPtr conn,
- int format) {
- switch (format) {
- case VIR_STORAGE_POOL_FS_AUTO:
- return "auto";
- case VIR_STORAGE_POOL_FS_EXT2:
- return "ext2";
- case VIR_STORAGE_POOL_FS_EXT3:
- return "ext3";
- case VIR_STORAGE_POOL_FS_EXT4:
- return "ext4";
- case VIR_STORAGE_POOL_FS_UFS:
- return "ufs";
- case VIR_STORAGE_POOL_FS_ISO:
- return "iso";
- case VIR_STORAGE_POOL_FS_UDF:
- return "udf";
- case VIR_STORAGE_POOL_FS_GFS:
- return "gfs";
- case VIR_STORAGE_POOL_FS_GFS2:
- return "gfs2";
- case VIR_STORAGE_POOL_FS_VFAT:
- return "vfat";
- case VIR_STORAGE_POOL_FS_HFSPLUS:
- return "hfs+";
- case VIR_STORAGE_POOL_FS_XFS:
- return "xfs";
- }
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %d"), format);
- return NULL;
-}
-
-
-static int
-virStorageBackendFileSystemNetPoolFormatFromString(virConnectPtr conn,
- const char *format) {
- if (format == NULL)
- return VIR_STORAGE_POOL_NETFS_AUTO;
-
- if (STREQ(format, "auto"))
- return VIR_STORAGE_POOL_NETFS_AUTO;
- if (STREQ(format, "nfs"))
- return VIR_STORAGE_POOL_NETFS_NFS;
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %s"), format);
- return -1;
-}
-
-static const char *
-virStorageBackendFileSystemNetPoolFormatToString(virConnectPtr conn,
- int format) {
- switch (format) {
- case VIR_STORAGE_POOL_NETFS_AUTO:
- return "auto";
- case VIR_STORAGE_POOL_NETFS_NFS:
- return "nfs";
- }
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported volume format %d"), format);
- return NULL;
-}
-
-
/**
* Probe the header of a file to determine what type of disk image
* it is, and info about its capacity if available.
MOUNT,
"-t",
pool->def->type == VIR_STORAGE_POOL_FS ?
- virStorageBackendFileSystemPoolFormatToString(conn,
- pool->def->source.format) :
- virStorageBackendFileSystemNetPoolFormatToString(conn,
- pool->def->source.format),
+ virStorageBackendFileSystemPoolTypeToString(pool->def->source.format) :
+ virStorageBackendFileSystemNetPoolTypeToString(pool->def->source.format),
NULL, /* Fill in shortly - careful not to add extra fields
before this */
pool->def->target.path,
char size[100];
const char *imgargv[7];
- if ((type = virStorageBackendFileSystemVolFormatToString(conn,
- vol->target.format)) == NULL) {
+ if ((type = virStorageBackendFileSystemVolTypeToString(vol->target.format)) == NULL) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("unknown storage vol type %d"),
vol->target.format);
.deleteVol = virStorageBackendFileSystemVolDelete,
.volOptions = {
- .formatFromString = virStorageBackendFileSystemVolFormatFromString,
- .formatToString = virStorageBackendFileSystemVolFormatToString,
+ .formatFromString = virStorageBackendFileSystemVolTypeFromString,
+ .formatToString = virStorageBackendFileSystemVolTypeToString,
},
.volType = VIR_STORAGE_VOL_FILE,
};
.poolOptions = {
.flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE),
- .formatFromString = virStorageBackendFileSystemPoolFormatFromString,
- .formatToString = virStorageBackendFileSystemPoolFormatToString,
+ .formatFromString = virStorageBackendFileSystemPoolTypeFromString,
+ .formatToString = virStorageBackendFileSystemPoolTypeToString,
},
.volOptions = {
- .formatFromString = virStorageBackendFileSystemVolFormatFromString,
- .formatToString = virStorageBackendFileSystemVolFormatToString,
+ .formatFromString = virStorageBackendFileSystemVolTypeFromString,
+ .formatToString = virStorageBackendFileSystemVolTypeToString,
},
.volType = VIR_STORAGE_VOL_FILE,
};
.poolOptions = {
.flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_HOST |
VIR_STORAGE_BACKEND_POOL_SOURCE_DIR),
- .formatFromString = virStorageBackendFileSystemNetPoolFormatFromString,
- .formatToString = virStorageBackendFileSystemNetPoolFormatToString,
+ .formatFromString = virStorageBackendFileSystemNetPoolTypeFromString,
+ .formatToString = virStorageBackendFileSystemNetPoolTypeToString,
},
.volOptions = {
- .formatFromString = virStorageBackendFileSystemVolFormatFromString,
- .formatToString = virStorageBackendFileSystemVolFormatToString,
+ .formatFromString = virStorageBackendFileSystemVolTypeFromString,
+ .formatToString = virStorageBackendFileSystemVolTypeToString,
},
.volType = VIR_STORAGE_VOL_FILE,
};
return 0;
}
-
virStorageBackend virStorageBackendISCSI = {
- .type = VIR_STORAGE_POOL_ISCSI,
+ .type = VIR_STORAGE_POOL_ISCSI,
- .startPool = virStorageBackendISCSIStartPool,
- .refreshPool = virStorageBackendISCSIRefreshPool,
- .stopPool = virStorageBackendISCSIStopPool,
+ .startPool = virStorageBackendISCSIStartPool,
+ .refreshPool = virStorageBackendISCSIRefreshPool,
+ .stopPool = virStorageBackendISCSIStopPool,
- .poolOptions = {
+ .poolOptions = {
.flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_HOST |
VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE)
},
- .volType = VIR_STORAGE_VOL_BLOCK,
+ .volType = VIR_STORAGE_VOL_BLOCK,
+ .volOptions = {
+ .formatToString = virStorageBackendPartTableTypeToString,
+ }
};
#define PV_BLANK_SECTOR_SIZE 512
enum {
- VIR_STORAGE_POOL_LOGICAL_LVM2 = 0,
+ VIR_STORAGE_POOL_LOGICAL_UNKNOWN = 0,
+ VIR_STORAGE_POOL_LOGICAL_LVM2 = 1,
+ VIR_STORAGE_POOL_LOGICAL_LAST,
};
-
-
-static int
-virStorageBackendLogicalPoolFormatFromString(virConnectPtr conn,
- const char *format) {
- if (format == NULL)
- return VIR_STORAGE_POOL_LOGICAL_LVM2;
-
- if (STREQ(format, "lvm2"))
- return VIR_STORAGE_POOL_LOGICAL_LVM2;
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported pool format %s"), format);
- return -1;
-}
-
-static const char *
-virStorageBackendLogicalPoolFormatToString(virConnectPtr conn,
- int format) {
- switch (format) {
- case VIR_STORAGE_POOL_LOGICAL_LVM2:
- return "lvm2";
- }
-
- virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("unsupported pool format %d"), format);
- return NULL;
-}
+VIR_ENUM_DECL(virStorageBackendLogicalPool);
+VIR_ENUM_IMPL(virStorageBackendLogicalPool,
+ VIR_STORAGE_POOL_LOGICAL_LAST,
+ "unknown", "lvm2");
static int
virStorageBackendLogicalSetActive(virConnectPtr conn,
.poolOptions = {
.flags = (VIR_STORAGE_BACKEND_POOL_SOURCE_NAME |
VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE),
- .formatFromString = virStorageBackendLogicalPoolFormatFromString,
- .formatToString = virStorageBackendLogicalPoolFormatToString,
+ .formatFromString = virStorageBackendLogicalPoolTypeFromString,
+ .formatToString = virStorageBackendLogicalPoolTypeToString,
},
.volType = VIR_STORAGE_VOL_BLOCK,
if (options->formatFromString) {
char *format = virXPathString(conn, "string(/pool/source/format/@type)", ctxt);
- if ((ret->source.format = (options->formatFromString)(conn, format)) < 0) {
+ if ((ret->source.format = (options->formatFromString)(format)) < 0) {
VIR_FREE(format);
goto cleanup;
}
virBufferVSprintf(&buf," <name>%s</name>\n", def->source.name);
if (options->formatToString) {
- const char *format = (options->formatToString)(conn, def->source.format);
+ const char *format = (options->formatToString)(def->source.format);
if (!format)
goto cleanup;
virBufferVSprintf(&buf," <format type='%s'/>\n", format);
ret->target.path = virXPathString(conn, "string(/volume/target/path)", ctxt);
if (options->formatFromString) {
char *format = virXPathString(conn, "string(/volume/target/format/@type)", ctxt);
- if ((ret->target.format = (options->formatFromString)(conn, format)) < 0) {
+ if ((ret->target.format = (options->formatFromString)(format)) < 0) {
VIR_FREE(format);
goto cleanup;
}
virBufferVSprintf(&buf," <path>%s</path>\n", def->target.path);
if (options->formatToString) {
- const char *format = (options->formatToString)(conn,
- def->target.format);
+ const char *format = (options->formatToString)(def->target.format);
if (!format)
goto cleanup;
virBufferVSprintf(&buf," <format type='%s'/>\n", format);