tools/xenstore: more cleanups
v3 cover tools/xenstore: more cleanups
Some more cleanups of Xenstore.
Based on top of the previous Xenstore series "tools/xenstore: rework internal accounting".
Changes in V2:
- rebase
- one small modification of patch 10
- added patches 11-13
Changes in V3:
- rebase
- modified patch 4
- added patches 10, 11 and 13
Juergen Gross (16):
tools/xenstore: verify command line parameters better tools/xenstore: do some cleanup of hashtable.c tools/xenstore: modify interface of create_hashtable() tools/xenstore: rename hashtable_insert() and let it return 0 on
success
tools/xenstore: make some write limit functions static tools/xenstore: switch write limiting to use millisecond time base tools/xenstore: remove stale TODO file
tools/xenstore: remove unused events list tools/xenstore: remove support of file backed data base tools/libs/store: use xen_list.h instead of xenstore/list.h tools/libs/store: make libxenstore independent of utils.h tools/xenstore: remove no longer needed functions from xs_lib.c tools/xenstore: replace xs_lib.c with a header tools/xenstore: split out environment specific live update code tools/xenstore: split out rest of live update control code tools/xenstore: remove unused stuff from list.h
.gitignore | 1 - MAINTAINERS | 1 + tools/include/xen-tools/xenstore-common.h | 128 +++++ tools/include/xenstore.h | 3 + tools/include/xenstore_lib.h | 3 - tools/libs/store/Makefile | 4 - tools/libs/store/xs.c | 131 +++-- tools/xenstore/COPYING | 514 ----------------- tools/xenstore/Makefile | 7 +- tools/xenstore/Makefile.common | 12 +- tools/xenstore/TODO | 10 - tools/xenstore/hashtable.c | 98 ++-- tools/xenstore/hashtable.h | 22 +- tools/xenstore/list.h | 227 -------- tools/xenstore/xenstore_client.c | 133 ++++- tools/xenstore/xenstored_control.c | 661 +--------------------- tools/xenstore/xenstored_control.h | 8 - tools/xenstore/xenstored_core.c | 72 +-- tools/xenstore/xenstored_core.h | 7 +- tools/xenstore/xenstored_domain.c | 458 ++++++++------- tools/xenstore/xenstored_domain.h | 24 +- tools/xenstore/xenstored_lu.c | 400 +++++++++++++ tools/xenstore/xenstored_lu.h | 81 +++ tools/xenstore/xenstored_lu_daemon.c | 133 +++++ tools/xenstore/xenstored_lu_minios.c | 121 ++++ tools/xenstore/xenstored_transaction.c | 4 +- tools/xenstore/xenstored_watch.c | 5 - tools/xenstore/xs_lib.c | 292 ---------- tools/xenstore/xs_lib.h | 50 -- tools/xenstore/xs_tdb_dump.c | 86 --- 30 files changed, 1409 insertions(+), 2287 deletions(-) create mode 100644 tools/include/xen-tools/xenstore-common.h delete mode 100644 tools/xenstore/COPYING delete mode 100644 tools/xenstore/TODO create mode 100644 tools/xenstore/xenstored_lu.c create mode 100644 tools/xenstore/xenstored_lu.h create mode 100644 tools/xenstore/xenstored_lu_daemon.c create mode 100644 tools/xenstore/xenstored_lu_minios.c delete mode 100644 tools/xenstore/xs_lib.c delete mode 100644 tools/xenstore/xs_lib.h delete mode 100644 tools/xenstore/xs_tdb_dump.c
Signature · 1 line
2.35.3
PATCH v3 1/16 tools/xenstore: verify command line parameters better
Add some more verification of command line parameters.
--- tools/xenstore/xenstored_core.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
tools/xenstore/xenstored_core.c +9 -10
@@ -2820,7 +2820,7 @@ int main(int argc, char *argv[]) no_domain_init = true;break ;case 'E' : - hard_quotas[ACC_NODES ].val =strtoul (optarg,NULL ,10 ); + hard_quotas[ACC_NODES ].val =get_optval_uint (optarg);break ;case 'F' : pidfile = optarg;
@@ -2838,10 +2838,10 @@ int main(int argc, char *argv[]) recovery = false;break ;case 'S' : - hard_quotas[ACC_NODESZ ].val =strtoul (optarg,NULL ,10 ); + hard_quotas[ACC_NODESZ ].val =get_optval_uint (optarg);break ;case 't' : - hard_quotas[ACC_TRANS ].val =strtoul (optarg,NULL ,10 ); + hard_quotas[ACC_TRANS ].val =get_optval_uint (optarg);break ;case 'T' : tracefile = optarg;
@@ -2861,14 +2861,13 @@ int main(int argc, char *argv[]) verbose = true;break ;case 'W' : - hard_quotas[ACC_WATCH ].val =strtoul (optarg,NULL ,10 ); + hard_quotas[ACC_WATCH ].val =get_optval_uint (optarg);break ;case 'A' : - hard_quotas[ACC_NPERM ].val =strtoul (optarg,NULL ,10 ); + hard_quotas[ACC_NPERM ].val =get_optval_uint (optarg);break ;case 'M' : - hard_quotas[ACC_PATHLEN ].val = -strtoul (optarg,NULL ,10 ); + hard_quotas[ACC_PATHLEN ].val =get_optval_uint (optarg); hard_quotas[ACC_PATHLEN ].val =min ((unsigned int )XENSTORE_REL_PATH_MAX , hard_quotas[ACC_PATHLEN ].val);
@@ -2883,13 +2882,13 @@ int main(int argc, char *argv[])set_timeout (optarg);break ;case 'e' : - dom0_event =strtol (optarg,NULL ,10 ); + dom0_event =get_optval_uint (optarg);break ;case 'm' : - dom0_domid =strtol (optarg,NULL ,10 ); + dom0_domid =get_optval_uint (optarg);break ;case 'p' : - priv_domid =strtol (optarg,NULL ,10 ); + priv_domid =get_optval_uint (optarg);break ;#ifndef NO_LIVE_UPDATE case 'U' :
Signature · 1 line
2.35.3
PATCH v3 2/16 tools/xenstore: do some cleanup of hashtable.c
In reply to Juergen GrossDo the following cleanups:
- hashtable_count() isn't used at all, so remove it
- replace prime_table_length and max_load_factor with macros
- make hash() static
- add a loadlimit() helper function
- remove the /***/ lines between functions
- do some style corrections
---
V3:
- more style corrections (Julien Grall)
--- tools/xenstore/hashtable.c | 76 +++++++++++++++----------------------- tools/xenstore/hashtable.h | 10 ----- 2 files changed, 30 insertions(+), 56 deletions(-)
tools/xenstore/hashtable.c +30 -46
@@ -40,22 +40,25 @@ static const unsigned int primes[] = {50331653 ,100663319 ,201326611 ,402653189 , 805306457, 1610612741 }; -const unsigned int prime_table_length =sizeof (primes)/sizeof (primes[0 ]); -const unsigned int max_load_factor =65 ;/* percentage */ -/*****************************************************************************/ -/* indexFor */ -static inline unsigned int -indexFor (unsigned int tablelength,unsigned int hashvalue) { +#define PRIME_TABLE_LEN ARRAY_SIZE(primes) +#define MAX_LOAD_PERCENT 65 + +static inline unsigned int indexFor (unsigned int tablelength, +unsigned int hashvalue) +{return (hashvalue % tablelength); } -/*****************************************************************************/ -struct hashtable * -create_hashtable (const void *ctx,unsigned int minsize, -unsigned int (*hashf) (const void *), -int (*eqf) (const void *,const void *), -unsigned int flags) +static unsigned int loadlimit (unsigned int pindex) +{ +return ((uint64_t )primes[pindex] *MAX_LOAD_PERCENT ) /100 ; +} + +struct hashtable *create_hashtable (const void *ctx,unsigned int minsize, +unsigned int (*hashf) (const void *), +int (*eqf) (const void *,const void *), +unsigned int flags) {struct hashtable *h;unsigned int pindex, size = primes[0 ];
@@ -64,8 +67,11 @@ create_hashtable(const void *ctx, unsigned int minsize,if (minsize > (1u <<30 ))return NULL ;/* Enforce size as prime */ -for (pindex=0 ; pindex < prime_table_length; pindex++) { -if (primes[pindex] > minsize) { size = primes[pindex];break ; } +for (pindex =0 ; pindex <PRIME_TABLE_LEN ; pindex++) { +if (primes[pindex] > minsize) { + size = primes[pindex]; +break ; + } } h = talloc_zero(ctx, struct hashtable);
@@ -81,7 +87,7 @@ create_hashtable(const void *ctx, unsigned int minsize, h->entrycount =0 ; h->hashfn = hashf; h->eqfn = eqf; - h->loadlimit = (unsigned int )(((uint64_t )size * max_load_factor) /100 ); + h->loadlimit =loadlimit (pindex);return h; err1:
@@ -90,9 +96,7 @@ err0:return NULL ; } -/*****************************************************************************/ -unsigned int -hash (const struct hashtable *h,const void *k) +static unsigned int hash (const struct hashtable *h,const void *k) {/* Aim to protect against poor hash functions by adding logic here * - logic taken from java 1.4 hashtable source */
@@ -104,9 +108,7 @@ hash(const struct hashtable *h, const void *k)return i; } -/*****************************************************************************/ -static int -hashtable_expand (struct hashtable *h) +static int hashtable_expand (struct hashtable *h) {/* Double the size of the table to accomodate more entries */ struct entry **newtable;
@@ -114,7 +116,7 @@ hashtable_expand(struct hashtable *h)struct entry **pE;unsigned int newsize, i, index;/* Check we're not hitting max capacity */ -if (h->primeindex == (prime_table_length -1 ))return 0 ; +if (h->primeindex == (PRIME_TABLE_LEN -1 ))return 0 ; newsize = primes[++(h->primeindex)]; newtable = talloc_realloc(h, h->table, struct entry *, newsize);
@@ -144,21 +146,11 @@ hashtable_expand(struct hashtable *h) } h->tablelength = newsize; - h->loadlimit = (unsigned int ) - (((uint64_t )newsize * max_load_factor) /100 ); + h->loadlimit =loadlimit (h->primeindex);return -1 ; } -/*****************************************************************************/ -unsigned int -hashtable_count (const struct hashtable *h) -{ -return h->entrycount; -} - -/*****************************************************************************/ -int -hashtable_insert (struct hashtable *h,void *k,void *v) +int hashtable_insert (struct hashtable *h,void *k,void *v) {/* This method allows duplicate keys - but they shouldn't be used */ unsigned int index;
@@ -186,9 +178,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v)return -1 ; } -/*****************************************************************************/ -void */* returns value associated with key */ -hashtable_search (const struct hashtable *h,const void *k) +void *hashtable_search (const struct hashtable *h,const void *k) {struct entry *e;unsigned int hashvalue, index;
@@ -204,7 +194,6 @@ hashtable_search(const struct hashtable *h, const void *k)return NULL ; } -/*****************************************************************************/ void hashtable_remove (struct hashtable *h,const void *k) {
@@ -234,10 +223,8 @@ hashtable_remove(struct hashtable *h, const void *k) } } -/*****************************************************************************/ -int -hashtable_iterate (struct hashtable *h, -int (*func)(const void *k,void *v,void *arg),void *arg) +int hashtable_iterate (struct hashtable *h, +int (*func)(const void *k,void *v,void *arg),void *arg) {int ret;unsigned int i;
@@ -260,10 +247,7 @@ hashtable_iterate(struct hashtable *h,return 0 ; } -/*****************************************************************************/ -/* destroy */ -void -hashtable_destroy (struct hashtable *h) +void hashtable_destroy (struct hashtable *h) {talloc_free (h); }
tools/xenstore/hashtable.h +0 -10
@@ -74,16 +74,6 @@ hashtable_search(const struct hashtable *h, const void *k);void hashtable_remove (struct hashtable *h,const void *k); -/***************************************************************************** -* hashtable_count -- * @name hashtable_count -* @param h the hashtable -* @return the number of items stored in the hashtable -*/ -unsigned int -hashtable_count (const struct hashtable *h); -/***************************************************************************** * hashtable_iterate
Signature · 1 line
2.35.3
PATCH v3 3/16 tools/xenstore: modify interface of create_hashtable()
In reply to Juergen GrossThe minsize parameter of create_hashtable() doesn't have any real use case for Xenstore, so drop it.
For better talloc_report_full() diagnostic output add a name parameter to create_hashtable().
---
V3:
- make code more readable (Julien Grall)
--- tools/xenstore/hashtable.c | 23 ++++++----------------- tools/xenstore/hashtable.h | 4 ++-- tools/xenstore/xenstored_core.c | 2 +- tools/xenstore/xenstored_domain.c | 4 ++-- 4 files changed, 11 insertions(+), 22 deletions(-)
tools/xenstore/hashtable.c +6 -17
@@ -55,39 +55,28 @@ static unsigned int loadlimit(unsigned int pindex)return ((uint64_t )primes[pindex] *MAX_LOAD_PERCENT ) /100 ; } -struct hashtable *create_hashtable (const void *ctx,unsigned int minsize, +struct hashtable *create_hashtable (const void *ctx,const char *name,unsigned int (*hashf) (const void *),int (*eqf) (const void *,const void *),unsigned int flags) {struct hashtable *h; -unsigned int pindex, size = primes[0 ]; - -/* Check requested hashtable isn't too large */ -if (minsize > (1u <<30 ))return NULL ; - -/* Enforce size as prime */ -for (pindex =0 ; pindex <PRIME_TABLE_LEN ; pindex++) { -if (primes[pindex] > minsize) { - size = primes[pindex]; -break ; - } - } h = talloc_zero(ctx, struct hashtable);if (NULL == h) goto err0; - h->table = talloc_zero_array(h, struct entry *, size); +talloc_set_name_const (h, name); + h->table = talloc_zero_array(h, struct entry *, primes[0]);if (NULL == h->table) goto err1; - h->tablelength = size; + h->primeindex =0 ; + h->tablelength = primes[h->primeindex]; h->flags = flags; - h->primeindex = pindex; h->entrycount =0 ; h->hashfn = hashf; h->eqfn = eqf; - h->loadlimit =loadlimit (pindex); + h->loadlimit =loadlimit (h->primeindex);return h; err1:
tools/xenstore/hashtable.h +2 -2
@@ -10,7 +10,7 @@ struct hashtable;* @name create_hashtable * @param ctx talloc context to use for allocations -* @param minsize minimum initial size of hashtable +* @param name talloc name of the hashtable * @param hashfunction function for hashing keys * @param key_eq_fn function for determining key equality * @param flags flags HASHTABLE_*
@@ -23,7 +23,7 @@ struct hashtable;#define HASHTABLE_FREE_KEY (1U << 1)struct hashtable * -create_hashtable (const void *ctx,unsigned int minsize, +create_hashtable (const void *ctx,const char *name,unsigned int (*hashfunction) (const void *),int (*key_eq_fn) (const void *,const void *), unsigned int flags
tools/xenstore/xenstored_core.c +1 -1
@@ -2521,7 +2521,7 @@ void check_store(void)struct check_store_data data;/* Don't free values (they are all void *1) */ - data.reachable =create_hashtable (NULL ,16 , hash_from_key_fn, + data.reachable =create_hashtable (NULL ,"checkstore" , hash_from_key_fn, keys_equal_fn,HASHTABLE_FREE_KEY );if (!data.reachable) {log ("check_store: ENOMEM" );
tools/xenstore/xenstored_domain.c +2 -2
@@ -1015,7 +1015,7 @@ void domain_init(int evtfd)int rc;/* Start with a random rather low domain count for the hashtable. */ - domhash =create_hashtable (NULL ,8 , domhash_fn, domeq_fn,0 ); + domhash =create_hashtable (NULL ,"domains" , domhash_fn, domeq_fn,0 );if (!domhash)barf_perror ("Failed to allocate domain hashtable" );
@@ -1807,7 +1807,7 @@ struct hashtable *domain_check_acc_init(void) {struct hashtable *domains; - domains =create_hashtable (NULL ,8 , domhash_fn, domeq_fn, + domains =create_hashtable (NULL ,"domain_check" , domhash_fn, domeq_fn,HASHTABLE_FREE_VALUE );if (!domains)return NULL ;
Signature · 1 line
2.35.3
Re: [PATCH v3 03/16] tools/xenstore: modify interface of create_hashtable()
Hi Juergen,
Quoted 7 lines · Juergen Gross
The minsize parameter of
create_hashtable()doesn't have any real use case for Xenstore, so drop it.For better
talloc_report_full()diagnostic output add a name parameter tocreate_hashtable().Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 4/16 tools/xenstore: rename hashtable_insert() and let it return 0 on success
In reply to Juergen GrossToday hashtable_insert() returns 0 in case of an error. Change that to let it return an errno value in the error case and 0 in case of success. In order to avoid any missed return value checks or related future backport errors, rename hashtable_insert() to hashtable_add().
Even if not used today, do the same switch for the return value of hashtable_expand().
---
V3:
- rename to hashtable_add() (triggered by Julien Grall)
--- tools/xenstore/hashtable.c | 17 +++++++++++------ tools/xenstore/hashtable.h | 8 ++++---- tools/xenstore/xenstored_core.c | 6 +++--- tools/xenstore/xenstored_domain.c | 4 ++-- tools/xenstore/xenstored_transaction.c | 4 ++-- 5 files changed, 22 insertions(+), 17 deletions(-)
tools/xenstore/hashtable.c +11 -6
@@ -105,14 +105,15 @@ static int hashtable_expand(struct hashtable *h)struct entry **pE;unsigned int newsize, i, index;/* Check we're not hitting max capacity */ -if (h->primeindex == (PRIME_TABLE_LEN -1 ))return 0 ; +if (h->primeindex == (PRIME_TABLE_LEN -1 )) +return ENOSPC ; newsize = primes[++(h->primeindex)]; newtable = talloc_realloc(h, h->table, struct entry *, newsize);if (!newtable) { h->primeindex--; -return 0 ; +return ENOMEM ; } h->table = newtable;
@@ -136,10 +137,10 @@ static int hashtable_expand(struct hashtable *h) h->tablelength = newsize; h->loadlimit =loadlimit (h->primeindex); -return -1 ; +return 0 ; } -int hashtable_insert (struct hashtable *h,void *k,void *v) +int hashtable_add (struct hashtable *h,void *k,void *v) {/* This method allows duplicate keys - but they shouldn't be used */ unsigned int index;
@@ -153,7 +154,11 @@ int hashtable_insert(struct hashtable *h, void *k, void *v)hashtable_expand (h); } e = talloc_zero(h, struct entry); -if (NULL == e) { --(h->entrycount);return 0 ; }/*oom*/ +if (NULL == e) + { + --h->entrycount; +return ENOMEM ; + } e->h =hash (h,k); index =indexFor (h->tablelength,e->h); e->k = k;
@@ -164,7 +169,7 @@ int hashtable_insert(struct hashtable *h, void *k, void *v)talloc_steal (e, v); e->next = h->table[index]; h->table[index] = e; -return -1 ; +return 0 ; }void *hashtable_search (const struct hashtable *h,const void *k)
tools/xenstore/hashtable.h +4 -4
@@ -30,13 +30,13 @@ create_hashtable(const void *ctx, const char *name, );/***************************************************************************** -* hashtable_insert +* hashtable_add - * @name hashtable_insert +* @name hashtable_add * @param h the hashtable to insert into * @param k the key - hashtable claims ownership and will free on removal * @param v the value - does not claim ownership -* @return non-zero for successful insertion +* @return zero for successful insertion * * This function will cause the table to expand if the insertion would take * the ratio of entries to table size over the maximum load factor.
@@ -49,7 +49,7 @@ create_hashtable(const void *ctx, const char *name,*/ int -hashtable_insert (struct hashtable *h,void *k,void *v); +hashtable_add (struct hashtable *h,void *k,void *v);/***************************************************************************** * hashtable_search
tools/xenstore/xenstored_core.c +3 -3
@@ -2404,8 +2404,8 @@ int remember_string(struct hashtable *hash, const char *str)char *k =talloc_strdup (NULL , str);if (!k) -return 0 ; -return hashtable_insert (hash, k, (void *)1 ); +return ENOMEM ; +return hashtable_add (hash, k, (void *)1 ); }/**
@@ -2438,7 +2438,7 @@ static int check_store_step(const void *ctx, struct connection *conn, : WALK_TREE_SKIP_CHILDREN; } -if (!remember_string (data->reachable, node->name)) +if (remember_string (data->reachable, node->name))return WALK_TREE_ERROR_STOP ;domain_check_acc_add (node, data->domains);
tools/xenstore/xenstored_domain.c +2 -2
@@ -538,7 +538,7 @@ static struct domain *alloc_domain(const void *context, unsigned int domid) domain->generation = generation; domain->introduced = false; -if (!hashtable_insert (domhash, &domain->domid, domain)) { +if (hashtable_add (domhash, &domain->domid, domain)) {talloc_free (domain); errno =ENOMEM ;return NULL ;
@@ -1795,7 +1795,7 @@ static int domain_check_acc_init_sub(const void *k, void *v, void *arg)*/ dom->nodes = -d->acc[ACC_NODES ].val; -if (!hashtable_insert (domains, &dom->domid, dom)) { +if (hashtable_add (domains, &dom->domid, dom)) {talloc_free (dom);return -1 ; }
tools/xenstore/xenstored_transaction.c +2 -2
@@ -601,13 +601,13 @@ int check_transactions(struct hashtable *hash)list_for_each_entry (trans, &conn->transaction_list, list) { tname =talloc_asprintf (trans,"%" PRIu64, trans->generation); -if (!tname || !remember_string (hash, tname)) +if (!tname ||remember_string (hash, tname)) goto nomem;list_for_each_entry (i, &trans->accessed, list) {if (!i->ta_node)continue ; -if (!remember_string (hash, i->trans_name)) +if (remember_string (hash, i->trans_name)) goto nomem; }
Signature · 1 line
2.35.3
Re: [PATCH v3 04/16] tools/xenstore: rename hashtable_insert() and let it return 0 on success
Hi Juergen,
Quoted 9 lines · Juergen Gross
Today
hashtable_insert()returns 0 in case of an error. Change that to let it return an errno value in the error case and 0 in case of success. In order to avoid any missed return value checks or related future backport errors, renamehashtable_insert()tohashtable_add().Even if not used today, do the same switch for the return value of
hashtable_expand().Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 5/16 tools/xenstore: make some write limit functions static
In reply to Juergen GrossSome wrl_*() functions are only used in xenstored_domain.c, so make them static. In order to avoid the need of forward declarations, move the whole function block to the start of the file.
--- tools/xenstore/xenstored_domain.c | 456 +++++++++++++++--------------- tools/xenstore/xenstored_domain.h | 3 - 2 files changed, 228 insertions(+), 231 deletions(-)
tools/xenstore/xenstored_domain.c +228 -228
@@ -157,6 +157,234 @@ struct changed_domainstatic struct hashtable *domhash; +static wrl_creditt wrl_config_writecost =WRL_FACTOR ; +static wrl_creditt wrl_config_rate =WRL_RATE *WRL_FACTOR ; +static wrl_creditt wrl_config_dburst =WRL_DBURST *WRL_FACTOR ; +static wrl_creditt wrl_config_gburst =WRL_GBURST *WRL_FACTOR ; +static wrl_creditt wrl_config_newdoms_dburst = +WRL_DBURST *WRL_NEWDOMS *WRL_FACTOR ; + +long wrl_ntransactions; + +static long wrl_ndomains; +static wrl_creditt wrl_reserve;/* [-wrl_config_newdoms_dburst, +_gburst ] */ +static time_t wrl_log_last_warning;/* 0: no previous warning */ + +#define trace_wrl (...) \ +do { \ + if (trace_flags & TRACE_WRL) \ + trace("wrl: " __VA_ARGS__); \ +} while (0) + +void wrl_gettime_now (struct wrl_timestampt *now_wt) +{ +struct timespec now_ts; +int r; + + r =clock_gettime (CLOCK_MONOTONIC , &now_ts); +if (r) +barf_perror ("Could not find time (clock_gettime failed)" ); + + now_wt->sec = now_ts.tv_sec; + now_wt->msec = now_ts.tv_nsec /1000000 ; +} + +static void wrl_xfer_credit (wrl_creditt *debit,wrl_creditt debit_floor, +wrl_creditt *credit,wrl_creditt credit_ceil) +/* +* Transfers zero or more credit from "debit" to "credit". +* Transfers as much as possible while maintaining +* debit >= debit_floor and credit <= credit_ceil. +* (If that's violated already, does nothing.) +* +* Sufficient conditions to avoid overflow, either of: +* |every argument| <= 0x3fffffff +* |every argument| <= 1E9 +* |every argument| <= WRL_CREDIT_MAX +* (And this condition is preserved.) +*/ +{ +wrl_creditt xfer =MIN ( *debit - debit_floor, + credit_ceil - *credit ); +if (xfer >0 ) { + *debit -= xfer; + *credit += xfer; + } +} + +static void wrl_domain_new (struct domain *domain) +{ + domain->wrl_credit =0 ; +wrl_gettime_now (&domain->wrl_timestamp); + wrl_ndomains++; +/* Steal up to DBURST from the reserve */ +wrl_xfer_credit (&wrl_reserve, -wrl_config_newdoms_dburst, + &domain->wrl_credit, wrl_config_dburst); +} + +static void wrl_domain_destroy (struct domain *domain) +{ + wrl_ndomains--; +/* +* Don't bother recalculating domain's credit - this just +* means we don't give the reserve the ending domain's credit +* for time elapsed since last update. +*/ +wrl_xfer_credit (&domain->wrl_credit,0 , + &wrl_reserve, wrl_config_dburst); +} + +static void wrl_credit_update (struct domain *domain,struct wrl_timestampt now) +{ +/* +* We want to calculate +* credit += (now - timestamp) * RATE / ndoms; +* But we want it to saturate, and to avoid floating point. +* To avoid rounding errors from constantly adding small +* amounts of credit, we only add credit for whole milliseconds. +*/ +long seconds = now.sec - domain->wrl_timestamp.sec; +long milliseconds = now.msec - domain->wrl_timestamp.msec; +long msec; +int64_t denom, num; +wrl_creditt surplus; + + seconds =MIN (seconds,1000 *1000 );/* arbitrary, prevents overflow */ + msec = seconds *1000 + milliseconds; + +if (msec <0 ) +/* shouldn't happen with CLOCK_MONOTONIC */ + msec =0 ; + +/* 32x32 -> 64 cannot overflow */ + denom = (int64_t )msec * wrl_config_rate; + num = (int64_t )wrl_ndomains *1000 ; +/* denom / num <= 1E6 * wrl_config_rate, so with +reasonable wrl_config_rate, denom / num << 2^64 */ + +/* at last! */ + domain->wrl_credit =MIN ( (int64_t )domain->wrl_credit + denom / num, +WRL_CREDIT_MAX ); +/* (maybe briefly violating the DBURST cap on wrl_credit) */ + +/* maybe take from the reserve to make us nonnegative */ +wrl_xfer_credit (&wrl_reserve,0 , + &domain->wrl_credit,0 ); + +/* return any surplus (over DBURST) to the reserve */ + surplus =0 ; +wrl_xfer_credit (&domain->wrl_credit, wrl_config_dburst, + &surplus,WRL_CREDIT_MAX ); +wrl_xfer_credit (&surplus,0 , + &wrl_reserve, wrl_config_gburst); +/* surplus is now implicitly discarded */ + + domain->wrl_timestamp = now; + +trace_wrl ("dom %4d %6ld msec %9ld credit %9ld reserve %9ld discard\n" , + domain->domid, msec, (long )domain->wrl_credit, + (long )wrl_reserve, (long )surplus); +} + +void wrl_check_timeout (struct domain *domain, +struct wrl_timestampt now, +int *ptimeout) +{ +uint64_t num, denom; +int wakeup; + +wrl_credit_update (domain, now); + +if (domain->wrl_credit >=0 ) +/* not blocked */ +return ; + +if (!*ptimeout) +/* already decided on immediate wakeup, +so no need to calculate our timeout */ +return ; + +/* calculate wakeup = now + -credit / (RATE / ndoms); */ + +/* credit cannot go more -ve than one transaction, +* so the first multiplication cannot overflow even 32-bit */ + num = (uint64_t )(-domain->wrl_credit *1000 ) * wrl_ndomains; + denom = wrl_config_rate; + + wakeup =MIN ( num / denom/* uint64_t */ ,INT_MAX ); +if (*ptimeout==-1 || wakeup < *ptimeout) + *ptimeout = wakeup; + +trace_wrl ("domain %u credit=%ld (reserve=%ld) SLEEPING for %d\n" , + domain->domid, (long )domain->wrl_credit, (long )wrl_reserve, + wakeup); +} + +#define WRL_LOG (now, ...) \ + (syslog(LOG_WARNING, "write rate limit: " __VA_ARGS__)) + +void wrl_apply_debit_actual (struct domain *domain) +{ +struct wrl_timestampt now; + +if (!domain || !domain_is_unprivileged (domain->conn)) +/* sockets and privileged domain escape the write rate limit */ +return ; + +wrl_gettime_now (&now); +wrl_credit_update (domain, now); + + domain->wrl_credit -= wrl_config_writecost; +trace_wrl ("domain %u credit=%ld (reserve=%ld)\n" , domain->domid, + (long )domain->wrl_credit, (long )wrl_reserve); + +if (domain->wrl_credit <0 ) { +if (!domain->wrl_delay_logged) { + domain->wrl_delay_logged = true; +WRL_LOG (now,"domain %ld is affected\n" , + (long )domain->domid); + }else if (!wrl_log_last_warning) { +WRL_LOG (now,"rate limiting restarts\n" ); + } + wrl_log_last_warning = now.sec; + } +} + +void wrl_log_periodic (struct wrl_timestampt now) +{ +if (wrl_log_last_warning && + (now.sec - wrl_log_last_warning) >WRL_LOGEVERY ) { +WRL_LOG (now,"not in force recently\n" ); + wrl_log_last_warning =0 ; + } +} + +void wrl_apply_debit_direct (struct connection *conn) +{ +if (!conn) +/* some writes are generated internally */ +return ; + +if (conn->transaction) +/* these are accounted for when the transaction ends */ +return ; + +if (!wrl_ntransactions) +/* we don't conflict with anyone */ +return ; + +wrl_apply_debit_actual (conn->domain); +} + +void wrl_apply_debit_trans_commit (struct connection *conn) +{ +if (wrl_ntransactions <=1 ) +/* our own transaction appears in the counter */ +return ; + +wrl_apply_debit_actual (conn->domain); +} +static bool check_indexes (XENSTORE_RING_IDX cons,XENSTORE_RING_IDX prod) {return ((prod - cons) <=XENSTORE_RING_SIZE );
@@ -1446,234 +1674,6 @@ unsigned int domain_transaction_get(struct connection *conn) : 0; } -static wrl_creditt wrl_config_writecost =WRL_FACTOR ; -static wrl_creditt wrl_config_rate =WRL_RATE *WRL_FACTOR ; -static wrl_creditt wrl_config_dburst =WRL_DBURST *WRL_FACTOR ; -static wrl_creditt wrl_config_gburst =WRL_GBURST *WRL_FACTOR ; -static wrl_creditt wrl_config_newdoms_dburst = -WRL_DBURST *WRL_NEWDOMS *WRL_FACTOR ; - -long wrl_ntransactions; - -static long wrl_ndomains; -static wrl_creditt wrl_reserve;/* [-wrl_config_newdoms_dburst, +_gburst ] */ -static time_t wrl_log_last_warning;/* 0: no previous warning */ - -#define trace_wrl (...) \ -do { \ - if (trace_flags & TRACE_WRL) \ - trace("wrl: " __VA_ARGS__); \ -} while (0) - -void wrl_gettime_now (struct wrl_timestampt *now_wt) -{ -struct timespec now_ts; -int r; - - r =clock_gettime (CLOCK_MONOTONIC , &now_ts); -if (r) -barf_perror ("Could not find time (clock_gettime failed)" ); - - now_wt->sec = now_ts.tv_sec; - now_wt->msec = now_ts.tv_nsec /1000000 ; -} - -static void wrl_xfer_credit (wrl_creditt *debit,wrl_creditt debit_floor, -wrl_creditt *credit,wrl_creditt credit_ceil) -/* -* Transfers zero or more credit from "debit" to "credit". -* Transfers as much as possible while maintaining -* debit >= debit_floor and credit <= credit_ceil. -* (If that's violated already, does nothing.) -* -* Sufficient conditions to avoid overflow, either of: -* |every argument| <= 0x3fffffff -* |every argument| <= 1E9 -* |every argument| <= WRL_CREDIT_MAX -* (And this condition is preserved.) -*/ -{ -wrl_creditt xfer =MIN ( *debit - debit_floor, - credit_ceil - *credit ); -if (xfer >0 ) { - *debit -= xfer; - *credit += xfer; - } -} - -void wrl_domain_new (struct domain *domain) -{ - domain->wrl_credit =0 ; -wrl_gettime_now (&domain->wrl_timestamp); - wrl_ndomains++; -/* Steal up to DBURST from the reserve */ -wrl_xfer_credit (&wrl_reserve, -wrl_config_newdoms_dburst, - &domain->wrl_credit, wrl_config_dburst); -} - -void wrl_domain_destroy (struct domain *domain) -{ - wrl_ndomains--; -/* -* Don't bother recalculating domain's credit - this just -* means we don't give the reserve the ending domain's credit -* for time elapsed since last update. -*/ -wrl_xfer_credit (&domain->wrl_credit,0 , - &wrl_reserve, wrl_config_dburst); -} - -void wrl_credit_update (struct domain *domain,struct wrl_timestampt now) -{ -/* -* We want to calculate -* credit += (now - timestamp) * RATE / ndoms; -* But we want it to saturate, and to avoid floating point. -* To avoid rounding errors from constantly adding small -* amounts of credit, we only add credit for whole milliseconds. -*/ -long seconds = now.sec - domain->wrl_timestamp.sec; -long milliseconds = now.msec - domain->wrl_timestamp.msec; -long msec; -int64_t denom, num; -wrl_creditt surplus; - - seconds =MIN (seconds,1000 *1000 );/* arbitrary, prevents overflow */ - msec = seconds *1000 + milliseconds; - -if (msec <0 ) -/* shouldn't happen with CLOCK_MONOTONIC */ - msec =0 ; - -/* 32x32 -> 64 cannot overflow */ - denom = (int64_t )msec * wrl_config_rate; - num = (int64_t )wrl_ndomains *1000 ; -/* denom / num <= 1E6 * wrl_config_rate, so with -reasonable wrl_config_rate, denom / num << 2^64 */ - -/* at last! */ - domain->wrl_credit =MIN ( (int64_t )domain->wrl_credit + denom / num, -WRL_CREDIT_MAX ); -/* (maybe briefly violating the DBURST cap on wrl_credit) */ - -/* maybe take from the reserve to make us nonnegative */ -wrl_xfer_credit (&wrl_reserve,0 , - &domain->wrl_credit,0 ); - -/* return any surplus (over DBURST) to the reserve */ - surplus =0 ; -wrl_xfer_credit (&domain->wrl_credit, wrl_config_dburst, - &surplus,WRL_CREDIT_MAX ); -wrl_xfer_credit (&surplus,0 , - &wrl_reserve, wrl_config_gburst); -/* surplus is now implicitly discarded */ - - domain->wrl_timestamp = now; - -trace_wrl ("dom %4d %6ld msec %9ld credit %9ld reserve %9ld discard\n" , - domain->domid, msec, (long )domain->wrl_credit, - (long )wrl_reserve, (long )surplus); -} - -void wrl_check_timeout (struct domain *domain, -struct wrl_timestampt now, -int *ptimeout) -{ -uint64_t num, denom; -int wakeup; - -wrl_credit_update (domain, now); - -if (domain->wrl_credit >=0 ) -/* not blocked */ -return ; - -if (!*ptimeout) -/* already decided on immediate wakeup, -so no need to calculate our timeout */ -return ; - -/* calculate wakeup = now + -credit / (RATE / ndoms); */ - -/* credit cannot go more -ve than one transaction, -* so the first multiplication cannot overflow even 32-bit */ - num = (uint64_t )(-domain->wrl_credit *1000 ) * wrl_ndomains; - denom = wrl_config_rate; - - wakeup =MIN ( num / denom/* uint64_t */ ,INT_MAX ); -if (*ptimeout==-1 || wakeup < *ptimeout) - *ptimeout = wakeup; - -trace_wrl ("domain %u credit=%ld (reserve=%ld) SLEEPING for %d\n" , - domain->domid, (long )domain->wrl_credit, (long )wrl_reserve, - wakeup); -} - -#define WRL_LOG (now, ...) \ - (syslog(LOG_WARNING, "write rate limit: " __VA_ARGS__)) - -void wrl_apply_debit_actual (struct domain *domain) -{ -struct wrl_timestampt now; - -if (!domain || !domid_is_unprivileged (domain->domid)) -/* sockets and privileged domain escape the write rate limit */ -return ; - -wrl_gettime_now (&now); -wrl_credit_update (domain, now); - - domain->wrl_credit -= wrl_config_writecost; -trace_wrl ("domain %u credit=%ld (reserve=%ld)\n" , domain->domid, - (long )domain->wrl_credit, (long )wrl_reserve); - -if (domain->wrl_credit <0 ) { -if (!domain->wrl_delay_logged) { - domain->wrl_delay_logged = true; -WRL_LOG (now,"domain %ld is affected\n" , - (long )domain->domid); - }else if (!wrl_log_last_warning) { -WRL_LOG (now,"rate limiting restarts\n" ); - } - wrl_log_last_warning = now.sec; - } -} - -void wrl_log_periodic (struct wrl_timestampt now) -{ -if (wrl_log_last_warning && - (now.sec - wrl_log_last_warning) >WRL_LOGEVERY ) { -WRL_LOG (now,"not in force recently\n" ); - wrl_log_last_warning =0 ; - } -} - -void wrl_apply_debit_direct (struct connection *conn) -{ -if (!conn) -/* some writes are generated internally */ -return ; - -if (conn->transaction) -/* these are accounted for when the transaction ends */ -return ; - -if (!wrl_ntransactions) -/* we don't conflict with anyone */ -return ; - -wrl_apply_debit_actual (conn->domain); -} - -void wrl_apply_debit_trans_commit (struct connection *conn) -{ -if (wrl_ntransactions <=1 ) -/* our own transaction appears in the counter */ -return ; - -wrl_apply_debit_actual (conn->domain); -} -const char *dump_state_connections (FILE *fp) {const char *ret =NULL ;
tools/xenstore/xenstored_domain.h +0 -3
@@ -163,9 +163,6 @@ struct wrl_timestampt {extern long wrl_ntransactions;void wrl_gettime_now (struct wrl_timestampt *now_ts); -void wrl_domain_new (struct domain *domain); -void wrl_domain_destroy (struct domain *domain); -void wrl_credit_update (struct domain *domain,struct wrl_timestampt now);void wrl_check_timeout (struct domain *domain,struct wrl_timestampt now,int *ptimeout);
Signature · 1 line
2.35.3
Re: [PATCH v3 05/16] tools/xenstore: make some write limit functions static
Hi Juergen,
Quoted 5 lines · Juergen Gross
Some wrl_*() functions are only used in
xenstored_domain.c, so make them static. In order to avoid the need of forward declarations, move the whole function block to the start of the file.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 6/16 tools/xenstore: switch write limiting to use millisecond time base
In reply to Juergen GrossThere is no need to keep struct wrl_timestampt, as it serves the same purpose as the more simple time base provided by get_now().
Move some more stuff from xenstored_domain.h into xenstored_domain.c as it is being used nowhere else.
--- tools/xenstore/xenstored_core.c | 8 ++--- tools/xenstore/xenstored_core.h | 7 ++-- tools/xenstore/xenstored_domain.c | 56 +++++++++++++------------------ tools/xenstore/xenstored_domain.h | 21 ++---------- 4 files changed, 32 insertions(+), 60 deletions(-)
tools/xenstore/xenstored_core.c +3 -5
@@ -192,7 +192,7 @@ void reopen_log(void) } } -static uint64_t get_now_msec (void ) +uint64_t get_now_msec (void ) {struct timespec now_ts;
@@ -510,7 +510,6 @@ fail:static void initialize_fds (int *p_sock_pollfd_idx,int *ptimeout) {struct connection *conn; -struct wrl_timestampt now;uint64_t msecs;if (fds)
@@ -530,13 +529,12 @@ static void initialize_fds(int *p_sock_pollfd_idx, int *ptimeout) xce_pollfd_idx =set_fd (xenevtchn_fd (xce_handle),POLLIN |POLLPRI ); -wrl_gettime_now (&now); -wrl_log_periodic (now); msecs =get_now_msec (); +wrl_log_periodic (msecs);list_for_each_entry (conn, &connections, list) {if (conn->domain) { -wrl_check_timeout (conn->domain, now, ptimeout); +wrl_check_timeout (conn->domain, msecs, ptimeout);check_event_timeout (conn, msecs, ptimeout); if (conn_can_read(conn) || (conn_can_write(conn) &&
tools/xenstore/xenstored_core.h +3 -4
@@ -47,10 +47,6 @@/* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */ #define DEFAULT_BUFFER_SIZE 16 -typedef int32_t wrl_creditt ; -#define WRL_CREDIT_MAX (1000*1000*1000) -/* ^ satisfies non-overflow condition for wrl_xfer_credit */ -struct xs_state_connection ;struct buffered_data
@@ -320,6 +316,9 @@ extern bool keep_orphans;extern unsigned int timeout_watch_event_msec; +/* Get internal time in milliseconds. */ +uint64_t get_now_msec (void ); +/* Map the kernel's xenstore page. */ void *xenbus_map (void );void unmap_xenbus (void *interface);
tools/xenstore/xenstored_domain.c +24 -32
130 lines not on this page · raw message
tools/xenstore/xenstored_domain.h +2 -19
@@ -146,27 +146,10 @@ void domain_reset_global_acc(void);bool domain_max_chk (const struct connection *conn,unsigned int what,unsigned int val); -/* Write rate limiting */ - -#define WRL_FACTOR 1000/* for fixed-point arithmetic */ -#define WRL_RATE 200 -#define WRL_DBURST 10 -#define WRL_GBURST 1000 -#define WRL_NEWDOMS 5 -#define WRL_LOGEVERY 120/* seconds */ - -struct wrl_timestampt { -time_t sec; -int msec; -}; -extern long wrl_ntransactions; -void wrl_gettime_now (struct wrl_timestampt *now_ts); -void wrl_check_timeout (struct domain *domain, -struct wrl_timestampt now, -int *ptimeout); -void wrl_log_periodic (struct wrl_timestampt now); +void wrl_check_timeout (struct domain *domain,uint64_t now,int *ptimeout); +void wrl_log_periodic (uint64_t now);void wrl_apply_debit_direct (struct connection *conn);void wrl_apply_debit_trans_commit (struct connection *conn);
Signature · 1 line
2.35.3
Re: [PATCH v3 06/16] tools/xenstore: switch write limiting to use millisecond time base
Hi Juergen,
Quoted 7 lines · Juergen Gross
There is no need to keep struct
wrl_timestampt, as it serves the same purpose as the more simple time base provided byget_now().Move some more stuff from
xenstored_domain.hintoxenstored_domain.cas it is being used nowhere else.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 7/16 tools/xenstore: remove stale TODO file
In reply to Juergen GrossThe TODO file is not really helpful any longer. It contains only entries which no longer apply or it is unknown what they are meant for ("Dynamic/supply nodes", "Remove assumption that rename doesn't fail").
--- tools/xenstore/TODO | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 tools/xenstore/TODO
tools/xenstore/TODO deleted +0 -10
@@ -1,10 +0,0 @@ -TODO in no particular order. Some of these will never be done. There -are omissions of important but necessary things. It is up to the -reader to fill in the blanks. - -- Timeout failed watch responses -- Dynamic/supply nodes -- Persistant storage of introductions, watches and transactions, so daemon can restart -- Remove assumption that rename doesn't fail -- Multi-root transactions, for setting up front and back ends at same time. -
Signature · 1 line
2.35.3
PATCH v3 8/16 tools/xenstore: remove unused events list
In reply to Juergen Grossstruct watch contains an unused struct list_head events. Remove it.
--- tools/xenstore/xenstored_watch.c | 5 ----- 1 file changed, 5 deletions(-)
tools/xenstore/xenstored_watch.c +0 -5
@@ -36,9 +36,6 @@ struct watch/* Watches on this connection */ struct list_head list; -/* Current outstanding events applying to this watch. */ -struct list_head events; -/* Offset into path for skipping prefix (used for relative paths). */ unsigned int prefix_len;
@@ -205,8 +202,6 @@ static struct watch *add_watch(struct connection *conn, char *path, char *token, watch->prefix_len = relative ?strlen (get_implicit_path (conn)) +1 :0 ; -INIT_LIST_HEAD (&watch->events); -domain_watch_inc (conn);list_add_tail (&watch->list, &conn->watches);talloc_set_destructor (watch, destroy_watch);
Signature · 1 line
2.35.3
PATCH v3 9/16 tools/xenstore: remove support of file backed data base
In reply to Juergen GrossIn order to prepare the replacement of TDB with direct accessible nodes in memory, remove the support for a file backed data base.
This allows to remove xs_tdb_dump, too.
--- .gitignore | 1 - tools/xenstore/Makefile | 5 +- tools/xenstore/xenstored_core.c | 18 ++----- tools/xenstore/xs_tdb_dump.c | 86 --------------------------------- 4 files changed, 4 insertions(+), 106 deletions(-) delete mode 100644 tools/xenstore/xs_tdb_dump.c
.gitignore +0 -1
@@ -248,7 +248,6 @@ tools/xenstore/xenstore-rm tools/xenstore/xenstore-watch tools/xenstore/xenstore-write tools/xenstore/xenstored -tools/xenstore/xs_tdb_dump tools/xentop/xentop tools/xentrace/xentrace_setsize tools/xentrace/tbctl
tools/xenstore/Makefile +1 -4
@@ -29,7 +29,7 @@ CLIENTS += xenstore-write xenstore-ls xenstore-watch TARGETS := xenstore $(CLIENTS) xenstore-control ifeq ($(XENSTORE_XENSTORED),y) -TARGETS += xs_tdb_dump xenstored +TARGETS += xenstored endif .PHONY: all
@@ -50,9 +50,6 @@ xenstore: xenstore_client.o xs_lib.o xenstore-control: xenstore_control.o $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(APPEND_LDFLAGS) -xs_tdb_dump: xs_tdb_dump.o utils.o tdb.o talloc.o - $(CC) $(LDFLAGS) $^ -o $@ $(APPEND_LDFLAGS) - .PHONY: clean clean:: $(RM) $(TARGETS) $(DEPS_RM)
tools/xenstore/xenstored_core.c +3 -15
@@ -2301,8 +2301,6 @@ static void accept_connection(int sock) }#endif -static int tdb_flags =TDB_INTERNAL |TDB_NOLOCK ; -/* We create initial nodes manually. */ static void manual_node (const char *name,const char *child) {
@@ -2354,14 +2352,11 @@ void setup_structure(bool live_update) {char *tdbname; - tdbname =talloc_strdup (talloc_autofree_context (),xs_daemon_tdb ()); + tdbname =talloc_strdup (talloc_autofree_context (),"/dev/mem" );if (!tdbname)barf_perror ("Could not create tdbname" ); -if (!(tdb_flags &TDB_INTERNAL )) -unlink (tdbname); - - tdb_ctx =tdb_open_ex (tdbname,7919 , tdb_flags, + tdb_ctx =tdb_open_ex (tdbname,7919 ,TDB_INTERNAL |TDB_NOLOCK ,O_RDWR |O_CREAT |O_EXCL |O_CLOEXEC ,0640 , &tdb_logger,NULL );if (!tdb_ctx)
@@ -2659,8 +2654,6 @@ static void usage(void)" watch-event: time a watch-event is kept pending\n" " -R, --no-recovery to request that no recovery should be attempted when\n" " the store is corrupted (debug only),\n" -" -I, --internal-db [on|off] store database in memory, not on disk, default is\n" -" memory, with \"--internal-db off\" it is on disk\n" " -K, --keep-orphans don't delete nodes owned by a domain when the\n" " domain is deleted (this is a security risk!)\n" " -V, --verbose to request verbose execution.\n");
@@ -2687,7 +2680,6 @@ static struct option options[] = { { "quota-soft", 1, NULL, 'q' }, { "timeout", 1, NULL, 'w' }, { "no-recovery", 0, NULL, 'R' }, - { "internal-db", 2, NULL, 'I' }, { "keep-orphans", 0, NULL, 'K' }, { "verbose", 0, NULL, 'V' }, { "watch-nb", 1, NULL, 'W' },
@@ -2811,7 +2803,7 @@ int main(int argc, char *argv[]) orig_argv = argv;while ((opt =getopt_long (argc, argv, -"DE:F:HI::KNPS:t:A:M:Q:q:T:RVW:w:U" , +"DE:F:H::KNPS:t:A:M:Q:q:T:RVW:w:U" , options,NULL )) !=-1 ) {switch (opt) {case 'D' :
@@ -2848,10 +2840,6 @@ int main(int argc, char *argv[])if (set_trace_switch (optarg))barf ("Illegal trace switch \"%s\"\n" , optarg);break ; -case 'I' : -if (optarg && !strcmp (optarg,"off" )) - tdb_flags =0 ; -break ;case 'K' : keep_orphans = true;break ;
tools/xenstore/xs_tdb_dump.c deleted +0 -86
86 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH v3 09/16] tools/xenstore: remove support of file backed data base
Hi Juergen,
Quoted 6 lines · Juergen Gross
In order to prepare the replacement of TDB with direct accessible nodes in memory, remove the support for a file backed data base.
This allows to remove
xs_tdb_dump, too.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 10/16 tools/libs/store: use xen_list.h instead of xenstore/list.h
In reply to Juergen GrossReplace the usage of the xenstore private list.h header with the common xen_list.h one.
---
V3:
- new patch
--- tools/libs/store/xs.c | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-)
tools/libs/store/xs.c +28 -28
@@ -35,13 +35,13 @@#include <errno.h> #include "xenstore.h" #include "xs_lib.h" -#include "list.h" #include "utils.h" #include <xentoolcore_internal.h> +#include <xen_list.h> struct xs_stored_msg { -struct list_head list; +XEN_TAILQ_ENTRY (struct xs_stored_msg ) list;struct xsd_sockmsg hdr;char *body; };
@@ -70,7 +70,7 @@ struct xs_handle {* A list of fired watch messages, protected by a mutex. Users can * wait on the conditional variable until a watch is pending. */ -struct list_head watch_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) watch_list;pthread_mutex_t watch_mutex;pthread_cond_t watch_condvar;
@@ -84,7 +84,7 @@ struct xs_handle {* because we serialise requests. The requester can wait on the * conditional variable for its response. */ -struct list_head reply_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) reply_list;pthread_mutex_t reply_mutex;pthread_cond_t reply_condvar;
@@ -133,8 +133,8 @@ static void *read_thread(void *arg);struct xs_handle {int fd;Xentoolcore__Active_Handle tc_ah;/* for restrict */ -struct list_head reply_list; -struct list_head watch_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) reply_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) watch_list;/* Clients can select() on this pipe to wait for a watch to fire. */ int watch_pipe[2 ];/* Filtering watch event in unwatch function? */
@@ -180,7 +180,7 @@ int xs_fileno(struct xs_handle *h)if ((h->watch_pipe[0 ] ==-1 ) && (pipe (h->watch_pipe) !=-1 )) {/* Kick things off if the watch list is already non-empty. */ -if (!list_empty (&h->watch_list)) +if (!XEN_TAILQ_EMPTY (&h->watch_list))while (write (h->watch_pipe[1 ], &c,1 ) !=1 )continue ; }
@@ -262,8 +262,8 @@ static struct xs_handle *get_handle(const char *connect_to)if (h->fd ==-1 ) goto err; -INIT_LIST_HEAD (&h->reply_list); -INIT_LIST_HEAD (&h->watch_list); +XEN_TAILQ_INIT (&h->reply_list); +XEN_TAILQ_INIT (&h->watch_list);/* Watch pipe is allocated on demand in xs_fileno(). */ h->watch_pipe[0 ] = h->watch_pipe[1 ] =-1 ;
@@ -329,12 +329,12 @@ struct xs_handle *xs_open(unsigned long flags)static void close_free_msgs (struct xs_handle *h) {struct xs_stored_msg *msg, *tmsg; -list_for_each_entry_safe (msg, tmsg, &h->reply_list, list) { + XEN_TAILQ_FOREACH_SAFE(msg, &h->reply_list, list, tmsg) {free (msg->body);free (msg); } -list_for_each_entry_safe (msg, tmsg, &h->watch_list, list) { + XEN_TAILQ_FOREACH_SAFE(msg, &h->watch_list, list, tmsg) {free (msg->body);free (msg); }
@@ -459,17 +459,17 @@ static void *read_reply(mutex_lock (&h->reply_mutex);#ifdef USE_PTHREAD -while (list_empty (&h->reply_list) && read_from_thread && h->fd !=-1 ) +while (XEN_TAILQ_EMPTY (&h->reply_list) && read_from_thread && h->fd !=-1 )condvar_wait (&h->reply_condvar, &h->reply_mutex);#endif -if (list_empty (&h->reply_list)) { +if (XEN_TAILQ_EMPTY (&h->reply_list)) {mutex_unlock (&h->reply_mutex); errno =EINVAL ;return NULL ; } - msg = list_top(&h->reply_list, struct xs_stored_msg, list); -list_del (&msg->list); -assert (list_empty (&h->reply_list)); + msg =XEN_TAILQ_FIRST (&h->reply_list); +XEN_TAILQ_REMOVE (&h->reply_list, msg, list); +assert (XEN_TAILQ_EMPTY (&h->reply_list));mutex_unlock (&h->reply_mutex); *type = msg->hdr.type;
@@ -883,7 +883,7 @@ static void xs_maybe_clear_watch_pipe(struct xs_handle *h) {char c; -if (list_empty (&h->watch_list) && (h->watch_pipe[0 ] !=-1 )) +if (XEN_TAILQ_EMPTY (&h->watch_list) && (h->watch_pipe[0 ] !=-1 ))while (read (h->watch_pipe[0 ], &c,1 ) !=1 )continue ; }
@@ -907,7 +907,7 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,* we haven't called xs_watch. Presumably the application * will do so later; in the meantime we just block. */ -while (list_empty (&h->watch_list) && h->fd !=-1 ) { +while (XEN_TAILQ_EMPTY (&h->watch_list) && h->fd !=-1 ) {if (nonblocking) {mutex_unlock (&h->watch_mutex); errno =EAGAIN ;
@@ -925,13 +925,13 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,#endif /* !defined(USE_PTHREAD) */ -if (list_empty (&h->watch_list)) { +if (XEN_TAILQ_EMPTY (&h->watch_list)) {mutex_unlock (&h->watch_mutex); errno =EINVAL ;return NULL ; } - msg = list_top(&h->watch_list, struct xs_stored_msg, list); -list_del (&msg->list); + msg =XEN_TAILQ_FIRST (&h->watch_list); +XEN_TAILQ_REMOVE (&h->watch_list, msg, list);xs_maybe_clear_watch_pipe (h);mutex_unlock (&h->watch_mutex);
@@ -1007,12 +1007,12 @@ bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)/* Filter the watch list to remove potential message */ mutex_lock (&h->watch_mutex); -if (list_empty (&h->watch_list)) { +if (XEN_TAILQ_EMPTY (&h->watch_list)) {mutex_unlock (&h->watch_mutex);return res; } -list_for_each_entry_safe (msg, tmsg, &h->watch_list, list) { + XEN_TAILQ_FOREACH_SAFE(msg, &h->watch_list, list, tmsg) {assert (msg->hdr.type ==XS_WATCH_EVENT ); s = msg->body;
@@ -1034,7 +1034,7 @@ bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)if (l_token && !strcmp (token, l_token) && l_path &&xs_path_is_subpath (path, l_path)) { -list_del (&msg->list); +XEN_TAILQ_REMOVE (&h->watch_list, msg, list);free (msg); } }
@@ -1290,12 +1290,12 @@ static int read_message(struct xs_handle *h, int nonblocking)cleanup_push (pthread_mutex_unlock, &h->watch_mutex);/* Kick users out of their select() loop. */ -if (list_empty (&h->watch_list) && +if (XEN_TAILQ_EMPTY (&h->watch_list) && (h->watch_pipe[1 ] !=-1 ))while (write (h->watch_pipe[1 ], body,1 ) !=1 )/* Cancellation point */ continue ; -list_add_tail (&msg->list, &h->watch_list); +XEN_TAILQ_INSERT_TAIL (&h->watch_list, msg, list);condvar_signal (&h->watch_condvar);
@@ -1304,13 +1304,13 @@ static int read_message(struct xs_handle *h, int nonblocking)mutex_lock (&h->reply_mutex);/* There should only ever be one response pending! */ -if (!list_empty (&h->reply_list)) { +if (!XEN_TAILQ_EMPTY (&h->reply_list)) {mutex_unlock (&h->reply_mutex); saved_errno =EEXIST ; goto error_freebody; } -list_add_tail (&msg->list, &h->reply_list); +XEN_TAILQ_INSERT_TAIL (&h->reply_list, msg, list);condvar_signal (&h->reply_condvar);mutex_unlock (&h->reply_mutex);
Signature · 1 line
2.35.3
Re: [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h
Hi Juergen,
Quoted 18 lines · Juergen Gross
Replace the usage of the xenstore private
list.hheader with the commonxen_list.hone.Signed-off-by Juergen Gross <[email protected]>---
V3:
- new patch--- tools/libs/store/xs.c | 56 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-)tools/libs/store/xs.c +0
-0@@ -35,13 +35,13 @@#include <errno.h> #include "xenstore.h"
tools/libs/store/xs.c line 44
Quoted 10 lines
tools/libs/store/xs.c +2
-2#include "xs_lib.h" -#include "list.h" #include "utils.h" #include <xentoolcore_internal.h> +#include <xen_list.h> struct xs_stored_msg { -struct list_head list; +XEN_TAILQ_ENTRY (struct xs_stored_msg ) list;
I have expected us to use to XEN_LIST_*. Can you explain why you didn't use them?
Quoted 180 lines
tools/libs/store/xs.c +26
-26struct xsd_sockmsg hdr;char *body; };@@ -70,7 +70,7 @@ struct xs_handle {* A list of fired watch messages, protected by a mutex. Users can * wait on the conditional variable until a watch is pending. */ -struct list_head watch_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) watch_list;pthread_mutex_t watch_mutex;pthread_cond_t watch_condvar;@@ -84,7 +84,7 @@ struct xs_handle {* because we serialise requests. The requester can wait on the * conditional variable for its response. */ -struct list_head reply_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) reply_list;pthread_mutex_t reply_mutex;pthread_cond_t reply_condvar;@@ -133,8 +133,8 @@ static void *read_thread(void *arg);struct xs_handle {int fd;Xentoolcore__Active_Handle tc_ah;/* for restrict */ -struct list_head reply_list; -struct list_head watch_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) reply_list; + XEN_TAILQ_HEAD(, struct xs_stored_msg) watch_list;/* Clients can select() on this pipe to wait for a watch to fire. */ int watch_pipe[2 ];/* Filtering watch event in unwatch function? */ @@ -180,7 +180,7 @@ int xs_fileno(struct xs_handle *h)if ((h->watch_pipe[0 ] ==-1 ) && (pipe (h->watch_pipe) !=-1 )) {/* Kick things off if the watch list is already non-empty. */ -if (!list_empty (&h->watch_list)) +if (!XEN_TAILQ_EMPTY (&h->watch_list))while (write (h->watch_pipe[1 ], &c,1 ) !=1 )continue ; }@@ -262,8 +262,8 @@ static struct xs_handle *get_handle(const char *connect_to)if (h->fd ==-1 ) goto err; -INIT_LIST_HEAD (&h->reply_list); -INIT_LIST_HEAD (&h->watch_list); +XEN_TAILQ_INIT (&h->reply_list); +XEN_TAILQ_INIT (&h->watch_list);/* Watch pipe is allocated on demand in xs_fileno(). */ h->watch_pipe[0 ] = h->watch_pipe[1 ] =-1 ;@@ -329,12 +329,12 @@ struct xs_handle *xs_open(unsigned long flags)static void close_free_msgs (struct xs_handle *h) {struct xs_stored_msg *msg, *tmsg; -list_for_each_entry_safe (msg, tmsg, &h->reply_list, list) { + XEN_TAILQ_FOREACH_SAFE(msg, &h->reply_list, list, tmsg) {free (msg->body);free (msg); } -list_for_each_entry_safe (msg, tmsg, &h->watch_list, list) { + XEN_TAILQ_FOREACH_SAFE(msg, &h->watch_list, list, tmsg) {free (msg->body);free (msg); }@@ -459,17 +459,17 @@ static void *read_reply(mutex_lock (&h->reply_mutex);#ifdef USE_PTHREAD -while (list_empty (&h->reply_list) && read_from_thread && h->fd !=-1 ) +while (XEN_TAILQ_EMPTY (&h->reply_list) && read_from_thread && h->fd !=-1 )condvar_wait (&h->reply_condvar, &h->reply_mutex);#endif -if (list_empty (&h->reply_list)) { +if (XEN_TAILQ_EMPTY (&h->reply_list)) {mutex_unlock (&h->reply_mutex); errno =EINVAL ;return NULL ; } - msg = list_top(&h->reply_list, struct xs_stored_msg, list); -list_del (&msg->list); -assert (list_empty (&h->reply_list)); + msg =XEN_TAILQ_FIRST (&h->reply_list); +XEN_TAILQ_REMOVE (&h->reply_list, msg, list); +assert (XEN_TAILQ_EMPTY (&h->reply_list));mutex_unlock (&h->reply_mutex); *type = msg->hdr.type;@@ -883,7 +883,7 @@ static void xs_maybe_clear_watch_pipe(struct xs_handle *h) {char c; -if (list_empty (&h->watch_list) && (h->watch_pipe[0 ] !=-1 )) +if (XEN_TAILQ_EMPTY (&h->watch_list) && (h->watch_pipe[0 ] !=-1 ))while (read (h->watch_pipe[0 ], &c,1 ) !=1 )continue ; }@@ -907,7 +907,7 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,* we haven't called xs_watch. Presumably the application * will do so later; in the meantime we just block. */ -while (list_empty (&h->watch_list) && h->fd !=-1 ) { +while (XEN_TAILQ_EMPTY (&h->watch_list) && h->fd !=-1 ) {if (nonblocking) {mutex_unlock (&h->watch_mutex); errno =EAGAIN ;@@ -925,13 +925,13 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,#endif /* !defined(USE_PTHREAD) */ -if (list_empty (&h->watch_list)) { +if (XEN_TAILQ_EMPTY (&h->watch_list)) {mutex_unlock (&h->watch_mutex); errno =EINVAL ;return NULL ; } - msg = list_top(&h->watch_list, struct xs_stored_msg, list); -list_del (&msg->list); + msg =XEN_TAILQ_FIRST (&h->watch_list); +XEN_TAILQ_REMOVE (&h->watch_list, msg, list);xs_maybe_clear_watch_pipe (h);mutex_unlock (&h->watch_mutex);@@ -1007,12 +1007,12 @@ bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)/* Filter the watch list to remove potential message */ mutex_lock (&h->watch_mutex); -if (list_empty (&h->watch_list)) { +if (XEN_TAILQ_EMPTY (&h->watch_list)) {mutex_unlock (&h->watch_mutex);return res; } -list_for_each_entry_safe (msg, tmsg, &h->watch_list, list) { + XEN_TAILQ_FOREACH_SAFE(msg, &h->watch_list, list, tmsg) {assert (msg->hdr.type ==XS_WATCH_EVENT ); s = msg->body;@@ -1034,7 +1034,7 @@ bool xs_unwatch(struct xs_handle *h, const char *path, const char *token)if (l_token && !strcmp (token, l_token) && l_path &&xs_path_is_subpath (path, l_path)) { -list_del (&msg->list); +XEN_TAILQ_REMOVE (&h->watch_list, msg, list);free (msg); } }@@ -1290,12 +1290,12 @@ static int read_message(struct xs_handle *h, int nonblocking)cleanup_push (pthread_mutex_unlock, &h->watch_mutex);/* Kick users out of their select() loop. */ -if (list_empty (&h->watch_list) && +if (XEN_TAILQ_EMPTY (&h->watch_list) && (h->watch_pipe[1 ] !=-1 ))while (write (h->watch_pipe[1 ], body,1 ) !=1 )/* Cancellation point */ continue ; -list_add_tail (&msg->list, &h->watch_list); +XEN_TAILQ_INSERT_TAIL (&h->watch_list, msg, list);condvar_signal (&h->watch_condvar);@@ -1304,13 +1304,13 @@ static int read_message(struct xs_handle *h, int nonblocking)mutex_lock (&h->reply_mutex);/* There should only ever be one response pending! */ -if (!list_empty (&h->reply_list)) { +if (!XEN_TAILQ_EMPTY (&h->reply_list)) {mutex_unlock (&h->reply_mutex); saved_errno =EEXIST ; goto error_freebody; } -list_add_tail (&msg->list, &h->reply_list); +XEN_TAILQ_INSERT_TAIL (&h->reply_list, msg, list);condvar_signal (&h->reply_condvar);mutex_unlock (&h->reply_mutex);
Signature · 1 line
Julien Grall
Re: [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h
Quoted 23 lines · Julien Grall
Hi Juergen,
Quoted 20 lines · Juergen Gross
Replace the usage of the xenstore private
list.hheader with the commonxen_list.hone.Signed-off-by Juergen Gross <[email protected]>---
V3:
- new patch
---
tools/libs/store/xs.c| 56 +++++++++++++++++++++----------------------1 file changed, 28 insertions(+), 28 deletions(-)tools/libs/store/xs.c +0
-1@@ -35,13 +35,13 @@ #include <errno.h> #include "xenstore.h" #include "xs_lib.h" -#include "list.h"
Quoted 8 lines
tools/libs/store/xs.c line 44
Quoted 6 lines
tools/libs/store/xs.c +2
-1#include "utils.h" #include <xentoolcore_internal.h> +#include <xen_list.h> struct xs_stored_msg { - struct list_head list; + XEN_TAILQ_ENTRY(struct xs_stored_msg) list;I have expected us to use to XEN_LIST_*. Can you explain why you didn't use them?
XEN_LIST_* doesn't provide a list_add_tail() replacement.
Juergen
Julien Grall
Acked-byRe: [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h
Hi,
Quoted 33 lines · Juergen Gross
Quoted 23 lines · Julien Grall
Hi Juergen,
Quoted 20 lines · Juergen Gross
Replace the usage of the xenstore private
list.hheader with the commonxen_list.hone.Signed-off-by Juergen Gross <[email protected]>---
V3:
- new patch
---
tools/libs/store/xs.c| 56 +++++++++++++++++++++----------------------1 file changed, 28 insertions(+), 28 deletions(-)tools/libs/store/xs.c +0
-1@@ -35,13 +35,13 @@ #include <errno.h> #include "xenstore.h" #include "xs_lib.h" -#include "list.h" Quoted 8 lines
tools/libs/store/xs.c line 44
Quoted 6 lines
tools/libs/store/xs.c +2
-1#include "utils.h" #include <xentoolcore_internal.h> +#include <xen_list.h> struct xs_stored_msg { - struct list_head list; + XEN_TAILQ_ENTRY(struct xs_stored_msg) list;I have expected us to use to XEN_LIST_*. Can you explain why you didn't use them?
Quoted 1 line
XEN_LIST_* doesn't provide a
list_add_tail()replacement.
Ok. Did you look at whether list_add_tail() could be replaced with adding the element at the head?
Anyway, I can understand that this would not be a straight swap. But it would be good to have some rationale in the commit message as this helps understanding the choice.
With that:
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h
Quoted 36 lines · Julien Grall
Hi,
Quoted 33 lines · Juergen Gross
Quoted 31 lines · Julien Grall
Hi Juergen,
Quoted 16 lines · Juergen Gross
Replace the usage of the xenstore private
list.hheader with the commonxen_list.hone.Signed-off-by Juergen Gross <[email protected]>---
V3:
- new patch
---
tools/libs/store/xs.c| 56 +++++++++++++++++++++----------------------1 file changed, 28 insertions(+), 28 deletions(-)tools/libs/store/xs.c +0
-0tools/libs/store/xs.c line 42
Quoted 10 lines
tools/libs/store/xs.c +2
-2@@ -35,13 +35,13 @@ #include <errno.h> #include "xenstore.h" #include "xs_lib.h" -#include "list.h" #include "utils.h" #include <xentoolcore_internal.h> +#include <xen_list.h> struct xs_stored_msg { - struct list_head list; + XEN_TAILQ_ENTRY(struct xs_stored_msg) list;I have expected us to use to XEN_LIST_*. Can you explain why you didn't use them?
Quoted 5 lines
Quoted 1 line
XEN_LIST_* doesn't provide a
list_add_tail()replacement.Ok. Did you look at whether
list_add_tail()could be replaced with adding the element at the head?Anyway, I can understand that this would not be a straight swap. But it would be good to have some rationale in the commit message as this helps understanding the choice.
Okay, I'll add: "Use the XEN_TAILQ type list, as it allows to directly swap the related macros/functions without having to change the logic."
Quoted 4 lines
With that:
Acked-by Julien Grall <[email protected]>
Thanks,
Juergen
Re: [PATCH v3 10/16] tools/libs/store: use xen_list.h instead of xenstore/list.h
Quoted 38 lines · Juergen Gross
Quoted 37 lines · Julien Grall
Hi,
Quoted 34 lines · Juergen Gross
Quoted 32 lines · Julien Grall
Hi Juergen,
Quoted 17 lines · Juergen Gross
Replace the usage of the xenstore private
list.hheader with the commonxen_list.hone.Signed-off-by Juergen Gross <[email protected]>---
V3:
- new patch
---
tools/libs/store/xs.c| 56
+++++++++++++++++++++----------------------1 file changed, 28 insertions(+), 28 deletions(-)tools/libs/store/xs.c +0
-0tools/libs/store/xs.c line 42
Quoted 10 lines
tools/libs/store/xs.c +2
-2@@ -35,13 +35,13 @@ #include <errno.h> #include "xenstore.h" #include "xs_lib.h" -#include "list.h" #include "utils.h" #include <xentoolcore_internal.h> +#include <xen_list.h> struct xs_stored_msg { - struct list_head list; + XEN_TAILQ_ENTRY(struct xs_stored_msg) list;I have expected us to use to XEN_LIST_*. Can you explain why you didn't use them?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
XEN_LIST_* doesn't provide a
list_add_tail()replacement.Ok. Did you look at whether
list_add_tail()could be replaced with adding the element at the head?Anyway, I can understand that this would not be a straight swap. But it would be good to have some rationale in the commit message as this helps understanding the choice.
Okay, I'll add: "Use the
XEN_TAILQtype list, as it allows to directly swap the related macros/functions without having to change the logic."
Thanks. I am happy to add it whilst committing.
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 11/16 tools/libs/store: make libxenstore independent of utils.h
In reply to Juergen GrossThere is no real need for including tools/xenstore/utils.h from libxenstore, as only streq() and ARRAY_SIZE() are obtained via that header.
streq() is just !strcmp(), and ARRAY_SIZE() is brought in via xen-tools/common-macros.h.
---
V3:
- new patch
--- tools/libs/store/xs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libs/store/xs.c +2 -2
@@ -33,9 +33,9 @@#include <signal.h> #include <stdint.h> #include <errno.h> +#include <xen-tools/common-macros.h> #include "xenstore.h" #include "xs_lib.h" -#include "utils.h" #include <xentoolcore_internal.h> #include <xen_list.h>
@@ -437,7 +437,7 @@ static int get_error(const char *errorstring) {unsigned int i; -for (i =0 ; !streq (errorstring, xsd_errors[i].errstring); i++) +for (i =0 ;strcmp (errorstring, xsd_errors[i].errstring); i++)if (i ==ARRAY_SIZE (xsd_errors) -1 )return EINVAL ;return xsd_errors[i].errnum;
Signature · 1 line
2.35.3
Re: [PATCH v3 11/16] tools/libs/store: make libxenstore independent of utils.h
Hi Juergen,
Quoted 8 lines · Juergen Gross
There is no real need for including
tools/xenstore/utils.hfrom libxenstore, as onlystreq()andARRAY_SIZE()are obtained via that header.
streq()is just !strcmp(), andARRAY_SIZE()is brought in viaxen-tools/common-macros.h.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 12/16 tools/xenstore: remove no longer needed functions from xs_lib.c
In reply to Juergen Grossxs_daemon_tdb() in xs_lib.c is no longer used at all, so it can be removed. xs_domain_dev() and xs_write_all() are not used by xenstored, so they can be moved to tools/libs/store/xs.c.
xs_daemon_rootdir() is used by xenstored only and it only calls xs_daemon_rundir(), so replace its use cases with xs_daemon_rundir() and remove it from xs_lib.c.
xs_daemon_socket_ro() is needed in libxenstore only, so move it to tools/libs/store/xs.c.
Move functions used by xenstore-client only to xenstore_client.c.
---
V2:
- move xs_write_all(), too
V3:
- remove xs_daemon_rootdir(), move xs_daemon_socket_ro()
--- tools/include/xenstore.h | 3 + tools/include/xenstore_lib.h | 3 - tools/libs/store/xs.c | 43 ++++++++ tools/xenstore/xenstore_client.c | 129 ++++++++++++++++++++++ tools/xenstore/xenstored_control.c | 4 +- tools/xenstore/xenstored_core.c | 3 +- tools/xenstore/xs_lib.c | 166 ----------------------------- tools/xenstore/xs_lib.h | 19 ---- 8 files changed, 178 insertions(+), 192 deletions(-)
tools/include/xenstore.h +3 -0
@@ -113,6 +113,9 @@ void *xs_read(struct xs_handle *h, xs_transaction_t t,bool xs_write (struct xs_handle *h,xs_transaction_t t,const char *path,const void *data,unsigned int len); +/* Simple write function: loops for you. */ +bool xs_write_all (int fd,const void *data,unsigned int len); +/* Create a new directory. * Returns false on failure, or success if it already exists. */
tools/include/xenstore_lib.h +0 -3
@@ -47,9 +47,6 @@ const char *xs_daemon_rundir(void);const char *xs_daemon_socket (void );const char *xs_daemon_socket_ro (void ); -/* Simple write function: loops for you. */ -bool xs_write_all (int fd,const void *data,unsigned int len); -/* Convert strings to permissions. False if a problem. */ bool xs_strings_to_perms (struct xs_permissions *perms,unsigned int num,const char *strings);
tools/libs/store/xs.c +43 -0
61 lines not on this page · raw message
tools/xenstore/xenstore_client.c +129 -0
147 lines not on this page · raw message
tools/xenstore/xenstored_control.c +2 -2
@@ -560,7 +560,7 @@ static FILE *lu_dump_open(const void *ctx)char *filename;int fd; - filename =talloc_asprintf (ctx,"%s/state_dump" ,xs_daemon_rootdir ()); + filename =talloc_asprintf (ctx,"%s/state_dump" ,xs_daemon_rundir ());if (!filename)return NULL ;
@@ -583,7 +583,7 @@ static void lu_get_dump_state(struct lu_dump_state *state) state->size =0 ; state->filename =talloc_asprintf (NULL ,"%s/state_dump" , -xs_daemon_rootdir ()); +xs_daemon_rundir ());if (!state->filename)barf ("Allocation failure" );
tools/xenstore/xenstored_core.c +1 -2
@@ -2888,10 +2888,9 @@ int main(int argc, char *argv[])reopen_log (); -/* make sure xenstored directories exist */ +/* Make sure xenstored directory exists. */ /* Errors ignored here, will be reported when we open files */ mkdir (xs_daemon_rundir (),0755 ); -mkdir (xs_daemon_rootdir (),0755 );if (dofork) {openlog ("xenstored" ,0 ,LOG_DAEMON );
tools/xenstore/xs_lib.c +0 -166
186 lines not on this page · raw message
tools/xenstore/xs_lib.h +0 -19
@@ -21,10 +21,6 @@#include "xenstore_lib.h" -const char *xs_daemon_rootdir (void ); -const char *xs_domain_dev (void ); -const char *xs_daemon_tdb (void ); -/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */ bool xs_perm_to_string (const struct xs_permissions *perm,char *buffer,size_t buf_len);
@@ -32,19 +28,4 @@ bool xs_perm_to_string(const struct xs_permissions *perm,/* Given a string and a length, count how many strings (nul terms). */ unsigned int xs_count_strings (const char *strings,unsigned int len); -/* Sanitising (quoting) possibly-binary strings. */ -struct expanding_buffer { -char *buf; -int avail; -}; - -/* Ensure that given expanding buffer has at least min_avail characters. */ -char *expanding_buffer_ensure (struct expanding_buffer *,int min_avail); - -/* sanitise_value() may return NULL if malloc fails. */ -char *sanitise_value (struct expanding_buffer *,const char *val,unsigned len); - -/* *out_len_r on entry is ignored; out must be at least strlen(in)+1 bytes. */ -void unsanitise_value (char *out,unsigned *out_len_r,const char *in); -#endif /* XS_LIB_H */
Signature · 1 line
2.35.3
Re: [PATCH v3 12/16] tools/xenstore: remove no longer needed functions from xs_lib.c
Hi Juergen,
Quoted 8 lines · Juergen Gross
xs_daemon_tdb()inxs_lib.cis no longer used at all, so it can be removed.xs_domain_dev()andxs_write_all()are not used by xenstored, so they can be moved totools/libs/store/xs.c.
xs_daemon_rootdir()is used by xenstored only and it only callsxs_daemon_rundir(), so replace its use cases withxs_daemon_rundir()and remove it fromxs_lib.c.
Quoted 6 lines
xs_daemon_socket_ro()is needed in libxenstore only, so move it totools/libs/store/xs.c.Move functions used by xenstore-client only to
xenstore_client.c.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 13/16 tools/xenstore: replace xs_lib.c with a header
In reply to Juergen GrossInstead of including the same small C source in multiple binaries from 2 source directories, use a header file with inline functions as a replacement.
As some of the functions are exported by libxenstore, rename the inline functions from xs_*() do xenstore_*() and add xs_*() wrappers to libxenstore.
With that no sources required to build libxenstore are left in tools/xenstore, so the file COPYING can be removed now.
---
V3:
- new patch
--- MAINTAINERS | 1 + tools/include/xen-tools/xenstore-common.h | 128 ++++++ tools/libs/store/Makefile | 4 - tools/libs/store/xs.c | 28 +- tools/xenstore/COPYING | 514 ---------------------- tools/xenstore/Makefile | 2 +- tools/xenstore/Makefile.common | 2 +- tools/xenstore/xenstore_client.c | 4 +- tools/xenstore/xenstored_control.c | 9 +- tools/xenstore/xenstored_core.c | 15 +- tools/xenstore/xs_lib.c | 126 ------ tools/xenstore/xs_lib.h | 31 -- 12 files changed, 168 insertions(+), 696 deletions(-) create mode 100644 tools/include/xen-tools/xenstore-common.h delete mode 100644 tools/xenstore/COPYING delete mode 100644 tools/xenstore/xs_lib.c delete mode 100644 tools/xenstore/xs_lib.h
MAINTAINERS +1 -0
@@ -657,6 +657,7 @@ F: tools/helpers/init-xenstore-domain.c F: tools/include/xenstore-compat/ F: tools/include/xenstore.h F: tools/include/xenstore_lib.h +F: tools/include/xen-tools/xenstore-common.h F: tools/libs/store/ F: tools/xenstore/
tools/include/xen-tools/xenstore-common.h new file +128 -0
128 lines not on this page · raw message
tools/libs/store/Makefile +0 -4
@@ -9,7 +9,6 @@ ifeq ($(CONFIG_Linux),y) LDLIBS += -ldl endif -OBJS-y += xs_lib.o OBJS-y += xs.o LIBHEADER = xenstore.h xenstore_lib.h
@@ -21,9 +20,6 @@ CFLAGS += -include $(XEN_ROOT)/tools/config.h CFLAGS += $(CFLAGS_libxentoolcore) CFLAGS += -DXEN_RUN_STORED="\"$(XEN_RUN_STORED)\"" -vpath xs_lib.c $(XEN_ROOT)/tools/xenstore -CFLAGS += -iquote $(XEN_ROOT)/tools/xenstore - xs.opic: CFLAGS += -DUSE_PTHREAD ifeq ($(CONFIG_Linux),y) xs.opic: CFLAGS += -DUSE_DLSYM
tools/libs/store/xs.c +22 -6
@@ -34,8 +34,8 @@#include <stdint.h> #include <errno.h> #include <xen-tools/common-macros.h> +#include <xen-tools/xenstore-common.h> #include "xenstore.h" -#include "xs_lib.h" #include <xentoolcore_internal.h> #include <xen_list.h>
@@ -627,7 +627,7 @@ static char **xs_directory_common(char *strings, unsigned int len,char *p, **ret;/* Count the strings. */ - *num =xs_count_strings (strings, len); + *num =xenstore_count_strings (strings, len);/* Transfer to one big alloc for easy freeing. */ ret =malloc (*num *sizeof (char *) + len);
@@ -775,7 +775,7 @@ struct xs_permissions *xs_get_permissions(struct xs_handle *h,return NULL ;/* Count the strings: each one perms then domid. */ - *num =xs_count_strings (strings, len); + *num =xenstore_count_strings (strings, len);/* Transfer to one big alloc for easy freeing. */ ret =malloc (*num *sizeof (struct xs_permissions ));
@@ -784,7 +784,7 @@ struct xs_permissions *xs_get_permissions(struct xs_handle *h,return NULL ; } -if (!xs_strings_to_perms (ret, *num, strings)) { +if (!xenstore_strings_to_perms (ret, *num, strings)) {free_no_errno (ret); ret =NULL ; }
@@ -811,7 +811,7 @@ bool xs_set_permissions(struct xs_handle *h,for (i =0 ; i < num_perms; i++) { char buffer[MAX_STRLEN(unsigned int)+1]; -if (!xs_perm_to_string (&perms[i], buffer,sizeof (buffer))) +if (!xenstore_perm_to_string (&perms[i], buffer,sizeof (buffer))) goto unwind; iov[i+1 ].iov_base =strdup (buffer);
@@ -977,7 +977,7 @@ static char **read_watch_internal(struct xs_handle *h, unsigned int *num,assert (msg->hdr.type ==XS_WATCH_EVENT ); strings = msg->body; - num_strings =xs_count_strings (strings, msg->hdr.len); + num_strings =xenstore_count_strings (strings, msg->hdr.len); ret =malloc (sizeof (char *) * num_strings + msg->hdr.len);if (!ret) {
@@ -1366,11 +1366,27 @@ error:return ret; } +const char *xs_daemon_socket (void ) +{ +return xenstore_daemon_path (); +} +const char *xs_daemon_socket_ro (void ) {return xs_daemon_socket (); } +const char *xs_daemon_rundir (void ) +{ +return xenstore_daemon_rundir (); +} + +bool xs_strings_to_perms (struct xs_permissions *perms,unsigned int num, +const char *strings) +{ +return xenstore_strings_to_perms (perms, num, strings); +} +#ifdef USE_PTHREAD static void *read_thread (void *arg) {
tools/xenstore/COPYING deleted +0 -514
514 lines not on this page · raw message
tools/xenstore/Makefile +1 -1
@@ -44,7 +44,7 @@ xenstored: $(XENSTORED_OBJS-y) $(CLIENTS): xenstore ln -f xenstore $@ -xenstore: xenstore_client.o xs_lib.o +xenstore: xenstore_client.o $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(APPEND_LDFLAGS) xenstore-control: xenstore_control.o
tools/xenstore/Makefile.common +1 -1
@@ -2,7 +2,7 @@ XENSTORED_OBJS-y := xenstored_core.o xenstored_watch.o xenstored_domain.o XENSTORED_OBJS-y += xenstored_transaction.o xenstored_control.o -XENSTORED_OBJS-y += xs_lib.o talloc.o utils.o tdb.o hashtable.o +XENSTORED_OBJS-y += talloc.o utils.o tdb.o hashtable.o XENSTORED_OBJS-$(CONFIG_Linux) += xenstored_posix.o XENSTORED_OBJS-$(CONFIG_NetBSD) += xenstored_posix.o
tools/xenstore/xenstore_client.c +2 -2
@@ -23,7 +23,7 @@#include <sys/ioctl.h> -#include "xs_lib.h" +#include <xen-tools/xenstore-common.h> #define PATH_SEP '/'#define MAX_PATH_LEN 256
@@ -361,7 +361,7 @@ static void do_ls(struct xs_handle *h, char *path, int cur_depth, int show_permsfor (i =0 ; i < nperms; i++) {if (i)putchar (',' ); -xs_perm_to_string (perms+i, buf,sizeof (buf)); +xenstore_perm_to_string (perms+i, buf,sizeof (buf));fputs (buf, stdout); }putchar (')' );
tools/xenstore/xenstored_control.c +5 -4
@@ -31,10 +31,10 @@#include <fcntl.h> #include <unistd.h> #include <xenctrl.h> +#include <xen-tools/xenstore-common.h> #include "utils.h" #include "talloc.h" -#include "xs_lib.h" #include "xenstored_core.h" #include "xenstored_control.h" #include "xenstored_domain.h"
@@ -560,7 +560,8 @@ static FILE *lu_dump_open(const void *ctx)char *filename;int fd; - filename =talloc_asprintf (ctx,"%s/state_dump" ,xs_daemon_rundir ()); + filename =talloc_asprintf (ctx,"%s/state_dump" , +xenstore_daemon_rundir ());if (!filename)return NULL ;
@@ -583,7 +584,7 @@ static void lu_get_dump_state(struct lu_dump_state *state) state->size =0 ; state->filename =talloc_asprintf (NULL ,"%s/state_dump" , -xs_daemon_rundir ()); +xenstore_daemon_rundir ());if (!state->filename)barf ("Allocation failure" );
@@ -1017,7 +1018,7 @@ int do_control(const void *ctx, struct connection *conn,if (cmd ==ARRAY_SIZE (cmds))return EINVAL ; - num =xs_count_strings (in->buffer, in->used); + num =xenstore_count_strings (in->buffer, in->used);if (cmds[cmd].max_pars) num =min (num, cmds[cmd].max_pars); vec = talloc_array(ctx, char *, num);
tools/xenstore/xenstored_core.c +8 -7
@@ -42,11 +42,11 @@#include <setjmp.h> #include <xenevtchn.h> +#include <xen-tools/xenstore-common.h> #include "utils.h" #include "list.h" #include "talloc.h" -#include "xs_lib.h" #include "xenstored_core.h" #include "xenstored_watch.h" #include "xenstored_transaction.h"
@@ -1201,7 +1201,8 @@ static char *perms_to_strings(const void *ctx, const struct node_perms *perms, char buffer[MAX_STRLEN(unsigned int) + 1];for (*len =0 , i =0 ; i < perms->num; i++) { -if (!xs_perm_to_string (&perms->p[i], buffer,sizeof (buffer))) +if (!xenstore_perm_to_string (&perms->p[i], buffer, +sizeof (buffer)))return NULL ; strings = talloc_realloc(ctx, strings, char,
@@ -1279,7 +1280,7 @@ static int send_directory_part(const void *ctx, struct connection *conn,struct node *node;char gen[24 ]; -if (xs_count_strings (in->buffer, in->used) !=2 ) +if (xenstore_count_strings (in->buffer, in->used) !=2 )return EINVAL ;/* First arg is node name. */
@@ -1766,7 +1767,7 @@ static int do_set_perms(const void *ctx, struct connection *conn,char *name, *permstr;struct node *node; - perms.num =xs_count_strings (in->buffer, in->used); + perms.num =xenstore_count_strings (in->buffer, in->used);if (perms.num <2 )return EINVAL ;
@@ -1779,7 +1780,7 @@ static int do_set_perms(const void *ctx, struct connection *conn, perms.p = talloc_array(ctx, struct xs_permissions, perms.num);if (!perms.p)return ENOMEM ; -if (!xs_strings_to_perms (perms.p, perms.num, permstr)) +if (!xenstore_strings_to_perms (perms.p, perms.num, permstr))return errno;if (domain_alloc_permrefs (&perms) <0 )
@@ -2575,7 +2576,7 @@ static void destroy_fds(void)static void init_sockets (void ) {struct sockaddr_un addr; -const char *soc_str =xs_daemon_socket (); +const char *soc_str =xenstore_daemon_path ();if (!soc_str)barf_perror ("Failed to obtain xs domain socket" );
@@ -2890,7 +2891,7 @@ int main(int argc, char *argv[])/* Make sure xenstored directory exists. */ /* Errors ignored here, will be reported when we open files */ -mkdir (xs_daemon_rundir (),0755 ); +mkdir (xenstore_daemon_rundir (),0755 );if (dofork) {openlog ("xenstored" ,0 ,LOG_DAEMON );
tools/xenstore/xs_lib.c deleted +0 -126
126 lines not on this page · raw message
tools/xenstore/xs_lib.h deleted +0 -31
@@ -1,31 +0,0 @@ -/* -Common routines between Xen store user library and daemon. -Copyright (C) 2005 Rusty Russell IBM Corporation - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef XS_LIB_H -#define XS_LIB_H - -#include "xenstore_lib.h" - -/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */ -bool xs_perm_to_string (const struct xs_permissions *perm, -char *buffer,size_t buf_len); - -/* Given a string and a length, count how many strings (nul terms). */ -unsigned int xs_count_strings (const char *strings,unsigned int len); - -#endif /* XS_LIB_H */
Signature · 1 line
2.35.3
Re: [PATCH v3 13/16] tools/xenstore: replace xs_lib.c with a header
Hi Juergen,
Quoted 4 lines · Juergen Gross
Instead of including the same small C source in multiple binaries from 2 source directories, use a header file with inline functions as a replacement.
Quoted 8 lines
As some of the functions are exported by libxenstore, rename the inline functions from xs_*() do xenstore_*() and add xs_*() wrappers to libxenstore.
With that no sources required to build libxenstore are left in
tools/xenstore, so the file COPYING can be removed now.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 14/16 tools/xenstore: split out environment specific live update code
In reply to Juergen GrossInstead of using #ifdef in xenstored_control.c split out the code of environment specific functions (daemon or Mini-OS) to dedicated source files.
--- tools/xenstore/Makefile.common | 8 +- tools/xenstore/xenstored_control.c | 253 +-------------------------- tools/xenstore/xenstored_lu.h | 56 ++++++ tools/xenstore/xenstored_lu_daemon.c | 133 ++++++++++++++ tools/xenstore/xenstored_lu_minios.c | 121 +++++++++++++ 5 files changed, 317 insertions(+), 254 deletions(-) create mode 100644 tools/xenstore/xenstored_lu.h create mode 100644 tools/xenstore/xenstored_lu_daemon.c create mode 100644 tools/xenstore/xenstored_lu_minios.c
tools/xenstore/Makefile.common +4 -4
@@ -4,10 +4,10 @@ XENSTORED_OBJS-y := xenstored_core.o xenstored_watch.o xenstored_domain.o XENSTORED_OBJS-y += xenstored_transaction.o xenstored_control.o XENSTORED_OBJS-y += talloc.o utils.o tdb.o hashtable.o -XENSTORED_OBJS-$(CONFIG_Linux) += xenstored_posix.o -XENSTORED_OBJS-$(CONFIG_NetBSD) += xenstored_posix.o -XENSTORED_OBJS-$(CONFIG_FreeBSD) += xenstored_posix.o -XENSTORED_OBJS-$(CONFIG_MiniOS) += xenstored_minios.o +XENSTORED_OBJS-$(CONFIG_Linux) += xenstored_posix.o xenstored_lu_daemon.o +XENSTORED_OBJS-$(CONFIG_NetBSD) += xenstored_posix.o xenstored_lu_daemon.o +XENSTORED_OBJS-$(CONFIG_FreeBSD) += xenstored_posix.o xenstored_lu_daemon.o +XENSTORED_OBJS-$(CONFIG_MiniOS) += xenstored_minios.o xenstored_lu_minios.o # Include configure output (config.h) CFLAGS += -include $(XEN_ROOT)/tools/config.h
tools/xenstore/xenstored_control.c +3 -250
269 lines not on this page · raw message
tools/xenstore/xenstored_lu.h new file +56 -0
56 lines not on this page · raw message
tools/xenstore/xenstored_lu_daemon.c new file +133 -0
133 lines not on this page · raw message
tools/xenstore/xenstored_lu_minios.c new file +121 -0
121 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH v3 14/16] tools/xenstore: split out environment specific live update code
Hi Juergen,
Quoted 11 lines · Juergen Gross
tools/xenstore/xenstored_control.c +0
-11-static struct live_update *lu_status; - -struct lu_dump_state { -void *buf; -unsigned int size; -#ifndef __MINIOS__ -int fd; -char *filename; -#endif -}; -
tools/xenstore/xenstored_control.c line 95
Quoted 10 lines
tools/xenstore/xenstored_control.c +0
-10-static int lu_destroy (void *data) -{ -#ifdef __MINIOS__ -if (lu_status->dump_state) -munmap (lu_status->dump_state, lu_status->dump_size); -#endif - lu_status =NULL ; - -return 0 ; -}
I think moving all lu_destroy() out of xenstored_control.c is a mistake because we now need to remember that any common change in lu_begin() may need an update in the two implementation of lu_destroy().
Even if this seems pointless for a few lines, it would be best to split lu_destroy() in two parts: one common and one per lu backend.
The rest of the changes look good to me.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 14/16] tools/xenstore: split out environment specific live update code
Quoted 27 lines · Julien Grall
Hi Juergen,
Quoted 11 lines · Juergen Gross
tools/xenstore/xenstored_control.c +0
-11-static struct live_update *lu_status; - -struct lu_dump_state { - void *buf; - unsigned int size; -#ifndef __MINIOS__ - int fd; - char *filename; -#endif -}; -tools/xenstore/xenstored_control.c line 95
Quoted 10 lines
tools/xenstore/xenstored_control.c +0
-10-static int lu_destroy (void *data) -{ -#ifdef __MINIOS__ - if (lu_status->dump_state) - munmap(lu_status->dump_state, lu_status->dump_size); -#endif - lu_status = NULL; - - return 0; -}I think moving all
lu_destroy()out ofxenstored_control.cis a mistake because we now need to remember that any common change inlu_begin()may need an update in the two implementation oflu_destroy().
Quoted 1 line
Even if this seems pointless for a few lines, it would be best to split
lu_destroy()in two parts: one common and one per lu backend.
Okay, fine with me.
Quoted 2 lines
The rest of the changes look good to me.
Thanks,
Juergen
PATCH v3 15/16 tools/xenstore: split out rest of live update control code
In reply to Juergen GrossMove the rest of live update related code from xenstored_control.c to a dedicated new source file.
--- tools/xenstore/Makefile.common | 2 +- tools/xenstore/xenstored_control.c | 409 ----------------------------- tools/xenstore/xenstored_control.h | 8 - tools/xenstore/xenstored_core.c | 1 + tools/xenstore/xenstored_lu.c | 400 ++++++++++++++++++++++++++++ tools/xenstore/xenstored_lu.h | 25 ++ 6 files changed, 427 insertions(+), 418 deletions(-) create mode 100644 tools/xenstore/xenstored_lu.c
tools/xenstore/Makefile.common +1 -1
@@ -1,7 +1,7 @@ # Makefile shared with stubdom XENSTORED_OBJS-y := xenstored_core.o xenstored_watch.o xenstored_domain.o -XENSTORED_OBJS-y += xenstored_transaction.o xenstored_control.o +XENSTORED_OBJS-y += xenstored_transaction.o xenstored_control.o xenstored_lu.o XENSTORED_OBJS-y += talloc.o utils.o tdb.o hashtable.o XENSTORED_OBJS-$(CONFIG_Linux) += xenstored_posix.o xenstored_lu_daemon.o
tools/xenstore/xenstored_control.c +0 -409
434 lines not on this page · raw message
tools/xenstore/xenstored_control.h +0 -8
@@ -18,11 +18,3 @@int do_control (const void *ctx,struct connection *conn,struct buffered_data *in); -void lu_read_state (void ); - -struct connection *lu_get_connection (void ); - -/* Write the "OK" response for the live-update command */ -unsigned int lu_write_response (FILE *fp); - -bool lu_is_pending (void );
tools/xenstore/xenstored_core.c +1 -0
@@ -52,6 +52,7 @@#include "xenstored_transaction.h" #include "xenstored_domain.h" #include "xenstored_control.h" +#include "xenstored_lu.h" #include "tdb.h" #ifndef NO_SOCKETS
tools/xenstore/xenstored_lu.c new file +400 -0
400 lines not on this page · raw message
tools/xenstore/xenstored_lu.h +25 -0
@@ -43,6 +43,16 @@ struct lu_dump_state {extern struct live_update *lu_status; +struct connection *lu_get_connection (void ); +bool lu_is_pending (void ); +void lu_read_state (void ); + +/* Write the "OK" response for the live-update command */ +unsigned int lu_write_response (FILE *fp); + +int do_control_lu (const void *ctx,struct connection *conn,char **vec, +int num); +/* Live update private interfaces. */ void lu_get_dump_state (struct lu_dump_state *state);void lu_close_dump_state (struct lu_dump_state *state);
@@ -53,4 +63,19 @@ const char *lu_arch(const void *ctx, struct connection *conn, char **vec, int num);const char *lu_begin (struct connection *conn);int lu_destroy (void *data); +#else +static inline struct connection *lu_get_connection (void ) +{ +return NULL ; +} + +static inline unsigned int lu_write_response (FILE *fp) +{ +return 0 ; +} + +static inline bool lu_is_pending (void ) +{ +return false; +}#endif
Signature · 1 line
2.35.3
Re: [PATCH v3 15/16] tools/xenstore: split out rest of live update control code
Hi Juergen,
Quoted 4 lines · Juergen Gross
Move the rest of live update related code from
xenstored_control.cto a dedicated new source file.Signed-off-by Juergen Gross <[email protected]>
Depending on the outcome of the discussion in patch #15, this patch may need to be updated. At its current state:
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 16/16 tools/xenstore: remove unused stuff from list.h
In reply to Juergen GrossRemove the hlist defines/functions and the rcu related functions from tools/xenstore/list.h, as they are not used.
--- tools/xenstore/list.h | 227 ------------------------------------------ 1 file changed, 227 deletions(-)
tools/xenstore/list.h +0 -227
@@ -88,48 +88,6 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)__list_add (new, head->prev, head); } -/* -* Insert a new entry between two known consecutive entries. -* -* This is only for internal list manipulation where we know -* the prev/next entries already! -*/ -static __inline__void __list_add_rcu (struct list_head * new, -struct list_head * prev, -struct list_head * next) -{ - new->next = next; - new->prev = prev; - next->prev = new; - prev->next = new; -} - -/** -* list_add_rcu - add a new entry to rcu-protected list -* @new: new entry to be added -* @head: list head to add it after -* -* Insert a new entry after the specified head. -* This is good for implementing stacks. -*/ -static __inline__void list_add_rcu (struct list_head *new,struct list_head *head) -{ -__list_add_rcu (new, head, head->next); -} - -/** -* list_add_tail_rcu - add a new entry to rcu-protected list -* @new: new entry to be added -* @head: list head to add it before -* -* Insert a new entry before the specified head. -* This is useful for implementing queues. -*/ -static __inline__void list_add_tail_rcu (struct list_head *new,struct list_head *head) -{ -__list_add_rcu (new, head->prev, head); -} -/* * Delete a list entry by making the prev/next entries * point to each other.
@@ -156,23 +114,6 @@ static inline void list_del(struct list_head *entry) entry->prev =LIST_POISON2 ; } -/** -* list_del_rcu - deletes entry from list without re-initialization -* @entry: the element to delete from the list. -* -* Note: list_empty on entry does not return true after this, -* the entry is in an undefined state. It is useful for RCU based -* lockfree traversal. -* -* In particular, it means that we can not poison the forward -* pointers that may still be used for walking the list. -*/ -static inline void list_del_rcu (struct list_head *entry) -{ -__list_del (entry->prev, entry->next); - entry->prev =LIST_POISON2 ; -} -/** * list_del_init - deletes entry from list and reinitialize it. * @entry: the element to delete from the list.
@@ -339,172 +280,4 @@ static inline void list_splice_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) - -/* -* Double linked lists with a single pointer list head. -* Mostly useful for hash tables where the two pointer list head is -* too wasteful. -* You lose the ability to access the tail in O(1). -*/ - -struct hlist_head { -struct hlist_node *first; -}; - -struct hlist_node { -struct hlist_node *next, **pprev; -}; - -#define HLIST_HEAD_INIT { .first = NULL } -#define HLIST_HEAD (name) struct hlist_head name = { .first = NULL } -#define INIT_HLIST_HEAD (ptr) ((ptr)->first = NULL) -#define INIT_HLIST_NODE (ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL) - -static __inline__int hlist_unhashed (struct hlist_node *h) -{ -return !h->pprev; -} - -static __inline__int hlist_empty (struct hlist_head *h) -{ -return !h->first; -} - -static __inline__void __hlist_del (struct hlist_node *n) -{ -struct hlist_node *next = n->next; -struct hlist_node **pprev = n->pprev; - *pprev = next; -if (next) - next->pprev = pprev; -} - -static __inline__void hlist_del (struct hlist_node *n) -{ -__hlist_del (n); - n->next =LIST_POISON1 ; - n->pprev =LIST_POISON2 ; -} - -/** -* hlist_del_rcu - deletes entry from hash list without re-initialization -* @entry: the element to delete from the hash list. -* -* Note: list_unhashed() on entry does not return true after this, -* the entry is in an undefined state. It is useful for RCU based -* lockfree traversal. -* -* In particular, it means that we can not poison the forward -* pointers that may still be used for walking the hash list. -*/ -static inline void hlist_del_rcu (struct hlist_node *n) -{ -__hlist_del (n); - n->pprev =LIST_POISON2 ; -} - -static __inline__void hlist_del_init (struct hlist_node *n) -{ -if (n->pprev) { -__hlist_del (n); -INIT_HLIST_NODE (n); - } -} - -#define hlist_del_rcu_init hlist_del_init - -static __inline__void hlist_add_head (struct hlist_node *n,struct hlist_head *h) -{ -struct hlist_node *first = h->first; - n->next = first; -if (first) - first->pprev = &n->next; - h->first = n; - n->pprev = &h->first; -} - -static __inline__void hlist_add_head_rcu (struct hlist_node *n,struct hlist_head *h) -{ -struct hlist_node *first = h->first; - n->next = first; - n->pprev = &h->first; -if (first) - first->pprev = &n->next; - h->first = n; -} - -/* next must be != NULL */ -static __inline__void hlist_add_before (struct hlist_node *n,struct hlist_node *next) -{ - n->pprev = next->pprev; - n->next = next; - next->pprev = &n->next; - *(n->pprev) = n; -} - -static __inline__void hlist_add_after (struct hlist_node *n, -struct hlist_node *next) -{ - next->next = n->next; - *(next->pprev) = n; - n->next = next; -} - -#define hlist_entry (ptr, type, member) container_of(ptr,type,member) - -/* Cannot easily do prefetch unfortunately */ -#define hlist_for_each (pos, head) \ - for (pos = (head)->first; pos; pos = pos->next) - -#define hlist_for_each_safe (pos, n, head) \ - for (pos = (head)->first; n = pos ? pos->next : 0, pos; \ - pos = n) - -/** -* hlist_for_each_entry - iterate over list of given type -* @tpos: the type * to use as a loop counter. -* @pos: the &struct hlist_node to use as a loop counter. -* @head: the head for your list. -* @member: the name of the hlist_node within the struct. -*/ -#define hlist_for_each_entry (tpos, pos, head, member) \ - for (pos = (head)->first; \ - pos && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = pos->next) - -/** -* hlist_for_each_entry_continue - iterate over a hlist continuing after existing point -* @tpos: the type * to use as a loop counter. -* @pos: the &struct hlist_node to use as a loop counter. -* @member: the name of the hlist_node within the struct. -*/ -#define hlist_for_each_entry_continue (tpos, pos, member) \ - for (pos = (pos)->next; \ - pos && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = pos->next) - -/** -* hlist_for_each_entry_from - iterate over a hlist continuing from existing point -* @tpos: the type * to use as a loop counter. -* @pos: the &struct hlist_node to use as a loop counter. -* @member: the name of the hlist_node within the struct. -*/ -#define hlist_for_each_entry_from (tpos, pos, member) \ - for (; pos && ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = pos->next) - -/** -* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry -* @tpos: the type * to use as a loop counter. -* @pos: the &struct hlist_node to use as a loop counter. -* @n: another &struct hlist_node to use as temporary storage -* @head: the head for your list. -* @member: the name of the hlist_node within the struct. -*/ -#define hlist_for_each_entry_safe (tpos, pos, n, head, member) \ - for (pos = (head)->first; \ - pos && ({ n = pos->next; 1; }) && \ - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = n) -#endif
Signature · 1 line
2.35.3
Re: [PATCH v3 16/16] tools/xenstore: remove unused stuff from list.h
Hi Juergen,
Quoted 4 lines · Juergen Gross
Remove the hlist defines/functions and the rcu related functions from
tools/xenstore/list.h, as they are not used.Signed-off-by Juergen Gross <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Hi Juergen,
Quoted 15 lines · Juergen Gross
Some more cleanups of Xenstore.
Based on top of the previous Xenstore series "
tools/xenstore: rework internal accounting".Changes in V2:
- rebase
- one small modification of patch 10
- added patches 11-13Changes in V3:
- rebase
- modified patch 4
- added patches 10, 11 and 13
Quoted 11 lines
Juergen Gross (16):
tools/xenstore: verify command line parameters bettertools/xenstore: do some cleanup ofhashtable.ctools/xenstore: modify interface ofcreate_hashtable()tools/xenstore: renamehashtable_insert()and let it return 0 on
success
tools/xenstore: make some write limit functions statictools/xenstore: switch write limiting to use millisecond time basetools/xenstore: remove stale TODO file
tools/xenstore: remove unused events listtools/xenstore: remove support of file backed data base
I have committed up to here. I still need to review the rest.
Cheers,
Signature · 1 line
Julien Grall