# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1203463791 28800
# Node ID b59709a9c0ae71d78399327d411e703b19080177
# Parent 839b8d433ef5157fc34f5bb7f003e9cb8ed700c7
Add support for ref checking to VSMigrationCapabilities.
Updates:
-Initialize inst to NULL in return_vsmc() to prevent seg fault
-Use pfx_from_conn() in get_migration_caps() instead of CLASSNAME(ref)
-Initialize CMPIStatus s in get_migration_caps()
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 839b8d433ef5 -r b59709a9c0ae src/Virt_VSMigrationCapabilities.c
--- a/src/Virt_VSMigrationCapabilities.c Tue Feb 19 15:27:18 2008 -0800
+++ b/src/Virt_VSMigrationCapabilities.c Tue Feb 19 15:29:51 2008 -0800
@@ -81,13 +81,24 @@ static CMPIStatus set_method_properties(
CMPIStatus get_migration_caps(const CMPIObjectPath *ref,
CMPIInstance **_inst,
- const CMPIBroker *broker)
+ const CMPIBroker *broker,
+ bool is_get_inst)
{
CMPIInstance *inst;
- CMPIStatus s;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ virConnectPtr conn = NULL;
+
+ conn = connect_by_classname(broker, CLASSNAME(ref), &s);
+ if (conn == NULL) {
+ if (is_get_inst)
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance");
+ goto out;
+ }
inst = get_typed_instance(broker,
- CLASSNAME(ref),
+ pfx_from_conn(conn),
"VirtualSystemMigrationCapabilities",
NAMESPACE(ref));
if (inst == NULL) {
@@ -102,28 +113,42 @@ CMPIStatus get_migration_caps(const CMPI
s = set_method_properties(broker, inst);
- if (s.rc == CMPI_RC_OK)
- *_inst = inst;
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (is_get_inst) {
+ s = cu_validate_ref(broker, ref, inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+ }
+
+ *_inst = inst;
+
+ out:
+
+ virConnectClose(conn);
return s;
}
static CMPIStatus return_vsmc(const CMPIObjectPath *ref,
const CMPIResult *results,
- bool name_only)
-{
- CMPIInstance *inst;
+ bool name_only,
+ bool is_get_inst)
+{
+ CMPIInstance *inst = NULL;
CMPIStatus s;
- s = get_migration_caps(ref, &inst, _BROKER);
-
- if (s.rc == CMPI_RC_OK) {
- if (name_only)
- cu_return_instance_name(results, inst);
- else
- CMReturnInstance(results, inst);
- }
-
+ s = get_migration_caps(ref, &inst, _BROKER, is_get_inst);
+ if ((s.rc != CMPI_RC_OK) || (inst == NULL))
+ goto out;
+
+ if (name_only)
+ cu_return_instance_name(results, inst);
+ else
+ CMReturnInstance(results, inst);
+
+ out:
return s;
}
@@ -132,7 +157,7 @@ static CMPIStatus EnumInstanceNames(CMPI
const CMPIResult *results,
const CMPIObjectPath *ref)
{
- return return_vsmc(ref, results, true);
+ return return_vsmc(ref, results, true, false);
}
static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -142,7 +167,7 @@ static CMPIStatus EnumInstances(CMPIInst
const char **properties)
{
- return return_vsmc(ref, results, false);
+ return return_vsmc(ref, results, false, false);
}
@@ -152,24 +177,7 @@ static CMPIStatus GetInstance(CMPIInstan
const CMPIObjectPath *ref,
const char **properties)
{
- CMPIInstance *inst;
- CMPIStatus s;
- const char *prop;
-
- s = get_migration_caps(ref, &inst, _BROKER);
- if (s.rc != CMPI_RC_OK)
- return s;
-
- prop = cu_compare_ref(ref, inst);
- if (prop != NULL) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", prop);
- } else {
- CMReturnInstance(results, inst);
- }
-
- return s;
+ return return_vsmc(ref, results, false, true);
}
DEFAULT_CI();
diff -r 839b8d433ef5 -r b59709a9c0ae src/Virt_VSMigrationCapabilities.h
--- a/src/Virt_VSMigrationCapabilities.h Tue Feb 19 15:27:18 2008 -0800
+++ b/src/Virt_VSMigrationCapabilities.h Tue Feb 19 15:29:51 2008 -0800
@@ -21,7 +21,8 @@
CMPIStatus get_migration_caps(const CMPIObjectPath *reference,
CMPIInstance **_inst,
- const CMPIBroker *broker);
+ const CMPIBroker *broker,
+ bool is_get_inst);
/*
* Local Variables: