[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [RFC PATCH 3/4] xl: introduce facility to run function with per-domain lock held
On Wed, Jun 14, 2017 at 06:19:20PM +0100, Wei Liu wrote: > Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> > --- > tools/xl/xl.h | 1 + > tools/xl/xl_utils.c | 19 +++++++++++++++++++ > tools/xl/xl_utils.h | 3 +++ > 3 files changed, 23 insertions(+) > > diff --git a/tools/xl/xl.h b/tools/xl/xl.h > index 93ec4d7e4c..8d667ff444 100644 > --- a/tools/xl/xl.h > +++ b/tools/xl/xl.h > @@ -292,6 +292,7 @@ extern void printf_info_sexp(int domid, > libxl_domain_config *d_config, FILE *fh) > > #define XL_GLOBAL_CONFIG XEN_CONFIG_DIR "/xl.conf" > #define XL_LOCK_FILE XEN_LOCK_DIR "/xl" > +#define XL_DOMAIN_LOCK_FILE_FMT XEN_LOCK_DIR "/xl-%u" > > #endif /* XL_H */ > > diff --git a/tools/xl/xl_utils.c b/tools/xl/xl_utils.c > index e7038ec324..bb32ba0a1f 100644 > --- a/tools/xl/xl_utils.c > +++ b/tools/xl/xl_utils.c > @@ -27,6 +27,25 @@ > #include "xl.h" > #include "xl_utils.h" > > +int with_lock(uint32_t domid, domain_fn fn, void *arg) > +{ > + char filename[sizeof(XL_DOMAIN_LOCK_FILE_FMT)+15]; > + int fd_lock = -1; > + int rc; > + > + snprintf(filename, sizeof(filename), XL_DOMAIN_LOCK_FILE_FMT, domid); > + > + rc = acquire_lock(filename, &fd_lock); > + if (rc) goto out; > + It is necessary to check if the domain is still valid here. And we should probably accept a string instead of domid in this function and call find_domain, so that we can retry. Basically: retry: domid = find_domain(); snprintf(...) rc = acquire_lock() if (rc) goto out; if (domain is not valid anymore) { release_lock(); goto retry; } /* ... the rest ...*/ _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |