Commit 5584ea25 authored by Juergen Gross's avatar Juergen Gross Committed by Boris Ostrovsky

xen: modify xenstore watch event interface

Today a Xenstore watch event is delivered via a callback function
declared as:

void (*callback)(struct xenbus_watch *,
                 const char **vec, unsigned int len);

As all watch events only ever come with two parameters (path and token)
changing the prototype to:

void (*callback)(struct xenbus_watch *,
                 const char *path, const char *token);

is the natural thing to do.

Apply this change and adapt all users.

Cc: konrad.wilk@oracle.com
Cc: roger.pau@citrix.com
Cc: wei.liu2@citrix.com
Cc: paul.durrant@citrix.com
Cc: netdev@vger.kernel.org
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarPaul Durrant <paul.durrant@citrix.com>
Reviewed-by: default avatarWei Liu <wei.liu2@citrix.com>
Reviewed-by: default avatarRoger Pau Monné <roger.pau@citrix.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent 332f791d
...@@ -38,8 +38,8 @@ struct backend_info { ...@@ -38,8 +38,8 @@ struct backend_info {
static struct kmem_cache *xen_blkif_cachep; static struct kmem_cache *xen_blkif_cachep;
static void connect(struct backend_info *); static void connect(struct backend_info *);
static int connect_ring(struct backend_info *); static int connect_ring(struct backend_info *);
static void backend_changed(struct xenbus_watch *, const char **, static void backend_changed(struct xenbus_watch *, const char *,
unsigned int); const char *);
static void xen_blkif_free(struct xen_blkif *blkif); static void xen_blkif_free(struct xen_blkif *blkif);
static void xen_vbd_free(struct xen_vbd *vbd); static void xen_vbd_free(struct xen_vbd *vbd);
...@@ -661,7 +661,7 @@ static int xen_blkbk_probe(struct xenbus_device *dev, ...@@ -661,7 +661,7 @@ static int xen_blkbk_probe(struct xenbus_device *dev,
* ready, connect. * ready, connect.
*/ */
static void backend_changed(struct xenbus_watch *watch, static void backend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
int err; int err;
unsigned major; unsigned major;
......
...@@ -734,7 +734,7 @@ static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[]) ...@@ -734,7 +734,7 @@ static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
} }
static void xen_net_rate_changed(struct xenbus_watch *watch, static void xen_net_rate_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
struct xenvif *vif = container_of(watch, struct xenvif, credit_watch); struct xenvif *vif = container_of(watch, struct xenvif, credit_watch);
struct xenbus_device *dev = xenvif_to_xenbus_device(vif); struct xenbus_device *dev = xenvif_to_xenbus_device(vif);
...@@ -791,7 +791,7 @@ static void xen_unregister_credit_watch(struct xenvif *vif) ...@@ -791,7 +791,7 @@ static void xen_unregister_credit_watch(struct xenvif *vif)
} }
static void xen_mcast_ctrl_changed(struct xenbus_watch *watch, static void xen_mcast_ctrl_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
struct xenvif *vif = container_of(watch, struct xenvif, struct xenvif *vif = container_of(watch, struct xenvif,
mcast_ctrl_watch); mcast_ctrl_watch);
...@@ -866,8 +866,8 @@ static void unregister_hotplug_status_watch(struct backend_info *be) ...@@ -866,8 +866,8 @@ static void unregister_hotplug_status_watch(struct backend_info *be)
} }
static void hotplug_status_changed(struct xenbus_watch *watch, static void hotplug_status_changed(struct xenbus_watch *watch,
const char **vec, const char *path,
unsigned int vec_size) const char *token)
{ {
struct backend_info *be = container_of(watch, struct backend_info *be = container_of(watch,
struct backend_info, struct backend_info,
......
...@@ -68,13 +68,12 @@ static void vcpu_hotplug(unsigned int cpu) ...@@ -68,13 +68,12 @@ static void vcpu_hotplug(unsigned int cpu)
} }
static void handle_vcpu_hotplug_event(struct xenbus_watch *watch, static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
unsigned int cpu; unsigned int cpu;
char *cpustr; char *cpustr;
const char *node = vec[XS_WATCH_PATH];
cpustr = strstr(node, "cpu/"); cpustr = strstr(path, "cpu/");
if (cpustr != NULL) { if (cpustr != NULL) {
sscanf(cpustr, "cpu/%u", &cpu); sscanf(cpustr, "cpu/%u", &cpu);
vcpu_hotplug(cpu); vcpu_hotplug(cpu);
......
...@@ -218,7 +218,7 @@ static struct shutdown_handler shutdown_handlers[] = { ...@@ -218,7 +218,7 @@ static struct shutdown_handler shutdown_handlers[] = {
}; };
static void shutdown_handler(struct xenbus_watch *watch, static void shutdown_handler(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
char *str; char *str;
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
...@@ -266,8 +266,8 @@ static void shutdown_handler(struct xenbus_watch *watch, ...@@ -266,8 +266,8 @@ static void shutdown_handler(struct xenbus_watch *watch,
} }
#ifdef CONFIG_MAGIC_SYSRQ #ifdef CONFIG_MAGIC_SYSRQ
static void sysrq_handler(struct xenbus_watch *watch, const char **vec, static void sysrq_handler(struct xenbus_watch *watch, const char *path,
unsigned int len) const char *token)
{ {
char sysrq_key = '\0'; char sysrq_key = '\0';
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
......
...@@ -55,7 +55,7 @@ static int register_balloon(struct device *dev); ...@@ -55,7 +55,7 @@ static int register_balloon(struct device *dev);
/* React to a change in the target key */ /* React to a change in the target key */
static void watch_target(struct xenbus_watch *watch, static void watch_target(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
unsigned long long new_target; unsigned long long new_target;
int err; int err;
......
...@@ -652,7 +652,7 @@ static int xen_pcibk_setup_backend(struct xen_pcibk_device *pdev) ...@@ -652,7 +652,7 @@ static int xen_pcibk_setup_backend(struct xen_pcibk_device *pdev)
} }
static void xen_pcibk_be_watch(struct xenbus_watch *watch, static void xen_pcibk_be_watch(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
struct xen_pcibk_device *pdev = struct xen_pcibk_device *pdev =
container_of(watch, struct xen_pcibk_device, be_watch); container_of(watch, struct xen_pcibk_device, be_watch);
......
...@@ -40,8 +40,8 @@ struct xen_bus_type { ...@@ -40,8 +40,8 @@ struct xen_bus_type {
int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename); int (*get_bus_id)(char bus_id[XEN_BUS_ID_SIZE], const char *nodename);
int (*probe)(struct xen_bus_type *bus, const char *type, int (*probe)(struct xen_bus_type *bus, const char *type,
const char *dir); const char *dir);
void (*otherend_changed)(struct xenbus_watch *watch, const char **vec, void (*otherend_changed)(struct xenbus_watch *watch, const char *path,
unsigned int len); const char *token);
struct bus_type bus; struct bus_type bus;
}; };
...@@ -84,7 +84,7 @@ int xenbus_dev_resume(struct device *dev); ...@@ -84,7 +84,7 @@ int xenbus_dev_resume(struct device *dev);
int xenbus_dev_cancel(struct device *dev); int xenbus_dev_cancel(struct device *dev);
void xenbus_otherend_changed(struct xenbus_watch *watch, void xenbus_otherend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len, const char *path, const char *token,
int ignore_on_shutdown); int ignore_on_shutdown);
int xenbus_read_otherend_details(struct xenbus_device *xendev, int xenbus_read_otherend_details(struct xenbus_device *xendev,
......
...@@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(xenbus_strstate); ...@@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(xenbus_strstate);
int xenbus_watch_path(struct xenbus_device *dev, const char *path, int xenbus_watch_path(struct xenbus_device *dev, const char *path,
struct xenbus_watch *watch, struct xenbus_watch *watch,
void (*callback)(struct xenbus_watch *, void (*callback)(struct xenbus_watch *,
const char **, unsigned int)) const char *, const char *))
{ {
int err; int err;
...@@ -153,7 +153,7 @@ EXPORT_SYMBOL_GPL(xenbus_watch_path); ...@@ -153,7 +153,7 @@ EXPORT_SYMBOL_GPL(xenbus_watch_path);
int xenbus_watch_pathfmt(struct xenbus_device *dev, int xenbus_watch_pathfmt(struct xenbus_device *dev,
struct xenbus_watch *watch, struct xenbus_watch *watch,
void (*callback)(struct xenbus_watch *, void (*callback)(struct xenbus_watch *,
const char **, unsigned int), const char *, const char *),
const char *pathfmt, ...) const char *pathfmt, ...)
{ {
int err; int err;
......
...@@ -258,26 +258,23 @@ static struct watch_adapter *alloc_watch_adapter(const char *path, ...@@ -258,26 +258,23 @@ static struct watch_adapter *alloc_watch_adapter(const char *path,
} }
static void watch_fired(struct xenbus_watch *watch, static void watch_fired(struct xenbus_watch *watch,
const char **vec, const char *path,
unsigned int len) const char *token)
{ {
struct watch_adapter *adap; struct watch_adapter *adap;
struct xsd_sockmsg hdr; struct xsd_sockmsg hdr;
const char *path, *token; const char *token_caller;
int path_len, tok_len, body_len, data_len = 0; int path_len, tok_len, body_len;
int ret; int ret;
LIST_HEAD(staging_q); LIST_HEAD(staging_q);
adap = container_of(watch, struct watch_adapter, watch); adap = container_of(watch, struct watch_adapter, watch);
path = vec[XS_WATCH_PATH]; token_caller = adap->token;
token = adap->token;
path_len = strlen(path) + 1; path_len = strlen(path) + 1;
tok_len = strlen(token) + 1; tok_len = strlen(token_caller) + 1;
if (len > 2) body_len = path_len + tok_len;
data_len = vec[len] - vec[2] + 1;
body_len = path_len + tok_len + data_len;
hdr.type = XS_WATCH_EVENT; hdr.type = XS_WATCH_EVENT;
hdr.len = body_len; hdr.len = body_len;
...@@ -288,9 +285,7 @@ static void watch_fired(struct xenbus_watch *watch, ...@@ -288,9 +285,7 @@ static void watch_fired(struct xenbus_watch *watch,
if (!ret) if (!ret)
ret = queue_reply(&staging_q, path, path_len); ret = queue_reply(&staging_q, path, path_len);
if (!ret) if (!ret)
ret = queue_reply(&staging_q, token, tok_len); ret = queue_reply(&staging_q, token_caller, tok_len);
if (!ret && len > 2)
ret = queue_reply(&staging_q, vec[2], data_len);
if (!ret) { if (!ret) {
/* success: pass reply list onto watcher */ /* success: pass reply list onto watcher */
......
...@@ -169,7 +169,7 @@ int xenbus_read_otherend_details(struct xenbus_device *xendev, ...@@ -169,7 +169,7 @@ int xenbus_read_otherend_details(struct xenbus_device *xendev,
EXPORT_SYMBOL_GPL(xenbus_read_otherend_details); EXPORT_SYMBOL_GPL(xenbus_read_otherend_details);
void xenbus_otherend_changed(struct xenbus_watch *watch, void xenbus_otherend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len, const char *path, const char *token,
int ignore_on_shutdown) int ignore_on_shutdown)
{ {
struct xenbus_device *dev = struct xenbus_device *dev =
...@@ -180,18 +180,15 @@ void xenbus_otherend_changed(struct xenbus_watch *watch, ...@@ -180,18 +180,15 @@ void xenbus_otherend_changed(struct xenbus_watch *watch,
/* Protect us against watches firing on old details when the otherend /* Protect us against watches firing on old details when the otherend
details change, say immediately after a resume. */ details change, say immediately after a resume. */
if (!dev->otherend || if (!dev->otherend ||
strncmp(dev->otherend, vec[XS_WATCH_PATH], strncmp(dev->otherend, path, strlen(dev->otherend))) {
strlen(dev->otherend))) { dev_dbg(&dev->dev, "Ignoring watch at %s\n", path);
dev_dbg(&dev->dev, "Ignoring watch at %s\n",
vec[XS_WATCH_PATH]);
return; return;
} }
state = xenbus_read_driver_state(dev->otherend); state = xenbus_read_driver_state(dev->otherend);
dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n", dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n",
state, xenbus_strstate(state), dev->otherend_watch.node, state, xenbus_strstate(state), dev->otherend_watch.node, path);
vec[XS_WATCH_PATH]);
/* /*
* Ignore xenbus transitions during shutdown. This prevents us doing * Ignore xenbus transitions during shutdown. This prevents us doing
......
...@@ -181,9 +181,9 @@ static int xenbus_probe_backend(struct xen_bus_type *bus, const char *type, ...@@ -181,9 +181,9 @@ static int xenbus_probe_backend(struct xen_bus_type *bus, const char *type,
} }
static void frontend_changed(struct xenbus_watch *watch, static void frontend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
xenbus_otherend_changed(watch, vec, len, 0); xenbus_otherend_changed(watch, path, token, 0);
} }
static struct xen_bus_type xenbus_backend = { static struct xen_bus_type xenbus_backend = {
...@@ -204,11 +204,11 @@ static struct xen_bus_type xenbus_backend = { ...@@ -204,11 +204,11 @@ static struct xen_bus_type xenbus_backend = {
}; };
static void backend_changed(struct xenbus_watch *watch, static void backend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
DPRINTK(""); DPRINTK("");
xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_backend); xenbus_dev_changed(path, &xenbus_backend);
} }
static struct xenbus_watch be_watch = { static struct xenbus_watch be_watch = {
......
...@@ -86,9 +86,9 @@ static int xenbus_uevent_frontend(struct device *_dev, ...@@ -86,9 +86,9 @@ static int xenbus_uevent_frontend(struct device *_dev,
static void backend_changed(struct xenbus_watch *watch, static void backend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
xenbus_otherend_changed(watch, vec, len, 1); xenbus_otherend_changed(watch, path, token, 1);
} }
static void xenbus_frontend_delayed_resume(struct work_struct *w) static void xenbus_frontend_delayed_resume(struct work_struct *w)
...@@ -153,11 +153,11 @@ static struct xen_bus_type xenbus_frontend = { ...@@ -153,11 +153,11 @@ static struct xen_bus_type xenbus_frontend = {
}; };
static void frontend_changed(struct xenbus_watch *watch, static void frontend_changed(struct xenbus_watch *watch,
const char **vec, unsigned int len) const char *path, const char *token)
{ {
DPRINTK(""); DPRINTK("");
xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend); xenbus_dev_changed(path, &xenbus_frontend);
} }
...@@ -332,13 +332,13 @@ static DECLARE_WAIT_QUEUE_HEAD(backend_state_wq); ...@@ -332,13 +332,13 @@ static DECLARE_WAIT_QUEUE_HEAD(backend_state_wq);
static int backend_state; static int backend_state;
static void xenbus_reset_backend_state_changed(struct xenbus_watch *w, static void xenbus_reset_backend_state_changed(struct xenbus_watch *w,
const char **v, unsigned int l) const char *path, const char *token)
{ {
if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", if (xenbus_scanf(XBT_NIL, path, "", "%i",
&backend_state) != 1) &backend_state) != 1)
backend_state = XenbusStateUnknown; backend_state = XenbusStateUnknown;
printk(KERN_DEBUG "XENBUS: backend %s %s\n", printk(KERN_DEBUG "XENBUS: backend %s %s\n",
v[XS_WATCH_PATH], xenbus_strstate(backend_state)); path, xenbus_strstate(backend_state));
wake_up(&backend_state_wq); wake_up(&backend_state_wq);
} }
......
...@@ -64,8 +64,8 @@ struct xs_stored_msg { ...@@ -64,8 +64,8 @@ struct xs_stored_msg {
/* Queued watch events. */ /* Queued watch events. */
struct { struct {
struct xenbus_watch *handle; struct xenbus_watch *handle;
char **vec; const char *path;
unsigned int vec_size; const char *token;
} watch; } watch;
} u; } u;
}; };
...@@ -765,7 +765,7 @@ void unregister_xenbus_watch(struct xenbus_watch *watch) ...@@ -765,7 +765,7 @@ void unregister_xenbus_watch(struct xenbus_watch *watch)
if (msg->u.watch.handle != watch) if (msg->u.watch.handle != watch)
continue; continue;
list_del(&msg->list); list_del(&msg->list);
kfree(msg->u.watch.vec); kfree(msg->u.watch.path);
kfree(msg); kfree(msg);
} }
spin_unlock(&watch_events_lock); spin_unlock(&watch_events_lock);
...@@ -833,11 +833,10 @@ static int xenwatch_thread(void *unused) ...@@ -833,11 +833,10 @@ static int xenwatch_thread(void *unused)
if (ent != &watch_events) { if (ent != &watch_events) {
msg = list_entry(ent, struct xs_stored_msg, list); msg = list_entry(ent, struct xs_stored_msg, list);
msg->u.watch.handle->callback( msg->u.watch.handle->callback(msg->u.watch.handle,
msg->u.watch.handle, msg->u.watch.path,
(const char **)msg->u.watch.vec, msg->u.watch.token);
msg->u.watch.vec_size); kfree(msg->u.watch.path);
kfree(msg->u.watch.vec);
kfree(msg); kfree(msg);
} }
...@@ -903,24 +902,24 @@ static int process_msg(void) ...@@ -903,24 +902,24 @@ static int process_msg(void)
body[msg->hdr.len] = '\0'; body[msg->hdr.len] = '\0';
if (msg->hdr.type == XS_WATCH_EVENT) { if (msg->hdr.type == XS_WATCH_EVENT) {
msg->u.watch.vec = split(body, msg->hdr.len, if (count_strings(body, msg->hdr.len) != 2) {
&msg->u.watch.vec_size); err = -EINVAL;
if (IS_ERR(msg->u.watch.vec)) {
err = PTR_ERR(msg->u.watch.vec);
kfree(msg); kfree(msg);
kfree(body);
goto out; goto out;
} }
msg->u.watch.path = (const char *)body;
msg->u.watch.token = (const char *)strchr(body, '\0') + 1;
spin_lock(&watches_lock); spin_lock(&watches_lock);
msg->u.watch.handle = find_watch( msg->u.watch.handle = find_watch(msg->u.watch.token);
msg->u.watch.vec[XS_WATCH_TOKEN]);
if (msg->u.watch.handle != NULL) { if (msg->u.watch.handle != NULL) {
spin_lock(&watch_events_lock); spin_lock(&watch_events_lock);
list_add_tail(&msg->list, &watch_events); list_add_tail(&msg->list, &watch_events);
wake_up(&watch_events_waitq); wake_up(&watch_events_waitq);
spin_unlock(&watch_events_lock); spin_unlock(&watch_events_lock);
} else { } else {
kfree(msg->u.watch.vec); kfree(body);
kfree(msg); kfree(msg);
} }
spin_unlock(&watches_lock); spin_unlock(&watches_lock);
......
...@@ -61,7 +61,7 @@ struct xenbus_watch ...@@ -61,7 +61,7 @@ struct xenbus_watch
/* Callback (executed in a process context with no locks held). */ /* Callback (executed in a process context with no locks held). */
void (*callback)(struct xenbus_watch *, void (*callback)(struct xenbus_watch *,
const char **vec, unsigned int len); const char *path, const char *token);
}; };
...@@ -193,11 +193,11 @@ void xenbus_probe(struct work_struct *); ...@@ -193,11 +193,11 @@ void xenbus_probe(struct work_struct *);
int xenbus_watch_path(struct xenbus_device *dev, const char *path, int xenbus_watch_path(struct xenbus_device *dev, const char *path,
struct xenbus_watch *watch, struct xenbus_watch *watch,
void (*callback)(struct xenbus_watch *, void (*callback)(struct xenbus_watch *,
const char **, unsigned int)); const char *, const char *));
__printf(4, 5) __printf(4, 5)
int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch, int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
void (*callback)(struct xenbus_watch *, void (*callback)(struct xenbus_watch *,
const char **, unsigned int), const char *, const char *),
const char *pathfmt, ...); const char *pathfmt, ...);
int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state); int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment