tools: add support for per-domain xenstore quota
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.
Juergen Gross (11):
tools/libs/store: add get- and set-quota related functions 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: add infrastructure for per-domain quotas 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 | 20 ++ tools/include/xenstore.h | 19 ++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_dom.c | 8 + tools/libs/light/libxl_domain.c | 10 + tools/libs/light/libxl_types.idl | 10 + tools/libs/light/libxl_xsquota.c | 102 ++++++ 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 | 457 +++++++++++++++++++++------ tools/xenstored/domain.h | 32 +- 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 | 48 ++- tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 88 ++++++ 26 files changed, 972 insertions(+), 142 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 1/11 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.
--- tools/include/xenstore.h | 19 ++++++ tools/libs/store/Makefile | 2 +- tools/libs/store/libxenstore.map | 8 +++ tools/libs/store/xs.c | 111 +++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-)
tools/include/xenstore.h +19 -0
@@ -277,6 +277,25 @@ 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. */ +char **xs_get_quota_names (struct xs_handle *h,unsigned int *num); + +/* Get the value of one global quota. */ +bool xs_get_global_quota (struct xs_handle *h,char *quota, +unsigned int *value); + +/* Set the value of one global quota. */ +bool xs_set_global_quota (struct xs_handle *h,char *quota, +unsigned int value); + +/* Get the value of one domain quota. */ +bool xs_get_domain_quota (struct xs_handle *h,unsigned int domid, +char *quota,unsigned int *value); + +/* Set the value of one domain quota. */ +bool xs_set_domain_quota (struct xs_handle *h,unsigned int domid, +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 01/11] tools/libs/store: add get- and set-quota related functions
Quoted 17 lines · Juergen Gross
tools/include/xenstore.h +9
-0@@ -277,6 +277,25 @@ 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. */ +char **xs_get_quota_names (struct xs_handle *h,unsigned int *num); + +/* Get the value of one global quota. */ +bool xs_get_global_quota (struct xs_handle *h,char *quota, +unsigned int *value); + +/* Set the value of one global quota. */ +bool xs_set_global_quota(struct xs_handle *h, char *quota,
tools/include/xenstore.h bool xs_get_features_domain(struct xs_handle *h, unsigned int domid, · line 298
Quoted 10 lines
tools/include/xenstore.h +10
-0+ unsigned int value); + +/* Get the value of one domain quota. */ +bool xs_get_domain_quota (struct xs_handle *h,unsigned int domid, +char *quota,unsigned int *value); + +/* Set the value of one domain quota. */ +bool xs_set_domain_quota (struct xs_handle *h,unsigned int domid, +char *quota,unsigned int value); +
Do you think all those new prototype could get a bit more descriptions? Which parameter are actually output (and not input), what does it mean to return false, do they set errno, is there something to do with the return value of xs_get_quota_names?
For output arguments, libxl have a convention (well at least a mention in the coding style) to suffix argument names with _r or _out.
For the strings, could we use const char * instead of non-const one?
Quoted 26 lines
tools/libs/store/xs.c +18
-0@@ -1456,6 +1456,117 @@ bool xs_set_features_domain(struct xs_handle *h, unsigned int domid,return xs_bool (xs_talkv (h, iov,ARRAY_SIZE (iov),NULL )); } +char **xs_get_quota_names (struct xs_handle *h,unsigned int *num) +{ +struct xsd_sockmsg msg = { .type =XS_GET_QUOTA }; +struct iovec iov[1 ]; +char **quota; +char *reply; +char *c; +unsigned int i; + + iov[0 ].iov_base = &msg; + iov[0 ].iov_len =sizeof (msg); + + reply =xs_talkv (h, iov,ARRAY_SIZE (iov),NULL ); +if (!reply) +return NULL ; + + *num =1 ; +for (c = reply; *c; c++)
tools/libs/store/xs.c bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, · line 1486
Quoted 10 lines
tools/libs/store/xs.c +10
-0+if (*c ==' ' ) + (*num)++; + + quota =malloc (*num *sizeof (char *) +strlen (reply) +1 ); + c = (char *)(quota + *num); +strcpy (c, reply); +for (i =0 ; i < *num; i++) { + quota[i] = c; + c =strchr (c,' ' ); +if (c) {
If c is NULL, it's likely that this is the last iteration of the for loop. But just in case, should we prevent the code from doing another round and prevent strchr(NULL, ' ')? (Or just check that c is !NULL, and let the loop finish set NULL for the remaining slot in quota)
Quoted 17 lines
tools/libs/store/xs.c +17
-0+ *c =0 ; + c++; + } + } + +return quota; +} + +bool xs_get_global_quota (struct xs_handle *h,char *quota, +unsigned int *value) +{ +struct xsd_sockmsg msg = { .type =XS_GET_QUOTA }; +struct iovec iov[2 ]; + + iov[0 ].iov_base = &msg; + iov[0 ].iov_len =sizeof (msg); + iov[1 ].iov_base = quota;
tools/libs/store/xs.c bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, · line 1513
Quoted 10 lines
tools/libs/store/xs.c +10
-0+ iov[1 ].iov_len =strlen (quota) +1 ; + +return xs_uint (xs_talkv (h, iov,ARRAY_SIZE (iov),NULL ), value); +} + +bool xs_set_global_quota (struct xs_handle *h,char *quota, +unsigned int value) +{ +struct xsd_sockmsg msg = { .type =XS_SET_QUOTA }; +char val_str[MAX_STRLEN (value)];
MAX_STRLEN doesn't have a great name, I wounder what is was :-). And it's not about a maximum size of payload that could go on xs wire or something, it's actually the maximum string size that can take a numerical value, when converted to charaters.
The rest looks fine to me.
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 01/11] tools/libs/store: add get- and set-quota related functions
Quoted 25 lines · Anthony PERARD
Quoted 24 lines · Juergen Gross
tools/include/xenstore.h +16
-0@@ -277,6 +277,25 @@ 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. */ +char **xs_get_quota_names (struct xs_handle *h,unsigned int *num); + +/* Get the value of one global quota. */ +bool xs_get_global_quota (struct xs_handle *h,char *quota, +unsigned int *value); + +/* Set the value of one global quota. */ +bool xs_set_global_quota (struct xs_handle *h,char *quota, +unsigned int value); + +/* Get the value of one domain quota. */ +bool xs_get_domain_quota (struct xs_handle *h,unsigned int domid, +char *quota,unsigned int *value); + +/* Set the value of one domain quota. */
Quoted 8 lines
tools/include/xenstore.h bool xs_get_features_domain(struct xs_handle *h, unsigned int domid, · line 298
Quoted 3 lines
tools/include/xenstore.h +3
-0+bool xs_set_domain_quota (struct xs_handle *h,unsigned int domid, +char *quota,unsigned int value); +Do you think all those new prototype could get a bit more descriptions? Which parameter are actually output (and not input), what does it mean to return false, do they set errno, is there something to do with the return value of
xs_get_quota_names?
Oh yes, of course.
Quoted 2 lines
For output arguments, libxl have a convention (well at least a mention in the coding style) to suffix argument names with
_ror_out.
Hmm, I don't think I'd like to change style now. This is not libxl after all.
Quoted 1 line
For the strings, could we use
const char *instead of non-const one?
Yes.
Quoted 34 lines
Quoted 34 lines
tools/libs/store/xs.c +25
-0@@ -1456,6 +1456,117 @@ bool xs_set_features_domain(struct xs_handle *h, unsigned int domid,return xs_bool (xs_talkv (h, iov,ARRAY_SIZE (iov),NULL )); } +char **xs_get_quota_names (struct xs_handle *h,unsigned int *num) +{ +struct xsd_sockmsg msg = { .type =XS_GET_QUOTA }; +struct iovec iov[1 ]; +char **quota; +char *reply; +char *c; +unsigned int i; + + iov[0 ].iov_base = &msg; + iov[0 ].iov_len =sizeof (msg); + + reply =xs_talkv (h, iov,ARRAY_SIZE (iov),NULL ); +if (!reply) +return NULL ; + + *num =1 ; +for (c = reply; *c; c++) +if (*c ==' ' ) + (*num)++; + + quota =malloc (*num *sizeof (char *) +strlen (reply) +1 ); + c = (char *)(quota + *num); +strcpy (c, reply); +for (i =0 ; i < *num; i++) {
Quoted 8 lines
tools/libs/store/xs.c bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, · line 1486
Quoted 3 lines
tools/libs/store/xs.c +3
-0+ quota[i] = c; + c =strchr (c,' ' ); +if (c) {If
cis NULL, it's likely that this is the last iteration of theforloop. But just in case, should we prevent the code from doing another round and preventstrchr(NULL, ' ')? (Or just check thatcis !NULL, and let the loop finish set NULL for the remaining slot inquota)
Not sure this is really needed. *num is set just a few lines further up using the same way to count the number of strings. Do we really need to do consistency checks of intermediate results in such a short function?
Quoted 25 lines
Quoted 25 lines
tools/libs/store/xs.c +24
-0+ *c =0 ; + c++; + } + } + +return quota; +} + +bool xs_get_global_quota (struct xs_handle *h,char *quota, +unsigned int *value) +{ +struct xsd_sockmsg msg = { .type =XS_GET_QUOTA }; +struct iovec iov[2 ]; + + iov[0 ].iov_base = &msg; + iov[0 ].iov_len =sizeof (msg); + iov[1 ].iov_base = quota; + iov[1 ].iov_len =strlen (quota) +1 ; + +return xs_uint (xs_talkv (h, iov,ARRAY_SIZE (iov),NULL ), value); +} + +bool xs_set_global_quota (struct xs_handle *h,char *quota, +unsigned int value)
Quoted 8 lines
tools/libs/store/xs.c bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, · line 1513
Quoted 3 lines
tools/libs/store/xs.c +3
-0+{ +struct xsd_sockmsg msg = { .type =XS_SET_QUOTA }; +char val_str[MAX_STRLEN (value)];
MAX_STRLENdoesn't have a great name, I wounder what is was :-). And it's not about a maximum size of payload that could go on xs wire or something, it's actually the maximum string size that can take a numerical value, when converted to charaters.
Unfortunately the MAX_STRLEN() macro is defined in a public header file. I could define another macro with a different name doing the same and use that here, but MAX_STRLEN() would still be there.
What is your preference?
Juergen
Re: [PATCH 01/11] tools/libs/store: add get- and set-quota related functions
Quoted 43 lines · Jürgen Groß
Quoted 33 lines · Anthony PERARD
Quoted 32 lines · Juergen Gross
tools/libs/store/xs.c +25
-0@@ -1456,6 +1456,117 @@ bool xs_set_features_domain(struct xs_handle *h, unsigned int domid,return xs_bool (xs_talkv (h, iov,ARRAY_SIZE (iov),NULL )); } +char **xs_get_quota_names (struct xs_handle *h,unsigned int *num) +{ +struct xsd_sockmsg msg = { .type =XS_GET_QUOTA }; +struct iovec iov[1 ]; +char **quota; +char *reply; +char *c; +unsigned int i; + + iov[0 ].iov_base = &msg; + iov[0 ].iov_len =sizeof (msg); + + reply =xs_talkv (h, iov,ARRAY_SIZE (iov),NULL ); +if (!reply) +return NULL ; + + *num =1 ; +for (c = reply; *c; c++) +if (*c ==' ' ) + (*num)++; + + quota =malloc (*num *sizeof (char *) +strlen (reply) +1 ); + c = (char *)(quota + *num); +strcpy (c, reply); +for (i =0 ; i < *num; i++) {Quoted 8 lines
tools/libs/store/xs.c bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, · line 1486
Quoted 3 lines
tools/libs/store/xs.c +3
-0+ quota[i] = c; + c =strchr (c,' ' ); +if (c) {If
cis NULL, it's likely that this is the last iteration of theforloop. But just in case, should we prevent the code from doing another round and preventstrchr(NULL, ' ')? (Or just check thatcis !NULL, and let the loop finish set NULL for the remaining slot inquota)
Quoted 3 lines
Not sure this is really needed. *num is set just a few lines further up using the same way to count the number of strings. Do we really need to do consistency checks of intermediate results in such a short function?
I guess it's ok.
Quoted 34 lines
Quoted 25 lines
Quoted 25 lines
tools/libs/store/xs.c +24
-0+ *c =0 ; + c++; + } + } + +return quota; +} + +bool xs_get_global_quota (struct xs_handle *h,char *quota, +unsigned int *value) +{ +struct xsd_sockmsg msg = { .type =XS_GET_QUOTA }; +struct iovec iov[2 ]; + + iov[0 ].iov_base = &msg; + iov[0 ].iov_len =sizeof (msg); + iov[1 ].iov_base = quota; + iov[1 ].iov_len =strlen (quota) +1 ; + +return xs_uint (xs_talkv (h, iov,ARRAY_SIZE (iov),NULL ), value); +} + +bool xs_set_global_quota (struct xs_handle *h,char *quota, +unsigned int value)Quoted 8 lines
tools/libs/store/xs.c bool xs_set_features_domain(struct xs_handle *h, unsigned int domid, · line 1513
Quoted 3 lines
tools/libs/store/xs.c +3
-0+{ +struct xsd_sockmsg msg = { .type =XS_SET_QUOTA }; +char val_str[MAX_STRLEN (value)];
MAX_STRLENdoesn't have a great name, I wounder what is was :-). And it's not about a maximum size of payload that could go on xs wire or something, it's actually the maximum string size that can take a numerical value, when converted to charaters.
Quoted 5 lines
Unfortunately the
MAX_STRLEN()macro is defined in a public header file. I could define another macro with a different name doing the same and use that here, butMAX_STRLEN()would still be there.What is your preference?
Well, it's probably better to leave it like that. Having two different macro names might be more confusing than useful. And I see that the macro is only defined three time in the repo. Next time I'll stumble on MAX_STRLEN, I'll know what it mean.
Cheers,,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 2/11 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().
--- tools/xenstored/core.c | 4 +- tools/xenstored/domain.c | 74 +++++++++++++++++------------------ tools/xenstored/domain.h | 7 ++-- tools/xenstored/transaction.c | 2 +- tools/xenstored/watch.c | 4 +- 5 files changed, 43 insertions(+), 48 deletions(-)
tools/xenstored/core.c +2 -2
@@ -1538,7 +1538,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_check_quota_add (conn->domain,ACC_NODES ,1 )) { ret =ENOSPC ; goto err; }
@@ -2320,7 +2320,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 +3 -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,8 @@ 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_check_quota_add (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_check_quota_add (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_check_quota_add (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
Re: [PATCH 02/11] tools/xenstored: add central quota check functions
Quoted 7 lines · Juergen Gross
Add 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().
This patch changes the return value of do_watch(), from E2BIG to ENOSPC, but that's not mention.
tools/xenstored/domain.c static bool domain_can_read(struct connection *conn) · line 512
Quoted 10 lines
tools/xenstored/domain.c +1
-1@@ -490,10 +509,9 @@ static bool domain_can_read(struct connection *conn)if (domain_is_unprivileged (conn)) {if (domain->wrl_credit <0 )return false; -if (domain->acc[ACC_OUTST ].val >= hard_quotas[ACC_OUTST ].val) +if (domain_check_quota_add (domain,ACC_OUTST ,0 ))
Is this change fixing a potential bug? As now we check if there's a quota for OUTST.
Quoted 12 lines
tools/xenstored/domain.c +1
-2return false; -if (domain->acc[ACC_MEM ].val >= hard_quotas[ACC_MEM ].val && - hard_quotas[ACC_MEM ].val) +if (domain_check_quota_add (domain,ACC_MEM ,0 ))return false; }tools/xenstored/watch.c +0
-0
tools/xenstored/watch.c int do_watch(const void *ctx, struct connection *conn, struct buffered_data *in) · line 224
Quoted 7 lines
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_check_quota_add (conn->domain,ACC_WATCH ,1 )) +return ENOSPC ;
Change of return value here not mentionned, even if it now aligned with the value returned in other places.
tools/xenstored/watch.c int do_watch(const void *ctx, struct connection *conn, struct buffered_data *in) · line 227
Quoted 3 lines
tools/xenstored/watch.c +0
-0watch =add_watch (conn, vec[0 ], vec[1 ], relative, false);if (!watch)
Patch looks fine to me:
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 02/11] tools/xenstored: add central quota check functions
Quoted 11 lines · Anthony PERARD
Quoted 7 lines · Juergen Gross
Add 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().This patch changes the return value of
do_watch(), from E2BIG to ENOSPC, but that's not mention.
I can add a remark to the commit message.
Quoted 14 lines
tools/xenstored/domain.c static bool domain_can_read(struct connection *conn) · line 512
Quoted 11 lines
tools/xenstored/domain.c +1
-1@@ -490,10 +509,9 @@ static bool domain_can_read(struct connection *conn)if (domain_is_unprivileged (conn)) {if (domain->wrl_credit <0 )return false; -if (domain->acc[ACC_OUTST ].val >= hard_quotas[ACC_OUTST ].val) +if (domain_check_quota_add (domain,ACC_OUTST ,0 ))Is this change fixing a potential bug? As now we check if there's a quota for OUTST.
This is just changing how the quota is tested.
Quoted 25 lines
Quoted 13 lines
tools/xenstored/domain.c +1
-2return false; -if (domain->acc[ACC_MEM ].val >= hard_quotas[ACC_MEM ].val && - hard_quotas[ACC_MEM ].val) +if (domain_check_quota_add (domain,ACC_MEM ,0 ))return false; }tools/xenstored/watch.c +0
-0tools/xenstored/watch.c int do_watch(const void *ctx, struct connection *conn, struct buffered_data *in) · line 224
Quoted 7 lines
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_check_quota_add (conn->domain,ACC_WATCH ,1 )) +return ENOSPC ;Change of return value here not mentionned, even if it now aligned with the value returned in other places.
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
watch = add_watch(conn, vec[0], vec[1], relative, false); if (!watch)Patch looks fine to me:
Reviewed-by Anthony PERARD <[email protected]>
Thanks
Juergen
Re: [PATCH 02/11] tools/xenstored: add central quota check functions
In reply to Juergen GrossQuoted 17 lines · Juergen Gross
Add 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().Signed-off-by Juergen Gross <[email protected]>tools/xenstored/domain.c +0
-0@@ -389,6 +389,25 @@ void wrl_apply_debit_trans_commit(struct connection *conn)wrl_apply_debit_actual (conn->domain); }
tools/xenstored/domain.c void wrl_apply_debit_trans_commit(struct connection *conn) · line 400
Quoted 10 lines
tools/xenstored/domain.c +9
-0+static bool domain_check_quota_val (struct domain *d,enum accitem what, +unsigned int val) +{ +unsigned int quota = hard_quotas[what].val; + +if (!quota || !domid_is_unprivileged (d->domid)) +return false; + +return val >= quota;
Personally, I don't like the naming of *check* where the "good" return is false. That seems backwards from what I expect. So I'd suggest either flipping the return value or renaming. domain_quota_fail() or something?
tools/xenstored/domain.c void wrl_apply_debit_trans_commit(struct connection *conn) · line 413
Quoted 13 lines
tools/xenstored/domain.c +10
-0+} + +bool domain_check_quota_add (struct domain *d,enum accitem what,int add) +{ +if (add <0 || !d) +return false; + +return domain_check_quota_val (d, what, d->acc[what].val + add); +} +static bool check_indexes (XENSTORE_RING_IDX cons,XENSTORE_RING_IDX prod) {return ((prod - cons) <=XENSTORE_RING_SIZE );
As an example, here "good" is true.
I see Anthony already gave an R-b, so just consider it as a suggestion.
Thanks,
Jason
Re: [PATCH 02/11] tools/xenstored: add central quota check functions
Quoted 21 lines · Jason Andryuk
Quoted 20 lines · Juergen Gross
Add 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().Signed-off-by Juergen Gross <[email protected]>tools/xenstored/domain.c +3
-0@@ -389,6 +389,25 @@ void wrl_apply_debit_trans_commit(struct connection *conn) wrl_apply_debit_actual(conn->domain); } +static bool domain_check_quota_val (struct domain *d,enum accitem what, + unsigned int val) +{
Quoted 8 lines
tools/xenstored/domain.c void wrl_apply_debit_trans_commit(struct connection *conn) · line 400
Quoted 6 lines
tools/xenstored/domain.c +6
-0+ unsigned int quota = hard_quotas[what].val; + + if (!quota || !domid_is_unprivileged(d->domid)) + return false; + + return val >= quota;Personally, I don't like the naming of *check* where the "good" return is false. That seems backwards from what I expect. So I'd suggest either flipping the return value or renaming.
domain_quota_fail()or something?
I'll go with domain_quota_exceeded().
Thanks,
Juergen
PATCH 3/11 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
@@ -2613,10 +2613,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;
@@ -2625,8 +2624,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 ; } }
@@ -2634,6 +2634,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" ,
@@ -2687,7 +2692,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;
@@ -2699,10 +2704,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;
@@ -2715,22 +2720,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
Re: [PATCH 03/11] tools/xenstored: rework hard_quotas and soft_quotas arrays
Quoted 5 lines · Juergen Gross
Instead 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.
Quoted 7 lines
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.
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 4/11 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.
--- tools/xenstored/domain.c | 123 +++++++++++++++++++++++++++++++++++++++ tools/xenstored/domain.h | 2 + tools/xenstored/lu.c | 6 ++ 3 files changed, 131 insertions(+)
tools/xenstored/domain.c +123 -0
@@ -1332,6 +1332,27 @@ 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-" ,5 )) { + *idx =Q_IDX_HARD ; + }else { + *idx =Q_IDX_SOFT ; + name +=5 ; + } +for (q =0 ; q <ACC_N ; q++) { +if (quota_adm[q].name && !strcmp (quota_adm[q].name, name)) { + *qidx = q; +return false; + } + } + +return true; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);
@@ -2001,6 +2022,61 @@ void read_state_connection(const void *ctx, const void *state) } } +static unsigned int get_quota_size (struct quota *quota,unsigned int *len) +{ +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 ) { + 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) +5 +1 ; + } + } + +return n; +} + +static void build_quota_data (struct quota *quota,uint32_t *val,char *name) +{ +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 (name, quota_adm[q].name); + name +=strlen (name) +1 ; + } +if (quota[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + val[n++] = quota[q].val[Q_IDX_SOFT ]; +strcpy (name,"soft-" ); +strcpy (name +5 , quota_adm[q].name); + name +=strlen (name) +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;
@@ -2049,6 +2125,53 @@ 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 len =sizeof (*glb); +size_t ret; + + n_quota =get_quota_size (quotas, &len); + len += n_quota *sizeof (glb->quota_val[0 ]); + len =ROUNDUP (len,3 ); + + record =talloc_size (NULL , len +sizeof (*head)); +if (!record) +return "Dump global quota allocation error" ; + + head = record; + head->type =XS_STATE_TYPE_GLB_QUOTA ; + head->length = 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, 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
@@ -173,10 +173,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 04/11] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
tools/xenstored/domain.c int do_set_feature(const void *ctx, struct connection *conn, · line 1338
Quoted 12 lines · Juergen Gross
tools/xenstored/domain.c +4
-0@@ -1332,6 +1332,27 @@ 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;
What do you think of using something like:
const char soft_prefix[] = "soft-";
const size_t soft_prefix_len = sizeof(soft_prefix) - 1;
to explain the `5`, here and in e.g. the function build_quota_data() ?
We used this in libxl in one place:
https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/light/libxl_qmp.c#L1288But it's fine to leave it like that, as the '5's are close enought to the prefix that we can guess easly enough.
Quoted 29 lines
tools/xenstored/domain.c +22
-0+ +if (strncmp (name,"soft-" ,5 )) { + *idx =Q_IDX_HARD ; + }else { + *idx =Q_IDX_SOFT ; + name +=5 ; + } +for (q =0 ; q <ACC_N ; q++) { +if (quota_adm[q].name && !strcmp (quota_adm[q].name, name)) { + *qidx = q; +return false; + } + } + +return true; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);@@ -2001,6 +2022,61 @@ void read_state_connection(const void *ctx, const void *state) } } +static unsigned int get_quota_size (struct quota *quota,unsigned int *len) +{ +unsigned int q; +unsigned int n =0 ; +
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2039
Quoted 10 lines
tools/xenstored/domain.c +10
-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) +5 +1 ;
The value 5 here isn't explained. A comment would be nice.
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2046
Quoted 7 lines
tools/xenstored/domain.c +7
-0+ } + } + +return n; +} + +static void build_quota_data (struct quota *quota,uint32_t *val,char *name)
I guess we will need a leap of faith to trust that val is big enough, after finding out that it's actually an output of multiple values, and not an input of a single value.
And name seems to also be an output, and this is actually impossible to guess from the prototype.
Quoted 20 lines
tools/xenstored/domain.c +20
-0+{ +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 (name, quota_adm[q].name); + name +=strlen (name) +1 ; + } +if (quota[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + val[n++] = quota[q].val[Q_IDX_SOFT ]; +strcpy (name,"soft-" ); +strcpy (name +5 , quota_adm[q].name); + name +=strlen (name) +1 ; + } + } +}
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2076
Quoted 10 lines
tools/xenstored/domain.c +10
-0+ +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 ;
So for val, we have a size. But, we don't have a size for name, are we sure that it's safe to keep reading past NUL characters ? Is the size of name available somewhere?
Quoted 10 lines
tools/xenstored/domain.c +3
-0+ } +} +static int dump_state_domain (const void *k,void *v,void *arg) {struct domain *domain = v;@@ -2049,6 +2125,53 @@ void read_state_domain(const void *ctx, const void *state, unsigned int version) domain->features = sd->features; }
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2137
Quoted 10 lines
tools/xenstored/domain.c +10
-0+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 len =sizeof (*glb); +size_t ret; + + n_quota =get_quota_size (quotas, &len);
So, get_quota_size is actually an "add" the size to this variable, and not "store" the size in this variable. That's not confusing at all.
Quoted 4 lines
tools/xenstored/domain.c +4
-0+ len += n_quota *sizeof (glb->quota_val[0 ]); + len =ROUNDUP (len,3 ); + + record =talloc_size (NULL , len +sizeof (*head));
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2151
Quoted 10 lines
tools/xenstored/domain.c +10
-0+if (!record) +return "Dump global quota allocation error" ; + + head = record; + head->type =XS_STATE_TYPE_GLB_QUOTA ; + head->length = len; + + glb = (struct xs_state_glb_quota *)(head +1 ); + glb->n_dom_quota = n_quota; + glb->n_glob_quota =0 ;
Shouldn't n_quota be assigned to n_glob_quota instead? We don't have per-domain quota yet, and only have global quota, right?
Quoted 13 lines
tools/xenstored/domain.c +13
-0+ +build_quota_data (quotas, glb->quota_val, + (char *)(glb->quota_val + n_quota)); + + ret =fwrite (record, len +sizeof (*head),1 , fp); + +talloc_free (record); + +if (ret !=1 ||dump_state_align (fp)) +return "Dump global quota error" ; + +return NULL ; +}
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2174
Quoted 10 lines
tools/xenstored/domain.c +10
-0+ +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); +} +
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 04/11] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
Quoted 15 lines · Anthony PERARD
tools/xenstored/domain.c int do_set_feature(const void *ctx, struct connection *conn, · line 1338
Quoted 12 lines · Juergen Gross
tools/xenstored/domain.c +4
-0@@ -1332,6 +1332,27 @@ 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;What do you think of using something like:
Quoted 8 lines
const char soft_prefix[] = "soft-"; const size_t soft_prefix_len = sizeof(soft_prefix) - 1; to explain the `5`, here and in e.g. the function build_quota_data() ? We used this in libxl in one place: https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/light/libxl_qmp.c#L1288But it's fine to leave it like that, as the '5's are close enought to the prefix that we can guess easly enough.
I can change it, but I'd prefer to use macros for that purpose.
Quoted 34 lines
Quoted 34 lines
tools/xenstored/domain.c +26
-0+ +if (strncmp (name,"soft-" ,5 )) { + *idx =Q_IDX_HARD ; + }else { + *idx =Q_IDX_SOFT ; + name +=5 ; + } +for (q =0 ; q <ACC_N ; q++) { +if (quota_adm[q].name && !strcmp (quota_adm[q].name, name)) { + *qidx = q; +return false; + } + } + +return true; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);@@ -2001,6 +2022,61 @@ void read_state_connection(const void *ctx, const void *state) } } +static unsigned int get_quota_size (struct quota *quota,unsigned int *len) +{ +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 ) {
Quoted 8 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2039
Quoted 6 lines
tools/xenstored/domain.c +6
-0+ 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) +5 +1 ;The value 5 here isn't explained. A comment would be nice.
Using the macro mentioned above will make it more descriptive.
Quoted 12 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2046
Quoted 8 lines
tools/xenstored/domain.c +7
-0+ } + } + +return n; +} + +static void build_quota_data (struct quota *quota,uint32_t *val,char *name)I guess we will need a leap of faith to trust that
valis big enough, after finding out that it's actually an output of multiple values, and not an input of a single value.
That's what get_quota_size() is calculating.
Quoted 3 lines
And
nameseems to also be an output, and this is actually impossible to guess from the prototype.
True. What about names?
Quoted 27 lines
Quoted 27 lines
tools/xenstored/domain.c +26
-0+{ +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 (name, quota_adm[q].name); + name +=strlen (name) +1 ; + } +if (quota[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + val[n++] = quota[q].val[Q_IDX_SOFT ]; +strcpy (name,"soft-" ); +strcpy (name +5 , quota_adm[q].name); + name +=strlen (name) +1 ; + } + } +} + +static void parse_quota_data (const uint32_t *val,const char *name, +unsigned int n,struct quota *quota) +{ +unsigned int i, q, idx; +
Quoted 8 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2076
Quoted 4 lines
tools/xenstored/domain.c +4
-0+for (i =0 ; i < n; i++) { +if (!parse_quota_name (name, &q, &idx)) + quota[q].val[idx] = val[i]; + name +=strlen (name) +1 ;So for
val, we have a size. But, we don't have a size forname, are we sure that it's safe to keep reading pastNULcharacters ? Is the size of name available somewhere?
Yes. get_quota_size() calculated that as well.
Quoted 11 lines
Quoted 11 lines
tools/xenstored/domain.c +3
-0+ } +} +static int dump_state_domain (const void *k,void *v,void *arg) {struct domain *domain = v;@@ -2049,6 +2125,53 @@ void read_state_domain(const void *ctx, const void *state, unsigned int version) domain->features = sd->features; }
Quoted 13 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2137
Quoted 10 lines
tools/xenstored/domain.c +10
-0+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 len =sizeof (*glb); +size_t ret; + + n_quota =get_quota_size (quotas, &len);So,
get_quota_sizeis actually an "add" the size to this variable, and not "store" the size in this variable. That's not confusing at all.
Would it be better if len is renamed to names_len (both here and the parameter of get_quota_size())?
Quoted 10 lines
Quoted 10 lines
tools/xenstored/domain.c +9
-0+ len += n_quota *sizeof (glb->quota_val[0 ]); + len =ROUNDUP (len,3 ); + + record =talloc_size (NULL , len +sizeof (*head)); +if (!record) +return "Dump global quota allocation error" ; + + head = record; + head->type =XS_STATE_TYPE_GLB_QUOTA ;
Quoted 8 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2151
Quoted 5 lines
tools/xenstored/domain.c +5
-0+ head->length = len; + + glb = (struct xs_state_glb_quota *)(head +1 ); + glb->n_dom_quota = n_quota; + glb->n_glob_quota =0 ;Shouldn't
n_quotabe assigned ton_glob_quotainstead? We don't have per-domain quota yet, and only have global quota, right?
We are applying all global quota values to the domains, so this is fine.
It isn't about where we store the quota (per domain or globally), but how the quota values are used.
It would be possible to have e.g. "total_memory" or "total_nodes" quota which would not apply to single domains, but to all of xenstore. Those would need to be counted by n_glob_quota.
Quoted 16 lines
Quoted 16 lines
tools/xenstored/domain.c +15
-0+ +build_quota_data (quotas, glb->quota_val, + (char *)(glb->quota_val + n_quota)); + + ret =fwrite (record, 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)
Quoted 8 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2174
Quoted 8 lines
tools/xenstored/domain.c +8
-0+{ +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); +} +
Juergen
Re: [PATCH 04/11] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
Quoted 85 lines · Jürgen Groß
Quoted 21 lines · Anthony PERARD
tools/xenstored/domain.c int do_set_feature(const void *ctx, struct connection · line 1338
Quoted 12 lines · Juergen Gross
tools/xenstored/domain.c +4
-0@@ -1332,6 +1332,27 @@ 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;What do you think of using something like:
const char soft_prefix[] = "soft-";
constsize_tsoft_prefix_len=sizeof(soft_prefix)- 1;
to explain the5, here and in e.g. the functionbuild_quota_data()? We used this in libxl in one place:
https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/light/ libxl_qmp.c#L1288Quoted 2 lines
But it's fine to leave it like that, as the '5's are close enought to the prefix that we can guess easly enough.
I can change it, but I'd prefer to use macros for that purpose.
Quoted 34 lines
Quoted 34 lines
tools/xenstored/domain.c +26
-0+ + if (strncmp(name, "soft-", 5)) { + *idx = Q_IDX_HARD; + } else { + *idx = Q_IDX_SOFT; + name += 5; + } + for (q = 0; q < ACC_N; q++) { + if (quota_adm[q].name && !strcmp(quota_adm[q].name, name)) { + *qidx = q; + return false; + } + } + + return true; +} + static int close_xgt_handle(void *_handle) { xengnttab_close(*(xengnttab_handle **)_handle);@@ -2001,6 +2022,61 @@ void read_state_connection(const void *ctx, const void *state) } } +static unsigned int get_quota_size (struct quota *quota,unsigned int *len) +{ + 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) {Quoted 8 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2039
Quoted 6 lines
tools/xenstored/domain.c +6
-0+ 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) + 5 + 1;The value 5 here isn't explained. A comment would be nice.
Using the macro mentioned above will make it more descriptive.
Quoted 12 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2046
Quoted 8 lines
tools/xenstored/domain.c +7
-0+ } + } + + return n; +} + +static void build_quota_data (struct quota *quota,uint32_t *val,char *name)I guess we will need a leap of faith to trust that
valis big enough, after finding out that it's actually an output of multiple values, and not an input of a single value.
Quoted 7 lines
That's what
get_quota_size()is calculating.Quoted 3 lines
And
nameseems to also be an output, and this is actually impossible to guess from the prototype.True. What about names?
I have chosen names_buf instead, making it more clear that this is an output parameter for multiple names.
Quoted 64 lines
Quoted 28 lines
Quoted 28 lines
tools/xenstored/domain.c +26
-0+{ + 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(name, quota_adm[q].name); + name += strlen(name) + 1; + } + if (quota[q].val[Q_IDX_SOFT] != Q_VAL_DISABLED) { + val[n++] = quota[q].val[Q_IDX_SOFT]; + strcpy(name, "soft-"); + strcpy(name + 5, quota_adm[q].name); + name += strlen(name) + 1; + } + } +} + +static void parse_quota_data (const uint32_t *val,const char *name, + unsigned int n, struct quota *quota) +{ + unsigned int i, q, idx; +Quoted 8 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2076
Quoted 4 lines
tools/xenstored/domain.c +4
-0+ for (i = 0; i < n; i++) { + if (!parse_quota_name(name, &q, &idx)) + quota[q].val[idx] = val[i]; + name += strlen(name) + 1;So for
val, we have a size. But, we don't have a size forname, are we sure that it's safe to keep reading pastNULcharacters ? Is the size of name available somewhere?Yes.
get_quota_size()calculated that as well.Quoted 16 lines
Quoted 16 lines
tools/xenstored/domain.c +8
-0+ } +} + static int dump_state_domain(const void *k, void *v, void *arg) { struct domain *domain = v;@@ -2049,6 +2125,53 @@ 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;Quoted 8 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2137
Quoted 5 lines
tools/xenstored/domain.c +5
-0+ unsigned int n_quota; + unsigned int len = sizeof(*glb); + size_t ret; + + n_quota = get_quota_size(quotas, &len);So,
get_quota_sizeis actually an "add" the size to this variable, and not "store" the size in this variable. That's not confusing at all.
Quoted 2 lines
Would it be better if len is renamed to
names_len(both here and the parameter ofget_quota_size())?
In the end I have chosen to add a comment above get_quota_size() and rename "len" to "rec_len" in dump_state_glb_quota().
Juergen
Re: [PATCH 04/11] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
Quoted 12 lines · Juergen Gross
Quoted 11 lines · Jürgen Groß
Quoted 6 lines · Anthony PERARD
Quoted 1 line · Juergen Gross
+static void
build_quota_data(struct quota *quota, uint32_t *val, char *name)I guess we will need a leap of faith to trust that
valis big enough, after finding out that it's actually an output of multiple values, and not an input of a single value.That's what
get_quota_size()is calculating.Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
And
nameseems to also be an output, and this is actually impossible to guess from the prototype.True. What about names?
I have chosen
names_bufinstead, making it more clear that this is an output parameter for multiple names.
Sounds good.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2137
Quoted 10 lines
tools/xenstored/domain.c +10
-0+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 len = sizeof(*glb); + size_t ret; + + n_quota = get_quota_size(quotas, &len);So,
get_quota_sizeis actually an "add" the size to this variable, and not "store" the size in this variable. That's not confusing at all.
Quoted 5 lines
Quoted 2 lines
Would it be better if len is renamed to
names_len(both here and the parameter ofget_quota_size())?In the end I have chosen to add a comment above
get_quota_size()and rename "len" to "rec_len" indump_state_glb_quota().
It would still be counter-intuitive if get_quota_size() returns different values depending on the initial value of the second parameter. A comment won't help. So I would still propose to add "sizeof(*glb)" to len or rec_len after calling get_quota_size.
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 04/11] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
Quoted 40 lines · Anthony PERARD
Quoted 12 lines · Juergen Gross
Quoted 11 lines · Jürgen Groß
Quoted 6 lines · Anthony PERARD
Quoted 1 line · Juergen Gross
+static void
build_quota_data(struct quota *quota, uint32_t *val, char *name)I guess we will need a leap of faith to trust that
valis big enough, after finding out that it's actually an output of multiple values, and not an input of a single value.That's what
get_quota_size()is calculating.Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
And
nameseems to also be an output, and this is actually impossible to guess from the prototype.True. What about names?
I have chosen
names_bufinstead, making it more clear that this is an output parameter for multiple names.Sounds good.
Quoted 17 lines
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
tools/xenstored/domain.c +5
-0+const char *dump_state_glb_quota (FILE *fp) +{ + struct xs_state_record_header *head; + struct xs_state_glb_quota *glb; + void *record;Quoted 8 lines
Quoted 5 lines
+ unsigned int
n_quota;
+ unsigned int len =sizeof(*glb);
+size_tret;
+
+n_quota=get_quota_size(quotas, &len);So,
get_quota_sizeis actually an "add" the size to this variable, and not "store" the size in this variable. That's not confusing at all.Would it be better if len is renamed to
names_len(both here and the parameter ofget_quota_size())?
Quoted 7 lines
Quoted 2 lines
In the end I have chosen to add a comment above
get_quota_size()and rename "len" to "rec_len" indump_state_glb_quota().It would still be counter-intuitive if
get_quota_size()returns different values depending on the initial value of the second parameter. A comment won't help. So I would still propose to add "sizeof(*glb)" tolenorrec_lenafter callingget_quota_size.
Okay, will change that.
Juergen
Re: [PATCH 04/11] tools/xenstored: add GLOBAL_QUOTA_DATA record for live update
In reply to Jürgen GroßQuoted 21 lines · Jürgen Groß
Quoted 20 lines · Anthony PERARD
tools/xenstored/domain.c int do_set_feature(const void *ctx, struct connection *conn, · line 1337
Quoted 11 lines · Juergen Gross
tools/xenstored/domain.c +4
-0@@ -1332,6 +1332,27 @@ 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;What do you think of using something like:
const char soft_prefix[] = "soft-"; const size_t soft_prefix_len = sizeof(soft_prefix) - 1; to explain the `5`, here and in e.g. the function build_quota_data() ? We used this in libxl in one place: https://elixir.bootlin.com/xen/v4.21.0/source/tools/libs/light/libxl_qmp.c#L1288
Quoted 4 lines
Quoted 2 lines
But it's fine to leave it like that, as the '5's are close enought to the prefix that we can guess easly enough.
I can change it, but I'd prefer to use macros for that purpose.
Sounds good.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
tools/xenstored/domain.c +9
-0+static unsigned int get_quota_size (struct quota *quota,unsigned int *len) +{ +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 ) {Quoted 8 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2039
Quoted 6 lines
tools/xenstored/domain.c +6
-0+ 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) +5 +1 ;The value 5 here isn't explained. A comment would be nice.
Quoted 1 line
Using the macro mentioned above will make it more descriptive.
Thanks.
Quoted 13 lines
Quoted 12 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2046
Quoted 8 lines
tools/xenstored/domain.c +7
-0+ } + } + +return n; +} + +static void build_quota_data (struct quota *quota,uint32_t *val,char *name)I guess we will need a leap of faith to trust that
valis big enough, after finding out that it's actually an output of multiple values, and not an input of a single value.
Quoted 1 line
That's what
get_quota_size()is calculating.
Right. I'm probably just looking at function as been independent of the rest of the program a bit too much.
Quoted 5 lines
Quoted 3 lines
And
nameseems to also be an output, and this is actually impossible to guess from the prototype.True. What about names?
names would be better here, indeed.
Quoted 62 lines
Quoted 27 lines
Quoted 27 lines
tools/xenstored/domain.c +26
-0+{ +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 (name, quota_adm[q].name); + name +=strlen (name) +1 ; + } +if (quota[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + val[n++] = quota[q].val[Q_IDX_SOFT ]; +strcpy (name,"soft-" ); +strcpy (name +5 , quota_adm[q].name); + name +=strlen (name) +1 ; + } + } +} + +static void parse_quota_data (const uint32_t *val,const char *name, +unsigned int n,struct quota *quota) +{ +unsigned int i, q, idx; +Quoted 8 lines
tools/xenstored/domain.c void read_state_connection(const void *ctx, const void *state) · line 2076
Quoted 4 lines
tools/xenstored/domain.c +4
-0+for (i =0 ; i < n; i++) { +if (!parse_quota_name (name, &q, &idx)) + quota[q].val[idx] = val[i]; + name +=strlen (name) +1 ;So for
val, we have a size. But, we don't have a size forname, are we sure that it's safe to keep reading pastNULcharacters ? Is the size of name available somewhere?Yes.
get_quota_size()calculated that as well.Quoted 15 lines
Quoted 15 lines
tools/xenstored/domain.c +8
-0+ } +} +static int dump_state_domain (const void *k,void *v,void *arg) {struct domain *domain = v;@@ -2049,6 +2125,53 @@ 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;Quoted 8 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2137
Quoted 5 lines
tools/xenstored/domain.c +5
-0+unsigned int n_quota; +unsigned int len =sizeof (*glb); +size_t ret; + + n_quota =get_quota_size (quotas, &len);So,
get_quota_sizeis actually an "add" the size to this variable, and not "store" the size in this variable. That's not confusing at all.
Quoted 2 lines
Would it be better if len is renamed to
names_len(both here and the parameter ofget_quota_size())?
Do you mean adding a new variable names_len? And having get_quota_size set it to 0 before calculating the size?
I would be ok also with adding sizeof(*glb) to len after calling get_quota_size(), but still need to have get_quota_size() start counting from 0.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
tools/xenstored/domain.c +9
-0+ len += n_quota *sizeof (glb->quota_val[0 ]); + len =ROUNDUP (len,3 ); + + record =talloc_size (NULL , len +sizeof (*head)); +if (!record) +return "Dump global quota allocation error" ; + + head = record; + head->type =XS_STATE_TYPE_GLB_QUOTA ;Quoted 8 lines
tools/xenstored/domain.c void read_state_domain(const void *ctx, const void *state, unsigned int version) · line 2151
Quoted 5 lines
tools/xenstored/domain.c +5
-0+ head->length = len; + + glb = (struct xs_state_glb_quota *)(head +1 ); + glb->n_dom_quota = n_quota; + glb->n_glob_quota =0 ;Shouldn't
n_quotabe assigned ton_glob_quotainstead? We don't have per-domain quota yet, and only have global quota, right?
Quoted 8 lines
We are applying all global quota values to the domains, so this is fine.
It isn't about where we store the quota (per domain or globally), but how the quota values are used.
It would be possible to have e.g. "
total_memory" or "total_nodes" quota which would not apply to single domains, but to all of xenstore. Those would need to be counted byn_glob_quota.
Right, I think I figured that out only after seen the patch creating a different record for per-domain quota. (And seen that these two field were not changed in later patches). But thank for the explanation, and the possible way that n_glob_quota could be used.
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 5/11 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
@@ -140,10 +140,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;
@@ -410,7 +408,7 @@ bool domain_check_quota_add(struct domain *d, enum accitem what, int add)if (add <0 || !d)return false; -return domain_check_quota_val (d, what, d->acc[what].val + add); +return domain_check_quota_val (d, what, d->acc_val[what] + add); }static bool check_indexes (XENSTORE_RING_IDX cons,XENSTORE_RING_IDX prod)
@@ -582,7 +580,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)
@@ -590,7 +588,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,
@@ -774,7 +772,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 ; }
@@ -1637,10 +1635,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
@@ -1651,7 +1649,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;
@@ -1710,10 +1708,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)
@@ -1757,7 +1755,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 ; }
@@ -2193,7 +2191,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);
@@ -2248,7 +2246,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
Re: [PATCH 05/11] tools/xenstored: split acc[] array in struct domain
Quoted 6 lines · Juergen Gross
Prepare 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.
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 6/11 tools/xenstored: add infrastructure for per-domain quotas
In reply to Juergen GrossAdd the needed structures and helper functions for supporting quotas per domain.
--- tools/xenstored/domain.c | 59 ++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 15 deletions(-)
tools/xenstored/domain.c +44 -15
@@ -389,6 +389,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 ]; }
@@ -397,6 +400,9 @@ static bool domain_check_quota_val(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;
@@ -809,6 +815,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) {
@@ -822,6 +829,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 ;
@@ -2079,25 +2091,38 @@ 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 len =sizeof (*sd); +size_t ret; -if (lu_status->version >1 ) - sd.features = domain->features; + n_quota =get_quota_size (domain->acc, &len); + len += n_quota *sizeof (sd->quota_val[0 ]); + len =ROUNDUP (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 , len +sizeof (*head)); +if (!record)return 1 ; -return 0 ; + head = record; + head->type =XS_STATE_TYPE_DOMAIN ; + head->length = 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, len +sizeof (*head),1 , fp); + +talloc_free (record); + +return (ret !=1 ||dump_state_align (fp)) ?1 :0 ; }const char *dump_state_domains (FILE *fp)
@@ -2114,6 +2139,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)
@@ -2121,6 +2148,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
Re: [PATCH 06/11] tools/xenstored: add infrastructure for per-domain quotas
Quoted 2 lines · Juergen Gross
Add the needed structures and helper functions for supporting quotas per domain.
I don't see any new struct or new helpers. What this patch do now is updating the existing helpers to take per-domain quota into account. I guess that comment was from an earlier iteration of the patch before it got split into smaller ones, and easier to review.
Quoted 2 lines
Signed-off-by Juergen Gross <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 06/11] tools/xenstored: add infrastructure for per-domain quotas
Quoted 8 lines · Anthony PERARD
Quoted 2 lines · Juergen Gross
Add the needed structures and helper functions for supporting quotas per domain.
I don't see any new struct or new helpers. What this patch do now is updating the existing helpers to take per-domain quota into account. I guess that comment was from an earlier iteration of the patch before it got split into smaller ones, and easier to review.
Indeed.
Will change the commit message.
Quoted 5 lines
Quoted 3 lines
Signed-off-by Juergen Gross <[email protected]>Reviewed-by Anthony PERARD <[email protected]>
Thanks,
Juergen
PATCH 7/11 tools/xenstored: implement the GET/SET_QUOTA commands
In reply to Juergen GrossAdd the implementation of the GET_QUOTA and SET_QUOTA wire commands.
--- tools/xenstored/core.c | 4 ++ tools/xenstored/domain.c | 106 +++++++++++++++++++++++++++++++++++++++ tools/xenstored/domain.h | 8 +++ 3 files changed, 118 insertions(+)
tools/xenstored/core.c +4 -0
@@ -2034,6 +2034,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 +106 -0
112 lines not on this page · raw message
tools/xenstored/domain.h +8 -0
@@ -93,6 +93,14 @@ int do_get_feature(const void *ctx, struct connection *conn,int do_set_feature (const void *ctx,struct connection *conn,struct buffered_data *in); +/* Get quota names or value */ +int do_get_quota (const void *ctx,struct connection *conn, +struct buffered_data *in); + +/* Set quota value */ +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 07/11] tools/xenstored: implement the GET/SET_QUOTA commands
Quoted 33 lines · Juergen Gross
tools/xenstored/core.c +4
-0@@ -2034,6 +2034,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 +10
-0@@ -1363,6 +1363,112 @@ static bool parse_quota_name(const char *name, unsigned int *qidx,return true; } +int do_get_quota (const void *ctx,struct connection *conn, +struct buffered_data *in) +{ +const char *vec[2 ]; +unsigned int n_pars; +unsigned int domid; +unsigned int q; +unsigned int idx; +char *resp; +const char *name;
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1385
Quoted 10 lines
tools/xenstored/domain.c +10
-0+const struct quota *quota; +const struct domain *domain; + + n_pars =get_strings (in, vec,ARRAY_SIZE (vec)); + +if (n_pars >2 ) +return EINVAL ; + +if (n_pars ==0 ) { + resp =talloc_asprintf (ctx,"%s" ,"" );
This could be written with talloc_strdup() instead, since there's no formatting involve.
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1391
Quoted 6 lines
tools/xenstored/domain.c +6
-0+if (!resp) +return ENOMEM ; +for (q =0 ; q <ACC_N ; q++) { +if (!quota_adm[q].name) +continue ; +if (quotas[q].val[Q_IDX_HARD ] !=Q_VAL_DISABLED ) {
Having set internally a value of Q_VAL_DISABLED, does it mean the named quota is unsupported?
Quoted 8 lines
tools/xenstored/domain.c +8
-0+ resp =talloc_asprintf_append (resp,"%s%s" , + *resp ?" " :"" , quota_adm[q].name); +if (!resp) +return ENOMEM ; + } +if (quotas[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + resp =talloc_asprintf_append (resp,"%ssoft-%s" , + *resp ?" " :"" , quota_adm[q].name);
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1409
Quoted 10 lines
tools/xenstored/domain.c +10
-0+if (!resp) +return ENOMEM ; + } + } + }else { +if (n_pars ==1 ) { + quota = quotas; + name = vec[0 ]; + }else { + domid =atoi (vec[0 ]);
Shall we check that vec[0] actually contain a plausible domid? (An integer between 0..65535). Right now, this accept everything, and would return 0 if there's not a single digit.
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1420
Quoted 11 lines
tools/xenstored/domain.c +11
-0+ domain =find_or_alloc_existing_domain (domid); +if (!domain) +return ENOENT ; + quota = domain->acc; + name = vec[1 ]; + } + +if (parse_quota_name (name, &q, &idx)) +return EINVAL ; + + resp =talloc_asprintf (ctx,"%u" , quota[q].val[idx]);
Why do we return 4294967295 for disabled quota check when the spec say to return "0" when a quota check is disabled? That is for quota names that are supposed to be not supported (if we ask "GET_QUOTA" first).
Quoted 21 lines
tools/xenstored/domain.c +21
-0+if (!resp) +return ENOMEM ; + } + +send_reply (conn,XS_GET_QUOTA , resp,strlen (resp) +1 ); + +return 0 ; +} + +int do_set_quota (const void *ctx,struct connection *conn, +struct buffered_data *in) +{ +const char *vec[3 ]; +unsigned int n_pars; +unsigned int domid; +unsigned int q; +unsigned int idx; +const char *name; +unsigned int val; +struct quota *quota; +struct domain *domain;
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1451
Quoted 10 lines
tools/xenstored/domain.c +10
-0+ + n_pars =get_strings (in, vec,ARRAY_SIZE (vec)); + +if (n_pars <2 || n_pars >3 ) +return EINVAL ; + +if (n_pars ==2 ) { + quota = quotas; + name = vec[0 ]; + val =atoi (vec[1 ]);
We should check that vec[1] is a valid quota value, and also not an internal value. Otherwise, we can just have "-1" on the wire, and have unexpected changes for example. Only "0" is documented as a quota been disabled, "-1" or "4294967295" isn't.
Quoted 28 lines
tools/xenstored/domain.c +20
-0+ }else { + domid =atoi (vec[0 ]); + domain =find_or_alloc_existing_domain (domid); +if (!domain) +return ENOENT ; + quota = domain->acc; + name = vec[1 ]; + val =atoi (vec[2 ]); + } + +if (parse_quota_name (name, &q, &idx)) +return EINVAL ; + + quota[q].val[idx] = val; + +send_ack (conn,XS_SET_QUOTA ); + +return 0 ; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);tools/xenstored/domain.h +0
-0
tools/xenstored/domain.h int do_get_feature(const void *ctx, struct connection *conn, · line 96
Quoted 4 lines
tools/xenstored/domain.h +1
-0@@ -93,6 +93,14 @@ int do_get_feature(const void *ctx, struct connection *conn,int do_set_feature (const void *ctx,struct connection *conn,struct buffered_data *in); +/* Get quota names or value */
This could say "implement GET_QUOTA" or something instead. But a comment here isn't going to give much value for internal functions.
tools/xenstored/domain.h int do_get_feature(const void *ctx, struct connection *conn, · line 106
Quoted 10 lines
tools/xenstored/domain.h +7
-0+int do_get_quota (const void *ctx,struct connection *conn, +struct buffered_data *in); + +/* Set quota value */ +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);
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 07/11] tools/xenstored: implement the GET/SET_QUOTA commands
Quoted 39 lines · Anthony PERARD
Quoted 38 lines · Juergen Gross
tools/xenstored/core.c +4
-0@@ -2034,6 +2034,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 +15
-0@@ -1363,6 +1363,112 @@ static bool parse_quota_name(const char *name, unsigned int *qidx,return true; } +int do_get_quota (const void *ctx,struct connection *conn, +struct buffered_data *in) +{ +const char *vec[2 ]; +unsigned int n_pars; +unsigned int domid; +unsigned int q; +unsigned int idx; +char *resp; +const char *name; +const struct quota *quota; +const struct domain *domain; + + n_pars =get_strings (in, vec,ARRAY_SIZE (vec)); +
Quoted 8 lines
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1385
Quoted 5 lines
tools/xenstored/domain.c +5
-0+if (n_pars >2 ) +return EINVAL ; + +if (n_pars ==0 ) { + resp =talloc_asprintf (ctx,"%s" ,"" );This could be written with
talloc_strdup()instead, since there's no formatting involve.
Right.
Quoted 10 lines
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1391
Quoted 7 lines
tools/xenstored/domain.c +6
-0+if (!resp) +return ENOMEM ; +for (q =0 ; q <ACC_N ; q++) { +if (!quota_adm[q].name) +continue ; +if (quotas[q].val[Q_IDX_HARD ] !=Q_VAL_DISABLED ) {Having set internally a value of
Q_VAL_DISABLED, does it mean the named quota is unsupported?
Yes. Right now all hard quota are supported and only one soft quota is supported.
Quoted 15 lines
Quoted 15 lines
tools/xenstored/domain.c +14
-0+ resp =talloc_asprintf_append (resp,"%s%s" , + *resp ?" " :"" , quota_adm[q].name); +if (!resp) +return ENOMEM ; + } +if (quotas[q].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED ) { + resp =talloc_asprintf_append (resp,"%ssoft-%s" , + *resp ?" " :"" , quota_adm[q].name); +if (!resp) +return ENOMEM ; + } + } + }else { +if (n_pars ==1 ) {
Quoted 8 lines
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1409
Quoted 4 lines
tools/xenstored/domain.c +4
-0+ quota = quotas; + name = vec[0 ]; + }else { + domid =atoi (vec[0 ]);Shall we check that vec[0] actually contain a plausible domid? (An integer between 0..65535). Right now, this accept everything, and would return 0 if there's not a single digit.
I have followed the pattern used in other places where a domid is expected.
In the end nothing will really break.
Any integer not being a domid will result in ENOENT, while the case of not a digit is a bug in privileged software (domids can be specified by dom0 only).
Quoted 16 lines
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1420
Quoted 12 lines
tools/xenstored/domain.c +11
-0+ domain =find_or_alloc_existing_domain (domid); +if (!domain) +return ENOENT ; + quota = domain->acc; + name = vec[1 ]; + } + +if (parse_quota_name (name, &q, &idx)) +return EINVAL ; + + resp =talloc_asprintf (ctx,"%u" , quota[q].val[idx]);Why do we return 4294967295 for disabled quota check when the spec say to return "0" when a quota check is disabled? That is for quota names that are supposed to be not supported (if we ask "
GET_QUOTA" first).
parse_quota_name() should have returned true in this case, so EINVAL should be returned.
Will fix that.
Quoted 29 lines
Quoted 29 lines
tools/xenstored/domain.c +28
-0+if (!resp) +return ENOMEM ; + } + +send_reply (conn,XS_GET_QUOTA , resp,strlen (resp) +1 ); + +return 0 ; +} + +int do_set_quota (const void *ctx,struct connection *conn, +struct buffered_data *in) +{ +const char *vec[3 ]; +unsigned int n_pars; +unsigned int domid; +unsigned int q; +unsigned int idx; +const char *name; +unsigned int val; +struct quota *quota; +struct domain *domain; + + n_pars =get_strings (in, vec,ARRAY_SIZE (vec)); + +if (n_pars <2 || n_pars >3 ) +return EINVAL ; + +if (n_pars ==2 ) {
Quoted 8 lines
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1451
Quoted 3 lines
tools/xenstored/domain.c +3
-0+ quota = quotas; + name = vec[0 ]; + val =atoi (vec[1 ]);We should check that vec[1] is a valid quota value, and also not an internal value. Otherwise, we can just have "-1" on the wire, and have unexpected changes for example. Only "0" is documented as a quota been disabled, "-1" or "4294967295" isn't.
Right, I'll check for val != Q_VAL_DISABLED.
Quoted 32 lines
Quoted 32 lines
tools/xenstored/domain.c +20
-0+ }else { + domid =atoi (vec[0 ]); + domain =find_or_alloc_existing_domain (domid); +if (!domain) +return ENOENT ; + quota = domain->acc; + name = vec[1 ]; + val =atoi (vec[2 ]); + } + +if (parse_quota_name (name, &q, &idx)) +return EINVAL ; + + quota[q].val[idx] = val; + +send_ack (conn,XS_SET_QUOTA ); + +return 0 ; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);tools/xenstored/domain.h +0
-0@@ -93,6 +93,14 @@ int do_get_feature(const void *ctx, struct connection *conn,int do_set_feature (const void *ctx,struct connection *conn,struct buffered_data *in);
Quoted 4 lines
tools/xenstored/domain.h int do_get_feature(const void *ctx, struct connection *conn, · line 96
Quoted 1 line
tools/xenstored/domain.h +1
-0+/* Get quota names or value */ This could say "implement
GET_QUOTA" or something instead. But a comment here isn't going to give much value for internal functions.
If nobody objects I'll drop the comment.
Quoted 11 lines
tools/xenstored/domain.h int do_get_feature(const void *ctx, struct connection *conn, · line 106
Quoted 11 lines
tools/xenstored/domain.h +7
-0+int do_get_quota (const void *ctx,struct connection *conn, +struct buffered_data *in); + +/* Set quota value */ +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);
Thanks,
Juergen
Re: [PATCH 07/11] tools/xenstored: implement the GET/SET_QUOTA commands
Quoted 12 lines · Juergen Gross
Quoted 10 lines · Anthony PERARD
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1409
Quoted 5 lines · Juergen Gross
tools/xenstored/domain.c +5
-0+if (n_pars ==1 ) { + quota = quotas; + name = vec[0 ]; + }else { + domid =atoi (vec[0 ]);Shall we check that vec[0] actually contain a plausible domid? (An integer between 0..65535). Right now, this accept everything, and would return 0 if there's not a single digit.
Quoted 3 lines
I have followed the pattern used in other places where a domid is expected.
In the end nothing will really break.
On the daemon, no, not really.
Quoted 3 lines
Any integer not being a domid will result in ENOENT, while the case of not a digit is a bug in privileged software (domids can be specified by dom0 only).
It would be a bug, indeed, but xenstored can help telling exactly where there's a bug, instead of ignoring it and carry-on. Well, just return EINVAL when something other than a number is found. You do that for quota, why not for domid as well?
That can also help when the daemon is replace by a different implementation that actually do the checks. (well it would help finding bug in the client earlier)
Quoted 35 lines
Quoted 26 lines
Quoted 26 lines
tools/xenstored/domain.c +20
-0+ }else { + domid =atoi (vec[0 ]); + domain =find_or_alloc_existing_domain (domid); +if (!domain) +return ENOENT ; + quota = domain->acc; + name = vec[1 ]; + val =atoi (vec[2 ]); + } + +if (parse_quota_name (name, &q, &idx)) +return EINVAL ; + + quota[q].val[idx] = val; + +send_ack (conn,XS_SET_QUOTA ); + +return 0 ; +} +static int close_xgt_handle (void *_handle) {xengnttab_close (*(xengnttab_handle **)_handle);tools/xenstored/domain.h +0
-1--- a/tools/xenstored/domain.hQuoted 8 lines
tools/xenstored/domain.h int do_get_feature(const void *ctx, struct connection *conn, · line 95
Quoted 5 lines
+++
b/tools/xenstored/domain.htools/xenstored/domain.h +1
-0@@ -93,6 +93,14 @@ int do_get_feature(const void *ctx, struct connection *conn,int do_set_feature (const void *ctx,struct connection *conn,struct buffered_data *in); +/* Get quota names or value */ This could say "implement
GET_QUOTA" or something instead. But a comment here isn't going to give much value for internal functions.
Quoted 1 line
If nobody objects I'll drop the comment.
Sounds good.
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 07/11] tools/xenstored: implement the GET/SET_QUOTA commands
Quoted 23 lines · Anthony PERARD
Quoted 12 lines · Juergen Gross
Quoted 10 lines · Anthony PERARD
tools/xenstored/domain.c static bool parse_quota_name(const char *name, unsigned int *qidx, · line 1409
Quoted 5 lines · Juergen Gross
tools/xenstored/domain.c +5
-0+if (n_pars ==1 ) { + quota = quotas; + name = vec[0 ]; + }else { + domid =atoi (vec[0 ]);Shall we check that vec[0] actually contain a plausible domid? (An integer between 0..65535). Right now, this accept everything, and would return 0 if there's not a single digit.
Quoted 3 lines
I have followed the pattern used in other places where a domid is expected.
In the end nothing will really break.
On the daemon, no, not really.
Quoted 3 lines
Any integer not being a domid will result in ENOENT, while the case of not a digit is a bug in privileged software (domids can be specified by dom0 only).
Quoted 8 lines
It would be a bug, indeed, but xenstored can help telling exactly where there's a bug, instead of ignoring it and carry-on. Well, just return EINVAL when something other than a number is found. You do that for quota, why not for domid as well?
That can also help when the daemon is replace by a different implementation that actually do the checks. (well it would help finding bug in the client earlier)
I have added another patch introducing a domid parser and using it where needed.
Juergen
PATCH 8/11 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).
--- 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 | 102 +++++++++++++++++++++++++++ 6 files changed, 219 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 + } + +// NewXsQuotaSet returns an instance of XsQuotaSet initialized with defaults. +func NewXsQuotaSet() (*XsQuotaSet, error) { +var ( +x XsQuotaSet +xc C.libxl_xs_quota_set) + +C.libxl_xs_quota_set_init(&xc) +defer C.libxl_xs_quota_set_dispose(&xc) + +if err := x.fromC(&xc); err != nil { +return nil, err } + +return &x, nil} + +func (x *XsQuotaSet) fromC(xc *C.libxl_xs_quota_set) 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 *XsQuotaSet) toC(xc *C.libxl_xs_quota_set) (err error){defer func(){ +if err != nil{ +C.libxl_xs_quota_set_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 XsQuotaSet 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_xsquota_global_get() +* libxl_xsquota_global_set() +* libxl_xsquota_domain_get() +* libxl_xsquota_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_xsquota_global_get (libxl_ctx *ctx,libxl_xs_quota_set *q); +int libxl_xsquota_global_set (libxl_ctx *ctx,libxl_xs_quota_set *q); +int libxl_xsquota_domain_get (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_set *q); +int libxl_xsquota_domain_set (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_set *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_set = Struct("xs_quota_set", [ + ("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 +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 08/11] tools/libxl: add functions for retrieving and setting xenstore quota
Quoted 114 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]>--- 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 | 102 +++++++++++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 tools/libs/light/libxl_xsquota.ctools/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 + } + +// NewXsQuotaSet returns an instance of XsQuotaSet initialized with defaults. +func NewXsQuotaSet() (*XsQuotaSet, error) { +var ( +x XsQuotaSet +xc C.libxl_xs_quota_set) + +C.libxl_xs_quota_set_init(&xc) +defer C.libxl_xs_quota_set_dispose(&xc) + +if err := x.fromC(&xc); err != nil { +return nil, err } + +return &x, nil} + +func (x *XsQuotaSet) fromC(xc *C.libxl_xs_quota_set) 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 *XsQuotaSet) toC(xc *C.libxl_xs_quota_set) (err error){defer func(){ +if err != nil{ +C.libxl_xs_quota_set_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 +2
-0@@ -543,6 +543,15 @@ Altp2MModeExternal Altp2MMode = 2 Altp2MModeLimited Altp2MMode = 3 ) +type XsQuotaItem struct { +Name string
tools/golang/xenlight/types.gen.go Altp2MModeExternal Altp2MMode = 2 · line 557
Quoted 10 lines
tools/golang/xenlight/types.gen.go +7
-0+Val uint32 +} + +type XsQuotaSet struct { +Quota []XsQuotaItem +} + type DomainBuildInfo struct { MaxVcpus int AvailVcpus Bitmap
For the golang stuff:
Re: [PATCH 08/11] tools/libxl: add functions for retrieving and setting xenstore quota
In reply to Juergen GrossQuoted 24 lines · Juergen Gross
tools/include/libxl.h +12
-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_xsquota_global_get() +* libxl_xsquota_global_set() +* libxl_xsquota_domain_get() +* libxl_xsquota_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);
tools/include/libxl.h static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, · line 3027
Quoted 5 lines
tools/include/libxl.h +2
-0@@ -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_xsquota_global_get (libxl_ctx *ctx,libxl_xs_quota_set *q);
Could you rename the second arg as "q_r" or "q_out" ?
tools/include/libxl.h static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, · line 3030
Quoted 3 lines
tools/include/libxl.h +3
-0+int libxl_xsquota_global_set (libxl_ctx *ctx,libxl_xs_quota_set *q); +int libxl_xsquota_domain_get (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_set *q);
Same here.
tools/include/libxl.h static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, · line 3032
Quoted 2 lines
tools/include/libxl.h +2
-0+int libxl_xsquota_domain_set (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_set *q);
Could we prefix them all with "libxl_xs_quota_" ? I would rather that we only use "xs_quota" or "xsquota".
Quoted 21 lines
tools/include/libxl.h +1
-0+#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.otools/libs/light/libxl_types.idl +0
-0
tools/libs/light/libxl_types.idl libxl_altp2m_mode = Enumeration("altp2m_mode", [ · line 582
Quoted 9 lines
tools/libs/light/libxl_types.idl +6
-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_set = Struct("xs_quota_set", [
Could you use "_list" as a suffix instead? It's a bit confusing to have the word "set" as a double meaning, with a _set() function that takes a set.
Quoted 15 lines
tools/libs/light/libxl_types.idl +3
-0+ ("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 +3
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ + +/* Xenstore quota handling functions. */
tools/libs/light/libxl_xsquota.c line 13
Quoted 10 lines
tools/libs/light/libxl_xsquota.c new file +10
-0+ +#include "libxl_internal.h" + +static int get_quota (libxl_ctx *ctx,unsigned int domid,libxl_xs_quota_set *q, +bool (func )(struct xs_handle *h,unsigned int domid, +char *quota,unsigned int *value)) +{ +char **names; +unsigned int num, i; +int rc =0 ;
We don't init rc variable in libxl function. Set rc to 0 just before the "out" label.
tools/libs/light/libxl_xsquota.c line 21
Quoted 8 lines
tools/libs/light/libxl_xsquota.c new file +8
-0+GC_INIT (ctx); + + names =xs_get_quota_names (ctx->xsh, &num); +if (!names) { +/* Xenstore quota support is optional! */ +if (errno !=ENOSYS ) + rc =ERROR_FAIL ; + q->num_quota =0 ;
It feels wrong to make changes to the output argument on error, if we can avoid it. And here, I don't see any reason to change q.
tools/libs/light/libxl_xsquota.c line 24
Quoted 3 lines
tools/libs/light/libxl_xsquota.c new file +3
-0+ goto out; + } +
Can you call libxl_xs_quota_set_init() first? As you call _dispose() later.
tools/libs/light/libxl_xsquota.c line 29
Quoted 5 lines
tools/libs/light/libxl_xsquota.c new file +5
-0+ q->num_quota = num; + q->quota =libxl__calloc (NOGC , num,sizeof (*q->quota)); +for (i =0 ; i < num; i++) { + q->quota[i].name =libxl__strdup (NOGC , names[i]); +if (!func (ctx->xsh, domid, q->quota[i].name, &q->quota[i].val)) {
Could you store the return value of func() in ok, and test ok in the if instead?
tools/libs/light/libxl_xsquota.c line 32
Quoted 3 lines
tools/libs/light/libxl_xsquota.c new file +3
-0+libxl_xs_quota_set_dispose (q); + rc =ERROR_FAIL ; +break ;
This can be goto out once free(names) is moved to the out label.
tools/libs/light/libxl_xsquota.c line 36
Quoted 4 lines
tools/libs/light/libxl_xsquota.c new file +4
-0+ } + } + +free (names);
Could you do that after the "out" label? And init names to NULL.
Quoted 8 lines
tools/libs/light/libxl_xsquota.c new file +8
-0+ + out: +GC_FREE ; +return rc; +} + +static int set_quota(libxl_ctx *ctx, unsigned int domid, libxl_xs_quota_set *q, + bool (func)(struct xs_handle *h, unsigned int domid,
tools/libs/light/libxl_xsquota.c line 54
Quoted 10 lines
tools/libs/light/libxl_xsquota.c new file +10
-0+ char *quota, unsigned int value)) +{ +unsigned int i; +int rc =0 ; +GC_INIT (ctx); + +for (i =0 ; i < q->num_quota; i++) { +if (!func (ctx->xsh, domid, q->quota[i].name, q->quota[i].val)) { + rc =ERROR_FAIL ; +break ;
It would be better to write goto out instead.
tools/libs/light/libxl_xsquota.c line 41
Quoted 6 lines
tools/libs/light/libxl_xsquota.c new file +6
-0+ } + } + +GC_FREE ; +return rc; +}
Thanks,
--
| Vates
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 08/11] tools/libxl: add functions for retrieving and setting xenstore quota
Quoted 171 lines · Anthony PERARD
Quoted 24 lines · Juergen Gross
tools/include/libxl.h +12
-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_xsquota_global_get() +* libxl_xsquota_global_set() +* libxl_xsquota_domain_get() +* libxl_xsquota_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);tools/include/libxl.h static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, · line 3027
Quoted 5 lines
tools/include/libxl.h +2
-0@@ -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_xsquota_global_get (libxl_ctx *ctx,libxl_xs_quota_set *q);Could you rename the second arg as "
q_r" or "q_out" ?tools/include/libxl.h static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, · line 3030
Quoted 3 lines
tools/include/libxl.h +3
-0+int libxl_xsquota_global_set (libxl_ctx *ctx,libxl_xs_quota_set *q); +int libxl_xsquota_domain_get (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_set *q);Same here.
tools/include/libxl.h static inline int libxl_qemu_monitor_command_0x041200(libxl_ctx *ctx, · line 3032
Quoted 2 lines
tools/include/libxl.h +2
-0+int libxl_xsquota_domain_set (libxl_ctx *ctx,uint32_t domid, +libxl_xs_quota_set *q);Could we prefix them all with "
libxl_xs_quota_" ? I would rather that we only use "xs_quota" or "xsquota".Quoted 21 lines
tools/include/libxl.h +1
-0+#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.otools/libs/light/libxl_types.idl +0
-0tools/libs/light/libxl_types.idl libxl_altp2m_mode = Enumeration("altp2m_mode", [ · line 582
Quoted 9 lines
tools/libs/light/libxl_types.idl +6
-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_set = Struct("xs_quota_set", [Could you use "
_list" as a suffix instead? It's a bit confusing to have the word "set" as a double meaning, with a_set()function that takes a set.Quoted 15 lines
tools/libs/light/libxl_types.idl +3
-0+ ("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 +3
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ + +/* Xenstore quota handling functions. */ tools/libs/light/libxl_xsquota.c line 13
Quoted 10 lines
tools/libs/light/libxl_xsquota.c new file +10
-0+ +#include "libxl_internal.h" + +static int get_quota (libxl_ctx *ctx,unsigned int domid,libxl_xs_quota_set *q, +bool (func )(struct xs_handle *h,unsigned int domid, +char *quota,unsigned int *value)) +{ +char **names; +unsigned int num, i; +int rc =0 ;We don't init
rcvariable in libxl function. Setrcto 0 just before the "out" label.tools/libs/light/libxl_xsquota.c line 21
Quoted 8 lines
tools/libs/light/libxl_xsquota.c new file +8
-0+GC_INIT (ctx); + + names =xs_get_quota_names (ctx->xsh, &num); +if (!names) { +/* Xenstore quota support is optional! */ +if (errno !=ENOSYS ) + rc =ERROR_FAIL ; + q->num_quota =0 ;It feels wrong to make changes to the output argument on error, if we can avoid it. And here, I don't see any reason to change
q.tools/libs/light/libxl_xsquota.c line 24
Quoted 3 lines
tools/libs/light/libxl_xsquota.c new file +3
-0+ goto out; + } +Can you call
libxl_xs_quota_set_init()first? As you call_dispose()later.tools/libs/light/libxl_xsquota.c line 29
Quoted 5 lines
tools/libs/light/libxl_xsquota.c new file +5
-0+ q->num_quota = num; + q->quota =libxl__calloc (NOGC , num,sizeof (*q->quota)); +for (i =0 ; i < num; i++) { + q->quota[i].name =libxl__strdup (NOGC , names[i]); +if (!func (ctx->xsh, domid, q->quota[i].name, &q->quota[i].val)) {Could you store the return value of
func()inok, and testokin the if instead?tools/libs/light/libxl_xsquota.c line 32
Quoted 3 lines
tools/libs/light/libxl_xsquota.c new file +3
-0+libxl_xs_quota_set_dispose (q); + rc =ERROR_FAIL ; +break ;This can be
goto outonce free(names) is moved to the out label.tools/libs/light/libxl_xsquota.c line 36
Quoted 4 lines
tools/libs/light/libxl_xsquota.c new file +4
-0+ } + } + +free (names);Could you do that after the "out" label? And init
namesto NULL.Quoted 8 lines
tools/libs/light/libxl_xsquota.c new file +8
-0+ + out: +GC_FREE ; +return rc; +} + +static int set_quota(libxl_ctx *ctx, unsigned int domid, libxl_xs_quota_set *q, + bool (func)(struct xs_handle *h, unsigned int domid,tools/libs/light/libxl_xsquota.c line 54
Quoted 10 lines
tools/libs/light/libxl_xsquota.c new file +10
-0+ char *quota, unsigned int value)) +{ +unsigned int i; +int rc =0 ; +GC_INIT (ctx); + +for (i =0 ; i < q->num_quota; i++) { +if (!func (ctx->xsh, domid, q->quota[i].name, q->quota[i].val)) { + rc =ERROR_FAIL ; +break ;It would be better to write
goto outinstead.
Quoted 6 lines
tools/libs/light/libxl_xsquota.c line 41
Quoted 6 lines
tools/libs/light/libxl_xsquota.c new file +6
-0+ } + } + +GC_FREE ; +return rc; +}
To all your remarks: yes, will do.
Thanks,
Juergen
PATCH 9/11 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.
--- tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/libs/light/libxl_dom.c | 8 ++++++++ tools/libs/light/libxl_domain.c | 10 ++++++++++ tools/libs/light/libxl_types.idl | 1 + 5 files changed, 26 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 XsQuotaSet } type DomainBuildInfoTypeUnion interface {
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_xsquota_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 +10 -0
@@ -2533,6 +2533,16 @@ static void retrieve_domain_configuration_end(libxl__egc *egc, } } +/* Xenstore quota */ + { +libxl_xs_quota_set_dispose (&d_config->b_info.xenstore_quota); + rc =libxl_xsquota_domain_get (CTX , domid, &d_config->b_info.xenstore_quota); +if (rc) { +LOGD (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_set), ], dir=DIR_IN, copy_deprecated_fn="libxl__domain_build_info_copy_deprecated",
Signature · 1 line
2.53.0
Re: [PATCH 09/11] tools/libxl: add support for xenstore quota in domain_config
Quoted 42 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]>--- tools/golang/xenlight/helpers.gen.go | 6 ++++++ tools/golang/xenlight/types.gen.go | 1 + tools/libs/light/libxl_dom.c | 8 ++++++++ tools/libs/light/libxl_domain.c | 10 ++++++++++ tools/libs/light/libxl_types.idl | 1 + 5 files changed, 26 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 +0
-0
tools/golang/xenlight/types.gen.go VmtraceBufKb int · line 635
Quoted 7 lines
tools/golang/xenlight/types.gen.go +1
-0@@ -629,6 +629,7 @@ VmtraceBufKb int Vpmu Defbool TrapUnmappedAccesses Defbool XenstoreFeatureMask uint32 +XenstoreQuota XsQuotaSet } type DomainBuildInfoTypeUnion interface {
For the golang stuff:
Re: [PATCH 09/11] tools/libxl: add support for xenstore quota in domain_config
In reply to Juergen GrossQuoted 5 lines · Juergen Gross
tools/libs/light/libxl_domain.c +0
-0
tools/libs/light/libxl_domain.c static void retrieve_domain_configuration_end(libxl__egc *egc, · line 2541
Quoted 9 lines
tools/libs/light/libxl_domain.c +6
-0@@ -2533,6 +2533,16 @@ static void retrieve_domain_configuration_end(libxl__egc *egc, } } +/* Xenstore quota */ + { +libxl_xs_quota_set_dispose (&d_config->b_info.xenstore_quota); + rc =libxl_xsquota_domain_get (CTX , domid, &d_config->b_info.xenstore_quota); +if (rc) { +LOGD (ERROR , domid,"Fail to get xenstore quota" );
It would be useful to print "errno" with LOGED, right?
Quoted 12 lines
tools/libs/light/libxl_domain.c +4
-0+ goto out; + } + } +/* Devices: disk, nic, vtpm, pcidev etc. */ /* The MERGE macro implements following logic: tools/libs/light/libxl_types.idl +0
-0
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 763
Quoted 4 lines
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_set),
This would deserve a new LIBXL_HAVE_ macro, or a mention about the new field in the macro added in the previous patch.
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 09/11] tools/libxl: add support for xenstore quota in domain_config
Quoted 9 lines · Anthony PERARD
Quoted 8 lines · Juergen Gross
tools/libs/light/libxl_domain.c +0
-0@@ -2533,6 +2533,16 @@ static void retrieve_domain_configuration_end(libxl__egc *egc, } }
Quoted 8 lines
tools/libs/light/libxl_domain.c static void retrieve_domain_configuration_end(libxl__egc *egc, · line 2541
Quoted 6 lines
tools/libs/light/libxl_domain.c +6
-0+/* Xenstore quota */ + { +libxl_xs_quota_set_dispose (&d_config->b_info.xenstore_quota); + rc =libxl_xsquota_domain_get (CTX , domid, &d_config->b_info.xenstore_quota); +if (rc) { +LOGD (ERROR , domid,"Fail to get xenstore quota" );It would be useful to print "errno" with LOGED, right?
Okay.
Quoted 7 lines
Quoted 7 lines
tools/libs/light/libxl_domain.c +4
-0+ goto out; + } + } +/* Devices: disk, nic, vtpm, pcidev etc. */
Quoted 13 lines
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 763
Quoted 10 lines
tools/libs/light/libxl_domain.c +0
-0/* 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_set),This would deserve a new
LIBXL_HAVE_macro, or a mention about the new field in the macro added in the previous patch.
I'll do the latter.
Thanks,
Juergen
PATCH 10/11 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.
--- tools/xl/Makefile | 1 + tools/xl/xl.h | 2 + tools/xl/xl_cmdtable.c | 10 +++++ tools/xl/xl_parse.c | 25 ++++++++++++ tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 88 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 127 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 quota data" , +"<Domain>|-g" , + }, + { "xenstore-quota-set", + &main_xsquota_set,0 ,1 , +"Set global or domain specific Xenstore quota data" , + "<Domain>|-g <quota>=<val>...", + }, };const int cmdtable_len =ARRAY_SIZE (cmd_table);
tools/xl/xl_parse.c +25 -0
@@ -1314,6 +1314,31 @@ out:return ret; } +int parse_xsquota_item (const char *buf,struct libxl_xs_quota_item *item) +{ +const char *eq; +char *endptr; + + 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 ; + item->val =strtoul (eq +1 , &endptr,0 ); +if (errno || !eq[1 ] || *endptr) { +fprintf (stderr, +"Quota specification \"%s\" uses illegal value \"%s\".\n" , + buf, eq); +return ERROR_INVAL ; + } + +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 +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 10/11] tools/xl: add xl commands for xenstore quota operations
Quoted 44 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]>--- tools/xl/Makefile | 1 + tools/xl/xl.h | 2 + tools/xl/xl_cmdtable.c | 10 +++++ tools/xl/xl_parse.c | 25 ++++++++++++ tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 88 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 tools/xl/xl_xsquota.ctools/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 +0
-0
tools/xl/xl_cmdtable.c const struct cmd_spec cmd_table[] = { · line 654
Quoted 6 lines
tools/xl/xl_cmdtable.c +3
-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 quota data",
Maybe saying "quota values" instead of "quota data" would be slightly better. Or maybe even "quotas" would be enough.
Quoted 24 lines
tools/xl/xl_cmdtable.c +7
-0+ "<Domain>|-g", + }, + {"xenstore-quota-set" , + &main_xsquota_set,0 ,1 , +"Set global or domain specific Xenstore quota data" , + "<Domain>|-g <quota>=<val>...", + }, };const int cmdtable_len =ARRAY_SIZE (cmd_table);tools/xl/xl_parse.c +6
-0@@ -1314,6 +1314,31 @@ out:return ret; } +int parse_xsquota_item (const char *buf,struct libxl_xs_quota_item *item) +{ +const char *eq; +char *endptr; + + eq =strchr (buf,'=' );
tools/xl/xl_parse.c out: · line 1332
Quoted 10 lines
tools/xl/xl_parse.c +10
-0+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 ; + item->val =strtoul (eq +1 , &endptr,0 ); +if (errno || !eq[1 ] || *endptr) {
I think we also need to check that the value returned by strtoul() can actually be stored in item->val. It would be misleading to accept a quota value and store a different one.
Quoted 36 lines
tools/xl/xl_parse.c +9
-0+fprintf (stderr, +"Quota specification \"%s\" uses illegal value \"%s\".\n" , + buf, eq); +return ERROR_INVAL ; + } + +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 +6
-0@@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ + +#include <stdio.h> +#include <stdlib.h> +#include <libxl.h> +#include <libxlutil.h>
tools/xl/xl_xsquota.c line 16
Quoted 10 lines
tools/xl/xl_xsquota.c new file +10
-0+ +#include "xl.h" +#include "xl_utils.h" +#include "xl_parse.h" + +int main_xsquota_get (int argc,char **argv) +{ +libxl_xs_quota_set q; +unsigned int i; +int rc;
You should call libxl_xs_quota_set_init(&q). (That would avoid a segv later, when _disposed() is called.)
Quoted 27 lines
tools/xl/xl_xsquota.c new file +27
-0+ +if (argc !=2 ) { +fprintf (stderr,"Domain or \"-g\" must be specified.\n" ); +return EXIT_FAILURE ; + } + +if (!strcmp (argv[1 ],"-g" )) { + rc =libxl_xsquota_global_get (ctx, &q); + }else { +uint32_t domid =find_domain (argv[1 ]); + + rc =libxl_xsquota_domain_get (ctx, domid, &q); + } + +if (rc) { +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_set_dispose (&q); + +return EXIT_SUCCESS ;
tools/xl/xl_xsquota.c line 53
Quoted 10 lines
tools/xl/xl_xsquota.c new file +10
-0+} + +int main_xsquota_set (int argc,char **argv) +{ +unsigned int i; +libxl_xs_quota_set q; +int rc =EXIT_FAILURE ; + +if (argc <3 ) { +fprintf (stderr,"Not enough parameters.\n" );
I think you can call help("xenstore-quota-set") to provide the needed info about what the parameters are.
tools/xl/xl_xsquota.c line 62
Quoted 9 lines
tools/xl/xl_xsquota.c new file +9
-0+return EXIT_FAILURE ; + } + + q.num_quota = argc -2 ; + q.quota =calloc (q.num_quota,sizeof (*q.quota)); +if (!q.quota) { +fprintf (stderr,"Memory allocation failure!\n" ); + goto err; + }
There's `xcalloc() that can be use instead. It does check for memory allocation failure.
(And that would avoid a segv in libxl_xs_quota_set_dispose() as num_quota is set before quota is allocated.)
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 10/11] tools/xl: add xl commands for xenstore quota operations
Quoted 195 lines · Anthony PERARD
Quoted 44 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]>--- tools/xl/Makefile | 1 + tools/xl/xl.h | 2 + tools/xl/xl_cmdtable.c | 10 +++++ tools/xl/xl_parse.c | 25 ++++++++++++ tools/xl/xl_parse.h | 1 + tools/xl/xl_xsquota.c | 88 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+)create mode 100644
tools/xl/xl_xsquota.ctools/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 +0
-0tools/xl/xl_cmdtable.c const struct cmd_spec cmd_table[] = { · line 654
Quoted 6 lines
tools/xl/xl_cmdtable.c +3
-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 quota data",Maybe saying "quota values" instead of "quota data" would be slightly better. Or maybe even "quotas" would be enough.
Quoted 24 lines
tools/xl/xl_cmdtable.c +7
-0+ "<Domain>|-g", + }, + {"xenstore-quota-set" , + &main_xsquota_set,0 ,1 , +"Set global or domain specific Xenstore quota data" , + "<Domain>|-g <quota>=<val>...", + }, };const int cmdtable_len =ARRAY_SIZE (cmd_table);tools/xl/xl_parse.c +6
-0@@ -1314,6 +1314,31 @@ out:return ret; } +int parse_xsquota_item (const char *buf,struct libxl_xs_quota_item *item) +{ +const char *eq; +char *endptr; + + eq =strchr (buf,'=' );tools/xl/xl_parse.c out: · line 1332
Quoted 10 lines
tools/xl/xl_parse.c +10
-0+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 ; + item->val =strtoul (eq +1 , &endptr,0 ); +if (errno || !eq[1 ] || *endptr) {I think we also need to check that the value returned by
strtoul()can actually be stored initem->val. It would be misleading to accept a quota value and store a different one.Quoted 36 lines
tools/xl/xl_parse.c +9
-0+fprintf (stderr, +"Quota specification \"%s\" uses illegal value \"%s\".\n" , + buf, eq); +return ERROR_INVAL ; + } + +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 +6
-0@@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ + +#include <stdio.h> +#include <stdlib.h> +#include <libxl.h> +#include <libxlutil.h> tools/xl/xl_xsquota.c line 16
Quoted 10 lines
tools/xl/xl_xsquota.c new file +10
-0+ +#include "xl.h" +#include "xl_utils.h" +#include "xl_parse.h" + +int main_xsquota_get (int argc,char **argv) +{ +libxl_xs_quota_set q; +unsigned int i; +int rc;You should call
libxl_xs_quota_set_init(&q). (That would avoid a segv later, when_disposed()is called.)Quoted 27 lines
tools/xl/xl_xsquota.c new file +27
-0+ +if (argc !=2 ) { +fprintf (stderr,"Domain or \"-g\" must be specified.\n" ); +return EXIT_FAILURE ; + } + +if (!strcmp (argv[1 ],"-g" )) { + rc =libxl_xsquota_global_get (ctx, &q); + }else { +uint32_t domid =find_domain (argv[1 ]); + + rc =libxl_xsquota_domain_get (ctx, domid, &q); + } + +if (rc) { +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_set_dispose (&q); + +return EXIT_SUCCESS ;tools/xl/xl_xsquota.c line 53
Quoted 10 lines
tools/xl/xl_xsquota.c new file +10
-0+} + +int main_xsquota_set (int argc,char **argv) +{ +unsigned int i; +libxl_xs_quota_set q; +int rc =EXIT_FAILURE ; + +if (argc <3 ) { +fprintf (stderr,"Not enough parameters.\n" );I think you can call
help("xenstore-quota-set")to provide the needed info about what the parameters are.tools/xl/xl_xsquota.c line 62
Quoted 9 lines
tools/xl/xl_xsquota.c new file +9
-0+return EXIT_FAILURE ; + } + + q.num_quota = argc -2 ; + q.quota =calloc (q.num_quota,sizeof (*q.quota)); +if (!q.quota) { +fprintf (stderr,"Memory allocation failure!\n" ); + goto err; + }
Quoted 5 lines
There's `xcalloc() that can be use instead. It does check for memory allocation failure.
(And that would avoid a segv in
libxl_xs_quota_set_dispose()asnum_quotais set before quota is allocated.)
I'm fine with all your suggestions.
Thanks,
Juergen
PATCH 11/11 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.
--- docs/man/xl.cfg.5.pod.in | 13 +++++++++++++ tools/xl/xl_parse.c | 23 ++++++++++++++++++++++- 2 files changed, 35 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 +22 -1
@@ -1351,7 +1351,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 ;
@@ -1360,6 +1360,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;
@@ -1467,6 +1468,26 @@ 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 =calloc (num_xs_quota,sizeof (* b_info->xenstore_quota.quota)); +if (b_info->xenstore_quota.quota ==NULL ) { +fprintf (stderr,"unable to allocate memory for xenstore_quota\n" ); +exit (-1 ); + } + +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
Re: [PATCH 11/11] tools/xl: add support for xenstore quota setting via domain config
Quoted 1 line · Juergen Gross
Add a new "xenstore-quota" domain config parameter for setting the
You mean xenstore_quota ^ here.
Quoted 9 lines
Xenstore quota of a new domain via a list of <quota>=<val> items.
Signed-off-by Juergen Gross <[email protected]>---
tools/xl/xl_parse.c +0
-0
tools/xl/xl_parse.c void parse_config_data(const char *config_source, · line 1473
Quoted 6 lines
tools/xl/xl_parse.c +3
-0@@ -1467,6 +1468,26 @@ 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 =calloc (num_xs_quota,sizeof (* b_info->xenstore_quota.quota));
You can call xcalloc() instead, and then not need to check for allocation failure.
And with the two changes: Reviewed-by: Anthony PERARD <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 11/11] tools/xl: add support for xenstore quota setting via domain config
Quoted 17 lines · Anthony PERARD
Quoted 1 line · Juergen Gross
Add a new "xenstore-quota" domain config parameter for setting the
You mean
xenstore_quota^ here.Quoted 12 lines
Xenstore quota of a new domain via a list of <quota>=<val> items.
Signed-off-by Juergen Gross <[email protected]>---
tools/xl/xl_parse.c +0
-0@@ -1467,6 +1468,26 @@ 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;
Quoted 8 lines
tools/xl/xl_parse.c void parse_config_data(const char *config_source, · line 1473
Quoted 3 lines
tools/xl/xl_parse.c +3
-0+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 =calloc (num_xs_quota,sizeof (* b_info->xenstore_quota.quota));You can call
xcalloc()instead, and then not need to check for allocation failure.And with the two changes: Reviewed-by: Anthony PERARD <[email protected]>
Thanks,
Juergen