xref: /titanic_52/usr/src/uts/common/sys/lofi.h (revision 3d7072f8bd27709dba14f6fe336f149d25d9e207)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3d7072f8Seschrock  * Common Development and Distribution License (the "License").
6*3d7072f8Seschrock  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*3d7072f8Seschrock  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_LOFI_H
287c478bd9Sstevel@tonic-gate #define	_SYS_LOFI_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/time.h>
347c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
357c478bd9Sstevel@tonic-gate #include <sys/vtoc.h>
367c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * /dev names:
457c478bd9Sstevel@tonic-gate  *	/dev/lofictl	- master control device
467c478bd9Sstevel@tonic-gate  *	/dev/lofi	- block devices, named by minor number
477c478bd9Sstevel@tonic-gate  *	/dev/rlofi	- character devices, named by minor number
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate #define	LOFI_DRIVER_NAME	"lofi"
507c478bd9Sstevel@tonic-gate #define	LOFI_CTL_NODE		"ctl"
517c478bd9Sstevel@tonic-gate #define	LOFI_CTL_NAME		LOFI_DRIVER_NAME LOFI_CTL_NODE
527c478bd9Sstevel@tonic-gate #define	LOFI_BLOCK_NAME		LOFI_DRIVER_NAME
537c478bd9Sstevel@tonic-gate #define	LOFI_CHAR_NAME		"r" LOFI_DRIVER_NAME
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * Use is:
587c478bd9Sstevel@tonic-gate  *	ld = open("/dev/lofictl", O_RDWR | O_EXCL);
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * lofi must be opened exclusively. Access is controlled by permissions on
617c478bd9Sstevel@tonic-gate  * the device, which is 644 by default. Write-access is required for ioctls
627c478bd9Sstevel@tonic-gate  * that change state, but only read-access is required for the ioctls that
637c478bd9Sstevel@tonic-gate  * return information. Basically, only root can add and remove files, but
647c478bd9Sstevel@tonic-gate  * non-root can look at the current lists.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * ioctl usage:
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * kernel ioctls
697c478bd9Sstevel@tonic-gate  *
707c478bd9Sstevel@tonic-gate  *	strcpy(li.li_filename, "somefilename");
717c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_MAP_FILE, &li);
727c478bd9Sstevel@tonic-gate  *	newminor = li.li_minor;
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  *	strcpy(li.li_filename, "somefilename");
757c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_UNMAP_FILE, &li);
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  *	strcpy(li.li_filename, "somefilename");
787c478bd9Sstevel@tonic-gate  *	li.li_minor = minor_number;
797c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_MAP_FILE_MINOR, &li);
807c478bd9Sstevel@tonic-gate  *
817c478bd9Sstevel@tonic-gate  *	li.li_minor = minor_number;
827c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li);
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  *	li.li_minor = minor_number;
857c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_GET_FILENAME, &li);
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  *	strcpy(li.li_filename, "somefilename");
887c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_GET_MINOR, &li);
897c478bd9Sstevel@tonic-gate  *
907c478bd9Sstevel@tonic-gate  *	li.li_minor = 0;
917c478bd9Sstevel@tonic-gate  *	ioctl(ld, LOFI_GET_MAXMINOR, &li);
927c478bd9Sstevel@tonic-gate  *	maxminor = li.li_minor;
937c478bd9Sstevel@tonic-gate  *
94*3d7072f8Seschrock  * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if
95*3d7072f8Seschrock  * the device is busy, the underlying vnode will be closed, and any subsequent
96*3d7072f8Seschrock  * operations will fail.  It will behave as if the device had been forcibly
97*3d7072f8Seschrock  * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE.  When the device
98*3d7072f8Seschrock  * is last closed, it will be torn down.
99*3d7072f8Seschrock  *
1007c478bd9Sstevel@tonic-gate  * Oh, and last but not least: these ioctls are totally private and only
1017c478bd9Sstevel@tonic-gate  * for use by lofiadm(1M).
1027c478bd9Sstevel@tonic-gate  *
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate struct lofi_ioctl {
1067c478bd9Sstevel@tonic-gate 	uint32_t 	li_minor;
107*3d7072f8Seschrock 	boolean_t	li_force;
1087c478bd9Sstevel@tonic-gate 	char	li_filename[MAXPATHLEN + 1];
1097c478bd9Sstevel@tonic-gate };
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #define	LOFI_IOC_BASE		(('L' << 16) | ('F' << 8))
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #define	LOFI_MAP_FILE		(LOFI_IOC_BASE | 0x01)
1147c478bd9Sstevel@tonic-gate #define	LOFI_MAP_FILE_MINOR	(LOFI_IOC_BASE | 0x02)
1157c478bd9Sstevel@tonic-gate #define	LOFI_UNMAP_FILE		(LOFI_IOC_BASE | 0x03)
1167c478bd9Sstevel@tonic-gate #define	LOFI_UNMAP_FILE_MINOR	(LOFI_IOC_BASE | 0x04)
1177c478bd9Sstevel@tonic-gate #define	LOFI_GET_FILENAME	(LOFI_IOC_BASE | 0x05)
1187c478bd9Sstevel@tonic-gate #define	LOFI_GET_MINOR		(LOFI_IOC_BASE | 0x06)
1197c478bd9Sstevel@tonic-gate #define	LOFI_GET_MAXMINOR	(LOFI_IOC_BASE | 0x07)
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * file types that might be usable with lofi, maybe. Only regular
1237c478bd9Sstevel@tonic-gate  * files are documented though.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	S_ISLOFIABLE(mode) \
1267c478bd9Sstevel@tonic-gate 	(S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * We limit the maximum number of active lofi devices to 128, which seems very
1327c478bd9Sstevel@tonic-gate  * large. You can tune this by changing lofi_max_files in /etc/system.
1337c478bd9Sstevel@tonic-gate  * If you change it dynamically, which you probably shouldn't do, make sure
1347c478bd9Sstevel@tonic-gate  * to only _increase_ it.
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate #define	LOFI_MAX_FILES	128
1377c478bd9Sstevel@tonic-gate extern uint32_t lofi_max_files;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define	V_ISLOFIABLE(vtype) \
1407c478bd9Sstevel@tonic-gate 	((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate struct lofi_state {
1437c478bd9Sstevel@tonic-gate 	char		*ls_filename;	/* filename to open */
1447c478bd9Sstevel@tonic-gate 	size_t		ls_filename_sz;
1457c478bd9Sstevel@tonic-gate 	struct vnode	*ls_vp;		/* open vnode */
146*3d7072f8Seschrock 	kmutex_t	ls_vp_lock;	/* protects ls_vp */
147*3d7072f8Seschrock 	kcondvar_t	ls_vp_cv;	/* signal changes to ls_vp */
148*3d7072f8Seschrock 	uint32_t	ls_vp_iocount;	/* # pending I/O requests */
149*3d7072f8Seschrock 	boolean_t	ls_vp_closereq;	/* force close requested */
1507c478bd9Sstevel@tonic-gate 	u_offset_t	ls_vp_size;
1517c478bd9Sstevel@tonic-gate 	uint32_t	ls_blk_open;
1527c478bd9Sstevel@tonic-gate 	uint32_t	ls_chr_open;
1537c478bd9Sstevel@tonic-gate 	uint32_t	ls_lyr_open_count;
1547c478bd9Sstevel@tonic-gate 	int		ls_openflag;
1557c478bd9Sstevel@tonic-gate 	taskq_t		*ls_taskq;
1567c478bd9Sstevel@tonic-gate 	kstat_t		*ls_kstat;
1577c478bd9Sstevel@tonic-gate 	kmutex_t	ls_kstat_lock;
1587c478bd9Sstevel@tonic-gate 	struct dk_geom	ls_dkg;
1597c478bd9Sstevel@tonic-gate 	struct vtoc	ls_vtoc;
1607c478bd9Sstevel@tonic-gate 	struct dk_cinfo	ls_ci;
1617c478bd9Sstevel@tonic-gate };
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #endif
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate #endif
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #endif	/* _SYS_LOFI_H */
170