6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. 23 * All rights reserved. Use is subject to license terms. 24 */ 25 /* 26 * Copyright 2016 Joyent, Inc. 27 */ 28 29 #ifndef _SYS_FS_TMP_H 30 #define _SYS_FS_TMP_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* 37 * tmpfs per-mount data structure. 38 * 39 * All fields are protected by tm_contents. 40 * File renames on a particular file system are protected tm_renamelck. 41 */ 42 struct tmount { 43 struct vfs *tm_vfsp; /* filesystem's vfs struct */ 44 struct tmpnode *tm_rootnode; /* root tmpnode */ 45 char *tm_mntpath; /* name of tmpfs mount point */ 46 size_t tm_anonmax; /* file system max anon reservation */ 47 size_t tm_anonmem; /* bytes of reserved anon memory */ 48 /* and allocated kmem for the fs */ 49 size_t tm_allocmem; /* bytes alloced from tmp_kmem_ funcs */ 50 dev_t tm_dev; /* unique dev # of mounted `device' */ 51 uint_t tm_gen; /* pseudo generation number for files */ 52 kmutex_t tm_contents; /* lock for tmount structure */ 53 kmutex_t tm_renamelck; /* rename lock for this mount */ 54 }; 55 56 /* 57 * File system independent to tmpfs conversion macros 58 */ 59 #define VFSTOTM(vfsp) ((struct tmount *)(vfsp)->vfs_data) 60 #define VTOTM(vp) ((struct tmount *)(vp)->v_vfsp->vfs_data) 61 #define VTOTN(vp) ((struct tmpnode *)(vp)->v_data) 62 #define TNTOV(tp) ((tp)->tn_vnode) 63 #define TNTOTM(tp) (VTOTM(TNTOV(tp))) 64 #define tmpnode_hold(tp) VN_HOLD(TNTOV(tp)) 65 #define tmpnode_rele(tp) VN_RELE(TNTOV(tp)) 66 67 /* 68 * enums 69 */ 70 enum de_op { DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME }; /* direnter ops */ 71 enum dr_op { DR_REMOVE, DR_RMDIR, DR_RENAME }; /* dirremove ops */ 72 73 /* 74 * tmpfs_minfree is the amount (in pages) of anonymous memory that tmpfs 75 * leaves free for the rest of the system. In antiquity, this number could be 76 * relevant on a system-wide basis, as physical DRAM was routinely exhausted; 77 * however, in more modern times, the relative growth of DRAM with respect to 78 * application footprint means that this number is only likely to become 79 * factor in a virtualized OS environment (e.g., a zone) -- and even then only 80 * when DRAM and swap have both been capped low to allow for maximum tenancy. 81 * TMPMINFREE -- the value from which tmpfs_minfree is derived -- should 82 * therefore be configured to a value that is roughly the smallest practical 83 * value for memory + swap minus the largest reasonable size for tmpfs in such 84 * a configuration. As of this writing, the smallest practical memory + swap 85 * configuration is 128MB, and it seems reasonable to allow tmpfs to consume 86 * no more than seven-eighths of this, yielding a TMPMINFREE of 16MB. Care 87 * should be exercised in changing this: tuning this value too high will 88 * result in spurious ENOSPC errors in tmpfs in small zones (a problem that 89 * can induce cascading failure surprisingly often); tuning this value too low 90 * will result in tmpfs consumption alone to alone induce application-level 91 * memory allocation failure. 92 */ 93 #define TMPMINFREE 16 * 1024 * 1024 /* 16 Megabytes */ 94 95 extern size_t tmpfs_minfree; /* Anonymous memory in pages */ 96 97 extern void tmpnode_init(struct tmount *, struct tmpnode *, 98 struct vattr *, struct cred *); 99 extern void tmpnode_cleanup(struct tmpnode *tp); 100 extern int tmpnode_trunc(struct tmount *, struct tmpnode *, ulong_t); 101 extern void tmpnode_growmap(struct tmpnode *, ulong_t); 102 extern int tdirlookup(struct tmpnode *, char *, struct tmpnode **, 103 struct cred *); 104 extern int tdirdelete(struct tmpnode *, struct tmpnode *, char *, 105 enum dr_op, struct cred *); 106 extern int tdirinit(struct tmpnode *, struct tmpnode *); 107 extern void tdirtrunc(struct tmpnode *); 108 extern int tmp_resv(struct tmount *, struct tmpnode *, size_t, int); 109 extern int tmp_taccess(void *, int, struct cred *); 110 extern int tmp_sticky_remove_access(struct tmpnode *, struct tmpnode *, 111 struct cred *); 112 extern int tmp_convnum(char *, size_t *); 113 extern int tmp_convmode(char *, mode_t *); 114 extern int tdirenter(struct tmount *, struct tmpnode *, char *, 115 enum de_op, struct tmpnode *, struct tmpnode *, struct vattr *, 116 struct tmpnode **, struct cred *, caller_context_t *); 117 118 extern void *tmp_kmem_zalloc(struct tmount *, size_t, int); 119 extern void tmp_kmem_free(struct tmount *, void *, size_t); 120 121 #define TMP_MUSTHAVE 0x01 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif /* _SYS_FS_TMP_H */  | 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. 23 * All rights reserved. Use is subject to license terms. 24 */ 25 /* 26 * Copyright 2015 Joyent, Inc. 27 */ 28 29 #ifndef _SYS_FS_TMP_H 30 #define _SYS_FS_TMP_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* 37 * tmpfs per-mount data structure. 38 * 39 * All fields are protected by tm_contents. 40 * File renames on a particular file system are protected tm_renamelck. 41 */ 42 struct tmount { 43 struct vfs *tm_vfsp; /* filesystem's vfs struct */ 44 struct tmpnode *tm_rootnode; /* root tmpnode */ 45 char *tm_mntpath; /* name of tmpfs mount point */ 46 ulong_t tm_anonmax; /* file system max anon reservation */ 47 pgcnt_t tm_anonmem; /* pages of reserved anon memory */ 48 dev_t tm_dev; /* unique dev # of mounted `device' */ 49 uint_t tm_gen; /* pseudo generation number for files */ 50 kmutex_t tm_contents; /* lock for tmount structure */ 51 kmutex_t tm_renamelck; /* rename lock for this mount */ 52 }; 53 54 /* 55 * File system independent to tmpfs conversion macros 56 */ 57 #define VFSTOTM(vfsp) ((struct tmount *)(vfsp)->vfs_data) 58 #define VTOTM(vp) ((struct tmount *)(vp)->v_vfsp->vfs_data) 59 #define VTOTN(vp) ((struct tmpnode *)(vp)->v_data) 60 #define TNTOV(tp) ((tp)->tn_vnode) 61 #define tmpnode_hold(tp) VN_HOLD(TNTOV(tp)) 62 #define tmpnode_rele(tp) VN_RELE(TNTOV(tp)) 63 64 /* 65 * enums 66 */ 67 enum de_op { DE_CREATE, DE_MKDIR, DE_LINK, DE_RENAME }; /* direnter ops */ 68 enum dr_op { DR_REMOVE, DR_RMDIR, DR_RENAME }; /* dirremove ops */ 69 70 /* 71 * tmpfs_minfree is the amount (in pages) of anonymous memory that tmpfs 72 * leaves free for the rest of the system. E.g. in a system with 32MB of 73 * configured swap space, if 16MB were reserved (leaving 16MB free), 74 * tmpfs could allocate up to 16MB - tmpfs_minfree. The default value 75 * for tmpfs_minfree is btopr(TMPMINFREE) but it can cautiously patched 76 * to a different number of pages. 77 * NB: If tmpfs allocates too much swap space, other processes will be 78 * unable to execute. 79 */ 80 #define TMPMINFREE 2 * 1024 * 1024 /* 2 Megabytes */ 81 82 extern size_t tmpfs_minfree; /* Anonymous memory in pages */ 83 84 /* 85 * tmpfs can allocate only a certain percentage of kernel memory, 86 * which is used for tmpnodes, directories, file names, etc. 87 * This is statically set as TMPMAXFRACKMEM of physical memory. 88 * The actual number of allocatable bytes can be patched in tmpfs_maxkmem. 89 */ 90 #define TMPMAXFRACKMEM 25 /* 1/25 of physical memory */ 91 92 extern size_t tmp_kmemspace; 93 extern size_t tmpfs_maxkmem; /* Allocatable kernel memory in bytes */ 94 95 extern void tmpnode_init(struct tmount *, struct tmpnode *, 96 struct vattr *, struct cred *); 97 extern int tmpnode_trunc(struct tmount *, struct tmpnode *, ulong_t); 98 extern void tmpnode_growmap(struct tmpnode *, ulong_t); 99 extern int tdirlookup(struct tmpnode *, char *, struct tmpnode **, 100 struct cred *); 101 extern int tdirdelete(struct tmpnode *, struct tmpnode *, char *, 102 enum dr_op, struct cred *); 103 extern void tdirinit(struct tmpnode *, struct tmpnode *); 104 extern void tdirtrunc(struct tmpnode *); 105 extern void *tmp_memalloc(size_t, int); 106 extern void tmp_memfree(void *, size_t); 107 extern int tmp_resv(struct tmount *, struct tmpnode *, size_t, int); 108 extern int tmp_taccess(void *, int, struct cred *); 109 extern int tmp_sticky_remove_access(struct tmpnode *, struct tmpnode *, 110 struct cred *); 111 extern int tmp_convnum(char *, pgcnt_t *); 112 extern int tmp_convmode(char *, mode_t *); 113 extern int tdirenter(struct tmount *, struct tmpnode *, char *, 114 enum de_op, struct tmpnode *, struct tmpnode *, struct vattr *, 115 struct tmpnode **, struct cred *, caller_context_t *); 116 117 #define TMP_MUSTHAVE 0x01 118 119 #ifdef __cplusplus 120 } 121 #endif 122 123 #endif /* _SYS_FS_TMP_H */  |