On Fri, Dec 11, 2009 at 03:26:15PM -0500, Adam Litke wrote:
Use a dynamically sized xdr_array to pass memory stats on the wire.
This
supports the addition of future memory stats and reduces the message size since
only supported statistics are returned.
+ /* Allocate return buffer. We need 2 slots per stat: the tag and value. */
+ if (VIR_ALLOC_N(ret->stats.stats_val, nr_stats * 2) < 0) {
+ VIR_FREE(stats);
+ remoteDispatchOOMError(rerr);
+ return -1;
+ }
+
+ /* Copy the stats into the xdr return structure */
+ for (i = 0; i < nr_stats; i++) {
+ ret->stats.stats_val[2 * i] = (uint64_t) stats[i].tag;
+ ret->stats.stats_val[2 * i + 1] = stats[i].val;
+ }
+ ret->stats.stats_len = nr_stats * 2;
This is a slightly wierd way to encode the data on the wire. The
wire format ought to follow the public API struct format, rather
than packing both values into a single array.
+struct remote_domain_memory_stats_args {
+ remote_nonnull_domain dom;
+ u_int maxStats;
+};
+typedef struct remote_domain_memory_stats_args remote_domain_memory_stats_args;
+
+struct remote_domain_memory_stats_ret {
+ struct {
+ u_int stats_len;
+ uint64_t *stats_val;
+ } stats;
+};
XDR has a native array type which automatically tracks length. Also
for portability to OS-X/Solaris we avoid uint64_t and use hyper
instead for 64bit data.
The return value structure should thus look like this:
const REMOTE_DOMAIN_MEMORY_STATS_MAX = 1024;
struct remote_domain_memory_stat {
int tag;
unsigned hyper val;
};
struct remote_domain_memory_stats_ret {
remote_domain_memory_stat<REMOTE_DOMAIN_MEMORY_STATS_MAX>;
};
NB, the MAX constant there should not be fixed to the public API
max. This is just a wire protocol decoder limit to avoid DOS on
large arrays.
Regards,
Daniel
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|