libxl: base libxl_list_vm() on libxl_list_domain()

libxl_list_vm() is calling xc_domain_getinfolist() today with a limit
of 1024 domains. To avoid open coding a loop around
xc_domain_getinfolist() to avoid the 1024 domain limit just use
libxl_list_domain() instead.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Juergen Gross authored and Ian Campbell committed 2016-01-15 15:35:26 +00:00
1 parent ff1301576e
commit b4637669c4
1 file changed
+10 -11
+10 -11
View File
@@ -799,32 +799,31 @@ out:
libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm_out)
{
GC_INIT(ctx);
libxl_dominfo *info;
libxl_vminfo *ptr = NULL;
int idx, i, ret;
xc_domaininfo_t info[1024];
int idx, i, n_doms;
ret = xc_domain_getinfolist(ctx->xch, 1, ARRAY_SIZE(info), info);
if (ret < 0) {
LOGE(ERROR, "getting domain info list");
info = libxl_list_domain(ctx, &n_doms);
if (!info)
goto out;
}
/*
* Always make sure to allocate at least one element; if we don't and we
* request zero, libxl__calloc (might) think its internal call to calloc
* has failed (if it returns null), if so it would kill our process.
*/
ptr = libxl__calloc(NOGC, ret ? ret : 1, sizeof(libxl_vminfo));
ptr = libxl__calloc(NOGC, n_doms ? n_doms : 1, sizeof(libxl_vminfo));
for (idx = i = 0; i < ret; i++) {
if (libxl_is_stubdom(ctx, info[i].domain, NULL))
for (idx = i = 0; i < n_doms; i++) {
if (libxl_is_stubdom(ctx, info[i].domid, NULL))
continue;
memcpy(&(ptr[idx].uuid), info[i].handle, sizeof(xen_domain_handle_t));
ptr[idx].domid = info[i].domain;
ptr[idx].uuid = info[i].uuid;
ptr[idx].domid = info[i].domid;
idx++;
}
*nb_vm_out = idx;
libxl_dominfo_list_free(info, n_doms);
out:
GC_FREE;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.