tools/xl: add xl commands for xenstore quota operations

Add "xl xenstore-quota-get" and "xl xenstore-quota-set" commands for
retrieving and setting global and per-domain Xenstore quota.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>
This commit is contained in:
Juergen Gross authored and Anthony PERARD committed 2026-03-27 12:06:37 +01:00
1 parent a6f159f92c
commit ad860c6454
6 files changed
+132

No files matched your search

+1
View File
@@ -24,6 +24,7 @@ XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o
XL_OBJS += xl_info.o xl_console.o xl_misc.o
XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o
XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o
XL_OBJS += xl_xsquota.o
$(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
$(XL_OBJS): CFLAGS += $(CFLAGS_XL)
+2
View File
@@ -217,6 +217,8 @@ int main_psr_mba_set(int argc, char **argv);
int main_psr_mba_show(int argc, char **argv);
#endif
int main_qemu_monitor_command(int argc, char **argv);
int main_xsquota_get(int argc, char **argv);
int main_xsquota_set(int argc, char **argv);
void help(const char *command);
+10
View File
@@ -649,6 +649,16 @@ const struct cmd_spec cmd_table[] = {
"-h print this help\n"
},
#endif
{ "xenstore-quota-get",
&main_xsquota_get, 0, 0,
"List global or domain specific Xenstore quotas",
"<Domain>|-g",
},
{ "xenstore-quota-set",
&main_xsquota_set, 0, 1,
"Set global or domain specific Xenstore quotas",
"<Domain>|-g <quota>=<val>...",
},
};
const int cmdtable_len = ARRAY_SIZE(cmd_table);
+28
View File
@@ -1314,6 +1314,34 @@ out:
return ret;
}
int parse_xsquota_item(const char *buf, struct libxl_xs_quota_item *item)
{
const char *eq;
char *endptr;
unsigned long val;
eq = strchr(buf, '=');
if (!eq) {
fprintf(stderr, "Quota specification \"%s\" lacks \"=\".\n", buf);
return ERROR_INVAL;
}
errno = 0;
item->name = strndup(buf, eq - buf);
if (!item->name)
return ERROR_NOMEM;
val = strtoul(eq + 1, &endptr, 0);
if (errno || !eq[1] || *endptr || (unsigned int)val != val) {
fprintf(stderr,
"Quota specification \"%s\" uses illegal value \"%s\".\n",
buf, eq + 1);
return ERROR_INVAL;
}
item->val = val;
return 0;
}
void parse_config_data(const char *config_source,
const char *config_data,
int config_len,
+1
View File
@@ -36,6 +36,7 @@ int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token);
int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token);
int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec);
int parse_vkb_config(libxl_device_vkb *vkb, char *token);
int parse_xsquota_item(const char *buf, struct libxl_xs_quota_item *item);
int match_option_size(const char *prefix, size_t len,
char *arg, char **argopt);
+90
View File
@@ -0,0 +1,90 @@
/* SPDX-License-Identifier: LGPL-2.1-only */
#include <stdio.h>
#include <stdlib.h>
#include <libxl.h>
#include <libxlutil.h>
#include "xl.h"
#include "xl_utils.h"
#include "xl_parse.h"
int main_xsquota_get(int argc, char **argv)
{
libxl_xs_quota_list q;
unsigned int i;
int rc;
if (argc != 2) {
fprintf(stderr, "Domain or \"-g\" must be specified.\n");
return EXIT_FAILURE;
}
libxl_xs_quota_list_init(&q);
if (!strcmp(argv[1], "-g")) {
rc = libxl_xs_quota_global_get(ctx, &q);
} else {
uint32_t domid = find_domain(argv[1]);
rc = libxl_xs_quota_domain_get(ctx, domid, &q);
}
if (rc) {
libxl_xs_quota_list_dispose(&q);
fprintf(stderr, "Quota could not be obtained.\n");
return EXIT_FAILURE;
}
printf("Quota name Quota value\n");
printf("--------------------------------\n");
for (i = 0; i < q.num_quota; i++)
printf("%-20s %8u\n", q.quota[i].name, q.quota[i].val);
libxl_xs_quota_list_dispose(&q);
return EXIT_SUCCESS;
}
int main_xsquota_set(int argc, char **argv)
{
unsigned int i;
libxl_xs_quota_list q;
int rc = EXIT_FAILURE;
if (argc < 3) {
fprintf(stderr, "Not enough parameters.\n");
help("xenstore-quota-set");
return EXIT_FAILURE;
}
libxl_xs_quota_list_init(&q);
q.num_quota = argc - 2;
q.quota = xcalloc(q.num_quota, sizeof(*q.quota));
for (i = 2; i < argc; i++) {
if (parse_xsquota_item(argv[i], q.quota + i - 2))
goto err;
}
if (!strcmp(argv[1], "-g")) {
rc = libxl_xs_quota_global_set(ctx, &q);
} else {
uint32_t domid = find_domain(argv[1]);
rc = libxl_xs_quota_domain_set(ctx, domid, &q);
}
if (rc) {
fprintf(stderr, "Quota could not be set.\n");
rc = EXIT_FAILURE;
} else {
rc = EXIT_SUCCESS;
}
err:
libxl_xs_quota_list_dispose(&q);
return rc;
}
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.