10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*4451Seschrock * Common Development and Distribution License (the "License"). 6*4451Seschrock * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*4451Seschrock * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_LOFI_H 280Sstevel@tonic-gate #define _SYS_LOFI_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/time.h> 340Sstevel@tonic-gate #include <sys/taskq.h> 350Sstevel@tonic-gate #include <sys/vtoc.h> 360Sstevel@tonic-gate #include <sys/dkio.h> 370Sstevel@tonic-gate #include <sys/vnode.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef __cplusplus 400Sstevel@tonic-gate extern "C" { 410Sstevel@tonic-gate #endif 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * /dev names: 450Sstevel@tonic-gate * /dev/lofictl - master control device 460Sstevel@tonic-gate * /dev/lofi - block devices, named by minor number 470Sstevel@tonic-gate * /dev/rlofi - character devices, named by minor number 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate #define LOFI_DRIVER_NAME "lofi" 500Sstevel@tonic-gate #define LOFI_CTL_NODE "ctl" 510Sstevel@tonic-gate #define LOFI_CTL_NAME LOFI_DRIVER_NAME LOFI_CTL_NODE 520Sstevel@tonic-gate #define LOFI_BLOCK_NAME LOFI_DRIVER_NAME 530Sstevel@tonic-gate #define LOFI_CHAR_NAME "r" LOFI_DRIVER_NAME 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * 570Sstevel@tonic-gate * Use is: 580Sstevel@tonic-gate * ld = open("/dev/lofictl", O_RDWR | O_EXCL); 590Sstevel@tonic-gate * 600Sstevel@tonic-gate * lofi must be opened exclusively. Access is controlled by permissions on 610Sstevel@tonic-gate * the device, which is 644 by default. Write-access is required for ioctls 620Sstevel@tonic-gate * that change state, but only read-access is required for the ioctls that 630Sstevel@tonic-gate * return information. Basically, only root can add and remove files, but 640Sstevel@tonic-gate * non-root can look at the current lists. 650Sstevel@tonic-gate * 660Sstevel@tonic-gate * ioctl usage: 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * kernel ioctls 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 710Sstevel@tonic-gate * ioctl(ld, LOFI_MAP_FILE, &li); 720Sstevel@tonic-gate * newminor = li.li_minor; 730Sstevel@tonic-gate * 740Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 750Sstevel@tonic-gate * ioctl(ld, LOFI_UNMAP_FILE, &li); 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 780Sstevel@tonic-gate * li.li_minor = minor_number; 790Sstevel@tonic-gate * ioctl(ld, LOFI_MAP_FILE_MINOR, &li); 800Sstevel@tonic-gate * 810Sstevel@tonic-gate * li.li_minor = minor_number; 820Sstevel@tonic-gate * ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li); 830Sstevel@tonic-gate * 840Sstevel@tonic-gate * li.li_minor = minor_number; 850Sstevel@tonic-gate * ioctl(ld, LOFI_GET_FILENAME, &li); 860Sstevel@tonic-gate * 870Sstevel@tonic-gate * strcpy(li.li_filename, "somefilename"); 880Sstevel@tonic-gate * ioctl(ld, LOFI_GET_MINOR, &li); 890Sstevel@tonic-gate * 900Sstevel@tonic-gate * li.li_minor = 0; 910Sstevel@tonic-gate * ioctl(ld, LOFI_GET_MAXMINOR, &li); 920Sstevel@tonic-gate * maxminor = li.li_minor; 930Sstevel@tonic-gate * 94*4451Seschrock * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if 95*4451Seschrock * the device is busy, the underlying vnode will be closed, and any subsequent 96*4451Seschrock * operations will fail. It will behave as if the device had been forcibly 97*4451Seschrock * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE. When the device 98*4451Seschrock * is last closed, it will be torn down. 99*4451Seschrock * 1000Sstevel@tonic-gate * Oh, and last but not least: these ioctls are totally private and only 1010Sstevel@tonic-gate * for use by lofiadm(1M). 1020Sstevel@tonic-gate * 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate struct lofi_ioctl { 106*4451Seschrock uint32_t li_minor; 107*4451Seschrock boolean_t li_force; 1080Sstevel@tonic-gate char li_filename[MAXPATHLEN + 1]; 1090Sstevel@tonic-gate }; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate #define LOFI_IOC_BASE (('L' << 16) | ('F' << 8)) 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #define LOFI_MAP_FILE (LOFI_IOC_BASE | 0x01) 1140Sstevel@tonic-gate #define LOFI_MAP_FILE_MINOR (LOFI_IOC_BASE | 0x02) 1150Sstevel@tonic-gate #define LOFI_UNMAP_FILE (LOFI_IOC_BASE | 0x03) 1160Sstevel@tonic-gate #define LOFI_UNMAP_FILE_MINOR (LOFI_IOC_BASE | 0x04) 1170Sstevel@tonic-gate #define LOFI_GET_FILENAME (LOFI_IOC_BASE | 0x05) 1180Sstevel@tonic-gate #define LOFI_GET_MINOR (LOFI_IOC_BASE | 0x06) 1190Sstevel@tonic-gate #define LOFI_GET_MAXMINOR (LOFI_IOC_BASE | 0x07) 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * file types that might be usable with lofi, maybe. Only regular 1230Sstevel@tonic-gate * files are documented though. 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate #define S_ISLOFIABLE(mode) \ 1260Sstevel@tonic-gate (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode)) 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate #if defined(_KERNEL) 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * We limit the maximum number of active lofi devices to 128, which seems very 1320Sstevel@tonic-gate * large. You can tune this by changing lofi_max_files in /etc/system. 1330Sstevel@tonic-gate * If you change it dynamically, which you probably shouldn't do, make sure 1340Sstevel@tonic-gate * to only _increase_ it. 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate #define LOFI_MAX_FILES 128 1370Sstevel@tonic-gate extern uint32_t lofi_max_files; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate #define V_ISLOFIABLE(vtype) \ 1400Sstevel@tonic-gate ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR)) 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate struct lofi_state { 143*4451Seschrock char *ls_filename; /* filename to open */ 144*4451Seschrock size_t ls_filename_sz; 145*4451Seschrock struct vnode *ls_vp; /* open vnode */ 146*4451Seschrock kmutex_t ls_vp_lock; /* protects ls_vp */ 147*4451Seschrock kcondvar_t ls_vp_cv; /* signal changes to ls_vp */ 148*4451Seschrock uint32_t ls_vp_iocount; /* # pending I/O requests */ 149*4451Seschrock boolean_t ls_vp_closereq; /* force close requested */ 1500Sstevel@tonic-gate u_offset_t ls_vp_size; 1510Sstevel@tonic-gate uint32_t ls_blk_open; 1520Sstevel@tonic-gate uint32_t ls_chr_open; 1530Sstevel@tonic-gate uint32_t ls_lyr_open_count; 1540Sstevel@tonic-gate int ls_openflag; 1550Sstevel@tonic-gate taskq_t *ls_taskq; 1560Sstevel@tonic-gate kstat_t *ls_kstat; 1570Sstevel@tonic-gate kmutex_t ls_kstat_lock; 1580Sstevel@tonic-gate struct dk_geom ls_dkg; 1590Sstevel@tonic-gate struct vtoc ls_vtoc; 1600Sstevel@tonic-gate struct dk_cinfo ls_ci; 1610Sstevel@tonic-gate }; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate #endif 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate #ifdef __cplusplus 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate #endif 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #endif /* _SYS_LOFI_H */ 170