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 #include <sys/cmn_err.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate * CTFS routines for the /system/contract/all/<ctid> vnode.
490Sstevel@tonic-gate */
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * ctfs_create_symnode
530Sstevel@tonic-gate *
540Sstevel@tonic-gate * Creates and returns a symnode for the specified contract.
550Sstevel@tonic-gate */
560Sstevel@tonic-gate vnode_t *
ctfs_create_symnode(vnode_t * pvp,contract_t * ct)570Sstevel@tonic-gate ctfs_create_symnode(vnode_t *pvp, contract_t *ct)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate ctfs_symnode_t *symnode;
600Sstevel@tonic-gate vnode_t *vp;
610Sstevel@tonic-gate size_t len;
620Sstevel@tonic-gate
630Sstevel@tonic-gate vp = gfs_file_create(sizeof (ctfs_symnode_t), pvp, ctfs_ops_sym);
640Sstevel@tonic-gate vp->v_type = VLNK;
650Sstevel@tonic-gate symnode = vp->v_data;
660Sstevel@tonic-gate
670Sstevel@tonic-gate symnode->ctfs_sn_contract = ct;
680Sstevel@tonic-gate symnode->ctfs_sn_size = len = snprintf(NULL, 0, "../%s/%ld",
690Sstevel@tonic-gate ct->ct_type->ct_type_name, (long)ct->ct_id) + 1;
700Sstevel@tonic-gate symnode->ctfs_sn_string = kmem_alloc(len, KM_SLEEP);
710Sstevel@tonic-gate VERIFY(snprintf(symnode->ctfs_sn_string, len, "../%s/%ld",
720Sstevel@tonic-gate ct->ct_type->ct_type_name, (long)ct->ct_id) < len);
730Sstevel@tonic-gate
740Sstevel@tonic-gate contract_hold(ct);
750Sstevel@tonic-gate
760Sstevel@tonic-gate return (vp);
770Sstevel@tonic-gate }
780Sstevel@tonic-gate
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate * ctfs_sym_getattr - VOP_GETATTR entry point
810Sstevel@tonic-gate */
820Sstevel@tonic-gate /* ARGSUSED */
830Sstevel@tonic-gate static int
ctfs_sym_getattr(vnode_t * vp,vattr_t * vap,int flags,cred_t * cr,caller_context_t * ct)84*5331Samw ctfs_sym_getattr(
85*5331Samw vnode_t *vp,
86*5331Samw vattr_t *vap,
87*5331Samw int flags,
88*5331Samw cred_t *cr,
89*5331Samw caller_context_t *ct)
900Sstevel@tonic-gate {
910Sstevel@tonic-gate ctfs_symnode_t *symnode = vp->v_data;
920Sstevel@tonic-gate
930Sstevel@tonic-gate vap->va_type = VLNK;
940Sstevel@tonic-gate vap->va_mode = 0444;
950Sstevel@tonic-gate vap->va_nlink = 1;
960Sstevel@tonic-gate vap->va_size = symnode->ctfs_sn_size - 1;
970Sstevel@tonic-gate vap->va_mtime = vap->va_atime = vap->va_ctime =
980Sstevel@tonic-gate symnode->ctfs_sn_contract->ct_ctime;
990Sstevel@tonic-gate ctfs_common_getattr(vp, vap);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate return (0);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate /*
1050Sstevel@tonic-gate * ctfs_sym_readlink - VOP_READLINK entry point
1060Sstevel@tonic-gate *
1070Sstevel@tonic-gate * Since we built the symlink string in ctfs_create_symnode, this is
1080Sstevel@tonic-gate * just a uiomove.
1090Sstevel@tonic-gate */
1100Sstevel@tonic-gate /* ARGSUSED */
1110Sstevel@tonic-gate int
ctfs_sym_readlink(vnode_t * vp,uio_t * uiop,cred_t * cr,caller_context_t * ct)112*5331Samw ctfs_sym_readlink(vnode_t *vp, uio_t *uiop, cred_t *cr, caller_context_t *ct)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate ctfs_symnode_t *symnode = vp->v_data;
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate return (uiomove(symnode->ctfs_sn_string, symnode->ctfs_sn_size - 1,
1170Sstevel@tonic-gate UIO_READ, uiop));
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate /*
1210Sstevel@tonic-gate * ctfs_sym_inactive - VOP_INACTIVE entry point
1220Sstevel@tonic-gate */
1230Sstevel@tonic-gate /* ARGSUSED */
1240Sstevel@tonic-gate static void
ctfs_sym_inactive(vnode_t * vp,cred_t * cr,caller_context_t * ct)125*5331Samw ctfs_sym_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate ctfs_symnode_t *symnode;
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate if ((symnode = gfs_file_inactive(vp)) != NULL) {
1300Sstevel@tonic-gate contract_rele(symnode->ctfs_sn_contract);
1310Sstevel@tonic-gate kmem_free(symnode->ctfs_sn_string, symnode->ctfs_sn_size);
1320Sstevel@tonic-gate kmem_free(symnode, sizeof (ctfs_symnode_t));
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_sym[] = {
1373898Srsb { VOPNAME_OPEN, { .vop_open = ctfs_open } },
1383898Srsb { VOPNAME_CLOSE, { .vop_close = ctfs_close } },
1393898Srsb { VOPNAME_IOCTL, { .error = fs_inval } },
1403898Srsb { VOPNAME_GETATTR, { .vop_getattr = ctfs_sym_getattr } },
1413898Srsb { VOPNAME_READLINK, { .vop_readlink = ctfs_sym_readlink } },
1423898Srsb { VOPNAME_ACCESS, { .vop_access = ctfs_access_readonly } },
1433898Srsb { VOPNAME_READDIR, { .error = fs_notdir } },
1443898Srsb { VOPNAME_LOOKUP, { .error = fs_notdir } },
1453898Srsb { VOPNAME_INACTIVE, { .vop_inactive = ctfs_sym_inactive } },
1460Sstevel@tonic-gate { NULL, NULL }
1470Sstevel@tonic-gate };
148