1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/param.h> 31*0Sstevel@tonic-gate #include <sys/time.h> 32*0Sstevel@tonic-gate #include <sys/cred.h> 33*0Sstevel@tonic-gate #include <sys/vfs.h> 34*0Sstevel@tonic-gate #include <sys/gfs.h> 35*0Sstevel@tonic-gate #include <sys/vnode.h> 36*0Sstevel@tonic-gate #include <sys/systm.h> 37*0Sstevel@tonic-gate #include <sys/errno.h> 38*0Sstevel@tonic-gate #include <sys/sysmacros.h> 39*0Sstevel@tonic-gate #include <fs/fs_subr.h> 40*0Sstevel@tonic-gate #include <sys/contract.h> 41*0Sstevel@tonic-gate #include <sys/contract_impl.h> 42*0Sstevel@tonic-gate #include <sys/ctfs.h> 43*0Sstevel@tonic-gate #include <sys/ctfs_impl.h> 44*0Sstevel@tonic-gate #include <sys/file.h> 45*0Sstevel@tonic-gate #include <sys/pathname.h> 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* 48*0Sstevel@tonic-gate * Entries in a /system/contract/<type>/<ctid> directory. 49*0Sstevel@tonic-gate */ 50*0Sstevel@tonic-gate static gfs_dirent_t ctfs_ctls[] = { 51*0Sstevel@tonic-gate { "ctl", ctfs_create_ctlnode, GFS_CACHE_VNODE, }, 52*0Sstevel@tonic-gate { "status", ctfs_create_statnode, GFS_CACHE_VNODE }, 53*0Sstevel@tonic-gate { "events", ctfs_create_evnode }, 54*0Sstevel@tonic-gate { NULL } 55*0Sstevel@tonic-gate }; 56*0Sstevel@tonic-gate #define CTFS_NCTLS ((sizeof ctfs_ctls / sizeof (gfs_dirent_t)) - 1) 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate static ino64_t ctfs_cdir_do_inode(vnode_t *, int); 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate /* 61*0Sstevel@tonic-gate * ctfs_create_cdirnode 62*0Sstevel@tonic-gate * 63*0Sstevel@tonic-gate * If necessary, creates a cdirnode for the specified contract and 64*0Sstevel@tonic-gate * inserts it into the contract's list of vnodes. Returns either the 65*0Sstevel@tonic-gate * existing vnode or the new one. 66*0Sstevel@tonic-gate */ 67*0Sstevel@tonic-gate vnode_t * 68*0Sstevel@tonic-gate ctfs_create_cdirnode(vnode_t *pvp, contract_t *ct) 69*0Sstevel@tonic-gate { 70*0Sstevel@tonic-gate vnode_t *vp; 71*0Sstevel@tonic-gate ctfs_cdirnode_t *cdir; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate if ((vp = contract_vnode_get(ct, pvp->v_vfsp)) != NULL) 74*0Sstevel@tonic-gate return (vp); 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate vp = gfs_dir_create(sizeof (ctfs_cdirnode_t), pvp, ctfs_ops_cdir, 77*0Sstevel@tonic-gate ctfs_ctls, ctfs_cdir_do_inode, CTFS_NAME_MAX, NULL, NULL); 78*0Sstevel@tonic-gate cdir = vp->v_data; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate /* 81*0Sstevel@tonic-gate * We must set the inode because this is called explicitly rather than 82*0Sstevel@tonic-gate * through GFS callbacks. 83*0Sstevel@tonic-gate */ 84*0Sstevel@tonic-gate gfs_file_set_inode(vp, CTFS_INO_CT_DIR(ct->ct_id)); 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate cdir->ctfs_cn_contract = ct; 87*0Sstevel@tonic-gate contract_hold(ct); 88*0Sstevel@tonic-gate contract_vnode_set(ct, &cdir->ctfs_cn_linkage, vp); 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate return (vp); 91*0Sstevel@tonic-gate } 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate /* 94*0Sstevel@tonic-gate * ctfs_cdir_getattr - VOP_GETATTR entry point 95*0Sstevel@tonic-gate */ 96*0Sstevel@tonic-gate /* ARGSUSED */ 97*0Sstevel@tonic-gate static int 98*0Sstevel@tonic-gate ctfs_cdir_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr) 99*0Sstevel@tonic-gate { 100*0Sstevel@tonic-gate ctfs_cdirnode_t *cdirnode = vp->v_data; 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate vap->va_type = VDIR; 103*0Sstevel@tonic-gate vap->va_mode = 0555; 104*0Sstevel@tonic-gate vap->va_nlink = 2 + CTFS_NCTLS; 105*0Sstevel@tonic-gate vap->va_size = vap->va_nlink; 106*0Sstevel@tonic-gate vap->va_ctime = cdirnode->ctfs_cn_contract->ct_ctime; 107*0Sstevel@tonic-gate mutex_enter(&cdirnode->ctfs_cn_contract->ct_events.ctq_lock); 108*0Sstevel@tonic-gate vap->va_atime = vap->va_mtime = 109*0Sstevel@tonic-gate cdirnode->ctfs_cn_contract->ct_events.ctq_atime; 110*0Sstevel@tonic-gate mutex_exit(&cdirnode->ctfs_cn_contract->ct_events.ctq_lock); 111*0Sstevel@tonic-gate ctfs_common_getattr(vp, vap); 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate return (0); 114*0Sstevel@tonic-gate } 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate /* 117*0Sstevel@tonic-gate * ctfs_cdir_do_inode - return inode number based on static index 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate static ino64_t 120*0Sstevel@tonic-gate ctfs_cdir_do_inode(vnode_t *vp, int index) 121*0Sstevel@tonic-gate { 122*0Sstevel@tonic-gate ctfs_cdirnode_t *cdirnode = vp->v_data; 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate return (CTFS_INO_CT_FILE(cdirnode->ctfs_cn_contract->ct_id, index)); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate /* 128*0Sstevel@tonic-gate * ctfs_cdir_inactive - VOP_INACTIVE entry point 129*0Sstevel@tonic-gate */ 130*0Sstevel@tonic-gate /* ARGSUSED */ 131*0Sstevel@tonic-gate static void 132*0Sstevel@tonic-gate ctfs_cdir_inactive(vnode_t *vp, cred_t *cr) 133*0Sstevel@tonic-gate { 134*0Sstevel@tonic-gate ctfs_cdirnode_t *cdirnode = vp->v_data; 135*0Sstevel@tonic-gate contract_t *ct = cdirnode->ctfs_cn_contract; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate mutex_enter(&ct->ct_lock); 138*0Sstevel@tonic-gate if (gfs_dir_inactive(vp) == NULL) { 139*0Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 140*0Sstevel@tonic-gate return; 141*0Sstevel@tonic-gate } 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate list_remove(&ct->ct_vnodes, &cdirnode->ctfs_cn_linkage); 144*0Sstevel@tonic-gate mutex_exit(&ct->ct_lock); 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate contract_rele(ct); 147*0Sstevel@tonic-gate kmem_free(cdirnode, sizeof (ctfs_cdirnode_t)); 148*0Sstevel@tonic-gate } 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_cdir[] = { 152*0Sstevel@tonic-gate { VOPNAME_OPEN, ctfs_open }, 153*0Sstevel@tonic-gate { VOPNAME_CLOSE, ctfs_close }, 154*0Sstevel@tonic-gate { VOPNAME_IOCTL, fs_inval }, 155*0Sstevel@tonic-gate { VOPNAME_GETATTR, ctfs_cdir_getattr }, 156*0Sstevel@tonic-gate { VOPNAME_ACCESS, ctfs_access_dir }, 157*0Sstevel@tonic-gate { VOPNAME_READDIR, gfs_vop_readdir }, 158*0Sstevel@tonic-gate { VOPNAME_LOOKUP, gfs_vop_lookup }, 159*0Sstevel@tonic-gate { VOPNAME_SEEK, fs_seek }, 160*0Sstevel@tonic-gate { VOPNAME_INACTIVE, (fs_generic_func_p) ctfs_cdir_inactive }, 161*0Sstevel@tonic-gate { NULL, NULL } 162*0Sstevel@tonic-gate }; 163