提交 ab5be538 编写于 作者: D Daniel P. Berrange

Wire up free memory APIs to remote driver/daemon

上级 dd674689
Thu May 22 11:15:29 EST 2008 Daniel P. Berrange <berrange@redhat.com>
Support the free memory API calls in the remote driver/daemon
* qemud/Makefile.am: Remove tabs from generated RPC header
* qemud/qemud/remote_generate_stubs.pl: Remove tabs from
generated C file
* qemud/remote_dispatch_*.h: Re-generated with for RPC calls
* qemud/remote_protocol.x: Added NUMA free memory apis
* qemud/remote_protocol.{c,h}: Re-generated with new RPC calls
* qemud/remote.c: Implement dispatcher for free memory APIs
* src/remote_internal.c: Implement functions for free
memory APIs
Thu May 22 11:06:29 EST 2008 Daniel P. Berrange <berrange@redhat.com>
Fix misc memory leaks
......
......@@ -26,6 +26,9 @@ endif
.x.h:
rm -f $@
rpcgen -h -o $@ $<
if GLIBC_RPCGEN
perl -i -p -e 's/\t/ /g' $@
endif
endif
remote_protocol.c: remote_protocol.h
......
......@@ -595,6 +595,53 @@ remoteDispatchGetCapabilities (struct qemud_server *server ATTRIBUTE_UNUSED,
return 0;
}
static int
remoteDispatchNodeGetCellsFreeMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
struct qemud_client *client,
remote_message_header *req,
remote_node_get_cells_free_memory_args *args,
remote_node_get_cells_free_memory_ret *ret)
{
CHECK_CONN(client);
if (args->maxCells > REMOTE_NODE_MAX_CELLS) {
remoteDispatchError (client, req,
"%s", _("maxCells > REMOTE_NODE_MAX_CELLS"));
return -2;
}
/* Allocate return buffer. */
ret->freeMems.freeMems_val = calloc (args->maxCells, sizeof (*(ret->freeMems.freeMems_val)));
ret->freeMems.freeMems_len = virNodeGetCellsFreeMemory(client->conn,
(unsigned long long *)ret->freeMems.freeMems_val,
args->startCell,
args->maxCells);
if (ret->freeMems.freeMems_len == 0)
return -1;
return 0;
}
static int
remoteDispatchNodeGetFreeMemory (struct qemud_server *server ATTRIBUTE_UNUSED,
struct qemud_client *client,
remote_message_header *req,
void *args ATTRIBUTE_UNUSED,
remote_node_get_free_memory_ret *ret)
{
unsigned long long freeMem;
CHECK_CONN(client);
freeMem = virNodeGetFreeMemory(client->conn);
if (freeMem == 0) return -1;
ret->freeMem = freeMem;
return 0;
}
static int
remoteDispatchDomainGetSchedulerType (struct qemud_server *server ATTRIBUTE_UNUSED,
struct qemud_client *client,
......
......@@ -98,6 +98,8 @@ remote_domain_save_args lv_remote_domain_save_args;
remote_domain_migrate_prepare_args lv_remote_domain_migrate_prepare_args;
remote_domain_migrate_prepare_ret lv_remote_domain_migrate_prepare_ret;
remote_domain_undefine_args lv_remote_domain_undefine_args;
remote_node_get_cells_free_memory_args lv_remote_node_get_cells_free_memory_args;
remote_node_get_cells_free_memory_ret lv_remote_node_get_cells_free_memory_ret;
remote_domain_get_scheduler_type_args lv_remote_domain_get_scheduler_type_args;
remote_domain_get_scheduler_type_ret lv_remote_domain_get_scheduler_type_ret;
remote_get_version_ret lv_remote_get_version_ret;
......@@ -122,6 +124,7 @@ remote_storage_pool_undefine_args lv_remote_storage_pool_undefine_args;
remote_domain_set_autostart_args lv_remote_domain_set_autostart_args;
remote_storage_pool_get_autostart_args lv_remote_storage_pool_get_autostart_args;
remote_storage_pool_get_autostart_ret lv_remote_storage_pool_get_autostart_ret;
remote_node_get_free_memory_ret lv_remote_node_get_free_memory_ret;
remote_storage_vol_get_path_args lv_remote_storage_vol_get_path_args;
remote_storage_vol_get_path_ret lv_remote_storage_vol_get_path_ret;
remote_domain_lookup_by_id_args lv_remote_domain_lookup_by_id_args;
......
......@@ -491,6 +491,21 @@ case REMOTE_PROC_NETWORK_UNDEFINE:
args = (char *) &lv_remote_network_undefine_args;
memset (&lv_remote_network_undefine_args, 0, sizeof lv_remote_network_undefine_args);
break;
case REMOTE_PROC_NODE_GET_CELLS_FREE_MEMORY:
fn = (dispatch_fn) remoteDispatchNodeGetCellsFreeMemory;
args_filter = (xdrproc_t) xdr_remote_node_get_cells_free_memory_args;
args = (char *) &lv_remote_node_get_cells_free_memory_args;
memset (&lv_remote_node_get_cells_free_memory_args, 0, sizeof lv_remote_node_get_cells_free_memory_args);
ret_filter = (xdrproc_t) xdr_remote_node_get_cells_free_memory_ret;
ret = (char *) &lv_remote_node_get_cells_free_memory_ret;
memset (&lv_remote_node_get_cells_free_memory_ret, 0, sizeof lv_remote_node_get_cells_free_memory_ret);
break;
case REMOTE_PROC_NODE_GET_FREE_MEMORY:
fn = (dispatch_fn) remoteDispatchNodeGetFreeMemory;
ret_filter = (xdrproc_t) xdr_remote_node_get_free_memory_ret;
ret = (char *) &lv_remote_node_get_free_memory_ret;
memset (&lv_remote_node_get_free_memory_ret, 0, sizeof lv_remote_node_get_free_memory_ret);
break;
case REMOTE_PROC_NODE_GET_INFO:
fn = (dispatch_fn) remoteDispatchNodeGetInfo;
ret_filter = (xdrproc_t) xdr_remote_node_get_info_ret;
......
......@@ -67,6 +67,8 @@ static int remoteDispatchNetworkLookupByName (struct qemud_server *server, struc
static int remoteDispatchNetworkLookupByUuid (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_network_lookup_by_uuid_args *args, remote_network_lookup_by_uuid_ret *ret);
static int remoteDispatchNetworkSetAutostart (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_network_set_autostart_args *args, void *ret);
static int remoteDispatchNetworkUndefine (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_network_undefine_args *args, void *ret);
static int remoteDispatchNodeGetCellsFreeMemory (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, remote_node_get_cells_free_memory_args *args, remote_node_get_cells_free_memory_ret *ret);
static int remoteDispatchNodeGetFreeMemory (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_node_get_free_memory_ret *ret);
static int remoteDispatchNodeGetInfo (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_node_get_info_ret *ret);
static int remoteDispatchNumOfDefinedDomains (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_num_of_defined_domains_ret *ret);
static int remoteDispatchNumOfDefinedNetworks (struct qemud_server *server, struct qemud_client *client, remote_message_header *req, void *args, remote_num_of_defined_networks_ret *ret);
......
......@@ -84,8 +84,8 @@ if ($opt_d) {
my @keys = sort (keys %calls);
foreach (@keys) {
print "$_:\n";
print "\tname $calls{$_}->{name} ($calls{$_}->{ProcName})\n";
print "\t$calls{$_}->{args} -> $calls{$_}->{ret}\n";
print " name $calls{$_}->{name} ($calls{$_}->{ProcName})\n";
print " $calls{$_}->{args} -> $calls{$_}->{ret}\n";
}
}
......@@ -117,18 +117,18 @@ elsif ($opt_w) {
my @keys = sort (keys %calls);
foreach (@keys) {
print "case REMOTE_PROC_$calls{$_}->{UC_NAME}:\n";
print "\tfn = (dispatch_fn) remoteDispatch$calls{$_}->{ProcName};\n";
print " fn = (dispatch_fn) remoteDispatch$calls{$_}->{ProcName};\n";
if ($calls{$_}->{args} ne "void") {
print "\targs_filter = (xdrproc_t) xdr_$calls{$_}->{args};\n";
print "\targs = (char *) &lv_$calls{$_}->{args};\n";
print "\tmemset (&lv_$calls{$_}->{args}, 0, sizeof lv_$calls{$_}->{args});\n"
print " args_filter = (xdrproc_t) xdr_$calls{$_}->{args};\n";
print " args = (char *) &lv_$calls{$_}->{args};\n";
print " memset (&lv_$calls{$_}->{args}, 0, sizeof lv_$calls{$_}->{args});\n"
}
if ($calls{$_}->{ret} ne "void") {
print "\tret_filter = (xdrproc_t) xdr_$calls{$_}->{ret};\n";
print "\tret = (char *) &lv_$calls{$_}->{ret};\n";
print "\tmemset (&lv_$calls{$_}->{ret}, 0, sizeof lv_$calls{$_}->{ret});\n"
print " ret_filter = (xdrproc_t) xdr_$calls{$_}->{ret};\n";
print " ret = (char *) &lv_$calls{$_}->{ret};\n";
print " memset (&lv_$calls{$_}->{ret}, 0, sizeof lv_$calls{$_}->{ret});\n"
}
print "\tbreak;\n";
print " break;\n";
}
}
......
......@@ -386,6 +386,36 @@ xdr_remote_get_capabilities_ret (XDR *xdrs, remote_get_capabilities_ret *objp)
return TRUE;
}
bool_t
xdr_remote_node_get_cells_free_memory_args (XDR *xdrs, remote_node_get_cells_free_memory_args *objp)
{
if (!xdr_int (xdrs, &objp->startCell))
return FALSE;
if (!xdr_int (xdrs, &objp->maxCells))
return FALSE;
return TRUE;
}
bool_t
xdr_remote_node_get_cells_free_memory_ret (XDR *xdrs, remote_node_get_cells_free_memory_ret *objp)
{
if (!xdr_array (xdrs, (char **)&objp->freeMems.freeMems_val, (u_int *) &objp->freeMems.freeMems_len, REMOTE_NODE_MAX_CELLS,
sizeof (quad_t), (xdrproc_t) xdr_quad_t))
return FALSE;
return TRUE;
}
bool_t
xdr_remote_node_get_free_memory_ret (XDR *xdrs, remote_node_get_free_memory_ret *objp)
{
if (!xdr_quad_t (xdrs, &objp->freeMem))
return FALSE;
return TRUE;
}
bool_t
xdr_remote_domain_get_scheduler_type_args (XDR *xdrs, remote_domain_get_scheduler_type_args *objp)
{
......
......@@ -30,6 +30,7 @@ typedef remote_nonnull_string *remote_string;
#define REMOTE_STORAGE_POOL_NAME_LIST_MAX 256
#define REMOTE_STORAGE_VOL_NAME_LIST_MAX 1024
#define REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX 16
#define REMOTE_NODE_MAX_CELLS 1024
#define REMOTE_AUTH_SASL_DATA_MAX 65536
#define REMOTE_AUTH_TYPE_LIST_MAX 20
......@@ -176,6 +177,25 @@ struct remote_get_capabilities_ret {
};
typedef struct remote_get_capabilities_ret remote_get_capabilities_ret;
struct remote_node_get_cells_free_memory_args {
int startCell;
int maxCells;
};
typedef struct remote_node_get_cells_free_memory_args remote_node_get_cells_free_memory_args;
struct remote_node_get_cells_free_memory_ret {
struct {
u_int freeMems_len;
quad_t *freeMems_val;
} freeMems;
};
typedef struct remote_node_get_cells_free_memory_ret remote_node_get_cells_free_memory_ret;
struct remote_node_get_free_memory_ret {
quad_t freeMem;
};
typedef struct remote_node_get_free_memory_ret remote_node_get_free_memory_ret;
struct remote_domain_get_scheduler_type_args {
remote_nonnull_domain dom;
};
......@@ -1116,6 +1136,8 @@ enum remote_procedure {
REMOTE_PROC_STORAGE_VOL_GET_INFO = 98,
REMOTE_PROC_STORAGE_VOL_DUMP_XML = 99,
REMOTE_PROC_STORAGE_VOL_GET_PATH = 100,
REMOTE_PROC_NODE_GET_CELLS_FREE_MEMORY = 101,
REMOTE_PROC_NODE_GET_FREE_MEMORY = 102,
};
typedef enum remote_procedure remote_procedure;
......@@ -1172,6 +1194,9 @@ extern bool_t xdr_remote_get_max_vcpus_args (XDR *, remote_get_max_vcpus_args*)
extern bool_t xdr_remote_get_max_vcpus_ret (XDR *, remote_get_max_vcpus_ret*);
extern bool_t xdr_remote_node_get_info_ret (XDR *, remote_node_get_info_ret*);
extern bool_t xdr_remote_get_capabilities_ret (XDR *, remote_get_capabilities_ret*);
extern bool_t xdr_remote_node_get_cells_free_memory_args (XDR *, remote_node_get_cells_free_memory_args*);
extern bool_t xdr_remote_node_get_cells_free_memory_ret (XDR *, remote_node_get_cells_free_memory_ret*);
extern bool_t xdr_remote_node_get_free_memory_ret (XDR *, remote_node_get_free_memory_ret*);
extern bool_t xdr_remote_domain_get_scheduler_type_args (XDR *, remote_domain_get_scheduler_type_args*);
extern bool_t xdr_remote_domain_get_scheduler_type_ret (XDR *, remote_domain_get_scheduler_type_ret*);
extern bool_t xdr_remote_domain_get_scheduler_parameters_args (XDR *, remote_domain_get_scheduler_parameters_args*);
......@@ -1344,6 +1369,9 @@ extern bool_t xdr_remote_get_max_vcpus_args ();
extern bool_t xdr_remote_get_max_vcpus_ret ();
extern bool_t xdr_remote_node_get_info_ret ();
extern bool_t xdr_remote_get_capabilities_ret ();
extern bool_t xdr_remote_node_get_cells_free_memory_args ();
extern bool_t xdr_remote_node_get_cells_free_memory_ret ();
extern bool_t xdr_remote_node_get_free_memory_ret ();
extern bool_t xdr_remote_domain_get_scheduler_type_args ();
extern bool_t xdr_remote_domain_get_scheduler_type_ret ();
extern bool_t xdr_remote_domain_get_scheduler_parameters_args ();
......
......@@ -87,6 +87,9 @@ const REMOTE_STORAGE_VOL_NAME_LIST_MAX = 1024;
/* Upper limit on list of scheduler parameters. */
const REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX = 16;
/* Upper limit on number of NUMA cells */
const REMOTE_NODE_MAX_CELLS = 1024;
/* Upper limit on SASL auth negotiation packet */
const REMOTE_AUTH_SASL_DATA_MAX = 65536;
......@@ -254,6 +257,19 @@ struct remote_get_capabilities_ret {
remote_nonnull_string capabilities;
};
struct remote_node_get_cells_free_memory_args {
int startCell;
int maxCells;
};
struct remote_node_get_cells_free_memory_ret {
hyper freeMems<REMOTE_NODE_MAX_CELLS>;
};
struct remote_node_get_free_memory_ret {
hyper freeMem;
};
struct remote_domain_get_scheduler_type_args {
remote_nonnull_domain dom;
};
......@@ -1017,7 +1033,10 @@ enum remote_procedure {
REMOTE_PROC_STORAGE_VOL_LOOKUP_BY_PATH = 97,
REMOTE_PROC_STORAGE_VOL_GET_INFO = 98,
REMOTE_PROC_STORAGE_VOL_DUMP_XML = 99,
REMOTE_PROC_STORAGE_VOL_GET_PATH = 100
REMOTE_PROC_STORAGE_VOL_GET_PATH = 100,
REMOTE_PROC_NODE_GET_CELLS_FREE_MEMORY = 101,
REMOTE_PROC_NODE_GET_FREE_MEMORY = 102
};
/* Custom RPC structure. */
......
......@@ -24,6 +24,8 @@ while (<>) {
next;
}
s/\t/ /g;
if (m/^}/) {
$in_function = 0;
......@@ -52,7 +54,7 @@ while (<>) {
foreach (keys %uses) {
$i = $uses{$_};
unshift @function,
("\tchar **objp_cpp$i = (char **) (void *) &$_;\n");
(" char **objp_cpp$i = (char **) (void *) &$_;\n");
$i++;
}
@function =
......
......@@ -1328,6 +1328,58 @@ remoteGetCapabilities (virConnectPtr conn)
return ret.capabilities;
}
static int
remoteNodeGetCellsFreeMemory(virConnectPtr conn,
unsigned long long *freeMems,
int startCell,
int maxCells)
{
remote_node_get_cells_free_memory_args args;
remote_node_get_cells_free_memory_ret ret;
int i;
GET_PRIVATE (conn, -1);
if (maxCells > REMOTE_NODE_MAX_CELLS) {
errorf (conn, VIR_ERR_RPC,
_("too many NUMA cells: %d > %d"),
maxCells,
REMOTE_NODE_MAX_CELLS);
return -1;
}
args.startCell = startCell;
args.maxCells = maxCells;
memset (&ret, 0, sizeof ret);
if (call (conn, priv, 0, REMOTE_PROC_NODE_GET_CELLS_FREE_MEMORY,
(xdrproc_t) xdr_remote_node_get_cells_free_memory_args, (char *)&args,
(xdrproc_t) xdr_remote_node_get_cells_free_memory_ret, (char *)&ret) == -1)
return -1;
for (i = 0 ; i < ret.freeMems.freeMems_len ; i++)
freeMems[i] = ret.freeMems.freeMems_val[i];
xdr_free((xdrproc_t) xdr_remote_node_get_cells_free_memory_ret, (char *) &ret);
return ret.freeMems.freeMems_len;
}
static unsigned long long
remoteNodeGetFreeMemory (virConnectPtr conn)
{
remote_node_get_free_memory_ret ret;
GET_PRIVATE (conn, -1);
memset (&ret, 0, sizeof ret);
if (call (conn, priv, 0, REMOTE_PROC_NODE_GET_FREE_MEMORY,
(xdrproc_t) xdr_void, NULL,
(xdrproc_t) xdr_remote_node_get_free_memory_ret, (char *)&ret) == -1)
return 0;
return ret.freeMem;
}
static int
remoteListDomains (virConnectPtr conn, int *ids, int maxids)
{
......@@ -4732,7 +4784,8 @@ static virDriver driver = {
.domainMigrateFinish = remoteDomainMigrateFinish,
.domainBlockStats = remoteDomainBlockStats,
.domainInterfaceStats = remoteDomainInterfaceStats,
.nodeGetCellsFreeMemory = NULL,
.nodeGetCellsFreeMemory = remoteNodeGetCellsFreeMemory,
.getFreeMemory = remoteNodeGetFreeMemory,
};
static virNetworkDriver network_driver = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册