xref: /titanic_50/usr/src/uts/common/sys/lofi.h (revision bf56214c0556fa6864189c826d39dbe156bb22a0)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 #ifndef	_SYS_LOFI_H
28 #define	_SYS_LOFI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <sys/taskq.h>
35 #include <sys/vtoc.h>
36 #include <sys/dkio.h>
37 #include <sys/vnode.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * /dev names:
45  *	/dev/lofictl	- master control device
46  *	/dev/lofi	- block devices, named by minor number
47  *	/dev/rlofi	- character devices, named by minor number
48  */
49 #define	LOFI_DRIVER_NAME	"lofi"
50 #define	LOFI_CTL_NODE		"ctl"
51 #define	LOFI_CTL_NAME		LOFI_DRIVER_NAME LOFI_CTL_NODE
52 #define	LOFI_BLOCK_NAME		LOFI_DRIVER_NAME
53 #define	LOFI_CHAR_NAME		"r" LOFI_DRIVER_NAME
54 
55 /*
56  *
57  * Use is:
58  *	ld = open("/dev/lofictl", O_RDWR | O_EXCL);
59  *
60  * lofi must be opened exclusively. Access is controlled by permissions on
61  * the device, which is 644 by default. Write-access is required for ioctls
62  * that change state, but only read-access is required for the ioctls that
63  * return information. Basically, only root can add and remove files, but
64  * non-root can look at the current lists.
65  *
66  * ioctl usage:
67  *
68  * kernel ioctls
69  *
70  *	strcpy(li.li_filename, "somefilename");
71  *	ioctl(ld, LOFI_MAP_FILE, &li);
72  *	newminor = li.li_minor;
73  *
74  *	strcpy(li.li_filename, "somefilename");
75  *	ioctl(ld, LOFI_UNMAP_FILE, &li);
76  *
77  *	strcpy(li.li_filename, "somefilename");
78  *	li.li_minor = minor_number;
79  *	ioctl(ld, LOFI_MAP_FILE_MINOR, &li);
80  *
81  *	li.li_minor = minor_number;
82  *	ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li);
83  *
84  *	li.li_minor = minor_number;
85  *	ioctl(ld, LOFI_GET_FILENAME, &li);
86  *
87  *	strcpy(li.li_filename, "somefilename");
88  *	ioctl(ld, LOFI_GET_MINOR, &li);
89  *
90  *	li.li_minor = 0;
91  *	ioctl(ld, LOFI_GET_MAXMINOR, &li);
92  *	maxminor = li.li_minor;
93  *
94  * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if
95  * the device is busy, the underlying vnode will be closed, and any subsequent
96  * operations will fail.  It will behave as if the device had been forcibly
97  * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE.  When the device
98  * is last closed, it will be torn down.
99  *
100  * Oh, and last but not least: these ioctls are totally private and only
101  * for use by lofiadm(1M).
102  *
103  */
104 
105 struct lofi_ioctl {
106 	uint32_t 	li_minor;
107 	boolean_t	li_force;
108 	char	li_filename[MAXPATHLEN + 1];
109 };
110 
111 #define	LOFI_IOC_BASE		(('L' << 16) | ('F' << 8))
112 
113 #define	LOFI_MAP_FILE		(LOFI_IOC_BASE | 0x01)
114 #define	LOFI_MAP_FILE_MINOR	(LOFI_IOC_BASE | 0x02)
115 #define	LOFI_UNMAP_FILE		(LOFI_IOC_BASE | 0x03)
116 #define	LOFI_UNMAP_FILE_MINOR	(LOFI_IOC_BASE | 0x04)
117 #define	LOFI_GET_FILENAME	(LOFI_IOC_BASE | 0x05)
118 #define	LOFI_GET_MINOR		(LOFI_IOC_BASE | 0x06)
119 #define	LOFI_GET_MAXMINOR	(LOFI_IOC_BASE | 0x07)
120 
121 /*
122  * file types that might be usable with lofi, maybe. Only regular
123  * files are documented though.
124  */
125 #define	S_ISLOFIABLE(mode) \
126 	(S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
127 
128 #if defined(_KERNEL)
129 
130 /*
131  * We limit the maximum number of active lofi devices to 128, which seems very
132  * large. You can tune this by changing lofi_max_files in /etc/system.
133  * If you change it dynamically, which you probably shouldn't do, make sure
134  * to only _increase_ it.
135  */
136 #define	LOFI_MAX_FILES	128
137 extern uint32_t lofi_max_files;
138 
139 #define	V_ISLOFIABLE(vtype) \
140 	((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
141 
142 struct lofi_state {
143 	char		*ls_filename;	/* filename to open */
144 	size_t		ls_filename_sz;
145 	struct vnode	*ls_vp;		/* open vnode */
146 	kmutex_t	ls_vp_lock;	/* protects ls_vp */
147 	kcondvar_t	ls_vp_cv;	/* signal changes to ls_vp */
148 	uint32_t	ls_vp_iocount;	/* # pending I/O requests */
149 	boolean_t	ls_vp_closereq;	/* force close requested */
150 	u_offset_t	ls_vp_size;
151 	uint32_t	ls_blk_open;
152 	uint32_t	ls_chr_open;
153 	uint32_t	ls_lyr_open_count;
154 	int		ls_openflag;
155 	taskq_t		*ls_taskq;
156 	kstat_t		*ls_kstat;
157 	kmutex_t	ls_kstat_lock;
158 	struct dk_geom	ls_dkg;
159 	struct vtoc	ls_vtoc;
160 	struct dk_cinfo	ls_ci;
161 };
162 
163 #endif
164 
165 #ifdef	__cplusplus
166 }
167 #endif
168 
169 #endif	/* _SYS_LOFI_H */
170