FreeBSD/sys/dev/xen/blkback/blkback.c
/**
 * Open a character device to be used for backend I/O.
 *
 * \param xbb  Per-instance xbb configuration structure.
 *
 * \return  0 for success, errno codes for failure.
 */
Open a character device to be used for backend I/O.
\param xbb  Per-instance xbb configuration structure.

\return  0 for success, errno codes for failure.
Open a character device to be used for backend I / O . \ param xbb Per - instance xbb configuration structure . \ return 0 for success errno codes for failure .
static int
xbb_open_dev(struct xbb_softc *xbb)
{
	struct vattr   vattr;
	struct cdev   *dev;
	struct cdevsw *devsw;
	int	       error;
	xbb->device_type = XBB_TYPE_DISK;
	xbb->dispatch_io = xbb_dispatch_dev;
	xbb->backend.dev.cdev = xbb->vn->v_rdev;
	xbb->backend.dev.csw = dev_refthread(xbb->backend.dev.cdev,
					     &xbb->backend.dev.dev_ref);
	if (xbb->backend.dev.csw == NULL)
		panic("Unable to retrieve device switch");
	error = VOP_GETATTR(xbb->vn, &vattr, NOCRED);
	if (error) {
		xenbus_dev_fatal(xbb->dev, error, "error getting "
				 "vnode attributes for device %s",
				 xbb->dev_name);
		return (error);
	}
	dev = xbb->vn->v_rdev;
	devsw = dev->si_devsw;
	if (!devsw->d_ioctl) {
		xenbus_dev_fatal(xbb->dev, ENODEV, "no d_ioctl for "
				 "device %s!", xbb->dev_name);
		return (ENODEV);
	}
	error = devsw->d_ioctl(dev, DIOCGSECTORSIZE,
			       (caddr_t)&xbb->sector_size, FREAD,
			       curthread);
	if (error) {
		xenbus_dev_fatal(xbb->dev, error,
				 "error calling ioctl DIOCGSECTORSIZE "
				 "for device %s", xbb->dev_name);
		return (error);
	}
	error = devsw->d_ioctl(dev, DIOCGMEDIASIZE,
			       (caddr_t)&xbb->media_size, FREAD,
			       curthread);
	if (error) {
		xenbus_dev_fatal(xbb->dev, error,
				 "error calling ioctl DIOCGMEDIASIZE "
				 "for device %s", xbb->dev_name);
		return (error);
	}
	return (0);
}
static int xbb_open_dev ( struct xbb_softc * xbb ) { struct vattr vattr ; struct cdev * dev ; struct cdevsw * devsw ; int error ; xbb -> device_type = XBB_TYPE_DISK ; xbb -> dispatch_io = xbb_dispatch_dev ; xbb -> backend . dev . cdev = xbb -> vn -> v_rdev ; xbb -> backend . dev . csw = dev_refthread ( xbb -> backend . dev . cdev , & xbb -> backend . dev . dev_ref ) ; if ( xbb -> backend . dev . csw == NULL ) panic ( " " ) ; error = VOP_GETATTR ( xbb -> vn , & vattr , NOCRED ) ; if ( error ) { xenbus_dev_fatal ( xbb -> dev , error , " " " " , xbb -> dev_name ) ; return ( error ) ; } dev = xbb -> vn -> v_rdev ; devsw = dev -> si_devsw ; if ( ! devsw -> d_ioctl ) { xenbus_dev_fatal ( xbb -> dev , ENODEV , " " " " , xbb -> dev_name ) ; return ( ENODEV ) ; } error = devsw -> d_ioctl ( dev , DIOCGSECTORSIZE , ( caddr_t ) & xbb -> sector_size , FREAD , curthread ) ; if ( error ) { xenbus_dev_fatal ( xbb -> dev , error , " " " " , xbb -> dev_name ) ; return ( error ) ; } error = devsw -> d_ioctl ( dev , DIOCGMEDIASIZE , ( caddr_t ) & xbb -> media_size , FREAD , curthread ) ; if ( error ) { xenbus_dev_fatal ( xbb -> dev , error , " " " " , xbb -> dev_name ) ; return ( error ) ; } return ( 0 ) ; }
Open a character device to be used for backend I/O.
Open a character device to be used for backend I / O .