[PATCH 0 of 4] Add support fore creating directory based storage pools

libvirt support various storage pool types - support for these pool types will be added in additional patchsets. This set just adds support for directory based pools.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1238773876 25200 # Node ID 9759b13c4f25d20f92bc2d50961e467c1b050acc # Parent 2f4943568299ef76e285e34412ec5ba5f2badbd7 Add disk support to pool_parsing Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 2f4943568299 -r 9759b13c4f25 libxkutil/pool_parsing.c --- a/libxkutil/pool_parsing.c Thu Apr 02 03:31:14 2009 -0300 +++ b/libxkutil/pool_parsing.c Fri Apr 03 08:51:16 2009 -0700 @@ -33,6 +33,16 @@ #include "pool_parsing.h" #include "../src/svpc_types.h" +/* + * * Right now, detect support and use it, if available. + * * Later, this can be a configure option if needed + * */ +#if LIBVIR_VERSION_NUMBER > 4000 +# define VIR_USE_LIBVIRT_STORAGE 1 +#else +# define VIR_USE_LIBVIRT_STORAGE 0 +#endif + static void cleanup_net_pool(struct net_pool pool) { free(pool.addr); free(pool.netmask); @@ -78,8 +88,27 @@ } virNetworkFree(ptr); + } else if (res_type == CIM_RES_TYPE_DISK) { +#if VIR_USE_LIBVIRT_STORAGE + virStoragePoolPtr ptr = virStoragePoolDefineXML(conn, xml, 0); + if (ptr == NULL) { + CU_DEBUG("Unable to define storage pool"); + return 0; + } + + if (virStoragePoolCreate(ptr, 0) != 0) { + CU_DEBUG("Unable to start storage pool"); + ret = 0; + + if (virStoragePoolUndefine(ptr) != 0) + CU_DEBUG("Unable to undefine storage pool"); + } + + virStoragePoolFree(ptr); +#endif } + return ret; } diff -r 2f4943568299 -r 9759b13c4f25 libxkutil/pool_parsing.h --- a/libxkutil/pool_parsing.h Thu Apr 02 03:31:14 2009 -0300 +++ b/libxkutil/pool_parsing.h Fri Apr 03 08:51:16 2009 -0700 @@ -36,10 +36,22 @@ char *forward_dev; }; +struct disk_pool { + enum {DISK_POOL_UNKNOWN, + DISK_POOL_DIR, + DISK_POOL_FS, + DISK_POOL_NETFS, + DISK_POOL_DISK, + DISK_POOL_ISCSI, + DISK_POOL_LOGICAL} pool_type; + char *path; +}; + struct virt_pool { uint16_t type; union { struct net_pool net; + struct disk_pool disk; } pool_info; char *id; };

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1238776731 25200 # Node ID 0d6b3f8aa95de7a57576e1d686ec23190903081e # Parent 9759b13c4f25d20f92bc2d50961e467c1b050acc Add storage pool support to xmlgen Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 9759b13c4f25 -r 0d6b3f8aa95d libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Apr 03 08:51:16 2009 -0700 +++ b/libxkutil/xmlgen.c Fri Apr 03 09:38:51 2009 -0700 @@ -845,6 +845,67 @@ return XML_ERROR; } +static const char *disk_pool_type_to_str(uint16_t type) +{ + switch (type) { + case DISK_POOL_DIR: + return "dir"; + case DISK_POOL_FS: + return "fs"; + case DISK_POOL_NETFS: + return "netfs"; + case DISK_POOL_DISK: + return "disk"; + case DISK_POOL_ISCSI: + return "iscsi"; + case DISK_POOL_LOGICAL: + return "logical"; + default: + CU_DEBUG("Unsupported disk pool type"); + } + + return NULL; +} + +static const char *disk_pool_xml(xmlNodePtr root, + struct virt_pool *_pool) +{ + xmlNodePtr disk = NULL; + xmlNodePtr name = NULL; + xmlNodePtr target = NULL; + xmlNodePtr path = NULL; + const char *type = NULL; + struct disk_pool *pool = &_pool->pool_info.disk; + + type = disk_pool_type_to_str(pool->pool_type); + if (type == NULL) + goto out; + + disk = xmlNewChild(root, NULL, BAD_CAST "pool", NULL); + if (disk == NULL) + goto out; + + if (xmlNewProp(disk, BAD_CAST "type", BAD_CAST type) == NULL) + goto out; + + name = xmlNewChild(disk, NULL, BAD_CAST "name", BAD_CAST _pool->id); + if (name == NULL) + goto out; + + target = xmlNewChild(disk, NULL, BAD_CAST "target", NULL); + if (target == NULL) + goto out; + + path = xmlNewChild(target, NULL, BAD_CAST "path", BAD_CAST pool->path); + if (target == NULL) + goto out; + + return NULL; + + out: + return XML_ERROR; + } + char *pool_to_xml(struct virt_pool *pool) { char *xml = NULL; xmlNodePtr root = NULL; @@ -862,6 +923,9 @@ case CIM_RES_TYPE_NET: func = net_pool_xml; break; + case CIM_RES_TYPE_DISK: + func = disk_pool_xml; + break; default: CU_DEBUG("pool_to_xml: invalid type specified: %d", type); msg = "pool_to_xml: invalid type specified";

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1238776732 25200 # Node ID 2bd3982a2285fbfb5287861cfecb1a70e0fe4b43 # Parent 0d6b3f8aa95de7a57576e1d686ec23190903081e Add DiskPoolRASD MOF definitions Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 0d6b3f8aa95d -r 2bd3982a2285 schema/ResourceAllocationSettingData.mof --- a/schema/ResourceAllocationSettingData.mof Fri Apr 03 09:38:51 2009 -0700 +++ b/schema/ResourceAllocationSettingData.mof Fri Apr 03 09:38:52 2009 -0700 @@ -163,7 +163,7 @@ string BusType; }; -[Description ("Xen virtual pool settings"), +[Description ("Xen virtual network pool settings"), Provider("cmpi::Virt_RASD") ] class Xen_NetPoolResourceAllocationSettingData : Xen_ResourceAllocationSettingData @@ -174,7 +174,7 @@ string ForwardMode; }; -[Description ("KVM virtual pool settings"), +[Description ("KVM virtual network pool settings"), Provider("cmpi::Virt_RASD") ] class KVM_NetPoolResourceAllocationSettingData : KVM_ResourceAllocationSettingData @@ -185,7 +185,7 @@ string ForwardMode; }; -[Description ("LXC virtual pool settings"), +[Description ("LXC virtual network pool settings"), Provider("cmpi::Virt_RASD") ] class LXC_NetPoolResourceAllocationSettingData : LXC_ResourceAllocationSettingData @@ -195,3 +195,43 @@ string IPRangeEnd; string ForwardMode; }; + +[Description ("Xen virtual disk pool settings"), + Provider("cmpi::Virt_RASD") +] +class Xen_DiskPoolResourceAllocationSettingData : Xen_ResourceAllocationSettingData +{ + [Description ("Storage pool type"), + ValueMap {"0", "1", "2", "3", "4", "5", "6"}, + Values {"Unknown", "Directory, File System, Network File System, " + "Disk, ISCSI, Logical"}] + uint16 Type; + string Path; +}; + +[Description ("KVM virtual disk pool settings"), + Provider("cmpi::Virt_RASD") +] +class KVM_DiskPoolResourceAllocationSettingData : KVM_ResourceAllocationSettingData +{ + [Description ("Storage pool type"), + ValueMap {"0", "1", "2", "3", "4", "5", "6"}, + Values {"Unknown", "Directory, File System, Network File System, " + "Disk, ISCSI, Logical"}] + uint16 Type; + string Path; +}; + +[Description ("LXC virtual disk pool settings"), + Provider("cmpi::Virt_RASD") +] +class LXC_DiskPoolResourceAllocationSettingData : LXC_ResourceAllocationSettingData +{ + [Description ("Storage pool type"), + ValueMap {"0", "1", "2", "3", "4", "5", "6"}, + Values {"Unknown", "Directory, File System, Network File System, " + "Disk, ISCSI, Logical"}] + uint16 Type; + string Path; +}; + diff -r 0d6b3f8aa95d -r 2bd3982a2285 src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Apr 03 09:38:51 2009 -0700 +++ b/src/Virt_RASD.c Fri Apr 03 09:38:52 2009 -0700 @@ -524,7 +524,8 @@ if (base == NULL) goto out; - if (STREQ(base, "DiskResourceAllocationSettingData")) + if ((STREQ(base, "DiskResourceAllocationSettingData")) || + (STREQ(base, "DiskPoolResourceAllocationSettingData"))) *type = CIM_RES_TYPE_DISK; else if ((STREQ(base, "NetResourceAllocationSettingData")) || (STREQ(base, "NetPoolResourceAllocationSettingData")))

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1238776732 25200 # Node ID d08b52d4da57fc8bbe946f8b4f9ddccdccf9dee6 # Parent 2bd3982a2285fbfb5287861cfecb1a70e0fe4b43 Add support for creating disk pools to RPCS Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 2bd3982a2285 -r d08b52d4da57 src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Fri Apr 03 09:38:52 2009 -0700 +++ b/src/Virt_ResourcePoolConfigurationService.c Fri Apr 03 09:38:52 2009 -0700 @@ -40,6 +40,16 @@ const char *DEF_POOL_NAME = "libvirt-cim-pool"; +/* + * * Right now, detect support and use it, if available. + * * Later, this can be a configure option if needed + * */ +#if LIBVIR_VERSION_NUMBER > 4000 +# define VIR_USE_LIBVIRT_STORAGE 1 +#else +# define VIR_USE_LIBVIRT_STORAGE 0 +#endif + static CMPIStatus create_child_pool_parse_args(const CMPIArgs *argsin, const char **name, CMPIArray **set, @@ -104,6 +114,40 @@ } +#if VIR_USE_LIBVIRT_STORAGE +static const char *disk_rasd_to_pool(CMPIInstance *inst, + struct virt_pool *pool, + const char *ns) +{ + const char *val = NULL; + const char *msg = NULL; + uint16_t type; + + if (cu_get_u16_prop(inst, "Type", &type) != CMPI_RC_OK) + return "Missing `Type' property"; + + if (type != DISK_POOL_DIR) + return "Storage pool type not supported"; + + pool->pool_info.disk.pool_type = type; + + if (cu_get_str_prop(inst, "Path", &val) != CMPI_RC_OK) + return "Missing `Path' property"; + + pool->pool_info.disk.path = strdup(val); + + return msg; + +} +#else +static const char *disk_rasd_to_pool(CMPIInstance *inst, + struct virt_pool *pool, + const char *ns) +{ + return "Storage pool creation not supported in this version of libvirt"; +} +#endif + static const char *rasd_to_vpool(CMPIInstance *inst, struct virt_pool *pool, uint16_t type, @@ -113,6 +157,8 @@ if (type == CIM_RES_TYPE_NET) { return net_rasd_to_pool(inst, pool, ns); + } else if (type == CIM_RES_TYPE_DISK) { + return disk_rasd_to_pool(inst, pool, ns); } pool->type = CIM_RES_TYPE_UNKNOWN; @@ -150,9 +196,6 @@ if (res_type_from_rasd_classname(CLASSNAME(op), &type) != CMPI_RC_OK) return "Unable to determine resource type"; - if (type != CIM_RES_TYPE_NET) - return "Only network pools currently supported"; - msg = rasd_to_vpool(inst, pool, type, NAMESPACE(op)); return msg;

+1 Kaitlin Rupert wrote:
libvirt support various storage pool types - support for these pool types will be added in additional patchsets. This set just adds support for directory based pools.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel