tools: add support for per-domain xenstore quota
v2 cover tools: add support for per-domain xenstore quota
This series is adding support for per-domain Xenstore quota to:
- xenstored
- libxenstore
- libxl
- xl
With this it is possible to e.g. allow larger limits for driver domains.
Changes in V2:
- addressed all comments
- new patch 2
Juergen Gross (12):
tools/libs/store: add get- and set-quota related functions tools/xenstored: add helper to parse domid tools/xenstored: add central quota check functions tools/xenstored: rework hard_quotas and soft_quotas arrays tools/xenstored: add GLOBAL_QUOTA_DATA record for live update tools/xenstored: split acc[] array in struct domain tools/xenstored: use per-domain quota settings tools/xenstored: implement the GET/SET_QUOTA commands tools/libxl: add functions for retrieving and setting xenstore quota tools/libxl: add support for xenstore quota in domain_config tools/xl: add xl commands for xenstore quota operations tools/xl: add support for xenstore quota setting via domain config
docs/man/xl.cfg.5.pod.in | 13 + tools/golang/xenlight/helpers.gen.go | 84 +++++ tools/golang/xenlight/types.gen.go | 10 + tools/include/libxl.h | 21 ++ tools/include/xenstore.h | 37 ++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_dom.c | 8 + tools/libs/light/libxl_domain.c | 11 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_xsquota.c | 116 ++++++ tools/libs/store/Makefile | 2 +- tools/libs/store/libxenstore.map | 8 + tools/libs/store/xs.c | 111 ++++++ tools/xenstored/control.c | 24 +- tools/xenstored/core.c | 41 ++- tools/xenstored/domain.c | 519 +++++++++++++++++++++------ tools/xenstored/domain.h | 28 +- tools/xenstored/lu.c | 6 + tools/xenstored/transaction.c | 2 +- tools/xenstored/watch.c | 4 +- tools/xl/Makefile | 1 + tools/xl/xl.h | 2 + tools/xl/xl_cmdtable.c | 10 + tools/xl/xl_parse.c | 47 ++- tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 90 +++++ 26 files changed, 1057 insertions(+), 150 deletions(-) create mode 100644 tools/libs/light/libxl_xsquota.c create mode 100644 tools/xl/xl_xsquota.c
Signature · 1 line
2.53.0
PATCH v2 1/12 tools/libs/store: add get- and set-quota related functions
Add functions for getting and setting Xenstore quota to libxenstore:
xs_get_quota_names(): get the names of the supported quota.
xs_get_global_quota(): get the value of one global quota.
xs_set_global_quota(): set the value of one global quota.
xs_get_domain_quota(): get the value of one quota of a domain.
xs_set_domain_quota(): set the value of one quota of a domain.
---
V2:
- make string parameters const (Anthony Perard)
- add function descriptions to header (Anthony Perard)
--- tools/include/xenstore.h | 37 +++++++++++ tools/libs/store/Makefile | 2 +- tools/libs/store/libxenstore.map | 8 +++ tools/libs/store/xs.c | 111 +++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-)
tools/include/xenstore.h +37 -0
@@ -277,6 +277,43 @@ bool xs_get_features_domain(struct xs_handle *h, unsigned int domid,bool xs_set_features_domain (struct xs_handle *h,unsigned int domid,unsigned int features); +/* Get names of supported quota. +* Returns an array of quota names supported by Xenstore. On return +* num will contain the number of quota names in the array. +* Will return NULL on failure. +* The returned array should be freed via free() after usage, this will +* free the array AND the strings of the quota names. +*/ +const char **xs_get_quota_names (struct xs_handle *h,unsigned int *num); + +/* Get the value of one global quota. +* Returns the global quota value specified by "quota" in "value". +* Return false on failure. +*/ +bool xs_get_global_quota (struct xs_handle *h,const char *quota, +unsigned int *value); + +/* Set the value of one global quota. +* Sets the global quota value specified by "quota" to "value". +* Return false on failure. +*/ +bool xs_set_global_quota (struct xs_handle *h,const char *quota, +unsigned int value); + +/* Get the value of one domain quota. +* Returns a domain's quota value specified by "quota" in "value". +* Return false on failure. +*/ +bool xs_get_domain_quota (struct xs_handle *h,unsigned int domid, +const char *quota,unsigned int *value); + +/* Set the value of one domain quota. +* Sets a domain's quota value specified by "quota" to "value". +* Return false on failure. +*/ +bool xs_set_domain_quota (struct xs_handle *h,unsigned int domid, +const char *quota,unsigned int value); +char *xs_control_command (struct xs_handle *h,const char *cmd,void *data,unsigned int len);/* Deprecated: use xs_control_command() instead. */
tools/libs/store/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT=$(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 4 -MINOR = 1 +MINOR = 2 version-script := libxenstore.map ifeq ($(CONFIG_Linux),y)
tools/libs/store/libxenstore.map +8 -0
@@ -45,3 +45,11 @@ VERS_4.1 { xs_get_features_domain; xs_set_features_domain; } VERS_4.0; +VERS_4.2 { + global: + xs_get_quota_names; + xs_get_global_quota; + xs_set_global_quota; + xs_get_domain_quota; + xs_set_domain_quota; +} VERS_4.1;
tools/libs/store/xs.c +111 -0
117 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 01/12] tools/libs/store: add get- and set-quota related functions
Quoted 6 lines · Juergen Gross
Add functions for getting and setting Xenstore quota to libxenstore:
xs_get_quota_names(): get the names of the supported quota.
xs_get_global_quota(): get the value of one global quota.
Quoted 7 lines
xs_set_global_quota(): set the value of one global quota.
xs_get_domain_quota(): get the value of one quota of a domain.
xs_set_domain_quota(): set the value of one quota of a domain.Signed-off-by Juergen Gross <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 2/12 tools/xenstored: add helper to parse domid
In reply to Juergen GrossToday a domid passed in by a command is parsed using atoi(). This will still "succeed" even with a domid like "x", resulting in "0" to be used instead.
Use a common domid parser instead rejecting everything but integers in the range 0..65535 like specified in docs/misc/xenstore.txt.
---
V2:
- new patch (kind of suggested by Anthony Perard)
--- tools/xenstored/domain.c | 47 +++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-)
tools/xenstored/domain.c +39 -8
@@ -732,6 +732,18 @@ static char *talloc_domain_path(const void *context, unsigned int domid)return talloc_asprintf (context,"/local/domain/%u" , domid); } +/* Parse a domid. Sets errno either to 0 or EINVAL. */ +static unsigned int parse_domid (const char *input) +{ +unsigned long domid; +char *endptr; + + domid =strtoul (input, &endptr,10 ); + errno = (*endptr !=0 || domid >65535 ) ?EINVAL :0 ; + +return domid; +} +int domain_get_quota (const void *ctx,struct connection *conn,unsigned int domid) {
@@ -1077,7 +1089,10 @@ int do_introduce(const void *ctx, struct connection *conn,if (get_strings (in, vec,ARRAY_SIZE (vec)) <ARRAY_SIZE (vec))return EINVAL ; - domid =atoi (vec[0 ]); + domid =parse_domid (vec[0 ]); +if (errno) +return errno; +/* Ignore the gfn, we don't need it. */ port =atoi (vec[2 ]);
@@ -1124,8 +1139,12 @@ int do_set_target(const void *ctx, struct connection *conn,if (get_strings (in, vec,ARRAY_SIZE (vec)) <ARRAY_SIZE (vec))return EINVAL ; - domid =atoi (vec[0 ]); - tdomid =atoi (vec[1 ]); + domid =parse_domid (vec[0 ]); +if (errno) +return errno; + tdomid =parse_domid (vec[1 ]); +if (errno) +return errno; domain =find_connected_domain (domid);if (IS_ERR (domain))
@@ -1152,7 +1171,9 @@ static struct domain *onearg_domain(struct connection *conn,if (!domid_str)return ERR_PTR (-EINVAL ); - domid =atoi (domid_str); + domid =parse_domid (domid_str); +if (errno) +return ERR_PTR (-errno);if (domid == store_domid || domid == priv_domid)return ERR_PTR (-EINVAL );
@@ -1200,11 +1221,15 @@ int do_get_domain_path(const void *ctx, struct connection *conn, {char *path;const char *domid_str =onearg (in); +unsigned int domid;if (!domid_str)return EINVAL ; - path =talloc_domain_path (ctx,atoi (domid_str)); + domid =parse_domid (domid_str); +if (errno) +return errno; + path =talloc_domain_path (ctx, domid);if (!path)return errno;
@@ -1223,7 +1248,9 @@ int do_is_domain_introduced(const void *ctx, struct connection *conn,if (!domid_str)return EINVAL ; - domid =atoi (domid_str); + domid =parse_domid (domid_str); +if (errno) +return errno;if (domid ==DOMID_SELF ) result =1 ;else
@@ -1261,7 +1288,9 @@ int do_get_feature(const void *ctx, struct connection *conn,return EINVAL ;if (n_args ==1 ) { - domid =atoi (vec[0 ]); + domid =parse_domid (vec[0 ]); +if (errno) +return errno; domain =find_or_alloc_existing_domain (domid);if (!domain)return ENOENT ;
@@ -1289,7 +1318,9 @@ int do_set_feature(const void *ctx, struct connection *conn,if (get_strings (in, vec,ARRAY_SIZE (vec)) !=ARRAY_SIZE (vec))return EINVAL ; - domid =atoi (vec[0 ]); + domid =parse_domid (vec[0 ]); +if (errno) +return errno; features =atoi (vec[1 ]); domain =find_or_alloc_existing_domain (domid);if (!domain)
Signature · 1 line
2.53.0
Re: [PATCH v2 02/12] tools/xenstored: add helper to parse domid
Quoted 11 lines · Juergen Gross
Today a domid passed in by a command is parsed using
atoi(). This will still "succeed" even with a domid like "x", resulting in "0" to be used instead.Use a common domid parser instead rejecting everything but integers in the range 0..65535 like specified in
docs/misc/xenstore.txt.Signed-off-by Juergen Gross <[email protected]>---
V2:
- new patch (kind of suggested by Anthony Perard)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 3/12 tools/xenstored: add central quota check functions
In reply to Juergen GrossAdd central functions for checking a value (either an absolute one or the current domain value plus an offset) against a specific quota.
This is in preparation of introducing per-domain quota.
The required changes allow to drop the "update" parameter from domain_nbentry_fix().
While at it, make the returned error for exceeded quota consistent by changing one instance from "E2BIG" to "ENOSPC".
---
V2:
- expand commit message (Anthony Perard)
- rename domain_check_quota_*() to domain_quota_*_exceeds() (Jason Andryuk)
--- tools/xenstored/core.c | 4 +- tools/xenstored/domain.c | 74 +++++++++++++++++------------------ tools/xenstored/domain.h | 6 +-- tools/xenstored/transaction.c | 2 +- tools/xenstored/watch.c | 4 +- 5 files changed, 42 insertions(+), 48 deletions(-)
tools/xenstored/core.c +2 -2
@@ -1539,7 +1539,7 @@ static struct node *create_node(struct connection *conn, const void *ctx,for (i = node; i; i = i->parent) {/* i->parent is set for each new node, so check quota. */ if (i->parent && -domain_nbentry (conn) >= hard_quotas[ACC_NODES ].val) { +domain_quota_add_exceeds (conn->domain,ACC_NODES ,1 )) { ret =ENOSPC ; goto err; }
@@ -2321,7 +2321,7 @@ void setup_structure(bool live_update)manual_node ("/tool/xenstored" ,NULL );manual_node ("@releaseDomain" ,NULL );manual_node ("@introduceDomain" ,NULL ); -domain_nbentry_fix (priv_domid,5 , true); +domain_nbentry_fix (priv_domid,5 ); } }
tools/xenstored/domain.c +35 -39
128 lines not on this page · raw message
tools/xenstored/domain.h +2 -4
@@ -113,8 +113,7 @@ int domain_alloc_permrefs(struct node_perms *perms);/* Quota manipulation */ int domain_nbentry_inc (struct connection *conn,unsigned int domid);int domain_nbentry_dec (struct connection *conn,unsigned int domid); -int domain_nbentry_fix (unsigned int domid,int num,bool update); -unsigned int domain_nbentry (struct connection *conn); +int domain_nbentry_fix (unsigned int domid,int num);int domain_memory_add (struct connection *conn,unsigned int domid,int mem,bool no_quota_check);
@@ -141,12 +140,10 @@ static inline void domain_memory_add_nochk(struct connection *conn, }void domain_watch_inc (struct connection *conn);void domain_watch_dec (struct connection *conn); -int domain_watch (struct connection *conn);void domain_outstanding_inc (struct connection *conn);void domain_outstanding_dec (struct connection *conn,unsigned int domid);void domain_transaction_inc (struct connection *conn);void domain_transaction_dec (struct connection *conn); -unsigned int domain_transaction_get (struct connection *conn);int domain_get_quota (const void *ctx,struct connection *conn,unsigned int domid);
@@ -161,6 +158,7 @@ int domain_max_global_acc(const void *ctx, struct connection *conn);void domain_reset_global_acc (void );bool domain_max_chk (const struct connection *conn,enum accitem what,unsigned int val); +bool domain_quota_add_exceeds (struct domain *d,enum accitem what,int add);extern long wrl_ntransactions;
tools/xenstored/transaction.c +1 -1
@@ -470,7 +470,7 @@ int do_transaction_start(const void *ctx, struct connection *conn,if (conn->transaction)return EBUSY ; -if (domain_transaction_get (conn) > hard_quotas[ACC_TRANS ].val) +if (domain_quota_add_exceeds (conn->domain,ACC_TRANS ,1 ))return ENOSPC ;/* Attach transaction to ctx for autofree until it's complete */
tools/xenstored/watch.c +2 -2
@@ -220,8 +220,8 @@ int do_watch(const void *ctx, struct connection *conn, struct buffered_data *in)return EEXIST ; } -if (domain_watch (conn) > hard_quotas[ACC_WATCH ].val) -return E2BIG ; +if (domain_quota_add_exceeds (conn->domain,ACC_WATCH ,1 )) +return ENOSPC ; watch =add_watch (conn, vec[0 ], vec[1 ], relative, false);if (!watch)
Signature · 1 line
2.53.0
PATCH v2 4/12 tools/xenstored: rework hard_quotas and soft_quotas arrays
In reply to Juergen GrossInstead of having one array for hard quotas and one for soft quotas, split them differently: have one array with the quota names and descriptions, and one with the quota values (soft and hard) and the maximum value so far.
This is in preparation of supporting per-domain quotas, as the layout of the second array elements will be reused in the domain data.
While at it add an accessor for getting a soft quota value, as this will be needed for per-domain quotas, too.
--- tools/xenstored/control.c | 24 ++++++++------- tools/xenstored/core.c | 33 +++++++++++--------- tools/xenstored/domain.c | 65 +++++++++++++++++++++------------------ tools/xenstored/domain.h | 15 +++++---- 4 files changed, 76 insertions(+), 61 deletions(-)
tools/xenstored/control.c +13 -11
@@ -101,7 +101,7 @@ static int do_control_log(const void *ctx, struct connection *conn, }static int quota_show_current (const void *ctx,struct connection *conn, -const struct quota *quotas) +unsigned int idx) {char *resp;unsigned int i;
@@ -111,11 +111,12 @@ static int quota_show_current(const void *ctx, struct connection *conn,return ENOMEM ;for (i =0 ; i <ACC_N ; i++) { -if (!quotas[i].name) +if (!quota_adm[i].name || quotas[i].val[idx] ==Q_VAL_DISABLED )continue ; resp =talloc_asprintf_append (resp,"%-17s: %8d %s\n" , - quotas[i].name, quotas[i].val, - quotas[i].descr); + quota_adm[i].name, + quotas[i].val[idx], + quota_adm[i].descr);if (!resp)return ENOMEM ; }
@@ -126,7 +127,7 @@ static int quota_show_current(const void *ctx, struct connection *conn, }static int quota_set (const void *ctx,struct connection *conn, -const char **vec,int num,struct quota *quotas) +const char **vec,int num,unsigned int idx) {unsigned int i;int val;
@@ -139,8 +140,9 @@ static int quota_set(const void *ctx, struct connection *conn,return EINVAL ;for (i =0 ; i <ACC_N ; i++) { -if (quotas[i].name && !strcmp (vec[0 ], quotas[i].name)) { - quotas[i].val = val; +if (quota_adm[i].name && !strcmp (vec[0 ], quota_adm[i].name) && + quotas[i].val[idx] !=Q_VAL_DISABLED ) { + quotas[i].val[idx] = val;send_ack (conn,XS_CONTROL );return 0 ; }
@@ -178,10 +180,10 @@ static int do_control_quota(const void *ctx, struct connection *conn, const char **vec, int num) { if (num == 0) - return quota_show_current(ctx, conn, hard_quotas); + return quota_show_current(ctx, conn, Q_IDX_HARD);if (!strcmp (vec[0 ],"set" )) -return quota_set (ctx, conn, vec +1 , num -1 , hard_quotas); +return quota_set (ctx, conn, vec +1 , num -1 ,Q_IDX_HARD );if (!strcmp (vec[0 ],"max" ))return quota_max (ctx, conn, vec +1 , num -1 );
@@ -193,10 +195,10 @@ static int do_control_quota_s(const void *ctx, struct connection *conn, const char **vec, int num) { if (num == 0) - return quota_show_current(ctx, conn, soft_quotas); + return quota_show_current(ctx, conn, Q_IDX_SOFT);if (!strcmp (vec[0 ],"set" )) -return quota_set (ctx, conn, vec +1 , num -1 , soft_quotas); +return quota_set (ctx, conn, vec +1 , num -1 ,Q_IDX_SOFT );return EINVAL ; }
tools/xenstored/core.c +19 -14
@@ -2614,10 +2614,9 @@ static void set_timeout(const char *arg)barf ("unknown timeout \"%s\"\n" , arg); } -static void set_quota (const char *arg,bool soft) +static void set_quota (const char *arg,unsigned int idx) {const char *eq =strchr (arg,'=' ); -struct quota *q = soft ? soft_quotas : hard_quotas;unsigned int val;unsigned int i;
@@ -2626,8 +2625,9 @@ static void set_quota(const char *arg, bool soft) val =get_optval_uint (eq +1 );for (i =0 ; i <ACC_N ; i++) { -if (what_matches (arg, q[i].name)) { - q[i].val = val; +if (what_matches (arg, quota_adm[i].name) && + quotas[i].val[idx] !=Q_VAL_DISABLED ) { + quotas[i].val[idx] = val;return ; } }
@@ -2635,6 +2635,11 @@ static void set_quota(const char *arg, bool soft)barf ("unknown quota \"%s\"\n" , arg); } +static void set_one_quota (const char *arg,unsigned int idx,enum accitem what) +{ + quotas[what].val[idx] =get_optval_uint (arg); +} +/* Sorted by bit values of TRACE_* flags. Flag is (1u << index). */ const char *const trace_switches[] = {"obj" ,"io" ,"wrl" ,"acc" ,"tdb" ,
@@ -2688,7 +2693,7 @@ int main(int argc, char *argv[]) options, NULL)) != -1) {switch (opt) {case 'E' : - hard_quotas[ACC_NODES ].val =get_optval_uint (optarg); +set_one_quota (optarg,Q_IDX_HARD ,ACC_NODES );break ;case 'F' : pidfile = optarg;
@@ -2700,10 +2705,10 @@ int main(int argc, char *argv[]) dofork = false;break ;case 'S' : - hard_quotas[ACC_NODESZ ].val =get_optval_uint (optarg); +set_one_quota (optarg,Q_IDX_HARD ,ACC_NODESZ );break ;case 't' : - hard_quotas[ACC_TRANS ].val =get_optval_uint (optarg); +set_one_quota (optarg,Q_IDX_HARD ,ACC_TRANS );break ;case 'T' : tracefile = optarg;
@@ -2716,22 +2721,22 @@ int main(int argc, char *argv[]) keep_orphans = true;break ;case 'W' : - hard_quotas[ACC_WATCH ].val =get_optval_uint (optarg); +set_one_quota (optarg,Q_IDX_HARD ,ACC_WATCH );break ;case 'A' : - hard_quotas[ACC_NPERM ].val =get_optval_uint (optarg); +set_one_quota (optarg,Q_IDX_HARD ,ACC_NPERM );break ;case 'M' : - hard_quotas[ACC_PATHLEN ].val =get_optval_uint (optarg); - hard_quotas[ACC_PATHLEN ].val = +set_one_quota (optarg,Q_IDX_HARD ,ACC_PATHLEN ); + quotas[ACC_PATHLEN ].val[Q_IDX_HARD ] =min ((unsigned int )XENSTORE_REL_PATH_MAX , - hard_quotas[ACC_PATHLEN ].val); + quotas[ACC_PATHLEN ].val[Q_IDX_HARD ]);break ;case 'Q' : -set_quota (optarg, false); +set_quota (optarg,Q_IDX_HARD );break ;case 'q' : -set_quota (optarg, true); +set_quota (optarg,Q_IDX_SOFT );break ;case 'w' :set_timeout (optarg);
tools/xenstored/domain.c +35 -30
166 lines not on this page · raw message
tools/xenstored/domain.h +9 -6
@@ -40,15 +40,18 @@ enum accitem { ACC_N, /* Number of elements per domain. */ }; -struct quota { +extern struct quotaadm {const char *name;const char *descr; -unsigned int val; -unsigned int max; -}; +} quota_adm[ACC_N ]; -extern struct quota hard_quotas[ACC_N ]; -extern struct quota soft_quotas[ACC_N ]; +extern struct quota { +unsigned int val[2 ]; +#define Q_IDX_HARD 0 +#define Q_IDX_SOFT 1 +#define Q_VAL_DISABLED UINT_MAX +unsigned int max; +} quotas[ACC_N ];void handle_event (void );
Signature · 1 line
2.53.0
PATCH v2 5/12 tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
In reply to Juergen GrossCommunicate the global quota settings via the GLOBAL_QUOTA_DATA record to the new Xenstore instance.
This avoids to lose global quota settings done via xenstore-control.
In theory it would be possible to drop any quota related command line parameters in the live update case, but they don't do any harm, as the record data is applied on top of the command line data.
For soft-quota just prepend "soft-" to the quota name.
Use sub-functions for building and analyzing the quota part of the migration stream, as they will be reused for per-domain quotas.
---
V2:
- add macros for soft-quota name prefix and its length (Anthony Perard)
- don't allow disabled quota in parse_quota_name() (Anthony Perard)
- rename "len" to "rec_len" in dump_state_glb_quota() (Anthony Perard)
- rename build_quota_data() parameter "name" to "names_buf" (Anthony Perard)
- let get_quota_size() start with len 0 (Anthony Perard)
--- tools/xenstored/domain.c | 132 +++++++++++++++++++++++++++++++++++++++ tools/xenstored/domain.h | 2 + tools/xenstored/lu.c | 6 ++ 3 files changed, 140 insertions(+)
tools/xenstored/domain.c +132 -0
@@ -107,6 +107,9 @@ struct quota quotas[ACC_N] = { [ACC_NODESZ] = { .val = { 2048, Q_VAL_DISABLED }, }, }; +#define SOFT_PREFIX "soft-" +#define SOFT_PREFIX_LEN (sizeof(SOFT_PREFIX) - 1) +typedef int32_t wrl_creditt ;struct domain
@@ -1363,6 +1366,29 @@ int do_set_feature(const void *ctx, struct connection *conn,return 0 ; } +static bool parse_quota_name (const char *name,unsigned int *qidx, +unsigned int *idx) +{ +unsigned int q; + +if (strncmp (name,SOFT_PREFIX ,SOFT_PREFIX_LEN )) { + *idx =Q_IDX_HARD ; + }else { + *idx =Q_IDX_SOFT ; + name +=SOFT_PREFIX_LEN ; + } +for (q =0 ; q <ACC_N ; q++) { +if (quota_adm[q].name && !strcmp (quota_adm[q].name, name)) { +if (quotas[q].val[*idx] ==Q_VAL_DISABLED ) +return true; + *qidx = q; +return false; + } + } + +return true; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);
@@ -2032,6 +2058,64 @@ void read_state_connection(const void *ctx, const void *state) } } +/* Returns number of quota and adds length of quota names to *len. */ +static unsigned int get_quota_size (struct quota *quota,unsigned int *len) +{ +unsigned int q; +unsigned int n =0 ; + + *len =0 ; +for (q =0 ; q <ACC_N ; q++) { +if (!quota_adm[q].name) +continue ; +if (quota[q].val[Q_IDX_HARD ] !=Q_VAL_DISABLED ) { + n++; + *len +=strlen (quota_adm[q].name) +1 ; + } +if (quota[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + n++; + *len +=strlen (quota_adm[q].name) +SOFT_PREFIX_LEN +1 ; + } + } + +return n; +} + +static void build_quota_data (struct quota *quota,uint32_t *val, +char *names_buf) +{ +unsigned int q; +unsigned int n =0 ; + +for (q =0 ; q <ACC_N ; q++) { +if (!quota_adm[q].name) +continue ; +if (quota[q].val[Q_IDX_HARD ] !=Q_VAL_DISABLED ) { + val[n++] = quota[q].val[Q_IDX_HARD ]; +strcpy (names_buf, quota_adm[q].name); + names_buf +=strlen (names_buf) +1 ; + } +if (quota[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + val[n++] = quota[q].val[Q_IDX_SOFT ]; +strcpy (names_buf,SOFT_PREFIX ); +strcpy (names_buf +SOFT_PREFIX_LEN , quota_adm[q].name); + names_buf +=strlen (names_buf) +1 ; + } + } +} + +static void parse_quota_data (const uint32_t *val,const char *name, +unsigned int n,struct quota *quota) +{ +unsigned int i, q, idx; + +for (i =0 ; i < n; i++) { +if (!parse_quota_name (name, &q, &idx)) + quota[q].val[idx] = val[i]; + name +=strlen (name) +1 ; + } +} +static int dump_state_domain (const void *k,void *v,void *arg) {struct domain *domain = v;
@@ -2080,6 +2164,54 @@ void read_state_domain(const void *ctx, const void *state, unsigned int version) domain->features = sd->features; } +const char *dump_state_glb_quota (FILE *fp) +{ +struct xs_state_record_header *head; +struct xs_state_glb_quota *glb; +void *record; +unsigned int n_quota; +unsigned int rec_len; +size_t ret; + + n_quota =get_quota_size (quotas, &rec_len); + rec_len += n_quota *sizeof (glb->quota_val[0 ]); + rec_len +=sizeof (*glb); + rec_len =ROUNDUP (rec_len,3 ); + + record =talloc_size (NULL , rec_len +sizeof (*head)); +if (!record) +return "Dump global quota allocation error" ; + + head = record; + head->type =XS_STATE_TYPE_GLB_QUOTA ; + head->length = rec_len; + + glb = (struct xs_state_glb_quota *)(head +1 ); + glb->n_dom_quota = n_quota; + glb->n_glob_quota =0 ; + +build_quota_data (quotas, glb->quota_val, + (char *)(glb->quota_val + n_quota)); + + ret =fwrite (record, rec_len +sizeof (*head),1 , fp); + +talloc_free (record); + +if (ret !=1 ||dump_state_align (fp)) +return "Dump global quota error" ; + +return NULL ; +} + +void read_state_glb_quota (const void *ctx,const void *state) +{ +const struct xs_state_glb_quota *glb = state; +unsigned int n_quota = glb->n_dom_quota + glb->n_glob_quota; +const char *name = (const char *)(glb->quota_val + n_quota); + +parse_quota_data (glb->quota_val, name, n_quota, quotas); +} +struct domain_acc {unsigned int domid;int nodes;
tools/xenstored/domain.h +2 -0
@@ -172,10 +172,12 @@ void wrl_apply_debit_trans_commit(struct connection *conn);const char *dump_state_connections (FILE *fp);const char *dump_state_domains (FILE *fp); +const char *dump_state_glb_quota (FILE *fp);void read_state_connection (const void *ctx,const void *state);void read_state_domain (const void *ctx,const void *state,unsigned int version); +void read_state_glb_quota (const void *ctx,const void *state);struct hashtable *domain_check_acc_init (void );void domain_check_acc_add (const struct node *node,struct hashtable *domains);
tools/xenstored/lu.c +6 -0
@@ -192,6 +192,9 @@ void lu_read_state(void)case XS_STATE_TYPE_DOMAIN :read_state_domain (ctx, state.buf, version);break ; +case XS_STATE_TYPE_GLB_QUOTA : +read_state_glb_quota (ctx, state.buf); +break ;default :xprintf ("live-update: unknown state record %08x\n" , head.type);
@@ -319,6 +322,9 @@ static const char *lu_dump_state(const void *ctx, struct connection *conn) } ret =dump_state_global (fp); +if (ret) + goto out; + ret =dump_state_glb_quota (fp);if (ret) goto out; ret =dump_state_connections (fp);
Signature · 1 line
2.53.0
Re: [PATCH v2 05/12] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
Quoted 14 lines · Juergen Gross
Communicate the global quota settings via the
GLOBAL_QUOTA_DATArecord to the new Xenstore instance.This avoids to lose global quota settings done via xenstore-control.
In theory it would be possible to drop any quota related command line parameters in the live update case, but they don't do any harm, as the record data is applied on top of the command line data.
For soft-quota just prepend "soft-" to the quota name.
Use sub-functions for building and analyzing the quota part of the migration stream, as they will be reused for per-domain quotas.
Quoted 8 lines
Signed-off-by Juergen Gross <[email protected]>---
V2:
- add macros for soft-quota name prefix and its length (Anthony Perard)
- don't allow disabled quota inparse_quota_name()(Anthony Perard)
- rename "len" to "rec_len" indump_state_glb_quota()(Anthony Perard)
- renamebuild_quota_data()parameter "name" to "names_buf" (Anthony Perard)
- letget_quota_size()start with len 0 (Anthony Perard)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 6/12 tools/xenstored: split acc[] array in struct domain
In reply to Juergen GrossPrepare using per-domain quota by splitting the acc[] array in struct domain into an array with the current accounting data, and an array of type struct quota for the per-domain quota and the seen max value of the domain.
--- tools/xenstored/domain.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-)
tools/xenstored/domain.c +16 -18
@@ -143,10 +143,8 @@ struct domainbool introduced;/* Accounting data for this domain. */ -struct acc { -unsigned int val; -unsigned int max; - } acc[ACC_N ]; +unsigned int acc_val[ACC_N ]; +struct quota acc[ACC_N ];/* Memory quota data for this domain. */ bool soft_quota_reported;
@@ -413,7 +411,7 @@ bool domain_quota_add_exceeds(struct domain *d, enum accitem what, int add)if (add <0 || !d)return false; -return domain_quota_val_exceeds (d, what, d->acc[what].val + add); +return domain_quota_val_exceeds (d, what, d->acc_val[what] + add); }static bool check_indexes (XENSTORE_RING_IDX cons,XENSTORE_RING_IDX prod)
@@ -585,7 +583,7 @@ static int domain_tree_remove_sub(const void *ctx, struct connection *conn, ret =WALK_TREE_SKIP_CHILDREN ; } -return domain->acc[ACC_NODES ].val ? ret :WALK_TREE_SUCCESS_STOP ; +return domain->acc_val[ACC_NODES ] ? ret :WALK_TREE_SUCCESS_STOP ; }static void domain_tree_remove (struct domain *domain)
@@ -593,7 +591,7 @@ static void domain_tree_remove(struct domain *domain)int ret;struct walk_funcs walkfuncs = { .enter = domain_tree_remove_sub }; -if (domain->acc[ACC_NODES ].val) { +if (domain->acc_val[ACC_NODES ]) { ret =walk_node_tree (domain,NULL ,"/" , &walkfuncs, domain);if (ret ==WALK_TREE_ERROR_STOP ) syslog(LOG_ERR,
@@ -789,7 +787,7 @@ int domain_get_quota(const void *ctx, struct connection *conn,continue ; resp =talloc_asprintf_append (resp,"%-17s: %8u (max %8u)\n" , quota_adm[i].name, - d->acc[i].val, d->acc[i].max); + d->acc_val[i], d->acc[i].max);if (!resp)return ENOMEM ; }
@@ -1673,10 +1671,10 @@ static int domain_acc_add_valid(struct domain *d, enum accitem what, int add) {unsigned int val; -assert (what <ARRAY_SIZE (d->acc)); +assert (what <ARRAY_SIZE (d->acc_val)); -if ((add <0 && -add > d->acc[what].val) || - (add >0 && (INT_MAX - d->acc[what].val) < add)) { +if ((add <0 && -add > d->acc_val[what]) || + (add >0 && (INT_MAX - d->acc_val[what]) < add)) {/* * In a transaction when a node is being added/removed AND the * same node has been added/removed outside the transaction in
@@ -1687,7 +1685,7 @@ static int domain_acc_add_valid(struct domain *d, enum accitem what, int add)return (add <0 ) ?0 :INT_MAX ; } - val = d->acc[what].val + add; + val = d->acc_val[what] + add;domain_acc_valid_max (d, what, val);return val;
@@ -1746,10 +1744,10 @@ static int domain_acc_add(struct connection *conn, unsigned int domid, }trace_acc ("global change domid %u: what=%u %u add %d\n" , domid, what, - d->acc[what].val, add); - d->acc[what].val =domain_acc_add_valid (d, what, add); + d->acc_val[what], add); + d->acc_val[what] =domain_acc_add_valid (d, what, add); -return d->acc[what].val; +return d->acc_val[what]; }void acc_drop (struct connection *conn)
@@ -1793,7 +1791,7 @@ static int domain_reset_global_acc_sub(const void *k, void *v, void *arg)unsigned int i;for (i =0 ; i <ACC_N ; i++) - d->acc[i].max = d->acc[i].val; + d->acc[i].max = d->acc_val[i];return 0 ; }
@@ -2233,7 +2231,7 @@ static int domain_check_acc_init_sub(const void *k, void *v, void *arg)* If everything is correct incrementing the value for each node will * result in dom->nodes being 0 at the end. */ - dom->nodes = -d->acc[ACC_NODES ].val; + dom->nodes = -d->acc_val[ACC_NODES ];if (hashtable_add (domains, &dom->domid, dom)) {talloc_free (dom);
@@ -2288,7 +2286,7 @@ static int domain_check_acc_cb(const void *k, void *v, void *arg)if (!d)return 0 ; - d->acc[ACC_NODES ].val += dom->nodes; + d->acc_val[ACC_NODES ] += dom->nodes;return 0 ; }
Signature · 1 line
2.53.0
PATCH v2 7/12 tools/xenstored: use per-domain quota settings
In reply to Juergen GrossInitialize the per-domain quota values with the global ones at domain introduction. Use the per-domain quota settings when checking for current values to exceed the quota.
Add per-domain quota support to live update.
---
V2:
- fix commit message (Anthony Perard)
- rename "len" to "rec_len" in dump_state_domain() (Anthony Perard)
--- tools/xenstored/domain.c | 60 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-)
tools/xenstored/domain.c +45 -15
@@ -392,6 +392,9 @@ void wrl_apply_debit_trans_commit(struct connection *conn)static unsigned int domain_get_soft_quota (struct domain *d,enum accitem what) { +if (d && d->acc[what].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) +return d->acc[what].val[Q_IDX_SOFT ]; +return quotas[what].val[Q_IDX_SOFT ]; }
@@ -400,6 +403,9 @@ static bool domain_quota_val_exceeds(struct domain *d, enum accitem what, {unsigned int quota = quotas[what].val[Q_IDX_HARD ]; +if (d->acc[what].val[Q_IDX_HARD ] !=Q_VAL_DISABLED ) + quota = d->acc[what].val[Q_IDX_HARD ]; +if (!quota || !domid_is_unprivileged (d->domid))return false;
@@ -824,6 +830,7 @@ static struct domain *alloc_domain(const void *context, unsigned int domid, uint64_t unique_id) {struct domain *domain; +unsigned int q; domain = talloc_zero(context, struct domain);if (!domain) {
@@ -837,6 +844,11 @@ static struct domain *alloc_domain(const void *context, unsigned int domid, domain->introduced = false; domain->features =XENSTORE_FEATURES ; +for (q =0 ; q <ACC_N ; q++) { + domain->acc[q].val[Q_IDX_HARD ] = quotas[q].val[Q_IDX_HARD ]; + domain->acc[q].val[Q_IDX_SOFT ] = quotas[q].val[Q_IDX_SOFT ]; + } +if (hashtable_add (domhash, &domain->domid, domain)) {talloc_free (domain); errno =ENOMEM ;
@@ -2118,25 +2130,39 @@ static int dump_state_domain(const void *k, void *v, void *arg) {struct domain *domain = v;FILE *fp = arg; -struct xs_state_domain sd; -struct xs_state_record_header head; - - head.type =XS_STATE_TYPE_DOMAIN ; - head.length =sizeof (sd); -memset (&sd,0 ,sizeof (sd)); - sd.domain_id = domain->domid; +struct xs_state_domain *sd; +struct xs_state_record_header *head; +void *record; +unsigned int n_quota; +unsigned int rec_len; +size_t ret; -if (lu_status->version >1 ) - sd.features = domain->features; + n_quota =get_quota_size (domain->acc, &rec_len); + rec_len += n_quota *sizeof (sd->quota_val[0 ]); + rec_len +=sizeof (*sd); + rec_len =ROUNDUP (rec_len,3 ); -if (fwrite (&head,sizeof (head),1 , fp) !=1 ) -return 1 ; -if (fwrite (&sd,sizeof (sd),1 , fp) !=1 ) -return 1 ; -if (dump_state_align (fp)) + record =talloc_size (NULL , rec_len +sizeof (*head)); +if (!record)return 1 ; -return 0 ; + head = record; + head->type =XS_STATE_TYPE_DOMAIN ; + head->length = rec_len; + + sd = (struct xs_state_domain *)(head +1 ); + sd->domain_id = domain->domid; + sd->n_quota = n_quota; + sd->features = (lu_status->version >1 ) ? domain->features :0 ; + +build_quota_data (domain->acc, sd->quota_val, + (char *)(sd->quota_val + n_quota)); + + ret =fwrite (record, rec_len +sizeof (*head),1 , fp); + +talloc_free (record); + +return (ret !=1 ||dump_state_align (fp)) ?1 :0 ; }const char *dump_state_domains (FILE *fp)
@@ -2153,6 +2179,8 @@ void read_state_domain(const void *ctx, const void *state, unsigned int version) {const struct xs_state_domain *sd = state;struct domain *domain; +unsigned int n_quota = sd->n_quota; +const char *name = (const char *)(sd->quota_val + n_quota); domain =find_domain_struct (sd->domain_id);if (!domain)
@@ -2160,6 +2188,8 @@ void read_state_domain(const void *ctx, const void *state, unsigned int version)if (version >1 ) domain->features = sd->features; + +parse_quota_data (sd->quota_val, name, n_quota, domain->acc); }const char *dump_state_glb_quota (FILE *fp)
Signature · 1 line
2.53.0
PATCH v2 8/12 tools/xenstored: implement the GET/SET_QUOTA commands
In reply to Juergen GrossAdd the implementation of the GET_QUOTA and SET_QUOTA wire commands.
---
V2:
- refuse quota value Q_VAL_DISABLED (Anthony Perard)
- use talloc_strdup() (Anthony Perard)
- drop comments in domain.h (Anthony Perard)
--- tools/xenstored/core.c | 4 ++ tools/xenstored/domain.c | 111 +++++++++++++++++++++++++++++++++++++++ tools/xenstored/domain.h | 5 ++ 3 files changed, 120 insertions(+)
tools/xenstored/core.c +4 -0
@@ -2035,6 +2035,10 @@ static struct { { "GET_FEATURE", do_get_feature, XS_FLAG_PRIV }, [XS_SET_FEATURE ] = { "SET_FEATURE", do_set_feature, XS_FLAG_PRIV }, + [XS_GET_QUOTA ] = + { "GET_QUOTA", do_get_quota, XS_FLAG_PRIV }, + [XS_SET_QUOTA ] = + { "SET_QUOTA", do_set_quota, XS_FLAG_PRIV }, };static const char *sockmsg_string (enum xsd_sockmsg_type type)
tools/xenstored/domain.c +111 -0
117 lines not on this page · raw message
tools/xenstored/domain.h +5 -0
@@ -93,6 +93,11 @@ int do_get_feature(const void *ctx, struct connection *conn,int do_set_feature (const void *ctx,struct connection *conn,struct buffered_data *in); +int do_get_quota (const void *ctx,struct connection *conn, +struct buffered_data *in); +int do_set_quota (const void *ctx,struct connection *conn, +struct buffered_data *in); +void domain_early_init (void );void domain_init (int evtfd);void init_domains (bool live_update);
Signature · 1 line
2.53.0
Re: [PATCH v2 08/12] tools/xenstored: implement the GET/SET_QUOTA commands
Quoted 8 lines · Juergen Gross
Add the implementation of the
GET_QUOTAandSET_QUOTAwire commands.Signed-off-by Juergen Gross <[email protected]>---
V2:
- refuse quota valueQ_VAL_DISABLED(Anthony Perard)
- usetalloc_strdup()(Anthony Perard)
- drop comments indomain.h(Anthony Perard)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 9/12 tools/libxl: add functions for retrieving and setting xenstore quota
In reply to Juergen GrossAdd some functions allowing to retrieve and set Xenstore quota (either global or domain specific).
---
V2:
- rename libxl functions to use "xs_quota" instead of "xsquota" (Anthony Perard)
- rename the libxl_xs_quota_*_get() "q" parameter to "q_out" (Anthony Perard)
- rename the struct xs_quota_set to xs_quota_list (Anthony Perard)
- several style changes (Anthony Perard)
--- tools/golang/xenlight/helpers.gen.go | 78 ++++++++++++++++++ tools/golang/xenlight/types.gen.go | 9 +++ tools/include/libxl.h | 20 +++++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_types.idl | 9 +++ tools/libs/light/libxl_xsquota.c | 116 +++++++++++++++++++++++++++ 6 files changed, 233 insertions(+) create mode 100644 tools/libs/light/libxl_xsquota.c
tools/golang/xenlight/helpers.gen.go +78 -0
@@ -998,6 +998,84 @@ xc.policy = C.libxl_rdm_reserve_policy(x.Policy) return nil } +// NewXsQuotaItem returns an instance of XsQuotaItem initialized with defaults. +func NewXsQuotaItem() (*XsQuotaItem, error) { +var ( +x XsQuotaItem +xc C.libxl_xs_quota_item) + +C.libxl_xs_quota_item_init(&xc) +defer C.libxl_xs_quota_item_dispose(&xc) + +if err := x.fromC(&xc); err != nil { +return nil, err } + +return &x, nil} + +func (x *XsQuotaItem) fromC(xc *C.libxl_xs_quota_item) error { + x.Name = C.GoString(xc.name) +x.Val = uint32(xc.val) + + return nil} + +func (x *XsQuotaItem) toC(xc *C.libxl_xs_quota_item) (err error){defer func(){ +if err != nil{ +C.libxl_xs_quota_item_dispose(xc)} +}() + +if x.Name != "" { +xc.name = C.CString(x.Name)} +xc.val = C.uint32_t(x.Val) + + return nil + } + +// NewXsQuotaList returns an instance of XsQuotaList initialized with defaults. +func NewXsQuotaList() (*XsQuotaList, error) { +var ( +x XsQuotaList +xc C.libxl_xs_quota_list) + +C.libxl_xs_quota_list_init(&xc) +defer C.libxl_xs_quota_list_dispose(&xc) + +if err := x.fromC(&xc); err != nil { +return nil, err } + +return &x, nil} + +func (x *XsQuotaList) fromC(xc *C.libxl_xs_quota_list) error { + x.Quota = nil +if n := int(xc.num_quota); n > 0 { +cQuota := (*[1<<28]C.libxl_xs_quota_item)(unsafe.Pointer(xc.quota))[:n:n] +x.Quota = make([]XsQuotaItem, n) +for i, v := range cQuota { +if err := x.Quota[i].fromC(&v); err != nil { +return fmt.Errorf("converting field Quota: %v", err) } +} +} + + return nil} + +func (x *XsQuotaList) toC(xc *C.libxl_xs_quota_list) (err error){defer func(){ +if err != nil{ +C.libxl_xs_quota_list_dispose(xc)} +}() + +if numQuota := len(x.Quota); numQuota > 0 { +xc.quota = (*C.libxl_xs_quota_item)(C.malloc(C.ulong(numQuota)*C.sizeof_libxl_xs_quota_item)) +xc.num_quota = C.int(numQuota) +cQuota := (*[1<<28]C.libxl_xs_quota_item)(unsafe.Pointer(xc.quota))[:numQuota:numQuota] +for i,v := range x.Quota { +if err := v.toC(&cQuota[i]); err != nil { +return fmt.Errorf("converting field Quota: %v", err) +} +} +} + + return nil + } + // NewDomainBuildInfo returns an instance of DomainBuildInfo initialized with defaults. func NewDomainBuildInfo(dtype DomainType) (*DomainBuildInfo, error) { var (
tools/golang/xenlight/types.gen.go +9 -0
@@ -543,6 +543,15 @@ Altp2MModeExternal Altp2MMode = 2 Altp2MModeLimited Altp2MMode = 3 ) +type XsQuotaItem struct { +Name string +Val uint32 +} + +type XsQuotaList struct { +Quota []XsQuotaItem +} + type DomainBuildInfo struct { MaxVcpus int AvailVcpus Bitmap
tools/include/libxl.h +20 -0
@@ -1537,6 +1537,18 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);*/ #define LIBXL_HAVE_XEN_PLATFORM_PCI_BAR_UC +/* +* LIBXL_HAVE_XENSTORE_QUOTA +* +* If this is defined the Xenstore quota related functions +* libxl_xs_quota_global_get() +* libxl_xs_quota_global_set() +* libxl_xs_quota_domain_get() +* libxl_xs_quota_domain_set() +* are available. +*/ +#define LIBXL_HAVE_XENSTORE_QUOTA +typedef char **libxl_string_list ;void libxl_string_list_dispose (libxl_string_list *sl);int libxl_string_list_length (const libxl_string_list *sl);
@@ -3011,6 +3023,14 @@ static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx,#define libxl_qemu_monitor_command libxl_qemu_monitor_command_0x041200#endif +/* Get/set global and per-domain Xenstore quota. */ +int libxl_xs_quota_global_get (libxl_ctx *ctx,libxl_xs_quota_list *q_out); +int libxl_xs_quota_global_set (libxl_ctx *ctx,libxl_xs_quota_list *q); +int libxl_xs_quota_domain_get (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_list *q_out); +int libxl_xs_quota_domain_set (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_list *q); +#include <libxl_event.h> /*
tools/libs/light/Makefile +1 -0
@@ -106,6 +106,7 @@ OBJS-y += libxl_pvcalls.o OBJS-y += libxl_vsnd.o OBJS-y += libxl_vkb.o OBJS-y += libxl_virtio.o +OBJS-y += libxl_xsquota.o OBJS-y += libxl_genid.o OBJS-y += _libxl_types.o OBJS-y += libxl_flask.o
tools/libs/light/libxl_types.idl +9 -0
@@ -574,6 +574,15 @@ libxl_altp2m_mode = Enumeration("altp2m_mode", [ (3, "limited"), ], init_val = "LIBXL_ALTP2M_MODE_DISABLED") +libxl_xs_quota_item = Struct("xs_quota_item", [ + ("name", string), + ("val", uint32), + ]) + +libxl_xs_quota_list = Struct("xs_quota_list", [ + ("quota", Array(libxl_xs_quota_item, "num_quota")) + ]) + libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), ("avail_vcpus", libxl_bitmap),
tools/libs/light/libxl_xsquota.c new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 09/12] tools/libxl: add functions for retrieving and setting xenstore quota
Quoted 5 lines · Juergen Gross
Add some functions allowing to retrieve and set Xenstore quota (either global or domain specific).
Signed-off-by Juergen Gross <[email protected]>
Quoted 8 lines
---
V2:
- rename libxl functions to use "xs_quota" instead of "xsquota" (Anthony Perard)
- rename the libxl_xs_quota_*_get() "q" parameter to "q_out" (Anthony Perard)
- rename the structxs_quota_settoxs_quota_list(Anthony Perard)
- several style changes (Anthony Perard)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 10/12 tools/libxl: add support for xenstore quota in domain_config
In reply to Juergen GrossAdd support for xenstore quota in the struct domain_config. Initially it will be used only for migration of a domain.
---
V2:
- use LOGED() for error logging (Anthony Perard)
- mention additional struct member xenstore_quota in libxl.h (Anthony Perard)
--- tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 1 + tools/libs/light/libxl_dom.c | 8 ++++++++ tools/libs/light/libxl_domain.c | 11 +++++++++++ tools/libs/light/libxl_types.idl | 1 + 6 files changed, 28 insertions(+)
tools/golang/xenlight/helpers.gen.go +6 -0
@@ -1286,6 +1286,9 @@ if err := x.TrapUnmappedAccesses.fromC(&xc.trap_unmapped_accesses);err != nil { return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err) } x.XenstoreFeatureMask = uint32(xc.xenstore_feature_mask) +if err := x.XenstoreQuota.fromC(&xc.xenstore_quota);err != nil { +return fmt.Errorf("converting field XenstoreQuota: %v", err) +} return nil}
@@ -1825,6 +1828,9 @@ if err := x.TrapUnmappedAccesses.toC(&xc.trap_unmapped_accesses); err != nil { return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err) } xc.xenstore_feature_mask = C.uint32_t(x.XenstoreFeatureMask) +if err := x.XenstoreQuota.toC(&xc.xenstore_quota); err != nil { +return fmt.Errorf("converting field XenstoreQuota: %v", err) +} return nil }
tools/golang/xenlight/types.gen.go +1 -0
@@ -629,6 +629,7 @@ VmtraceBufKb int Vpmu Defbool TrapUnmappedAccesses Defbool XenstoreFeatureMask uint32 +XenstoreQuota XsQuotaList } type DomainBuildInfoTypeUnion interface {
tools/include/libxl.h +1 -0
@@ -1545,6 +1545,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, const libxl_mac *src);* libxl_xs_quota_global_set() * libxl_xs_quota_domain_get() * libxl_xs_quota_domain_set() +* and the xenstore_quota member of struct domain_build_info * are available. */ #define LIBXL_HAVE_XENSTORE_QUOTA
tools/libs/light/libxl_dom.c +8 -0
@@ -509,6 +509,14 @@ retry_transaction:xs_introduce_domain (ctx->xsh, domid, state->store_mfn, state->store_port); +if (info->xenstore_quota.num_quota) { + rc =libxl_xs_quota_domain_set (ctx, domid, &info->xenstore_quota); +if (rc) { +LOGED (ERROR , domid,"Failed to set Xenstore quota" ); + goto out; + } + } + out:free (vm_path);return rc;
tools/libs/light/libxl_domain.c +11 -0
@@ -2533,6 +2533,17 @@ static void retrieve_domain_configuration_end(libxl__egc *egc, } } +/* Xenstore quota */ + { +libxl_xs_quota_list_dispose (&d_config->b_info.xenstore_quota); + rc =libxl_xs_quota_domain_get (CTX , domid, + &d_config->b_info.xenstore_quota); +if (rc) { +LOGED (ERROR , domid,"Fail to get xenstore quota" ); + goto out; + } + } +/* Devices: disk, nic, vtpm, pcidev etc. */ /* The MERGE macro implements following logic:
tools/libs/light/libxl_types.idl +1 -0
@@ -760,6 +760,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("vpmu", libxl_defbool), ("trap_unmapped_accesses", libxl_defbool), ("xenstore_feature_mask", uint32, {'init_val': '~0U'}), + ("xenstore_quota", libxl_xs_quota_list), ], dir=DIR_IN, copy_deprecated_fn="libxl__domain_build_info_copy_deprecated",
Signature · 1 line
2.53.0
Re: [PATCH v2 10/12] tools/libxl: add support for xenstore quota in domain_config
Quoted 10 lines · Juergen Gross
Add support for xenstore quota in the struct
domain_config. Initially it will be used only for migration of a domain.Signed-off-by Juergen Gross <[email protected]>---
V2:
- useLOGED()for error logging (Anthony Perard)
- mention additional struct memberxenstore_quotainlibxl.h(Anthony Perard)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v2 10/12] tools/libxl: add support for xenstore quota in domain_config
In reply to Juergen GrossQuoted 102 lines · Juergen Gross
Add support for xenstore quota in the struct
domain_config. Initially it will be used only for migration of a domain.Signed-off-by Juergen Gross <[email protected]>---
V2:
- useLOGED()for error logging (Anthony Perard)
- mention additional struct memberxenstore_quotainlibxl.h(Anthony Perard)--- tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/include/libxl.h | 1 + tools/libs/light/libxl_dom.c | 8 ++++++++ tools/libs/light/libxl_domain.c | 11 +++++++++++ tools/libs/light/libxl_types.idl | 1 + 6 files changed, 28 insertions(+)tools/golang/xenlight/helpers.gen.go +6
-0@@ -1286,6 +1286,9 @@ if err := x.TrapUnmappedAccesses.fromC(&xc.trap_unmapped_accesses);err != nil { return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err) } x.XenstoreFeatureMask = uint32(xc.xenstore_feature_mask) +if err := x.XenstoreQuota.fromC(&xc.xenstore_quota);err != nil { +return fmt.Errorf("converting field XenstoreQuota: %v", err) +} return nil}@@ -1825,6 +1828,9 @@ if err := x.TrapUnmappedAccesses.toC(&xc.trap_unmapped_accesses); err != nil { return fmt.Errorf("converting field TrapUnmappedAccesses: %v", err) } xc.xenstore_feature_mask = C.uint32_t(x.XenstoreFeatureMask) +if err := x.XenstoreQuota.toC(&xc.xenstore_quota); err != nil { +return fmt.Errorf("converting field XenstoreQuota: %v", err) +} return nil}tools/golang/xenlight/types.gen.go +1
-0@@ -629,6 +629,7 @@ VmtraceBufKb int Vpmu Defbool TrapUnmappedAccesses Defbool XenstoreFeatureMask uint32 +XenstoreQuota XsQuotaList } type DomainBuildInfoTypeUnion interface {tools/include/libxl.h +1
-0@@ -1545,6 +1545,7 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst,const libxl_mac *src); * libxl_xs_quota_global_set() * libxl_xs_quota_domain_get() * libxl_xs_quota_domain_set() +* and the xenstore_quota member of struct domain_build_info * are available. */ #define
LIBXL_HAVE_XENSTORE_QUOTAtools/libs/light/libxl_dom.c +8
-0@@ -509,6 +509,14 @@ retry_transaction:xs_introduce_domain (ctx->xsh, domid, state->store_mfn, state->store_port); +if (info->xenstore_quota.num_quota) { + rc =libxl_xs_quota_domain_set (ctx, domid, &info->xenstore_quota); +if (rc) { +LOGED (ERROR , domid,"Failed to set Xenstore quota" ); + goto out; + } + } + out:free (vm_path);return rc;tools/libs/light/libxl_domain.c +0
-0@@ -2533,6 +2533,17 @@ static void retrieve_domain_configuration_end(libxl__egc *egc, } }
tools/libs/light/libxl_domain.c static void · line 2546
Quoted 10 lines
tools/libs/light/libxl_domain.c +9
-0+/* Xenstore quota */ + { +libxl_xs_quota_list_dispose (&d_config->b_info.xenstore_quota); + rc =libxl_xs_quota_domain_get (CTX , domid, + &d_config->b_info.xenstore_quota); +if (rc) { +LOGED (ERROR , domid,"Fail to get xenstore quota" ); + goto out; + }
This change seems to cause xl list to hang on oxenstored systems.
I'm not an expert in ocaml; Claude seems to think that the problem is as follows:
1. oxenstored doesn't implement XS_GET_QUOTA, and
2. when it receives an unknown message it returns an error, but
3. the error payload is length zero, and
4. oxenstored has a bug such that it will never actually send messages with a zero-length payload.
Below is a more complete report from Claude; as I said, I don't know enough ocaml to evaluate it. Plan xl list only triggers it on staging, but apparently xl list -x will trigger it in Xen 4.21.
Assuming the analysis is correct, it's concerning that an issue with the default xenstored instance wasn't caught earlier.
-George
8<---
Subject: oxenstored hangs on any xenstore request with a zero-length payload
Affects, on oxenstored systems:
- xl info -x and xenstore watch -d N -- RELEASE-4.21.0,
RELEASE-4.21.1
- xl list -l, xl save, xl migrate -- 4.22.0-rc1..rc3, unstable
The C xenstored and xenstore-stubdom are unaffected.
Symptom
-------
On an idle dom0 with no guests, running oxenstored, xl list -l never returns and produces no output. The same holds for xl save, xl migrate, xl info -x, and xenstore watch -d N. Meanwhile xl list, xl list -v, xl info -n, xenstore-read and xenstore-ls all work normally.
The client is blocked in read(fd, buf, 16) awaiting an xsd_sockmsg header that never arrives. Both socket queues are empty. oxenstored itself remains healthy and continues to serve every other connection.
Root cause
----------
oxenstored's socket backend never delivers a request whose payload length is zero. This is independent of the opcode: XS_READ and XS_DIRECTORY with len == 0 hang exactly as XS_GET_QUOTA does.
In tools/ocaml/libs/xb/xb.ml, Xb.input() consumes the 16-byte header and sets partial_in <- HaveHdr pkt, then returns None unconditionally:
| NoHdr (i, buf) ->
(* we complete the partial header *)
if sz > 0 then
Bytes.blit b 0 buf (Partial.header_size () - i) sz;
con.partial_in <- if sz = i then
HaveHdr (Partial.of_string (Bytes.to_string buf)) else NoHdr (i
- sz, buf);
None
The packet would be produced by the *next* call to input() -- the HaveHdr branch handles Partial.to_complete = 0 without reading anything further. But has_more_input is hardcoded false for socket backends:
let has_more_input con =
match con.backend with
| Fd _ -> false
| Xenmmap backend -> backend.work_again
so xenstored.ml re-enters do_input only when poll() reports the fd readable.
- For len > 0, the payload is still buffered in the socket, so poll() fires again and the packet completes. This is why every other request works.
- For len == 0, nothing remains to be read. poll() never fires, and a fully-received request sits parked in partial_in indefinitely.
It is finally processed only when further input arrives on that connection -- including POLLHUP at client teardown -- at which point the reply is written to a dead socket.
oxenstored's dispatch layer is correct: XS_GET_QUOTA with a non-empty payload returns XS_ERROR "ENOSYS" in under a millisecond. Only the framing layer is broken.
Guest ring (Xenmmap) connections appear unaffected, since there has_more_input follows work_again. NOTE: this is a source-level inference; I did not exercise a ring connection with a zero-length request.
Evidence
--------
strace of oxenstored. \31 = 25 = XS_GET_QUOTA, \2 = XS_READ:
# len=0, unknown opcode 25 -- nothing written, silence, then client EOF 14:54:01.801066 read(23, "\31\0\0\0\336\300\0\0\0\0\0\0\0\0\0\0", 16) = 16
14:54:06.806325 write(18, "[...] A81 invalid", 50) <- only at POLLHUP
14:54:06.806811 read(23, "", 16) = 0
# len=0, WELL-KNOWN opcode 2 -- identical hang 14:54:10.840293 read(23, "\2\0\0\0\336\300\0\0\0\0\0\0\0\0\0\0", 16) = 16
14:54:15.845644 read(23, "", 16) = 0
# same opcode 25, len=2 -- answered instantly 14:54:19.879492 read(23, "\31\0\0\0\336\300\0\0\0\0\0\0\2\0\0\0", 16) = 16 14:54:19.879698 read(23, "0\0", 2) = 2 14:54:19.879810 write(18, "[...] A83 invalid / error ENOSYS", ...)
The poll() following the parked read requests POLLIN only -- no POLLOUT -- i.e. oxenstored has nothing queued to send. xenstored.log contains neither "process packet:" nor "got a bad client": process_packet is never entered.
Decisive: send the len == 0 header, wait three seconds (nothing), then send one unrelated byte. The ENOSYS reply *for the original request id* is emitted within 1 ms. The request was never dropped -- it was parked, waiting for a poll() that had nothing left to deliver.
Trigger
-------
libxenstore has exactly two zero-length senders, both recent. Before them, no xenstore client had ever sent a zero-length request over the socket, so the defect lay dormant.
xs_get_features_supported() XS_GET_FEATURE tools/libs/store/xs.c:1486
added by 5234b61eab
in: RELEASE-4.21.0, RELEASE-4.21.1, 4.22.0-rc*, unstable
reached by: xl info -x, xenstore watch -d N xs_get_quota_names() XS_GET_QUOTA tools/libs/store/xs.c:1537
added by ba90589447
in: 4.22.0-rc1..rc3, unstable
reached by: xl list -l, xl save, xl migrate -- since a6f159f92c made libxl_retrieve_domain_configuration() query xenstore quota
Both are the only struct iovec iov[1] call sites in xs.c.
libxl is not at fault
---------------------
tools/libs/light/libxl_xsquota.c explicitly treats quota as optional:
names = xs_get_quota_names(ctx->xsh, &num);
if (!names) {
/* Xenstore quota support is optional! */
if (errno != ENOSYS) { ... rc = ERROR_FAIL; }
else { rc = 0; }Confirmed empirically: with an LD_PRELOAD shim forcing xs_get_quota_names() to fail with ENOSYS, against the same hanging oxenstored, xl list -l returns rc=0 with full JSON and xl save writes a 2.1 GB savefile. A xenstored that lacks opcode 25 but *answers* ENOSYS works fine. The C xenstored answers ENOSYS to unknown opcodes at any length.
Age
---
The defect is present in oxenstored's original commit:
c3afd398ba7f349fdf59d79aaed4da256176806a
Keir Fraser <[email protected]>, 2010-05-06
"ocaml: Add XS bindings."git log -S has_more_input -- tools/ocaml/libs/xb/xb.ml returns that commit and no other; has_more_input has never been modified. The NoHdr branch is unchanged in substance since RELEASE-4.2.0, andgit diff RELEASE-4.21.0 HEAD -- tools/ocaml/libs/xb/{xb,partial,op}.ml is empty -- the files are byte-identical.
Reproducer
----------
Attached: oxs-zerolen.c (50 lines, no dependencies).
gcc -o oxs-zerolen oxs-zerolen.c && sudo ./oxs-zerolen
Against oxenstored:
XS_READ(2) len=21 (sanity) -> reply type=2 len=8 XS_GET_QUOTA(25) len=2 (unknown op) -> reply type=16 len=7 [ENOSYS] XS_READ(2) len=0 (known op!) -> NO REPLY (5s timeout) XS_DIRECTORY(1) len=0 (known op!) -> NO REPLY (5s timeout) XS_GET_FEATURE(23) len=0 (xl info -x) -> NO REPLY (5s timeout) XS_GET_QUOTA(25) len=0 (xl list -l) -> NO REPLY (5s timeout)
Against the C xenstored: all six reply in 0.000 s.
Fix
---
In Xb.input, return the packet as soon as a complete header with len == 0 has been read, rather than returning None and waiting for input that will never arrive:
| NoHdr (i, buf) ->
if sz > 0 then Bytes.blit b 0 buf (Partial.header_size () - i) sz; if sz = i then begin
let partial_pkt = Partial.of_string (Bytes.to_string buf) in if Partial.to_complete partial_pkt = 0 then begin
con.partial_in <- init_partial_in ();
Some (Packet.of_partialpkt partial_pkt) (* was: None *)
end else (con.partial_in <- HaveHdr partial_pkt; None)
end else (con.partial_in <- NoHdr (i - sz, buf); None)
Alternatively, fix has_more_input, which is where the invariant is actually violated -- "a complete packet is buffered" ought to imply more work is pending. This duplicates no packet construction, since the HaveHdr branch already handles to_complete = 0 with no read:
let has_more_input con =
match con.backend with
| Fd _ -> (match con.partial_in with
| HaveHdr p -> Partial.to_complete p = 0
| _ -> false)
| Xenmmap backend -> backend.work_againThe Fd arm being a hardcoded false while Xenmmap consults work_again is the asymmetry that hid this.
Tested on
---------
Xen 4.23-unstable, git e58a8e0889, debug=n, bare metal (Debian 13, x86_64). oxenstored built from the same tree; running binary sha256-verified against tools/ocaml/xenstored/oxenstored.
Not tested: 4.21.0 / 4.22-rc binaries were not built and run. The claim that they are affected rests on (a) the xb library being byte-identical to HEAD and (b) 5234b61eab / ba90589447 being present in those tags. Both were checked with git; neither was exercised.
---oxs-zerolen.c
/*
* oxs-zerolen.c - oxenstored never answers a request with len == 0. *
* gcc -o oxs-zerolen oxs-zerolen.c && sudo ./oxs-zerolen
*
* Against oxenstored: every len==0 request times out, whatever the opcode.
* Against C xenstored: every case replies immediately.
*/
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <poll.h>
#include <sys/socket.h>
#include <sys/un.h>
struct xsd_sockmsg { uint32_t type, req_id, tx_id, len; };
/* Send one request, wait up to 5s for a reply header. */ static void probe(const char *what, uint32_t type, const char *pl, uint32_t len)
{
struct sockaddr_un a = { .sun_family = AF_UNIX };
struct xsd_sockmsg m = { type, 0xC0DE, 0, len }, r;
struct pollfd p;
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
strcpy(a.sun_path, "/var/run/xenstored/socket");
if (connect(fd, (struct sockaddr *)&a, sizeof(a))) { perror("connect"); return; }
if (write(fd, &m, sizeof(m)) != sizeof(m)) { perror("write"); return; } if (len && write(fd, pl, len) != (ssize_t)len) { perror("write"); return; }
p.fd = fd; p.events = POLLIN;
if (poll(&p, 1, 5000) == 0)printf("%-42s -> NO REPLY (5s timeout)\n", what); else if (read(fd, &r, sizeof(r)) == sizeof(r)) printf("%-42s -> reply type=%u len=%u\n", what, r.type, r.len); close(fd);
}
int main(void)
{
probe("XS_READ(2) len=21 (sanity)", 2, "/local/domain/0/name", 21);
probe("XS_GET_QUOTA(25) len=2 (unknown op)", 25, "0\0", 2);
probe("XS_READ(2) len=0 (known op!)", 2, NULL, 0);
probe("XS_DIRECTORY(1) len=0 (known op!)", 1, NULL, 0);probe("XS_GET_FEATURE(23) len=0 (xl info -x)", 23, NULL, 0); probe("XS_GET_QUOTA(25) len=0 (xl list -l)", 25, NULL, 0); return 0;
}
PATCH v2 11/12 tools/xl: add xl commands for xenstore quota operations
In reply to Juergen GrossAdd "xl xenstore-quota-get" and "xl xenstore-quota-set" commands for retrieving and setting global and per-domain Xenstore quota.
---
V2:
- s/quota data/quotas/ in cmdtable (Anthony Perard)
- test for quota value to fit into type (Anthony Perard)
- use libxl_xs_quota_list_init() (Anthony Perard)
- use xcalloc() (Anthony Perard)
--- tools/xl/Makefile | 1 + tools/xl/xl.h | 2 + tools/xl/xl_cmdtable.c | 10 +++++ tools/xl/xl_parse.c | 28 +++++++++++++ tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 tools/xl/xl_xsquota.c
tools/xl/Makefile +1 -0
@@ -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)
tools/xl/xl.h +2 -0
@@ -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);
tools/xl/xl_cmdtable.c +10 -0
@@ -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);
tools/xl/xl_parse.c +28 -0
@@ -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,
tools/xl/xl_parse.h +1 -0
@@ -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);
tools/xl/xl_xsquota.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 11/12] tools/xl: add xl commands for xenstore quota operations
Quoted 10 lines · Juergen Gross
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 <[email protected]>---
V2:
- s/quota data/quotas/ in cmdtable (Anthony Perard)
- test for quota value to fit into type (Anthony Perard)
- uselibxl_xs_quota_list_init()(Anthony Perard)
- usexcalloc()(Anthony Perard)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 12/12 tools/xl: add support for xenstore quota setting via domain config
In reply to Juergen GrossAdd a new "xenstore_quota" domain config parameter for setting the Xenstore quota of a new domain via a list of <quota>=<val> items.
---
V2:
- fix typo in commit message (Anthony Perard)
- use xcalloc() (Anthony Perard)
--- docs/man/xl.cfg.5.pod.in | 13 +++++++++++++ tools/xl/xl_parse.c | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-)
docs/man/xl.cfg.5.pod.in +13 -0
@@ -748,6 +748,19 @@ via the B<xl info -x> command in dom0. The default value is B<0xffffffff>, meaning that all possible Xenstore features are visible by the guest. +=item B<xenstore_quota=[ QUOTA_SPEC, QUOTA_SPEC, ...]> + +Specifies Xenstore quota values of the domain, overriding the default +values of Xenstore. + +Each B<QUOTA_SPEC> is a B<quota-name>=B<value> specification. The supported +B<quota-name> identifiers can be obtained by the B<xl xenstore-quota-get -g> +command. B<value> is a non-negative integer. + +As per-domain Xenstore quota are an optional Xenstore feature, the +B<xenstore_quota> config parameter may not be supported by all Xenstore +implementations. + =back =head2 Devices
tools/xl/xl_parse.c +18 -1
@@ -1354,7 +1354,7 @@ void parse_config_data(const char *config_source,XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, *usbctrls, *usbdevs, *p9devs, *vdispls, *pvcallsifs_devs;XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs, - *mca_caps, *smbios, *llc_colors; + *mca_caps, *smbios, *llc_colors, *xs_quota;int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian, num_mca_caps;int num_smbios;int pci_power_mgmt =0 ;
@@ -1363,6 +1363,7 @@ void parse_config_data(const char *config_source,int pci_seize =0 ;int i, e;int num_llc_colors; +int num_xs_quota;char *kernel_basename;libxl_domain_create_info *c_info = &d_config->c_info;
@@ -1470,6 +1471,22 @@ void parse_config_data(const char *config_source,if (!xlu_cfg_get_long (config,"xenstore_feature_mask" , &l,0 )) b_info->xenstore_feature_mask = l; +if (!xlu_cfg_get_list (config,"xenstore_quota" , &xs_quota, &num_xs_quota,0 )) { + b_info->xenstore_quota.num_quota = num_xs_quota; + b_info->xenstore_quota.quota =xcalloc (num_xs_quota,sizeof (* b_info->xenstore_quota.quota)); + +for (i =0 ; i < num_xs_quota; i++) { + buf =xlu_cfg_get_listitem (xs_quota, i); +if (!buf) { +fprintf (stderr, +"xl: Can't get element %d in Xenstore quota list\n" , i); +exit (1 ); + } +if (parse_xsquota_item (buf, b_info->xenstore_quota.quota + i)) +exit (1 ); + } + } +libxl_domain_build_info_init_type (b_info, c_info->type);if (b_info->type ==LIBXL_DOMAIN_TYPE_PVH ) {
Signature · 1 line
2.53.0