FreeBSD/sys/xen/xenbus/xenbusb_back.c
/**
 * \brief Enumerate all devices of the given type on this bus.
 *
 * \param dev   NewBus device_t for this XenBus backend bus instance.
 * \param type  String indicating the device sub-tree (e.g. "vfb", "vif")
 *              to enumerate. 
 *
 * \return  On success, 0. Otherwise an errno value indicating the
 *          type of failure.
 *
 * Devices that are found are entered into the NewBus hierarchy via
 * xenbusb_add_device().  xenbusb_add_device() ignores duplicate detects
 * and ignores duplicate devices, so it can be called unconditionally
 * for any device found in the XenStore.
 *
 * The backend XenStore hierarchy has the following format:
 *
 *     backend/<device type>/<frontend vm id>/<device id>
 *
 */
\brief Enumerate all devices of the given type on this bus.
\param dev   NewBus device_t for this XenBus backend bus instance.
\param type  String indicating the device sub-tree
to enumerate.

\return  On success, 0. Otherwise an errno value indicating the
type of failure.

Devices that are found are entered into the NewBus hierarchy via
xenbusb_add_device().  xenbusb_add_device() ignores duplicate detects
and ignores duplicate devices, so it can be called unconditionally
for any device found in the XenStore.

The backend XenStore hierarchy has the following format.

backend///
\ brief Enumerate all devices of the given type on this bus . \ param dev NewBus device_t for this XenBus backend bus instance . \ param type String indicating the device sub - tree to enumerate . \ return On success 0 . Otherwise an errno value indicating the type of failure . Devices that are found are entered into the NewBus hierarchy via xenbusb_add_device () . xenbusb_add_device () ignores duplicate detects and ignores duplicate devices so it can be called unconditionally for any device found in the XenStore . The backend XenStore hierarchy has the following format . backend ///
static int
xenbusb_back_enumerate_type(device_t dev, const char *type)
{
	struct xenbusb_softc *xbs;
	const char **vms;
	u_int vm_idx;
	u_int vm_count;
	int error;
	xbs = device_get_softc(dev);
	error = xs_directory(XST_NIL, xbs->xbs_node, type, &vm_count, &vms);
	if (error)
		return (error);
	for (vm_idx = 0; vm_idx < vm_count; vm_idx++) {
		struct sbuf *vm_path;
		const char *vm;
		const char **devs;
		u_int dev_idx;
		u_int dev_count;
		vm = vms[vm_idx];
		vm_path = xs_join(type, vm);
		error = xs_directory(XST_NIL, xbs->xbs_node, sbuf_data(vm_path),
		    &dev_count, &devs);
		sbuf_delete(vm_path);
		if (error)
			break;
		for (dev_idx = 0; dev_idx < dev_count; dev_idx++) {
			const char *dev_num;
			struct sbuf *id;
			dev_num = devs[dev_idx];
			id = xs_join(vm, dev_num);
			xenbusb_add_device(dev, type, sbuf_data(id));
			sbuf_delete(id);
		}
		free(devs, M_XENSTORE);
	}
	free(vms, M_XENSTORE);
	return (0);
}
static int xenbusb_back_enumerate_type ( device_t dev , const char * type ) { struct xenbusb_softc * xbs ; const char * * vms ; u_int vm_idx ; u_int vm_count ; int error ; xbs = device_get_softc ( dev ) ; error = xs_directory ( XST_NIL , xbs -> xbs_node , type , & vm_count , & vms ) ; if ( error ) return ( error ) ; for ( vm_idx = 0 ; vm_idx < vm_count ; vm_idx ++ ) { struct sbuf * vm_path ; const char * vm ; const char * * devs ; u_int dev_idx ; u_int dev_count ; vm = vms [ vm_idx ] ; vm_path = xs_join ( type , vm ) ; error = xs_directory ( XST_NIL , xbs -> xbs_node , sbuf_data ( vm_path ) , & dev_count , & devs ) ; sbuf_delete ( vm_path ) ; if ( error ) break ; for ( dev_idx = 0 ; dev_idx < dev_count ; dev_idx ++ ) { const char * dev_num ; struct sbuf * id ; dev_num = devs [ dev_idx ] ; id = xs_join ( vm , dev_num ) ; xenbusb_add_device ( dev , type , sbuf_data ( id ) ) ; sbuf_delete ( id ) ; } free ( devs , M_XENSTORE ) ; } free ( vms , M_XENSTORE ) ; return ( 0 ) ; }
\brief Enumerate all devices of the given type on this bus.
\ brief Enumerate all devices of the given type on this bus .