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