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

\return  0 for success, errno codes for failure.
Open a file 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_file(struct xbb_softc *xbb)
{
	struct xbb_file_data *file_data;
	struct vattr          vattr;
	int                   error;
	file_data = &xbb->backend.file;
	xbb->device_type = XBB_TYPE_FILE;
	xbb->dispatch_io = xbb_dispatch_file;
	error = VOP_GETATTR(xbb->vn, &vattr, curthread->td_ucred);
	if (error != 0) {
		xenbus_dev_fatal(xbb->dev, error,
				 "error calling VOP_GETATTR()"
				 "for file %s", xbb->dev_name);
		return (error);
	}
	if (VOP_ISLOCKED(xbb->vn) != LK_EXCLUSIVE) {
		vn_lock(xbb->vn, LK_UPGRADE | LK_RETRY);
		if (xbb->vn->v_iflag & VI_DOOMED) {
			error = EBADF;
			xenbus_dev_fatal(xbb->dev, error,
					 "error locking file %s",
					 xbb->dev_name);
			return (error);
		}
	}
	file_data->cred = crhold(curthread->td_ucred);
	xbb->media_size = vattr.va_size;
#if 0
	xbb->sector_size = vattr.va_blocksize;
#endif
	xbb->sector_size = 512;
	if (xbb->media_size < xbb->sector_size) {
		error = EINVAL;
		xenbus_dev_fatal(xbb->dev, error,
				 "file %s size %ju < block size %u",
				 xbb->dev_name,
				 (uintmax_t)xbb->media_size,
				 xbb->sector_size);
	}
	return (error);
}
static int xbb_open_file ( struct xbb_softc * xbb ) { struct xbb_file_data * file_data ; struct vattr vattr ; int error ; file_data = & xbb -> backend . file ; xbb -> device_type = XBB_TYPE_FILE ; xbb -> dispatch_io = xbb_dispatch_file ; error = VOP_GETATTR ( xbb -> vn , & vattr , curthread -> td_ucred ) ; if ( error != 0 ) { xenbus_dev_fatal ( xbb -> dev , error , " " " " , xbb -> dev_name ) ; return ( error ) ; } if ( VOP_ISLOCKED ( xbb -> vn ) != LK_EXCLUSIVE ) { vn_lock ( xbb -> vn , LK_UPGRADE | LK_RETRY ) ; if ( xbb -> vn -> v_iflag & VI_DOOMED ) { error = EBADF ; xenbus_dev_fatal ( xbb -> dev , error , " " , xbb -> dev_name ) ; return ( error ) ; } } file_data -> cred = crhold ( curthread -> td_ucred ) ; xbb -> media_size = vattr . va_size ; #if 0 xbb -> sector_size = vattr . va_blocksize ; #endif xbb -> sector_size = 512 ; if ( xbb -> media_size < xbb -> sector_size ) { error = EINVAL ; xenbus_dev_fatal ( xbb -> dev , error , " " , xbb -> dev_name , ( uintmax_t ) xbb -> media_size , xbb -> sector_size ) ; } return ( error ) ; }
Open a file to be used for backend I/O.
Open a file to be used for backend I / O .
/*
	 * Verify that we have the ability to upgrade to exclusive
	 * access on this file so we can trap errors at open instead
	 * of reporting them during first access.
	 */ /*
	 * XXX KDM vattr.va_blocksize may be larger than 512 bytes here.
	 * With ZFS, it is 131072 bytes.  Block sizes that large don't work
	 * with disklabel and UFS on FreeBSD at least.  Large block sizes
	 * may not work with other OSes as well.  So just export a sector
	 * size of 512 bytes, which should work with any OS or
	 * application.  Since our backing is a file, any block size will
	 * work fine for the backing store.
	 */ /*
	 * Sanity check.  The media size has to be at least one
	 * sector long.
	 */