xref: /titanic_51/usr/src/uts/common/fs/ctfs/ctfs_sym.c (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5aa59c4cbSrsb  * Common Development and Distribution License (the "License").
6aa59c4cbSrsb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22aa59c4cbSrsb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/time.h>
317c478bd9Sstevel@tonic-gate #include <sys/cred.h>
327c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
33aa59c4cbSrsb #include <sys/vfs_opreg.h>
347c478bd9Sstevel@tonic-gate #include <sys/gfs.h>
357c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
367c478bd9Sstevel@tonic-gate #include <sys/systm.h>
377c478bd9Sstevel@tonic-gate #include <sys/errno.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
407c478bd9Sstevel@tonic-gate #include <sys/contract.h>
417c478bd9Sstevel@tonic-gate #include <sys/contract_impl.h>
427c478bd9Sstevel@tonic-gate #include <sys/ctfs.h>
437c478bd9Sstevel@tonic-gate #include <sys/ctfs_impl.h>
447c478bd9Sstevel@tonic-gate #include <sys/file.h>
457c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * CTFS routines for the /system/contract/all/<ctid> vnode.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * ctfs_create_symnode
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * Creates and returns a symnode for the specified contract.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate vnode_t *
577c478bd9Sstevel@tonic-gate ctfs_create_symnode(vnode_t *pvp, contract_t *ct)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	ctfs_symnode_t *symnode;
607c478bd9Sstevel@tonic-gate 	vnode_t *vp;
617c478bd9Sstevel@tonic-gate 	size_t len;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	vp = gfs_file_create(sizeof (ctfs_symnode_t), pvp, ctfs_ops_sym);
647c478bd9Sstevel@tonic-gate 	vp->v_type = VLNK;
657c478bd9Sstevel@tonic-gate 	symnode = vp->v_data;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	symnode->ctfs_sn_contract = ct;
687c478bd9Sstevel@tonic-gate 	symnode->ctfs_sn_size = len = snprintf(NULL, 0, "../%s/%ld",
697c478bd9Sstevel@tonic-gate 	    ct->ct_type->ct_type_name, (long)ct->ct_id) + 1;
707c478bd9Sstevel@tonic-gate 	symnode->ctfs_sn_string = kmem_alloc(len, KM_SLEEP);
717c478bd9Sstevel@tonic-gate 	VERIFY(snprintf(symnode->ctfs_sn_string, len, "../%s/%ld",
727c478bd9Sstevel@tonic-gate 	    ct->ct_type->ct_type_name, (long)ct->ct_id) < len);
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	contract_hold(ct);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	return (vp);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * ctfs_sym_getattr - VOP_GETATTR entry point
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate /* ARGSUSED */
837c478bd9Sstevel@tonic-gate static int
84*da6c28aaSamw ctfs_sym_getattr(
85*da6c28aaSamw 	vnode_t *vp,
86*da6c28aaSamw 	vattr_t *vap,
87*da6c28aaSamw 	int flags,
88*da6c28aaSamw 	cred_t *cr,
89*da6c28aaSamw 	caller_context_t *ct)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 	ctfs_symnode_t *symnode = vp->v_data;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	vap->va_type = VLNK;
947c478bd9Sstevel@tonic-gate 	vap->va_mode = 0444;
957c478bd9Sstevel@tonic-gate 	vap->va_nlink = 1;
967c478bd9Sstevel@tonic-gate 	vap->va_size = symnode->ctfs_sn_size - 1;
977c478bd9Sstevel@tonic-gate 	vap->va_mtime = vap->va_atime = vap->va_ctime =
987c478bd9Sstevel@tonic-gate 	    symnode->ctfs_sn_contract->ct_ctime;
997c478bd9Sstevel@tonic-gate 	ctfs_common_getattr(vp, vap);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	return (0);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * ctfs_sym_readlink - VOP_READLINK entry point
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  * Since we built the symlink string in ctfs_create_symnode, this is
1087c478bd9Sstevel@tonic-gate  * just a uiomove.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate /* ARGSUSED */
1117c478bd9Sstevel@tonic-gate int
112*da6c28aaSamw ctfs_sym_readlink(vnode_t *vp, uio_t *uiop, cred_t *cr, caller_context_t *ct)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate 	ctfs_symnode_t *symnode = vp->v_data;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	return (uiomove(symnode->ctfs_sn_string, symnode->ctfs_sn_size - 1,
1177c478bd9Sstevel@tonic-gate 	    UIO_READ, uiop));
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * ctfs_sym_inactive - VOP_INACTIVE entry point
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate /* ARGSUSED */
1247c478bd9Sstevel@tonic-gate static void
125*da6c28aaSamw ctfs_sym_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	ctfs_symnode_t *symnode;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	if ((symnode = gfs_file_inactive(vp)) != NULL) {
1307c478bd9Sstevel@tonic-gate 		contract_rele(symnode->ctfs_sn_contract);
1317c478bd9Sstevel@tonic-gate 		kmem_free(symnode->ctfs_sn_string, symnode->ctfs_sn_size);
1327c478bd9Sstevel@tonic-gate 		kmem_free(symnode, sizeof (ctfs_symnode_t));
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate const fs_operation_def_t ctfs_tops_sym[] = {
137aa59c4cbSrsb 	{ VOPNAME_OPEN,		{ .vop_open = ctfs_open } },
138aa59c4cbSrsb 	{ VOPNAME_CLOSE,	{ .vop_close = ctfs_close } },
139aa59c4cbSrsb 	{ VOPNAME_IOCTL,	{ .error = fs_inval } },
140aa59c4cbSrsb 	{ VOPNAME_GETATTR,	{ .vop_getattr = ctfs_sym_getattr } },
141aa59c4cbSrsb 	{ VOPNAME_READLINK,	{ .vop_readlink = ctfs_sym_readlink } },
142aa59c4cbSrsb 	{ VOPNAME_ACCESS,	{ .vop_access = ctfs_access_readonly } },
143aa59c4cbSrsb 	{ VOPNAME_READDIR,	{ .error = fs_notdir } },
144aa59c4cbSrsb 	{ VOPNAME_LOOKUP,	{ .error = fs_notdir } },
145aa59c4cbSrsb 	{ VOPNAME_INACTIVE,	{ .vop_inactive = ctfs_sym_inactive } },
1467c478bd9Sstevel@tonic-gate 	{ NULL, NULL }
1477c478bd9Sstevel@tonic-gate };
148