[PATCH 0 of 2] Beginnings of LXC DefineSystem() support

This patch adds some device type filtering framework to prevent a user from specifying an invalid device in a domain configuration (like a disk device to a container). It also adds early VSSD parsing support to VSMS.

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1209142945 25200 # Node ID a0cecff057584e71cc0cf2ff48ae0c5b31631c4c # Parent e1ce6d481719f6d884bcd662294b18136371c300 Enforce only types suitable to LXC (and the others). I figure that most system virtualization platforms will have similar device support, as will containers platforms. So, the differentiation as such in the new dispatch code seems reasonable at the moment. Right now, we don't support anything other than the memory device for LXC, so only dispatch for those. Disk/FS support will follow. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r e1ce6d481719 -r a0cecff05758 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Apr 25 10:02:17 2008 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Fri Apr 25 10:02:25 2008 -0700 @@ -360,7 +360,34 @@ static const char *mem_rasd_to_vdev(CMPI return NULL; } +static const char *_sysvirt_rasd_to_vdev(CMPIInstance *inst, + struct virt_device *dev, + uint16_t type) +{ + if (type == CIM_RES_TYPE_DISK) { + return disk_rasd_to_vdev(inst, dev); + } else if (type == CIM_RES_TYPE_NET) { + return net_rasd_to_vdev(inst, dev); + } else if (type == CIM_RES_TYPE_MEM) { + return mem_rasd_to_vdev(inst, dev); + } + + return "Resource type not supported on this platform"; +} + +static const char *_container_rasd_to_vdev(CMPIInstance *inst, + struct virt_device *dev, + uint16_t type) +{ + if (type == CIM_RES_TYPE_MEM) { + return mem_rasd_to_vdev(inst, dev); + } + + return "Resource type not supported on this platform"; +} + static const char *rasd_to_vdev(CMPIInstance *inst, + struct domain *domain, struct virt_device *dev) { uint16_t type; @@ -380,16 +407,13 @@ static const char *rasd_to_vdev(CMPIInst dev->type = (int)type; - if (type == CIM_RES_TYPE_DISK) { - msg = disk_rasd_to_vdev(inst, dev); - } else if (type == CIM_RES_TYPE_NET) { - msg = net_rasd_to_vdev(inst, dev); - } else if (type == CIM_RES_TYPE_MEM) { - msg = mem_rasd_to_vdev(inst, dev); - } + if (domain->type == DOMAIN_LXC) + msg = _container_rasd_to_vdev(inst, dev, type); + else + msg = _sysvirt_rasd_to_vdev(inst, dev, type); out: if (msg) - CU_DEBUG("rasd_to_vdev(): %s", msg); + CU_DEBUG("rasd_to_vdev(%s): %s", CLASSNAME(op), msg); return msg; } @@ -439,15 +463,19 @@ static const char *classify_resources(CM if (type == CIM_RES_TYPE_PROC) msg = rasd_to_vdev(inst, + domain, &domain->dev_vcpu[domain->dev_vcpu_ct++]); else if (type == CIM_RES_TYPE_MEM) msg = rasd_to_vdev(inst, + domain, &domain->dev_mem[domain->dev_mem_ct++]); else if (type == CIM_RES_TYPE_DISK) msg = rasd_to_vdev(inst, + domain, &domain->dev_disk[domain->dev_disk_ct++]); else if (type == CIM_RES_TYPE_NET) msg = rasd_to_vdev(inst, + domain, &domain->dev_net[domain->dev_net_ct++]); if (msg != NULL) @@ -933,7 +961,7 @@ static CMPIStatus resource_add(struct do dev->type = type; dev->id = strdup(devid); - rasd_to_vdev(rasd, dev); + rasd_to_vdev(rasd, dominfo, dev); s = _resource_dynamic(dominfo, dev, RESOURCE_ADD, CLASSNAME(op)); if (s.rc != CMPI_RC_OK) @@ -982,7 +1010,7 @@ static CMPIStatus resource_mod(struct do struct virt_device *dev = &list[i]; if (STREQ(dev->id, devid)) { - rasd_to_vdev(rasd, dev); + rasd_to_vdev(rasd, dominfo, dev); s = _resource_dynamic(dominfo, dev, RESOURCE_MOD,

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1209142960 25200 # Node ID a34b2f403fe423753084631235364f23220cb8f8 # Parent a0cecff057584e71cc0cf2ff48ae0c5b31631c4c DefineSystem changes for LXC Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r a0cecff05758 -r a34b2f403fe4 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Apr 25 10:02:25 2008 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Fri Apr 25 10:02:40 2008 -0700 @@ -171,6 +171,24 @@ static int fv_vssd_to_domain(CMPIInstanc return 1; } +static int lxc_vssd_to_domain(CMPIInstance *inst, + struct domain *domain) +{ + int ret; + const char *val; + + domain->type = DOMAIN_LXC; + + ret = cu_get_str_prop(inst, "InitPath", &val); + if (ret != CMPI_RC_OK) + val = "/bin/false"; + + free(domain->os_info.lxc.init); + domain->os_info.lxc.init = strdup(val); + + return 1; +} + static int vssd_to_domain(CMPIInstance *inst, struct domain *domain) { @@ -207,16 +225,18 @@ static int vssd_to_domain(CMPIInstance * domain->on_crash = (int)tmp; - if (STREQC(pfx, "KVM")) - fullvirt = true; - else if (cu_get_bool_prop(inst, "IsFullVirt", &fullvirt) != CMPI_RC_OK) + if (cu_get_bool_prop(inst, "IsFullVirt", &fullvirt) != CMPI_RC_OK) fullvirt = false; - if (fullvirt) + if (fullvirt || STREQC(pfx, "KVM")) ret = fv_vssd_to_domain(inst, domain, pfx); - else + else if (STREQC(pfx, "Xen")) ret = xenpv_vssd_to_domain(inst, domain); - + else if (STREQC(pfx, "LXC")) + ret = lxc_vssd_to_domain(inst, domain); + else { + CU_DEBUG("Unknown domain prefix: %s", pfx); + } out: free(pfx);

Dan Smith wrote:
This patch adds some device type filtering framework to prevent a user from specifying an invalid device in a domain configuration (like a disk device to a container). It also adds early VSSD parsing support to VSMS.
I haven't played around with containers yet, but this code appears sane. +1 -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert