xref: /illumos-gate/usr/src/uts/common/sys/fs/tmp.h (revision 401bc9af)
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
5da6c28aaSamw  * Common Development and Distribution License (the "License").
6da6c28aaSamw  * 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 /*
22da6c28aaSamw  * Copyright 2007 Sun Microsystems, Inc.
237c478bd9Sstevel@tonic-gate  * All rights reserved.  Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25*401bc9afSJoshua M. Clulow /*
26*401bc9afSJoshua M. Clulow  * Copyright 2015 Joyent, Inc.
27*401bc9afSJoshua M. Clulow  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_FS_TMP_H
307c478bd9Sstevel@tonic-gate #define	_SYS_FS_TMP_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * tmpfs per-mount data structure.
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * All fields are protected by tm_contents.
407c478bd9Sstevel@tonic-gate  * File renames on a particular file system are protected tm_renamelck.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate struct tmount {
437c478bd9Sstevel@tonic-gate 	struct vfs	*tm_vfsp;	/* filesystem's vfs struct */
447c478bd9Sstevel@tonic-gate 	struct tmpnode	*tm_rootnode;	/* root tmpnode */
457c478bd9Sstevel@tonic-gate 	char 		*tm_mntpath;	/* name of tmpfs mount point */
467c478bd9Sstevel@tonic-gate 	ulong_t		tm_anonmax;	/* file system max anon reservation */
477c478bd9Sstevel@tonic-gate 	pgcnt_t		tm_anonmem;	/* pages of reserved anon memory */
487c478bd9Sstevel@tonic-gate 	dev_t		tm_dev;		/* unique dev # of mounted `device' */
497c478bd9Sstevel@tonic-gate 	uint_t		tm_gen;		/* pseudo generation number for files */
507c478bd9Sstevel@tonic-gate 	kmutex_t	tm_contents;	/* lock for tmount structure */
517c478bd9Sstevel@tonic-gate 	kmutex_t	tm_renamelck;	/* rename lock for this mount */
527c478bd9Sstevel@tonic-gate };
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * File system independent to tmpfs conversion macros
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate #define	VFSTOTM(vfsp)		((struct tmount *)(vfsp)->vfs_data)
587c478bd9Sstevel@tonic-gate #define	VTOTM(vp)		((struct tmount *)(vp)->v_vfsp->vfs_data)
597c478bd9Sstevel@tonic-gate #define	VTOTN(vp)		((struct tmpnode *)(vp)->v_data)
607c478bd9Sstevel@tonic-gate #define	TNTOV(tp)		((tp)->tn_vnode)
617c478bd9Sstevel@tonic-gate #define	tmpnode_hold(tp)	VN_HOLD(TNTOV(tp))
627c478bd9Sstevel@tonic-gate #define	tmpnode_rele(tp)	VN_RELE(TNTOV(tp))
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * enums
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate enum de_op	{ DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME }; /* direnter ops */
687c478bd9Sstevel@tonic-gate enum dr_op	{ DR_REMOVE, DR_RMDIR, DR_RENAME };	/* dirremove ops */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * tmpfs_minfree is the amount (in pages) of anonymous memory that tmpfs
727c478bd9Sstevel@tonic-gate  * leaves free for the rest of the system.  E.g. in a system with 32MB of
737c478bd9Sstevel@tonic-gate  * configured swap space, if 16MB were reserved (leaving 16MB free),
747c478bd9Sstevel@tonic-gate  * tmpfs could allocate up to 16MB - tmpfs_minfree.  The default value
757c478bd9Sstevel@tonic-gate  * for tmpfs_minfree is btopr(TMPMINFREE) but it can cautiously patched
767c478bd9Sstevel@tonic-gate  * to a different number of pages.
777c478bd9Sstevel@tonic-gate  * NB: If tmpfs allocates too much swap space, other processes will be
787c478bd9Sstevel@tonic-gate  * unable to execute.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate #define	TMPMINFREE	2 * 1024 * 1024	/* 2 Megabytes */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate extern size_t	tmpfs_minfree;		/* Anonymous memory in pages */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * tmpfs can allocate only a certain percentage of kernel memory,
867c478bd9Sstevel@tonic-gate  * which is used for tmpnodes, directories, file names, etc.
877c478bd9Sstevel@tonic-gate  * This is statically set as TMPMAXFRACKMEM of physical memory.
887c478bd9Sstevel@tonic-gate  * The actual number of allocatable bytes can be patched in tmpfs_maxkmem.
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate #define	TMPMAXFRACKMEM	25	/* 1/25 of physical memory */
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate extern size_t 	tmp_kmemspace;
937c478bd9Sstevel@tonic-gate extern size_t	tmpfs_maxkmem;	/* Allocatable kernel memory in bytes */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate extern	void	tmpnode_init(struct tmount *, struct tmpnode *,
967c478bd9Sstevel@tonic-gate 	struct vattr *, struct cred *);
977c478bd9Sstevel@tonic-gate extern	int	tmpnode_trunc(struct tmount *, struct tmpnode *, ulong_t);
987c478bd9Sstevel@tonic-gate extern	void	tmpnode_growmap(struct tmpnode *, ulong_t);
997c478bd9Sstevel@tonic-gate extern	int	tdirlookup(struct tmpnode *, char *, struct tmpnode **,
1007c478bd9Sstevel@tonic-gate     struct cred *);
1017c478bd9Sstevel@tonic-gate extern	int	tdirdelete(struct tmpnode *, struct tmpnode *, char *,
1027c478bd9Sstevel@tonic-gate 	enum dr_op, struct cred *);
1037c478bd9Sstevel@tonic-gate extern	void	tdirinit(struct tmpnode *, struct tmpnode *);
1047c478bd9Sstevel@tonic-gate extern	void	tdirtrunc(struct tmpnode *);
1057c478bd9Sstevel@tonic-gate extern	void	*tmp_memalloc(size_t, int);
1067c478bd9Sstevel@tonic-gate extern	void	tmp_memfree(void *, size_t);
1077c478bd9Sstevel@tonic-gate extern	int	tmp_resv(struct tmount *, struct tmpnode *, size_t, int);
1087c478bd9Sstevel@tonic-gate extern	int	tmp_taccess(void *, int, struct cred *);
1097c478bd9Sstevel@tonic-gate extern	int	tmp_sticky_remove_access(struct tmpnode *, struct tmpnode *,
1107c478bd9Sstevel@tonic-gate 	struct cred *);
1117c478bd9Sstevel@tonic-gate extern	int	tmp_convnum(char *, pgcnt_t *);
112*401bc9afSJoshua M. Clulow extern	int	tmp_convmode(char *, mode_t *);
1137c478bd9Sstevel@tonic-gate extern	int	tdirenter(struct tmount *, struct tmpnode *, char *,
1147c478bd9Sstevel@tonic-gate 	enum de_op, struct tmpnode *, struct tmpnode *, struct vattr *,
115da6c28aaSamw 	struct tmpnode **, struct cred *, caller_context_t *);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	TMP_MUSTHAVE	0x01
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #endif	/* _SYS_FS_TMP_H */
124