diff options
author | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2016-12-07 15:21:05 +0000 |
---|---|---|
committer | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2016-12-07 15:21:05 +0000 |
commit | f41a376e2ce4ffa029c87f68f7dc5d08250e1be3 (patch) | |
tree | f8beda6a05e28e431bedfd739c89a0ad885d394c /sys/dev | |
parent | 364d8c8c7f3169b48c7ec9bf3e47a98833cc9701 (diff) |
Add a simple mechanism to poll for a change in the property value
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/pv/xenstore.c | 58 | ||||
-rw-r--r-- | sys/dev/pv/xenvar.h | 51 |
2 files changed, 89 insertions, 20 deletions
diff --git a/sys/dev/pv/xenstore.c b/sys/dev/pv/xenstore.c index 1d5f5f4cab2..b55e934dfe4 100644 --- a/sys/dev/pv/xenstore.c +++ b/sys/dev/pv/xenstore.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xenstore.c,v 1.34 2016/12/07 15:18:02 mikeb Exp $ */ +/* $OpenBSD: xenstore.c,v 1.35 2016/12/07 15:21:04 mikeb Exp $ */ /* * Copyright (c) 2015 Mike Belopuhov @@ -936,6 +936,62 @@ xs_setprop(void *xsc, const char *path, const char *property, char *value, } int +xs_cmpprop(void *xsc, const char *path, const char *property, const char *value, + int *result) +{ + struct xen_softc *sc = xsc; + struct xs_transaction xst; + struct iovec *iovp = NULL; + char key[256]; + int error, ret, iov_cnt = 0; + + if (!property) + return (EINVAL); + + memset(&xst, 0, sizeof(xst)); + xst.xst_id = 0; + xst.xst_cookie = sc->sc_xs; + if (cold) + xst.xst_flags = XST_POLL; + + if (path) + ret = snprintf(key, sizeof(key), "%s/%s", path, property); + else + ret = snprintf(key, sizeof(key), "%s", property); + if (ret == -1 || ret >= sizeof(key)) + return (EINVAL); + + if ((error = xs_cmd(&xst, XS_READ, key, &iovp, &iov_cnt)) != 0) + return (error); + + if (*result) + *result = strcmp(value, (char *)iovp->iov_base); + + xs_resfree(&xst, iovp, iov_cnt); + + return (0); +} + +int +xs_await_transition(void *xsc, const char *path, const char *property, + const char *value, int timo) +{ + struct xen_softc *sc = xsc; + int error, res; + + do { + error = xs_cmpprop(xsc, path, property, value, &res); + if (error) + return (error); + if (timo && --timo == 0) + return (ETIMEDOUT); + xs_poll(sc->sc_xs, cold); + } while (res != 0); + + return (0); +} + +int xs_kvop(void *xsc, int op, char *key, char *value, size_t valuelen) { struct xen_softc *sc = xsc; diff --git a/sys/dev/pv/xenvar.h b/sys/dev/pv/xenvar.h index 8378d1db0a2..5d7bf147a7c 100644 --- a/sys/dev/pv/xenvar.h +++ b/sys/dev/pv/xenvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: xenvar.h,v 1.41 2016/11/29 14:55:04 mikeb Exp $ */ +/* $OpenBSD: xenvar.h,v 1.42 2016/12/07 15:21:04 mikeb Exp $ */ /* * Copyright (c) 2015 Mike Belopuhov @@ -27,6 +27,24 @@ #define DPRINTF(x...) #endif +static inline void +clear_bit(u_int b, volatile void *p) +{ + atomic_clearbits_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f)); +} + +static inline void +set_bit(u_int b, volatile void *p) +{ + atomic_setbits_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f)); +} + +static inline int +test_bit(u_int b, volatile void *p) +{ + return !!(((volatile u_int *)p)[b >> 5] & (1 << (b & 0x1f))); +} + struct xen_intsrc { SLIST_ENTRY(xen_intsrc) xi_entry; struct evcount xi_evcnt; @@ -153,24 +171,6 @@ struct xs_transaction { void *xst_cookie; }; -static __inline void -clear_bit(u_int b, volatile void *p) -{ - atomic_clearbits_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f)); -} - -static __inline void -set_bit(u_int b, volatile void *p) -{ - atomic_setbits_int(((volatile u_int *)p) + (b >> 5), 1 << (b & 0x1f)); -} - -static __inline int -test_bit(u_int b, volatile void *p) -{ - return !!(((volatile u_int *)p)[b >> 5] & (1 << (b & 0x1f))); -} - int xs_cmd(struct xs_transaction *, int, const char *, struct iovec **, int *); void xs_resfree(struct xs_transaction *, struct iovec *, int); @@ -180,4 +180,17 @@ int xs_getprop(void *, const char *, const char *, char *, int); int xs_setprop(void *, const char *, const char *, char *, int); int xs_kvop(void *, int, char *, char *, size_t); +#define XEN_STATE_UNKNOWN "0" +#define XEN_STATE_INITIALIZING "1" +#define XEN_STATE_INITWAIT "2" +#define XEN_STATE_INITIALIZED "3" +#define XEN_STATE_CONNECTED "4" +#define XEN_STATE_CLOSING "5" +#define XEN_STATE_CLOSED "6" +#define XEN_STATE_RECONFIGURING "7" +#define XEN_STATE_RECONFIGURED "8" + +int xs_await_transition(void *, const char *, const char *, + const char *, int); + #endif /* _DEV_PV_XENVAR_H_ */ |