# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1195080791 28800
# Node ID cfb48c67f1e611f10003a6c17ba458080f9d76f4
# Parent c9e977e820e99070f0c0c0397061229f7382ac7b
[RFC] Transition back to connect_by_classname()
Previously, we used the incoming reference for all operations to determine
the URI to pass to libvirt during a connect operation. For some reason,
we transitioned away from that to a detection-based mechanism, which would
not support multiple technologies to be managed from the provider
simultaneously.
I think that we have enough other infrastructure in place now that this is
no longer a problem. As a test, I offer this patch with a few key instances
of lv_connect() replaced with connect_by_classname() for discussion.
I have tested that enumeration of Xen_ComputerSystem, KVM_ComputerSystem,
and CIM_ComputerSystem are exclusive, and do not return any duplicate
results.
Further, I have confirmed that resolving Xen_SystemDevice against a
KVM_ComputerSystem instance does not work, and that no duplicate results
are returned in the case of CIM_SystemDevice.
If this looks okay to people (and wider testing supports my findings),
I propose we start to convert uses of lv_connect() back to per-class
connections until we encounter a problem.
Comments welcome.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r c9e977e820e9 -r cfb48c67f1e6 libxkutil/misc_util.c
--- a/libxkutil/misc_util.c Wed Nov 14 13:06:06 2007 +0100
+++ b/libxkutil/misc_util.c Wed Nov 14 14:53:11 2007 -0800
@@ -64,6 +64,8 @@ virConnectPtr connect_by_classname(const
return NULL;
}
+ CU_DEBUG("Connecting to libvirt with uri `%s'", uri);
+
conn = virConnectOpen(uri);
if (!conn) {
CMSetStatusWithChars(broker, s,
@@ -334,28 +336,21 @@ bool provider_is_responsible(const CMPIB
const CMPIObjectPath *reference,
CMPIStatus *status)
{
- const char *dft_pfx;
char *pfx;
- bool rc = false;
+ bool rc = true;
CMSetStatus(status, CMPI_RC_OK);
pfx = class_prefix_name(CLASSNAME(reference));
- if (STREQC(pfx, "CIM"))
+ if (STREQC(pfx, "CIM")) {
cu_statusf(broker, status,
CMPI_RC_ERR_FAILED,
"Please exactly specify the class (check CIMOM
behavior!): %s",
CLASSNAME(reference));
-
- dft_pfx = default_prefix();
- if (dft_pfx == NULL)
- goto out;
-
- if (STREQC(pfx, dft_pfx))
- rc = true;
-
- out:
+ rc = false;
+ }
+
free(pfx);
return rc;
}
diff -r c9e977e820e9 -r cfb48c67f1e6 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Wed Nov 14 13:06:06 2007 +0100
+++ b/src/Virt_ComputerSystem.c Wed Nov 14 14:53:11 2007 -0800
@@ -346,7 +346,7 @@ static CMPIStatus return_enum_domains(co
if (!provider_is_responsible(_BROKER, reference, &s))
return s;
- conn = lv_connect(_BROKER, &s);
+ conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
if (conn == NULL)
return s;
@@ -386,7 +386,7 @@ static CMPIStatus get_domain(const CMPIO
return s;
}
- conn = lv_connect(_BROKER, &s);
+ conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s);
if (conn == NULL)
return s;
@@ -609,7 +609,7 @@ static CMPIStatus __state_change(char *n
virDomainPtr dom = NULL;
virDomainInfo info;
- conn = lv_connect(_BROKER, &s);
+ conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
if (conn == NULL)
goto out;
diff -r c9e977e820e9 -r cfb48c67f1e6 src/Virt_SystemDevice.c
--- a/src/Virt_SystemDevice.c Wed Nov 14 13:06:06 2007 +0100
+++ b/src/Virt_SystemDevice.c Wed Nov 14 14:53:11 2007 -0800
@@ -61,6 +61,7 @@ static int get_dom_devices(const char *n
static int get_dom_devices(const char *name,
struct inst_list *list,
int type,
+ const char *host_cn,
const char *ns)
{
virConnectPtr conn = NULL;
@@ -68,7 +69,7 @@ static int get_dom_devices(const char *n
CMPIStatus s;
int ret = 0;
- conn = lv_connect(_BROKER, &s);
+ conn = connect_by_classname(_BROKER, host_cn, &s);
if (conn == NULL)
goto out;
@@ -87,17 +88,19 @@ static int get_dom_devices(const char *n
static int get_all_devices(const char *name,
struct inst_list *list,
- char *ns)
+ const char *host_cn,
+ const char *ns)
{
int i;
for (i = 0; i < DEV_TYPE_COUNT; i++)
- get_dom_devices(name, list, device_types[i], ns);
+ get_dom_devices(name, list, device_types[i], host_cn, ns);
return i;
}
static CMPIInstance *host_instance(char *name,
+ const char *host_cn,
const char *ns)
{
CMPIInstance *inst = NULL;
@@ -114,7 +117,7 @@ static CMPIInstance *host_instance(char
if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op))
goto out;
- conn = lv_connect(_BROKER, &s);
+ conn = connect_by_classname(_BROKER, host_cn, &s);
if (conn == NULL)
goto out;
@@ -173,9 +176,16 @@ static CMPIStatus sys_to_dev(const CMPIO
type = device_type_from_classname(info->result_class);
- ret = get_dom_devices(host, list, type, NAMESPACE(ref));
+ ret = get_dom_devices(host,
+ list,
+ type,
+ CLASSNAME(ref),
+ NAMESPACE(ref));
} else {
- ret = get_all_devices(host, list, NAMESPACE(ref));
+ ret = get_all_devices(host,
+ list,
+ CLASSNAME(ref),
+ NAMESPACE(ref));
}
if (ret >= 0) {
@@ -218,6 +228,7 @@ static CMPIStatus dev_to_sys(const CMPIO
}
sys = host_instance(host,
+ CLASSNAME(ref),
NAMESPACE(ref));
if (sys == NULL)