[PATCH] Set additional properties of template RASDs

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223052389 25200 # Node ID 2952b0fb0fef8e77b34c04a779ac44b1d092876f # Parent 7244474e5d2e118316e1636b06f99acb54062489 Set additional properties of template RASDs. For Proc: -Set Limit and Weight For Mem: -Set Limit - use same values set for VirtualQuantity For Net: -Set address - get a default mac address For Disk: -Set VirtualDevice, Address, and Mountpoint properties -For Xen, the default is xvda, which is accurate for paravirt, but not for full virt. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 7244474e5d2e -r 2952b0fb0fef src/Makefile.am --- a/src/Makefile.am Thu Oct 02 14:11:39 2008 -0700 +++ b/src/Makefile.am Fri Oct 03 09:46:29 2008 -0700 @@ -131,12 +131,13 @@ -lVirt_VSMigrationService \ -lVirt_DevicePool -libVirt_SettingsDefineCapabilities_la_DEPENDENCIES = libVirt_RASD.la libVirt_DevicePool.la libVirt_VSMigrationCapabilities.la libVirt_VSMigrationSettingData.la +libVirt_SettingsDefineCapabilities_la_DEPENDENCIES = libVirt_RASD.la libVirt_DevicePool.la libVirt_VSMigrationCapabilities.la libVirt_VSMigrationSettingData.la libVirt_VirtualSystemManagementService.la libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c libVirt_SettingsDefineCapabilities_la_LIBADD = -lVirt_RASD \ -lVirt_DevicePool \ -lVirt_VSMigrationCapabilities \ - -lVirt_VSMigrationSettingData + -lVirt_VSMigrationSettingData \ + -lVirt_VirtualSystemManagementService libVirt_RegisteredProfile_la_SOURCES = Virt_RegisteredProfile.c diff -r 7244474e5d2e -r 2952b0fb0fef src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Thu Oct 02 14:11:39 2008 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Fri Oct 03 09:46:29 2008 -0700 @@ -46,6 +46,7 @@ #include "Virt_RASD.h" #include "Virt_VSMigrationCapabilities.h" #include "Virt_VSMigrationSettingData.h" +#include "Virt_VirtualSystemManagementService.h" const static CMPIBroker *_BROKER; @@ -249,12 +250,38 @@ return s; } +static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, + const CMPIObjectPath *ref, + uint16_t resource_type) +{ + CMPIInstance *inst = NULL; + const char *base = NULL; + + if (rasd_classname_from_type(resource_type, &base) != CMPI_RC_OK) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Resource type not known"); + goto out; + } + + inst = get_typed_instance(_BROKER, + CLASSNAME(ref), + base, + NAMESPACE(ref)); + + CMSetProperty(inst, "ResourceType", &resource_type, CMPI_uint16); + + out: + return inst; +} + static CMPIStatus mem_template(const CMPIObjectPath *ref, int template_type, - CMPIInstance *inst) + struct inst_list *list) { uint64_t mem_size; const char *id; + CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; switch (template_type) { @@ -281,11 +308,17 @@ goto out; } + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_MEM); + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); CMSetProperty(inst, "AllocationUnits", (CMPIValue *)"KiloBytes", CMPI_chars); CMSetProperty(inst, "VirtualQuantity", (CMPIValue *)&mem_size, CMPI_uint64); + CMSetProperty(inst, "Limit", + (CMPIValue *)&mem_size, CMPI_uint64); + + inst_list_add(list, inst); out: return s; @@ -316,30 +349,41 @@ static CMPIStatus proc_template(const CMPIObjectPath *ref, int template_type, - CMPIInstance *inst) + struct inst_list *list) { bool ret; uint64_t num_procs; + uint64_t limit; + uint32_t weight; const char *id; + CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; switch (template_type) { case SDC_RASD_MIN: num_procs = 0; + limit = 1; + weight = MIN_XEN_WEIGHT; id = "Minimum"; break; case SDC_RASD_MAX: ret = get_max_procs(ref, &num_procs, &s); if (!ret) goto out; + limit = 0; + weight = MAX_XEN_WEIGHT; id = "Maximum"; break; case SDC_RASD_INC: num_procs = 1; + limit = 50; + weight = INC_XEN_WEIGHT; id = "Increment"; break; case SDC_RASD_DEF: num_procs = 1; + limit = 0; + weight = DEFAULT_XEN_WEIGHT; id = "Default"; break; default: @@ -349,11 +393,21 @@ goto out; } + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_PROC); + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); CMSetProperty(inst, "AllocationUnits", (CMPIValue *)"Processors", CMPI_chars); CMSetProperty(inst, "VirtualQuantity", (CMPIValue *)&num_procs, CMPI_uint64); + + if (STARTS_WITH(CLASSNAME(ref), "Xen")) { + CMSetProperty(inst, "Limit", (CMPIValue *)&limit, CMPI_uint64); + CMSetProperty(inst, "Weight", + (CMPIValue *)&weight, CMPI_uint32); + } + + inst_list_add(list, inst); out: return s; @@ -438,11 +492,13 @@ static CMPIStatus net_template(const CMPIObjectPath *ref, int template_type, - CMPIInstance *inst) + struct inst_list *list) { bool ret; uint64_t num_nics; const char *id; + const char *mac; + CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; switch (template_type) { @@ -471,9 +527,22 @@ goto out; } + mac = _net_rand_mac(_BROKER); + if (mac == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to generate a MAC address"); + goto out; + } + + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_NET); + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); CMSetProperty(inst, "VirtualQuantity", (CMPIValue *)&num_nics, CMPI_uint64); + CMSetProperty(inst, "Address", (CMPIValue *)mac, CMPI_chars); + + inst_list_add(list, inst); out: return s; @@ -525,13 +594,64 @@ return ret; } +static CMPIStatus set_disk_props(int type, + const CMPIObjectPath *ref, + const char *id, + uint64_t disk_size, + struct inst_list *list) +{ + const char *addr; + const char *dev; + CMPIInstance *inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + if (type == DOMAIN_LXC) { + addr = "/tmp"; + dev = "/lxc_mnt/tmp"; + } + else { + dev = "hda"; + addr = "/dev/null"; + } + + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_DISK); + + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); + CMSetProperty(inst, "AllocationQuantity", + (CMPIValue *)"MegaBytes", CMPI_chars); + CMSetProperty(inst, "VirtualQuantity", + (CMPIValue *)&disk_size, CMPI_uint64); + CMSetProperty(inst, "Address", (CMPIValue *)addr, CMPI_chars); + + if (type == DOMAIN_LXC) + CMSetProperty(inst, "MountPoint", (CMPIValue *)dev, CMPI_chars); + else { + if (type == DOMAIN_XENPV) { + dev = "xvda"; + CMSetProperty(inst, "Caption", + (CMPIValue *)"PV disk", CMPI_chars); + } else if (type, DOMAIN_XENFV) { + CMSetProperty(inst, "Caption", + (CMPIValue *)"FV disk", CMPI_chars); + } + + CMSetProperty(inst, "VirtualDevice", + (CMPIValue *)dev, CMPI_chars); + } + + inst_list_add(list, inst); + + return s; +} + static CMPIStatus disk_template(const CMPIObjectPath *ref, int template_type, - CMPIInstance *inst) + struct inst_list *list) { bool ret; + char *pfx; + const char *id; uint64_t disk_size; - const char *id; CMPIStatus s = {CMPI_RC_OK, NULL}; switch(template_type) { @@ -560,57 +680,27 @@ goto out; } - CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); - CMSetProperty(inst, "AllocationQuantity", - (CMPIValue *)"MegaBytes", CMPI_chars); - CMSetProperty(inst, "VirtualQuantity", - (CMPIValue *)&disk_size, CMPI_uint64); + pfx = class_prefix_name(CLASSNAME(ref)); + + if (STREQ(pfx, "Xen")) { + s = set_disk_props(DOMAIN_XENPV, ref, id, disk_size, list); + + if (s.rc != CMPI_RC_OK) + goto out; + + s = set_disk_props(DOMAIN_XENFV, ref, id, disk_size, list); + } else if (STREQ(pfx, "KVM")) { + s = set_disk_props(DOMAIN_KVM, ref, id, disk_size, list); + } else if (STREQ(pfx, "LXC")) { + s = set_disk_props(DOMAIN_LXC, ref, id, disk_size, list); + } else { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unsupported virtualization type"); + } out: return s; -} - -static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, - const CMPIObjectPath *ref, - sdc_rasd_type type, - uint16_t resource_type) -{ - CMPIInstance *inst = NULL; - const char *base = NULL; - - if (rasd_classname_from_type(resource_type, &base) != CMPI_RC_OK) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Resource type not known"); - goto out; - } - - inst = get_typed_instance(_BROKER, - CLASSNAME(ref), - base, - NAMESPACE(ref)); - - if (resource_type == CIM_RES_TYPE_MEM) - *s = mem_template(ref, type, inst); - else if (resource_type == CIM_RES_TYPE_PROC) - *s = proc_template(ref, type, inst); - else if (resource_type == CIM_RES_TYPE_NET) - *s = net_template(ref, type, inst); - else if (resource_type == CIM_RES_TYPE_DISK) - *s = disk_template(ref, type, inst); - else { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Unsupported resource type"); - } - - if (s->rc != CMPI_RC_OK) - goto out; - - CMSetProperty(inst, "ResourceType", &resource_type, CMPI_uint16); - - out: - return inst; } static CMPIStatus sdc_rasds_for_type(const CMPIObjectPath *ref, @@ -618,21 +708,26 @@ uint16_t type) { CMPIStatus s = {CMPI_RC_OK, NULL}; - CMPIInstance *inst; int i; for (i = SDC_RASD_MIN; i <= SDC_RASD_INC; i++) { - inst = sdc_rasd_inst(&s, ref, i, type); + if (type == CIM_RES_TYPE_MEM) + s = mem_template(ref, i, list); + else if (type == CIM_RES_TYPE_PROC) + s = proc_template(ref, i, list); + else if (type == CIM_RES_TYPE_NET) + s = net_template(ref, i, list); + else if (type == CIM_RES_TYPE_DISK) + s = disk_template(ref, i, list); + else { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unsupported resource type"); + } + if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Problem getting inst"); + CU_DEBUG("Problem getting inst list"); goto out; - } - CU_DEBUG("Got inst"); - if ((s.rc == CMPI_RC_OK) && (inst != NULL)) { - inst_list_add(list, inst); - CU_DEBUG("Added inst"); - } else { - CU_DEBUG("Inst is null, not added"); } } diff -r 7244474e5d2e -r 2952b0fb0fef src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Thu Oct 02 14:11:39 2008 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Fri Oct 03 09:46:29 2008 -0700 @@ -321,7 +321,7 @@ return poolid; } -static const char *_net_rand_mac(void) +const char *_net_rand_mac(const CMPIBroker *broker) { int r; int ret; @@ -344,7 +344,7 @@ if (ret == -1) goto out; - str = CMNewString(_BROKER, mac, &status); + str = CMNewString(broker, mac, &status); if ((str == NULL) || (status.rc != CMPI_RC_OK)) { str = NULL; CU_DEBUG("Failed to create string"); @@ -369,7 +369,7 @@ const char *msg = NULL; if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK) { - val = _net_rand_mac(); + val = _net_rand_mac(_BROKER); if (val == NULL) { msg = "Unable to generate a MAC address"; goto out; diff -r 7244474e5d2e -r 2952b0fb0fef src/Virt_VirtualSystemManagementService.h --- a/src/Virt_VirtualSystemManagementService.h Thu Oct 02 14:11:39 2008 -0700 +++ b/src/Virt_VirtualSystemManagementService.h Fri Oct 03 09:46:29 2008 -0700 @@ -19,8 +19,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#define MIN_XEN_WEIGHT 1 +#define MAX_XEN_WEIGHT 65535 +#define INC_XEN_WEIGHT MAX_XEN_WEIGHT / 2 +#define DEFAULT_XEN_WEIGHT 1024 + CMPIStatus get_vsms(const CMPIObjectPath *reference, CMPIInstance **_inst, const CMPIBroker *broker, const CMPIContext *context, bool is_get_inst); + +const char *_net_rand_mac(const CMPIBroker *broker);

KR> For Net: KR> -Set address - get a default mac address I think we've had this discussion in the past, and decided it was better to not offer generated mac addresses in the template instances. Since resolving the association is the act of allocation (or pre-allocation), there's no easy way to say "I need three NICs" and get back unique MACs for each. Because of this lack of a formal allocation step, I think it's likely that clients would grab a template RASD and offer it multiple times in the DefineSystem() call, which wouldn't result in a valid domain configuration. The concession was that we would let the client leave out the MAC and assign one for it during DefineSystem(). That way if they want to specify a MAC, they can, but we don't have to deal with the other issues. So, I definitely think that the fields you're adding for the other templates are good, but I'd rather leave this one out of it, if possible. Thoughts? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
KR> For Net: KR> -Set address - get a default mac address
I think we've had this discussion in the past, and decided it was better to not offer generated mac addresses in the template instances.
We did, and it completely slipped my mind.
Since resolving the association is the act of allocation (or pre-allocation), there's no easy way to say "I need three NICs" and get back unique MACs for each. Because of this lack of a formal allocation step, I think it's likely that clients would grab a template RASD and offer it multiple times in the DefineSystem() call, which wouldn't result in a valid domain configuration.
The concession was that we would let the client leave out the MAC and assign one for it during DefineSystem(). That way if they want to specify a MAC, they can, but we don't have to deal with the other issues.
So, I definitely think that the fields you're adding for the other templates are good, but I'd rather leave this one out of it, if possible.
Yes, since the DefineSystem() call sets a MAC in the case its not supplied in the RASD, then I think it is fine to not advertise it in the template. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert