From 5c8dedddcc30baaac0cf6db6f682d539c352d938 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 7 Feb 2011 15:04:17 -0700 Subject: [PATCH] sysinfo: implement the remote protocol Done by editing the first three files, then running 'make -C src rpcgen', then editing src/remote_protocol-structs to match. * daemon/remote.c (remoteDispatchGetSysinfo): New function. * src/remote/remote_driver.c (remoteGetSysinfo, remote_driver): Client side serialization. * src/remote/remote_protocol.x (remote_get_sysinfo_args) (remote_get_sysinfo_ret): New types. (REMOTE_PROC_GET_SYSINFO): New enum value. * daemon/remote_dispatch_args.h: Regenerate. * daemon/remote_dispatch_prototypes.h: Likewise. * daemon/remote_dispatch_ret.h: Likewise. * daemon/remote_dispatch_table.h: Likewise. * src/remote/remote_protocol.c: Likewise. * src/remote/remote_protocol.h: Likewise. * src/remote_protocol-structs: Likewise. --- daemon/remote.c | 25 ++++++++++++++++++++++++- daemon/remote_dispatch_args.h | 1 + daemon/remote_dispatch_prototypes.h | 8 ++++++++ daemon/remote_dispatch_ret.h | 1 + daemon/remote_dispatch_table.h | 5 +++++ src/remote/remote_driver.c | 27 ++++++++++++++++++++++++++- src/remote/remote_protocol.c | 18 ++++++++++++++++++ src/remote/remote_protocol.h | 15 +++++++++++++++ src/remote/remote_protocol.x | 13 +++++++++++-- src/remote_protocol-structs | 6 ++++++ 10 files changed, 115 insertions(+), 4 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index aa6a1a42c0..de45ff9e1b 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1,7 +1,7 @@ /* * remote.c: handlers for RPC method calls * - * Copyright (C) 2007-2010 Red Hat, Inc. + * Copyright (C) 2007-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -584,6 +584,29 @@ remoteDispatchGetUri (struct qemud_server *server ATTRIBUTE_UNUSED, return 0; } +static int +remoteDispatchGetSysinfo (struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *rerr, + remote_get_sysinfo_args *args, + remote_get_sysinfo_ret *ret) +{ + unsigned int flags; + char *sysinfo; + + flags = args->flags; + sysinfo = virConnectGetSysinfo (conn, flags); + if (sysinfo == NULL) { + remoteDispatchConnError(rerr, conn); + return -1; + } + + ret->sysinfo = sysinfo; + return 0; +} + static int remoteDispatchGetMaxVcpus (struct qemud_server *server ATTRIBUTE_UNUSED, struct qemud_client *client ATTRIBUTE_UNUSED, diff --git a/daemon/remote_dispatch_args.h b/daemon/remote_dispatch_args.h index 221af88d9b..57962d10db 100644 --- a/daemon/remote_dispatch_args.h +++ b/daemon/remote_dispatch_args.h @@ -171,3 +171,4 @@ remote_domain_get_vcpus_flags_args val_remote_domain_get_vcpus_flags_args; remote_domain_open_console_args val_remote_domain_open_console_args; remote_domain_is_updated_args val_remote_domain_is_updated_args; + remote_get_sysinfo_args val_remote_get_sysinfo_args; diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h index 4a5246f28a..e59701ac7d 100644 --- a/daemon/remote_dispatch_prototypes.h +++ b/daemon/remote_dispatch_prototypes.h @@ -730,6 +730,14 @@ static int remoteDispatchGetMaxVcpus( remote_error *err, remote_get_max_vcpus_args *args, remote_get_max_vcpus_ret *ret); +static int remoteDispatchGetSysinfo( + struct qemud_server *server, + struct qemud_client *client, + virConnectPtr conn, + remote_message_header *hdr, + remote_error *err, + remote_get_sysinfo_args *args, + remote_get_sysinfo_ret *ret); static int remoteDispatchGetType( struct qemud_server *server, struct qemud_client *client, diff --git a/daemon/remote_dispatch_ret.h b/daemon/remote_dispatch_ret.h index c01f3ba34f..78e54694f5 100644 --- a/daemon/remote_dispatch_ret.h +++ b/daemon/remote_dispatch_ret.h @@ -138,3 +138,4 @@ remote_domain_get_memory_parameters_ret val_remote_domain_get_memory_parameters_ret; remote_domain_get_vcpus_flags_ret val_remote_domain_get_vcpus_flags_ret; remote_domain_is_updated_ret val_remote_domain_is_updated_ret; + remote_get_sysinfo_ret val_remote_get_sysinfo_ret; diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h index 3e55424f56..5d27390729 100644 --- a/daemon/remote_dispatch_table.h +++ b/daemon/remote_dispatch_table.h @@ -1017,3 +1017,8 @@ .args_filter = (xdrproc_t) xdr_remote_domain_is_updated_args, .ret_filter = (xdrproc_t) xdr_remote_domain_is_updated_ret, }, +{ /* GetSysinfo => 203 */ + .fn = (dispatch_fn) remoteDispatchGetSysinfo, + .args_filter = (xdrproc_t) xdr_remote_get_sysinfo_args, + .ret_filter = (xdrproc_t) xdr_remote_get_sysinfo_ret, +}, diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 1d9209d7f1..c33a930464 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1748,6 +1748,31 @@ done: return rv; } +static char * +remoteGetSysinfo (virConnectPtr conn, unsigned int flags) +{ + char *rv = NULL; + remote_get_sysinfo_args args; + remote_get_sysinfo_ret ret; + struct private_data *priv = conn->privateData; + + remoteDriverLock(priv); + + memset (&ret, 0, sizeof ret); + args.flags = flags; + if (call (conn, priv, 0, REMOTE_PROC_GET_SYSINFO, + (xdrproc_t) xdr_remote_get_sysinfo_args, (char *) &args, + (xdrproc_t) xdr_remote_get_sysinfo_ret, (char *) &ret) == -1) + goto done; + + /* Caller frees this. */ + rv = ret.sysinfo; + +done: + remoteDriverUnlock(priv); + return rv; +} + static int remoteIsSecure(virConnectPtr conn) { int rv = -1; @@ -10823,7 +10848,7 @@ static virDriver remote_driver = { remoteGetVersion, /* version */ remoteGetLibVersion, /* libvirtVersion */ remoteGetHostname, /* getHostname */ - NULL, /* getSysinfo */ + remoteGetSysinfo, /* getSysinfo */ remoteGetMaxVcpus, /* getMaxVcpus */ remoteNodeGetInfo, /* nodeGetInfo */ remoteGetCapabilities, /* getCapabilities */ diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c index 6e07b70cbe..bae92ca2c4 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -419,6 +419,24 @@ xdr_remote_get_hostname_ret (XDR *xdrs, remote_get_hostname_ret *objp) return TRUE; } +bool_t +xdr_remote_get_sysinfo_args (XDR *xdrs, remote_get_sysinfo_args *objp) +{ + + if (!xdr_u_int (xdrs, &objp->flags)) + return FALSE; + return TRUE; +} + +bool_t +xdr_remote_get_sysinfo_ret (XDR *xdrs, remote_get_sysinfo_ret *objp) +{ + + if (!xdr_remote_nonnull_string (xdrs, &objp->sysinfo)) + return FALSE; + return TRUE; +} + bool_t xdr_remote_get_uri_ret (XDR *xdrs, remote_get_uri_ret *objp) { diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h index 4240963ca6..46d526a6a2 100644 --- a/src/remote/remote_protocol.h +++ b/src/remote/remote_protocol.h @@ -242,6 +242,16 @@ struct remote_get_hostname_ret { }; typedef struct remote_get_hostname_ret remote_get_hostname_ret; +struct remote_get_sysinfo_args { + u_int flags; +}; +typedef struct remote_get_sysinfo_args remote_get_sysinfo_args; + +struct remote_get_sysinfo_ret { + remote_nonnull_string sysinfo; +}; +typedef struct remote_get_sysinfo_ret remote_get_sysinfo_ret; + struct remote_get_uri_ret { remote_nonnull_string uri; }; @@ -2320,6 +2330,7 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_VCPUS_FLAGS = 200, REMOTE_PROC_DOMAIN_OPEN_CONSOLE = 201, REMOTE_PROC_DOMAIN_IS_UPDATED = 202, + REMOTE_PROC_GET_SYSINFO = 203, }; typedef enum remote_procedure remote_procedure; @@ -2384,6 +2395,8 @@ extern bool_t xdr_remote_get_type_ret (XDR *, remote_get_type_ret*); extern bool_t xdr_remote_get_version_ret (XDR *, remote_get_version_ret*); extern bool_t xdr_remote_get_lib_version_ret (XDR *, remote_get_lib_version_ret*); extern bool_t xdr_remote_get_hostname_ret (XDR *, remote_get_hostname_ret*); +extern bool_t xdr_remote_get_sysinfo_args (XDR *, remote_get_sysinfo_args*); +extern bool_t xdr_remote_get_sysinfo_ret (XDR *, remote_get_sysinfo_ret*); extern bool_t xdr_remote_get_uri_ret (XDR *, remote_get_uri_ret*); 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*); @@ -2730,6 +2743,8 @@ extern bool_t xdr_remote_get_type_ret (); extern bool_t xdr_remote_get_version_ret (); extern bool_t xdr_remote_get_lib_version_ret (); extern bool_t xdr_remote_get_hostname_ret (); +extern bool_t xdr_remote_get_sysinfo_args (); +extern bool_t xdr_remote_get_sysinfo_ret (); extern bool_t xdr_remote_get_uri_ret (); extern bool_t xdr_remote_get_max_vcpus_args (); extern bool_t xdr_remote_get_max_vcpus_ret (); diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index e1981fd8bb..e77aca1243 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3,7 +3,7 @@ * remote_internal driver and libvirtd. This protocol is * internal and may change at any time. * - * Copyright (C) 2006-2010 Red Hat, Inc. + * Copyright (C) 2006-2011 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -379,6 +379,14 @@ struct remote_get_hostname_ret { remote_nonnull_string hostname; }; +struct remote_get_sysinfo_args { + unsigned int flags; +}; + +struct remote_get_sysinfo_ret { + remote_nonnull_string sysinfo; +}; + struct remote_get_uri_ret { remote_nonnull_string uri; }; @@ -2094,7 +2102,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_VCPUS_FLAGS = 200, REMOTE_PROC_DOMAIN_OPEN_CONSOLE = 201, - REMOTE_PROC_DOMAIN_IS_UPDATED = 202 + REMOTE_PROC_DOMAIN_IS_UPDATED = 202, + REMOTE_PROC_GET_SYSINFO = 203 /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 7ca968f031..6a7f03d746 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -107,6 +107,12 @@ struct remote_get_lib_version_ret { struct remote_get_hostname_ret { remote_nonnull_string hostname; }; +struct remote_get_sysinfo_args { + u_int flags; +}; +struct remote_get_sysinfo_ret { + remote_nonnull_string sysinfo; +}; struct remote_get_uri_ret { remote_nonnull_string uri; };