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 53898Srsb * Common Development and Distribution License (the "License"). 63898Srsb * 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 /* 223898Srsb * 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 #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/param.h> 300Sstevel@tonic-gate #include <sys/time.h> 310Sstevel@tonic-gate #include <sys/cred.h> 320Sstevel@tonic-gate #include <sys/vfs.h> 333898Srsb #include <sys/vfs_opreg.h> 340Sstevel@tonic-gate #include <sys/gfs.h> 350Sstevel@tonic-gate #include <sys/vnode.h> 360Sstevel@tonic-gate #include <sys/systm.h> 370Sstevel@tonic-gate #include <sys/errno.h> 380Sstevel@tonic-gate #include <sys/sysmacros.h> 390Sstevel@tonic-gate #include <fs/fs_subr.h> 400Sstevel@tonic-gate #include <sys/contract.h> 410Sstevel@tonic-gate #include <sys/contract_impl.h> 420Sstevel@tonic-gate #include <sys/ctfs.h> 430Sstevel@tonic-gate #include <sys/ctfs_impl.h> 440Sstevel@tonic-gate #include <sys/file.h> 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* 470Sstevel@tonic-gate * CTFS routines for the /system/contract/<type>/template vnode. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * ctfs_create_tmplnode 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * Creates a new template and tdirnode, and returns the tdirnode. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate vnode_t * 560Sstevel@tonic-gate ctfs_create_tmplnode(vnode_t *pvp) 570Sstevel@tonic-gate { 580Sstevel@tonic-gate vnode_t *vp; 590Sstevel@tonic-gate ctfs_tmplnode_t *tmplnode; 600Sstevel@tonic-gate 610Sstevel@tonic-gate ASSERT(gfs_file_index(pvp) < ct_ntypes); 620Sstevel@tonic-gate 630Sstevel@tonic-gate vp = gfs_file_create(sizeof (ctfs_tmplnode_t), pvp, ctfs_ops_tmpl); 640Sstevel@tonic-gate tmplnode = vp->v_data; 650Sstevel@tonic-gate tmplnode->ctfs_tmn_tmpl = 660Sstevel@tonic-gate ct_types[gfs_file_index(pvp)]->ct_type_default(); 670Sstevel@tonic-gate 680Sstevel@tonic-gate return (vp); 690Sstevel@tonic-gate } 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * ctfs_tmpl_open - VOP_OPEN entry point 730Sstevel@tonic-gate * 740Sstevel@tonic-gate * Just ensures the right mode bits are set. 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate /* ARGSUSED */ 770Sstevel@tonic-gate static int 780Sstevel@tonic-gate ctfs_tmpl_open(vnode_t **vpp, int flag, cred_t *cr) 790Sstevel@tonic-gate { 800Sstevel@tonic-gate if (flag != (FREAD | FWRITE | FOFFMAX)) 810Sstevel@tonic-gate return (EINVAL); 820Sstevel@tonic-gate 830Sstevel@tonic-gate return (0); 840Sstevel@tonic-gate } 850Sstevel@tonic-gate 860Sstevel@tonic-gate /* 870Sstevel@tonic-gate * ctfs_tmpl_getattr - VOP_GETATTR entry point 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate /* ARGSUSED */ 900Sstevel@tonic-gate static int 910Sstevel@tonic-gate ctfs_tmpl_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr) 920Sstevel@tonic-gate { 930Sstevel@tonic-gate vap->va_type = VREG; 940Sstevel@tonic-gate vap->va_mode = 0666; 950Sstevel@tonic-gate vap->va_nlink = 1; 960Sstevel@tonic-gate vap->va_size = 0; 970Sstevel@tonic-gate vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime; 980Sstevel@tonic-gate vap->va_ctime.tv_nsec = 0; 990Sstevel@tonic-gate vap->va_atime = vap->va_mtime = vap->va_ctime; 1000Sstevel@tonic-gate ctfs_common_getattr(vp, vap); 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate return (0); 1030Sstevel@tonic-gate } 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * ctfs_tmpl_ioctl - VOP_IOCTL entry point 1070Sstevel@tonic-gate * 1080Sstevel@tonic-gate * All the ct_tmpl_*(3contract) interfaces point here. 1090Sstevel@tonic-gate */ 1100Sstevel@tonic-gate /* ARGSUSED */ 1110Sstevel@tonic-gate static int 1120Sstevel@tonic-gate ctfs_tmpl_ioctl(vnode_t *vp, int cmd, intptr_t arg, int flag, cred_t *cr, 1130Sstevel@tonic-gate int *rvalp) 1140Sstevel@tonic-gate { 1150Sstevel@tonic-gate ctfs_tmplnode_t *tmplnode = vp->v_data; 1160Sstevel@tonic-gate ct_param_t param; 117*4845Svikram ctid_t ctid; 1180Sstevel@tonic-gate int error; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate switch (cmd) { 1210Sstevel@tonic-gate case CT_TACTIVATE: 1220Sstevel@tonic-gate ASSERT(tmplnode->ctfs_tmn_tmpl != NULL); 1230Sstevel@tonic-gate ctmpl_activate(tmplnode->ctfs_tmn_tmpl); 1240Sstevel@tonic-gate break; 1250Sstevel@tonic-gate case CT_TCLEAR: 1260Sstevel@tonic-gate ASSERT(tmplnode->ctfs_tmn_tmpl != NULL); 1270Sstevel@tonic-gate ctmpl_clear(tmplnode->ctfs_tmn_tmpl); 1280Sstevel@tonic-gate break; 1290Sstevel@tonic-gate case CT_TCREATE: 1300Sstevel@tonic-gate ASSERT(tmplnode->ctfs_tmn_tmpl != NULL); 131*4845Svikram error = ctmpl_create(tmplnode->ctfs_tmn_tmpl, &ctid); 132*4845Svikram if (error) 133*4845Svikram return (error); 134*4845Svikram *rvalp = ctid; 135*4845Svikram break; 1360Sstevel@tonic-gate case CT_TSET: 1370Sstevel@tonic-gate if (copyin((void *)arg, ¶m, sizeof (ct_param_t))) 1380Sstevel@tonic-gate return (EFAULT); 1390Sstevel@tonic-gate return (ctmpl_set(tmplnode->ctfs_tmn_tmpl, ¶m, cr)); 1400Sstevel@tonic-gate case CT_TGET: 1410Sstevel@tonic-gate if (copyin((void *)arg, ¶m, sizeof (ct_param_t))) 1420Sstevel@tonic-gate return (EFAULT); 1430Sstevel@tonic-gate error = ctmpl_get(tmplnode->ctfs_tmn_tmpl, ¶m); 1440Sstevel@tonic-gate if (error) 1450Sstevel@tonic-gate return (error); 1460Sstevel@tonic-gate if (copyout(¶m, (void *)arg, sizeof (ct_param_t))) 1470Sstevel@tonic-gate return (EFAULT); 1480Sstevel@tonic-gate break; 1490Sstevel@tonic-gate default: 1500Sstevel@tonic-gate return (EINVAL); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate return (0); 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* 1570Sstevel@tonic-gate * ctfs_tmpl_inactive - VOP_INACTIVE entry point 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate /* ARGSUSED */ 1600Sstevel@tonic-gate static void 1610Sstevel@tonic-gate ctfs_tmpl_inactive(vnode_t *vp, cred_t *cr) 1620Sstevel@tonic-gate { 1630Sstevel@tonic-gate ctfs_tmplnode_t *tmplnode; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate if ((tmplnode = gfs_file_inactive(vp)) != NULL) { 1660Sstevel@tonic-gate ctmpl_free(tmplnode->ctfs_tmn_tmpl); 1670Sstevel@tonic-gate kmem_free(tmplnode, sizeof (ctfs_tmplnode_t)); 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate } 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_tmpl[] = { 1723898Srsb { VOPNAME_OPEN, { .vop_open = ctfs_tmpl_open } }, 1733898Srsb { VOPNAME_CLOSE, { .vop_close = ctfs_close } }, 1743898Srsb { VOPNAME_IOCTL, { .vop_ioctl = ctfs_tmpl_ioctl } }, 1753898Srsb { VOPNAME_GETATTR, { .vop_getattr = ctfs_tmpl_getattr } }, 1763898Srsb { VOPNAME_ACCESS, { .vop_access = ctfs_access_readwrite } }, 1773898Srsb { VOPNAME_READDIR, { .error = fs_notdir } }, 1783898Srsb { VOPNAME_LOOKUP, { .error = fs_notdir } }, 1793898Srsb { VOPNAME_INACTIVE, { .vop_inactive = ctfs_tmpl_inactive } }, 1800Sstevel@tonic-gate { NULL, NULL } 1810Sstevel@tonic-gate }; 182