xenbusb_back.c (214077) | xenbusb_back.c (222975) |
---|---|
1/****************************************************************************** 2 * Talks to Xen Store to figure out what devices we have. 3 * 4 * Copyright (C) 2009, 2010 Spectra Logic Corporation 5 * Copyright (C) 2008 Doug Rabson 6 * Copyright (C) 2005 Rusty Russell, IBM Corporation 7 * Copyright (C) 2005 Mike Wray, Hewlett-Packard 8 * Copyright (C) 2005 XenSource Ltd --- 22 unchanged lines hidden (view full) --- 31 32/** 33 * \file xenbusb_back.c 34 * 35 * XenBus management of the NewBus bus containing the backend instances of 36 * Xen split devices. 37 */ 38#include <sys/cdefs.h> | 1/****************************************************************************** 2 * Talks to Xen Store to figure out what devices we have. 3 * 4 * Copyright (C) 2009, 2010 Spectra Logic Corporation 5 * Copyright (C) 2008 Doug Rabson 6 * Copyright (C) 2005 Rusty Russell, IBM Corporation 7 * Copyright (C) 2005 Mike Wray, Hewlett-Packard 8 * Copyright (C) 2005 XenSource Ltd --- 22 unchanged lines hidden (view full) --- 31 32/** 33 * \file xenbusb_back.c 34 * 35 * XenBus management of the NewBus bus containing the backend instances of 36 * Xen split devices. 37 */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/sys/xen/xenbus/xenbusb_back.c 214077 2010-10-19 20:53:30Z gibbs $"); | 39__FBSDID("$FreeBSD: head/sys/xen/xenbus/xenbusb_back.c 222975 2011-06-11 04:59:01Z gibbs $"); |
40 41#include <sys/param.h> 42#include <sys/bus.h> 43#include <sys/kernel.h> 44#include <sys/lock.h> 45#include <sys/malloc.h> 46#include <sys/module.h> 47#include <sys/sbuf.h> --- 155 unchanged lines hidden (view full) --- 203 204 error = xs_gather(XST_NIL, ivars->xd_node, 205 "frontend-id", "%i", &ivars->xd_otherend_id, 206 "frontend", NULL, &otherend_path, 207 NULL); 208 209 if (error == 0) { 210 ivars->xd_otherend_path = strdup(otherend_path, M_XENBUS); | 40 41#include <sys/param.h> 42#include <sys/bus.h> 43#include <sys/kernel.h> 44#include <sys/lock.h> 45#include <sys/malloc.h> 46#include <sys/module.h> 47#include <sys/sbuf.h> --- 155 unchanged lines hidden (view full) --- 203 204 error = xs_gather(XST_NIL, ivars->xd_node, 205 "frontend-id", "%i", &ivars->xd_otherend_id, 206 "frontend", NULL, &otherend_path, 207 NULL); 208 209 if (error == 0) { 210 ivars->xd_otherend_path = strdup(otherend_path, M_XENBUS); |
211 ivars->xd_otherend_path_len = strlen(otherend_path); |
|
211 free(otherend_path, M_XENSTORE); 212 } 213 return (error); 214} 215 216/** | 212 free(otherend_path, M_XENSTORE); 213 } 214 return (error); 215} 216 217/** |
217 * \brief Backend XenBus child instance variable write access method. 218 * 219 * \param dev The NewBus device representing this XenBus bus. 220 * \param child The NewBus device representing a child of dev%'s XenBus bus. 221 * \param index The index of the instance variable to access. 222 * \param value The new value to set in the instance variable accessed. 223 * 224 * \return On success, 0. Otherwise an errno value indicating the 225 * type of failure. 226 * 227 * Xenbus_back overrides this method so that it can trap state transitions 228 * of local backend devices and clean up their XenStore entries as necessary 229 * during device instance teardown. | 218 * \brief Backend XenBus method implementing responses to peer state changes. 219 * 220 * \param bus The XenBus bus parent of child. 221 * \param child The XenBus child whose peer stat has changed. 222 * \param state The current state of the peer. |
230 */ | 223 */ |
231static int 232xenbusb_back_write_ivar(device_t dev, device_t child, int index, 233 uintptr_t value) | 224static void 225xenbusb_back_otherend_changed(device_t bus, device_t child, 226 enum xenbus_state peer_state) |
234{ | 227{ |
235 int error; | 228 /* Perform default processing of state. */ 229 xenbusb_otherend_changed(bus, child, peer_state); |
236 | 230 |
237 error = xenbusb_write_ivar(dev, child, index, value); | 231 /* 232 * "Online" devices are never fully detached in the 233 * newbus sense. Only the front<->back connection is 234 * torn down. If the front returns to the initialising 235 * state after closing a previous connection, signal 236 * our willingness to reconnect and that all necessary 237 * XenStore data for feature negotiation is present. 238 */ 239 if (peer_state == XenbusStateInitialising 240 && xenbus_dev_is_online(child) != 0 241 && xenbus_get_state(child) == XenbusStateClosed) 242 xenbus_set_state(child, XenbusStateInitWait); 243} |
238 | 244 |
239 if (index == XENBUS_IVAR_STATE 240 && (enum xenbus_state)value == XenbusStateClosed 241 && xenbus_dev_is_online(child) == 0) { | 245/** 246 * \brief Backend XenBus method implementing responses to local 247 * XenStore changes. 248 * 249 * \param bus The XenBus bus parent of child. 250 * \param child The XenBus child whose peer stat has changed. 251 * \param_path The tree relative sub-path to the modified node. The empty 252 * string indicates the root of the tree was destroyed. 253 */ 254static void 255xenbusb_back_localend_changed(device_t bus, device_t child, const char *path) 256{ |
242 | 257 |
243 /* 244 * Cleanup the hotplug entry in the XenStore if 245 * present. The control domain expects any userland 246 * component associated with this device to destroy 247 * this node in order to signify it is safe to 248 * teardown the device. However, not all backends 249 * rely on userland components, and those that 250 * do should either use a communication channel 251 * other than the XenStore, or ensure the hotplug 252 * data is already cleaned up. 253 * 254 * This removal ensures that no matter what path 255 * is taken to mark a back-end closed, the control 256 * domain will understand that it is closed. 257 */ 258 xs_rm(XST_NIL, xenbus_get_node(child), "hotplug-status"); 259 } | 258 xenbusb_localend_changed(bus, child, path); |
260 | 259 |
261 return (error); | 260 if (strcmp(path, "/state") != 0 261 && strcmp(path, "/online") != 0) 262 return; 263 264 if (xenbus_get_state(child) != XenbusStateClosed 265 || xenbus_dev_is_online(child) != 0) 266 return; 267 268 /* 269 * Cleanup the hotplug entry in the XenStore if 270 * present. The control domain expects any userland 271 * component associated with this device to destroy 272 * this node in order to signify it is safe to 273 * teardown the device. However, not all backends 274 * rely on userland components, and those that 275 * do should either use a communication channel 276 * other than the XenStore, or ensure the hotplug 277 * data is already cleaned up. 278 * 279 * This removal ensures that no matter what path 280 * is taken to mark a back-end closed, the control 281 * domain will understand that it is closed. 282 */ 283 xs_rm(XST_NIL, xenbus_get_node(child), "hotplug-status"); |
262} 263 264/*-------------------- Private Device Attachment Data -----------------------*/ 265static device_method_t xenbusb_back_methods[] = { 266 /* Device interface */ 267 DEVMETHOD(device_identify, xenbusb_identify), 268 DEVMETHOD(device_probe, xenbusb_back_probe), 269 DEVMETHOD(device_attach, xenbusb_back_attach), 270 DEVMETHOD(device_detach, bus_generic_detach), 271 DEVMETHOD(device_shutdown, bus_generic_shutdown), 272 DEVMETHOD(device_suspend, bus_generic_suspend), 273 DEVMETHOD(device_resume, bus_generic_resume), 274 275 /* Bus Interface */ 276 DEVMETHOD(bus_print_child, xenbusb_print_child), 277 DEVMETHOD(bus_read_ivar, xenbusb_read_ivar), | 284} 285 286/*-------------------- Private Device Attachment Data -----------------------*/ 287static device_method_t xenbusb_back_methods[] = { 288 /* Device interface */ 289 DEVMETHOD(device_identify, xenbusb_identify), 290 DEVMETHOD(device_probe, xenbusb_back_probe), 291 DEVMETHOD(device_attach, xenbusb_back_attach), 292 DEVMETHOD(device_detach, bus_generic_detach), 293 DEVMETHOD(device_shutdown, bus_generic_shutdown), 294 DEVMETHOD(device_suspend, bus_generic_suspend), 295 DEVMETHOD(device_resume, bus_generic_resume), 296 297 /* Bus Interface */ 298 DEVMETHOD(bus_print_child, xenbusb_print_child), 299 DEVMETHOD(bus_read_ivar, xenbusb_read_ivar), |
278 DEVMETHOD(bus_write_ivar, xenbusb_back_write_ivar), | 300 DEVMETHOD(bus_write_ivar, xenbusb_write_ivar), |
279 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 280 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 281 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 282 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 283 284 /* XenBus Bus Interface */ 285 DEVMETHOD(xenbusb_enumerate_type, xenbusb_back_enumerate_type), 286 DEVMETHOD(xenbusb_get_otherend_node, xenbusb_back_get_otherend_node), | 301 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 302 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 303 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 304 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 305 306 /* XenBus Bus Interface */ 307 DEVMETHOD(xenbusb_enumerate_type, xenbusb_back_enumerate_type), 308 DEVMETHOD(xenbusb_get_otherend_node, xenbusb_back_get_otherend_node), |
309 DEVMETHOD(xenbusb_otherend_changed, xenbusb_back_otherend_changed), 310 DEVMETHOD(xenbusb_localend_changed, xenbusb_back_localend_changed), |
|
287 { 0, 0 } 288}; 289 290DEFINE_CLASS_0(xenbusb_back, xenbusb_back_driver, xenbusb_back_methods, 291 sizeof(struct xenbusb_softc)); 292devclass_t xenbusb_back_devclass; 293 294DRIVER_MODULE(xenbusb_back, xenstore, xenbusb_back_driver, 295 xenbusb_back_devclass, 0, 0); | 311 { 0, 0 } 312}; 313 314DEFINE_CLASS_0(xenbusb_back, xenbusb_back_driver, xenbusb_back_methods, 315 sizeof(struct xenbusb_softc)); 316devclass_t xenbusb_back_devclass; 317 318DRIVER_MODULE(xenbusb_back, xenstore, xenbusb_back_driver, 319 xenbusb_back_devclass, 0, 0); |