# HG changeset patch
# User kaitlin(a)elm3b43.beaverton.ibm.com
# Date 1224553244 25200
# Node ID d62634a3121f2991ed800491b2966ed9b531d4c3
# Parent 6d537f5e2b65c5d04963e9ff4e44e74c1e22b494
Return active/available/inactive console session
Instead of one session per guest.
Changes:
-Change Name attribute so that is is formatted in the following way:
"guest_name/guest_port:remote_port"
-Check /proc/net/tcp for listening / enabled ports
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 6d537f5e2b65 -r d62634a3121f src/Virt_KVMRedirectionSAP.c
--- a/src/Virt_KVMRedirectionSAP.c Mon Oct 20 18:24:30 2008 -0700
+++ b/src/Virt_KVMRedirectionSAP.c Mon Oct 20 18:40:44 2008 -0700
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
+#include <limits.h>
#include "cmpidt.h"
#include "cmpift.h"
@@ -155,21 +156,25 @@
return s;
}
-static int inst_from_dom(const CMPIBroker *broker,
- const CMPIObjectPath *ref,
- struct domain *dominfo,
- CMPIInstance *inst)
+static CMPIStatus inst_from_dom(const CMPIBroker *broker,
+ const CMPIObjectPath *ref,
+ struct domain *dominfo,
+ char *remote_port,
+ CMPIInstance *inst)
{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
char *sccn = NULL;
char *id = NULL;
char *pfx = NULL;
uint16_t prop_val;
- int ret = 1;
+ int val;
- if (asprintf(&id, "%s:%s", dominfo->name,
- dominfo->dev_graphics->dev.graphics.type) == -1) {
- CU_DEBUG("Unable to format name");
- ret = 0;
+ if (asprintf(&id, "%s/%s:%s", dominfo->name,
+ dominfo->dev_graphics->dev.graphics.port,
+ remote_port) == -1) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to format instance name");
goto out;
}
@@ -196,11 +201,22 @@
CMSetProperty(inst, "KVMProtocol",
(CMPIValue *)&prop_val, CMPI_uint16);
- /* Need to replace this with a check that determines whether
- the console session is enabled (in use) or available (not actively
- in use).
- */
- prop_val = (uint16_t)CIM_CRS_ENABLED_STATE;
+ s = port_convert(0, dominfo->dev_graphics->dev.graphics.port, &val);
+ if (s.rc != CMPI_RC_OK) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to format session port");
+ goto out;
+ }
+
+ /* If port is < 0, the session is inactive. */
+ if (val < 0)
+ prop_val = (uint16_t)CIM_SAP_INACTIVE_STATE;
+ else if (STREQ(remote_port, "0"))
+ prop_val = (uint16_t)CIM_SAP_AVAILABLE_STATE;
+ else
+ prop_val = (uint16_t)CIM_SAP_ACTIVE_STATE;
+
CMSetProperty(inst, "EnabledState",
(CMPIValue *)&prop_val, CMPI_uint16);
@@ -209,13 +225,14 @@
free(id);
free(sccn);
- return ret;
+ return s;
}
static CMPIInstance *get_console_sap(const CMPIBroker *broker,
const CMPIObjectPath *reference,
virConnectPtr conn,
struct domain *dominfo,
+ char *remote_port,
CMPIStatus *s)
{
@@ -233,14 +250,68 @@
goto out;
}
- if (inst_from_dom(broker, reference, dominfo, inst) != 1) {
- cu_statusf(broker, s,
- CMPI_RC_ERR_FAILED,
- "Unable to get instance from domain");
- }
+ *s = inst_from_dom(broker, reference, dominfo, remote_port, inst);
out:
return inst;
+}
+
+static CMPIStatus get_session_insts(const CMPIObjectPath *ref,
+ virConnectPtr conn,
+ struct domain *dominfo,
+ struct vnc_ports *vnc_hash[],
+ struct inst_list *list)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+ char *dport = NULL;
+ int dport_int = 0;
+ int index;
+ int i;
+
+ dport = strdup(dominfo->dev_graphics->dev.graphics.port);
+
+ s = port_convert(0, dport, &dport_int);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ /* If port is < 0, the session is inactive. No need to check
+ for active / available connections. */
+ if (dport_int < 0) {
+ inst = get_console_sap(_BROKER, ref, conn, dominfo, "-1",
&s);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (inst != NULL)
+ inst_list_add(list, inst);
+
+ goto out;
+ }
+
+ /* Otherwise, check for active / available sessions. */
+ index = get_vnc_hash_key(dport_int);
+ if (vnc_hash[index]->list != NULL) {
+ for (i = 0; i < vnc_hash[index]->cur; i++) {
+ inst = get_console_sap(_BROKER, ref, conn, dominfo,
+ vnc_hash[index]->list[i], &s);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (inst != NULL)
+ inst_list_add(list, inst);
+ }
+ } else {
+ inst = get_console_sap(_BROKER, ref, conn, dominfo, "-1",
&s);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ if (inst != NULL)
+ inst_list_add(list, inst);
+ }
+ out:
+ free(dport);
+
+ return s;
}
static CMPIStatus get_vnc_sessions(struct vnc_ports *vnc_hash[])
@@ -358,21 +429,19 @@
goto out;
for (i = 0; i < count; i++) {
- CMPIInstance *inst = NULL;
-
if (!check_graphics(domain_list[i], &dominfo)) {
virDomainFree(domain_list[i]);
cleanup_dominfo(&dominfo);
continue;
}
- inst = get_console_sap(_BROKER, ref, conn, dominfo, &s);
-
virDomainFree(domain_list[i]);
+
+ s = get_session_insts(ref, conn, dominfo, vnc_hash, &list);
cleanup_dominfo(&dominfo);
- if (inst != NULL)
- inst_list_add(&list, inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
}
if (names_only)
diff -r 6d537f5e2b65 -r d62634a3121f src/svpc_types.h
--- a/src/svpc_types.h Mon Oct 20 18:24:30 2008 -0700
+++ b/src/svpc_types.h Mon Oct 20 18:40:44 2008 -0700
@@ -59,6 +59,10 @@
#define CIM_CRS_OTHER 1
#define CIM_CRS_VNC 4
+#define CIM_SAP_ACTIVE_STATE 2
+#define CIM_SAP_INACTIVE_STATE 3
+#define CIM_SAP_AVAILABLE_STATE 6
+
#include <libcmpiutil/libcmpiutil.h>
#include <string.h>