diff options
author | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2016-01-29 18:49:07 +0000 |
---|---|---|
committer | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2016-01-29 18:49:07 +0000 |
commit | 9248f2908f780d5fc7aa9a498db6f47e2447789d (patch) | |
tree | d2b53a92246c5eb812b48307b4e4188b28085a82 /sys/dev | |
parent | 16ce633222d3f41f0f29436fcdb334ac4a1beb31 (diff) |
Cleanup XenStore API
Turns out that we want to let devices choose whether they're issuing
XenStore requests to the backend or frontend. This also unifies the
the API somewhat as providing the xen softcore structure is now
mandatory.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/pv/if_xnf.c | 56 | ||||
-rw-r--r-- | sys/dev/pv/xen.c | 18 | ||||
-rw-r--r-- | sys/dev/pv/xenstore.c | 60 | ||||
-rw-r--r-- | sys/dev/pv/xenvar.h | 8 |
4 files changed, 78 insertions, 64 deletions
diff --git a/sys/dev/pv/if_xnf.c b/sys/dev/pv/if_xnf.c index 324e6cf677a..cf935b4be54 100644 --- a/sys/dev/pv/if_xnf.c +++ b/sys/dev/pv/if_xnf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_xnf.c,v 1.15 2016/01/26 17:01:01 mikeb Exp $ */ +/* $OpenBSD: if_xnf.c,v 1.16 2016/01/29 18:49:06 mikeb Exp $ */ /* * Copyright (c) 2015, 2016 Mike Belopuhov @@ -23,15 +23,16 @@ #include <sys/param.h> #include <sys/systm.h> #include <sys/atomic.h> +#include <sys/device.h> +#include <sys/kernel.h> #include <sys/malloc.h> #include <sys/mbuf.h> -#include <sys/kernel.h> -#include <sys/device.h> +#include <sys/pool.h> +#include <sys/queue.h> #include <sys/socket.h> #include <sys/sockio.h> -#include <sys/queue.h> +#include <sys/task.h> #include <sys/timeout.h> -#include <sys/pool.h> #include <machine/bus.h> @@ -332,7 +333,8 @@ xnf_lladdr(struct xnf_softc *sc) char mac[32]; int i, j, lo, hi; - if (xs_getprop(&sc->sc_xa, "mac", mac, sizeof(mac))) + if (xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, "mac", + mac, sizeof(mac))) return (-1); for (i = 0, j = 0; j < ETHER_ADDR_LEN; i += 3) { @@ -1051,7 +1053,8 @@ xnf_capabilities(struct xnf_softc *sc) /* Query scatter-gather capability */ prop = "feature-sg"; - if ((error = xs_getprop(&sc->sc_xa, prop, val, sizeof(val))) == 0) { + if ((error = xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, + prop, val, sizeof(val))) == 0) { if (val[0] == '1') sc->sc_caps |= XNF_CAP_SG; } else if (error != ENOENT) @@ -1060,7 +1063,8 @@ xnf_capabilities(struct xnf_softc *sc) /* Query IPv4 checksum offloading capability, enabled by default */ sc->sc_caps |= XNF_CAP_CSUM4; prop = "feature-no-csum-offload"; - if ((error = xs_getprop(&sc->sc_xa, prop, val, sizeof(val))) == 0) { + if ((error = xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, + prop, val, sizeof(val))) == 0) { if (val[0] == '1') sc->sc_caps &= ~XNF_CAP_CSUM4; } else if (error != ENOENT) @@ -1068,7 +1072,8 @@ xnf_capabilities(struct xnf_softc *sc) /* Query IPv6 checksum offloading capability */ prop = "feature-ipv6-csum-offload"; - if ((error = xs_getprop(&sc->sc_xa, prop, val, sizeof(val))) == 0) { + if ((error = xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, + prop, val, sizeof(val))) == 0) { if (val[0] == '1') sc->sc_caps |= XNF_CAP_CSUM6; } else if (error != ENOENT) @@ -1076,7 +1081,8 @@ xnf_capabilities(struct xnf_softc *sc) /* Query multicast traffic contol capability */ prop = "feature-multicast-control"; - if ((error = xs_getprop(&sc->sc_xa, prop, val, sizeof(val))) == 0) { + if ((error = xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, + prop, val, sizeof(val))) == 0) { if (val[0] == '1') sc->sc_caps |= XNF_CAP_MCAST; } else if (error != ENOENT) @@ -1084,7 +1090,8 @@ xnf_capabilities(struct xnf_softc *sc) /* Query split Rx/Tx event channel capability */ prop = "feature-split-event-channels"; - if ((error = xs_getprop(&sc->sc_xa, prop, val, sizeof(val))) == 0) { + if ((error = xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, + prop, val, sizeof(val))) == 0) { if (val[0] == '1') sc->sc_caps |= XNF_CAP_SPLIT; } else if (error != ENOENT) @@ -1092,7 +1099,8 @@ xnf_capabilities(struct xnf_softc *sc) /* Query multiqueue capability */ prop = "multi-queue-max-queues"; - if ((error = xs_getprop(&sc->sc_xa, prop, val, sizeof(val))) == 0) + if ((error = xs_getprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_backend, + prop, val, sizeof(val))) == 0) sc->sc_caps |= XNF_CAP_MULTIQ; else if (error != ENOENT) goto errout; @@ -1116,29 +1124,34 @@ xnf_init_backend(struct xnf_softc *sc) /* Plumb the Rx ring */ prop = "rx-ring-ref"; snprintf(val, sizeof(val), "%u", sc->sc_rx_ref); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, val, + strlen(val))) goto errout; /* Enable "copy" mode */ prop = "request-rx-copy"; snprintf(val, sizeof(val), "%u", 1); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, val, + strlen(val))) goto errout; /* Enable notify mode */ prop = "feature-rx-notify"; snprintf(val, sizeof(val), "%u", 1); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, val, + strlen(val))) goto errout; /* Plumb the Tx ring */ prop = "tx-ring-ref"; snprintf(val, sizeof(val), "%u", sc->sc_tx_ref); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, val, + strlen(val))) goto errout; /* Enable scatter-gather mode */ if (sc->sc_tx_frags > 1) { prop = "feature-sg"; snprintf(val, sizeof(val), "%u", 1); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, + val, strlen(val))) goto errout; } @@ -1146,20 +1159,23 @@ xnf_init_backend(struct xnf_softc *sc) if (sc->sc_caps & XNF_CAP_CSUM6) { prop = "feature-ipv6-csum-offload"; snprintf(val, sizeof(val), "%u", 1); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, + val, strlen(val))) goto errout; } /* Plumb the event channel port */ prop = "event-channel"; snprintf(val, sizeof(val), "%u", sc->sc_xih); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, val, + strlen(val))) goto errout; /* Connect the device */ prop = "state"; snprintf(val, sizeof(val), "%u", 4); - if (xs_setprop(&sc->sc_xa, prop, val, strlen(val))) + if (xs_setprop(sc->sc_xa.xa_parent, sc->sc_xa.xa_node, prop, val, + strlen(val))) goto errout; return (0); diff --git a/sys/dev/pv/xen.c b/sys/dev/pv/xen.c index bed695dd1b7..e6848a6fdca 100644 --- a/sys/dev/pv/xen.c +++ b/sys/dev/pv/xen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xen.c,v 1.45 2016/01/28 11:19:49 mikeb Exp $ */ +/* $OpenBSD: xen.c,v 1.46 2016/01/29 18:49:06 mikeb Exp $ */ /* * Copyright (c) 2015 Mike Belopuhov @@ -1173,9 +1173,9 @@ xen_probe_devices(struct xen_softc *sc) { struct xen_attach_args xa; struct xs_transaction xst; - struct iovec *iovp1, *iovp2, *iovp3; - int i, j, error = 0, iov1_cnt, iov2_cnt, iov3_cnt; - char path[128]; + struct iovec *iovp1, *iovp2; + int i, j, error = 0, iov1_cnt, iov2_cnt; + char path[256]; memset(&xst, 0, sizeof(xst)); xst.xst_id = 0; @@ -1203,11 +1203,11 @@ xen_probe_devices(struct xen_softc *sc) snprintf(xa.xa_node, sizeof(xa.xa_node), "device/%s/%s", (char *)iovp1[i].iov_base, (char *)iovp2[j].iov_base); - snprintf(path, sizeof(path), "%s/backend", xa.xa_node); - if (!xs_cmd(&xst, XS_READ, path, &iovp3, &iov3_cnt)) { - strlcpy(xa.xa_backend, (char *)iovp3->iov_base, - sizeof(xa.xa_backend)); - xs_resfree(&xst, iovp3, iov3_cnt); + if (xs_getprop(sc, xa.xa_node, "backend", xa.xa_backend, + sizeof(xa.xa_backend))) { + printf("%s: failed to identify \"backend\" " + "for \"%s\"\n", sc->sc_dev.dv_xname, + xa.xa_node); } config_found((struct device *)sc, &xa, xen_attach_print); diff --git a/sys/dev/pv/xenstore.c b/sys/dev/pv/xenstore.c index adfc52f1185..65257423769 100644 --- a/sys/dev/pv/xenstore.c +++ b/sys/dev/pv/xenstore.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xenstore.c,v 1.22 2016/01/27 09:04:19 reyk Exp $ */ +/* $OpenBSD: xenstore.c,v 1.23 2016/01/29 18:49:06 mikeb Exp $ */ /* * Copyright (c) 2015 Mike Belopuhov @@ -753,14 +753,13 @@ xs_cmd(struct xs_transaction *xst, int cmd, const char *path, } int -xs_getprop(struct xen_attach_args *xa, const char *property, char *value, - int size) +xs_getprop(struct xen_softc *sc, const char *path, const char *property, + char *value, int size) { - struct xen_softc *sc = xa->xa_parent; struct xs_transaction xst; struct iovec *iovp; - char path[128]; - int error, iov_cnt; + char key[256]; + int error, iov_cnt, ret; if (!property) return (-1); @@ -771,17 +770,15 @@ xs_getprop(struct xen_attach_args *xa, const char *property, char *value, if (cold) xst.xst_flags = XST_POLL; - snprintf(path, sizeof(path), "%s/%s", xa->xa_node, property); - if ((error = xs_cmd(&xst, XS_READ, path, &iovp, &iov_cnt)) != 0 && - error != ENOENT) - return (error); + 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); - /* Try backend */ - if (error == ENOENT) { - snprintf(path, sizeof(path), "%s/%s", xa->xa_backend, property); - if ((error = xs_cmd(&xst, XS_READ, path, &iovp, &iov_cnt)) != 0) - return (error); - } + if ((error = xs_cmd(&xst, XS_READ, key, &iovp, &iov_cnt)) != 0) + return (error); strlcpy(value, (char *)iovp->iov_base, size); @@ -791,14 +788,13 @@ xs_getprop(struct xen_attach_args *xa, const char *property, char *value, } int -xs_setprop(struct xen_attach_args *xa, const char *property, char *value, - int size) +xs_setprop(struct xen_softc *sc, const char *path, const char *property, + char *value, int size) { - struct xen_softc *sc = xa->xa_parent; struct xs_transaction xst; struct iovec iov, *iovp = &iov; - char path[128]; - int error, iov_cnt; + char key[256]; + int error, iov_cnt, ret; if (!property) return (-1); @@ -809,17 +805,19 @@ xs_setprop(struct xen_attach_args *xa, const char *property, char *value, if (cold) xst.xst_flags = XST_POLL; - if (value && size > 0) { - iov.iov_base = value; - iov.iov_len = size; - iov_cnt = 1; + 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); + + iov.iov_base = value; + iov.iov_len = size; + iov_cnt = 1; + + error = xs_cmd(&xst, XS_WRITE, key, &iovp, &iov_cnt); - snprintf(path, sizeof(path), "%s/%s", xa->xa_node, property); - error = xs_cmd(&xst, XS_WRITE, path, &iovp, &iov_cnt); - } else { - snprintf(path, sizeof(path), "%s/%s", xa->xa_node, property); - error = xs_cmd(&xst, XS_RM, path, NULL, NULL); - } return (error); } diff --git a/sys/dev/pv/xenvar.h b/sys/dev/pv/xenvar.h index 89426c86feb..d557c73144b 100644 --- a/sys/dev/pv/xenvar.h +++ b/sys/dev/pv/xenvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: xenvar.h,v 1.25 2016/01/27 15:34:50 mikeb Exp $ */ +/* $OpenBSD: xenvar.h,v 1.26 2016/01/29 18:49:06 mikeb Exp $ */ /* * Copyright (c) 2015 Mike Belopuhov @@ -19,7 +19,7 @@ #ifndef _XENVAR_H_ #define _XENVAR_H_ -/* #define XEN_DEBUG */ +#define XEN_DEBUG #ifdef XEN_DEBUG #define DPRINTF(x...) printf(x) @@ -148,9 +148,9 @@ struct xs_transaction { int xs_cmd(struct xs_transaction *, int, const char *, struct iovec **, int *); -int xs_getprop(struct xen_attach_args *, const char *, char *, int); -int xs_setprop(struct xen_attach_args *, const char *, char *, int); void xs_resfree(struct xs_transaction *, struct iovec *, int); +int xs_getprop(struct xen_softc *, const char *, const char *, char *, int); +int xs_setprop(struct xen_softc *, const char *, const char *, char *, int); int xs_kvop(void *, int, char *, char *, size_t); #endif /* _XENVAR_H_ */ |