FreeBSD/sys/dev/xen/blkback/blkback.c
/**
 * Attach to a XenBus device that has been claimed by our probe routine.
 *
 * \param dev  NewBus device object representing this Xen Block Back instance.
 *
 * \return  0 for success, errno codes for failure.
 */
Attach to a XenBus device that has been claimed by our probe routine.
\param dev  NewBus device object representing this Xen Block Back instance.

\return  0 for success, errno codes for failure.
Attach to a XenBus device that has been claimed by our probe routine . \ param dev NewBus device object representing this Xen Block Back instance . \ return 0 for success errno codes for failure .
static int
xbb_attach(device_t dev)
{
	struct xbb_softc	*xbb;
	int			 error;
	u_int			 max_ring_page_order;
	struct sbuf		*watch_path;
	DPRINTF("Attaching to %s\n", xenbus_get_node(dev));
	xbb = device_get_softc(dev);
	xbb->dev = dev;
	xbb->otherend_id = xenbus_get_otherend_id(dev);
	TASK_INIT(&xbb->io_task, 0, xbb_run_queue, xbb);
	mtx_init(&xbb->lock, device_get_nameunit(dev), NULL, MTX_DEF);
	error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
			  "feature-barrier", "1");
	if (error) {
		xbb_attach_failed(xbb, error, "writing %s/feature-barrier",
				  xenbus_get_node(xbb->dev));
		return (error);
	}
	error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
			  "feature-flush-cache", "1");
	if (error) {
		xbb_attach_failed(xbb, error, "writing %s/feature-flush-cache",
				  xenbus_get_node(xbb->dev));
		return (error);
	}
	max_ring_page_order = flsl(XBB_MAX_RING_PAGES) - 1;
	error = xs_printf(XST_NIL, xenbus_get_node(xbb->dev),
			  "max-ring-page-order", "%u", max_ring_page_order);
	if (error) {
		xbb_attach_failed(xbb, error, "writing %s/max-ring-page-order",
				  xenbus_get_node(xbb->dev));
		return (error);
	}
	watch_path = xs_join(xenbus_get_node(xbb->dev), "physical-device-path");
	xbb->hotplug_watch.callback_data = (uintptr_t)dev;
	xbb->hotplug_watch.callback = xbb_attach_disk;
	KASSERT(xbb->hotplug_watch.node == NULL, ("watch node already setup"));
	xbb->hotplug_watch.node = strdup(sbuf_data(watch_path), M_XENBLOCKBACK);
	sbuf_delete(watch_path);
	error = xs_register_watch(&xbb->hotplug_watch);
	if (error != 0) {
		xbb_attach_failed(xbb, error, "failed to create watch on %s",
		    xbb->hotplug_watch.node);
		free(xbb->hotplug_watch.node, M_XENBLOCKBACK);
		return (error);
	}
	xenbus_set_state(dev, XenbusStateInitWait);
	return (0);
}
static int xbb_attach ( device_t dev ) { struct xbb_softc * xbb ; int error ; u_int max_ring_page_order ; struct sbuf * watch_path ; DPRINTF ( " \n " , xenbus_get_node ( dev ) ) ; xbb = device_get_softc ( dev ) ; xbb -> dev = dev ; xbb -> otherend_id = xenbus_get_otherend_id ( dev ) ; TASK_INIT ( & xbb -> io_task , 0 , xbb_run_queue , xbb ) ; mtx_init ( & xbb -> lock , device_get_nameunit ( dev ) , NULL , MTX_DEF ) ; error = xs_printf ( XST_NIL , xenbus_get_node ( xbb -> dev ) , " " , " " ) ; if ( error ) { xbb_attach_failed ( xbb , error , " " , xenbus_get_node ( xbb -> dev ) ) ; return ( error ) ; } error = xs_printf ( XST_NIL , xenbus_get_node ( xbb -> dev ) , " " , " " ) ; if ( error ) { xbb_attach_failed ( xbb , error , " " , xenbus_get_node ( xbb -> dev ) ) ; return ( error ) ; } max_ring_page_order = flsl ( XBB_MAX_RING_PAGES ) - 1 ; error = xs_printf ( XST_NIL , xenbus_get_node ( xbb -> dev ) , " " , " " , max_ring_page_order ) ; if ( error ) { xbb_attach_failed ( xbb , error , " " , xenbus_get_node ( xbb -> dev ) ) ; return ( error ) ; } watch_path = xs_join ( xenbus_get_node ( xbb -> dev ) , " " ) ; xbb -> hotplug_watch . callback_data = ( uintptr_t ) dev ; xbb -> hotplug_watch . callback = xbb_attach_disk ; KASSERT ( xbb -> hotplug_watch . node == NULL , ( " " ) ) ; xbb -> hotplug_watch . node = strdup ( sbuf_data ( watch_path ) , M_XENBLOCKBACK ) ; sbuf_delete ( watch_path ) ; error = xs_register_watch ( & xbb -> hotplug_watch ) ; if ( error != 0 ) { xbb_attach_failed ( xbb , error , " " , xbb -> hotplug_watch . node ) ; free ( xbb -> hotplug_watch . node , M_XENBLOCKBACK ) ; return ( error ) ; } xenbus_set_state ( dev , XenbusStateInitWait ) ; return ( 0 ) ; }
Attach to a XenBus device that has been claimed by our probe routine.
Attach to a XenBus device that has been claimed by our probe routine .
/*
	 * Basic initialization.
	 * After this block it is safe to call xbb_detach()
	 * to clean up any allocated data for this instance.
	 */ /*priority*/ /*
	 * Publish protocol capabilities for consumption by the
	 * front-end.
	 */ /*
	 * We need to wait for hotplug script execution before
	 * moving forward.
	 */ /* Tell the toolstack blkback has attached. */