1 // 2 // CDDL HEADER START 3 // 4 // The contents of this file are subject to the terms of the 5 // Common Development and Distribution License (the License). 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/CDDL.txt 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/CDDL.txt. 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 // 23 // Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 // Use is subject to license terms. 25 // 26 27 #pragma ident "@(#)px_vfsops.cc 1.11 08/05/20 SMI" 28 29 #include <sys/types.h> 30 #include <sys/vfs.h> 31 #include <sys/vnode.h> 32 #include <sys/uio.h> 33 #include <sys/statvfs.h> 34 #include <sys/mount.h> 35 #include <sys/debug.h> 36 37 #include <sys/sol_version.h> 38 #include <sys/os.h> 39 40 #include <pxfs/common/pxfslib.h> 41 #include "../version.h" 42 #include <pxfs/client/pxfobj.h> 43 #include <pxfs/client/pxvfs.h> 44 45 static int px_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr); 46 static int px_mountroot(vfs_t *vfsp, enum whymountroot why); 47 static int px_unmount(vfs_t *vfsp, int flags, cred_t *cr); 48 static int px_root(vfs_t *vfsp, vnode_t **vpp); 49 static int px_statvfs(vfs_t *vfsp, struct statvfs64 *sp); 50 static int px_sync(vfs_t *vfsp, short flag, cred_t *cr); 51 static int px_vget(vfs_t *vfsp, vnode_t **vpp, struct fid *fidp); 52 static int px_swapvp(vfs_t *vfsp, vnode_t **vpp, char *nm); 53 static void px_freevfs(vfs_t *vfsp); 54 55 #ifdef FSI 56 57 struct vfsops *pxfs_vfsopsp = NULL; 58 59 // 60 // px_vfs_init - initializes the pxfs vfs data structure operations vector 61 // for pxfs version 0. At mount time, the system will substitute this 62 // vfs operations vector to replace the generic vfs operations vector 63 // when pxfs version 0 will support the file system. 64 // 65 int 66 px_vfs_init() 67 { 68 static const fs_operation_def_t px_vfsops_template[] = { 69 VFSNAME_MOUNT, (fs_generic_func_p)px_mount, 70 VFSNAME_UNMOUNT, (fs_generic_func_p)px_unmount, 71 VFSNAME_ROOT, (fs_generic_func_p)px_root, 72 VFSNAME_STATVFS, (fs_generic_func_p)px_statvfs, 73 VFSNAME_SYNC, (fs_generic_func_p)px_sync, 74 VFSNAME_VGET, (fs_generic_func_p)px_vget, 75 VFSNAME_MOUNTROOT, (fs_generic_func_p)px_mountroot, 76 "swapvp", (fs_generic_func_p)px_swapvp, 77 VFSNAME_FREEVFS, (fs_generic_func_p)px_freevfs, 78 NULL, NULL 79 }; 80 81 int error; 82 83 // 84 // The following function allocates memory for a vfs operations vector, 85 // and initializes the data structure. 86 // 87 error = vfs_makefsops(px_vfsops_template, &pxfs_vfsopsp); 88 if (error != 0) { 89 return (error); 90 } 91 return (0); 92 } 93 94 // 95 // px_vfs_uninit - undoes the vfs initialization, 96 // which basically means destroying the vfs operations vector. 97 // 98 void 99 px_vfs_uninit() 100 { 101 if (pxfs_vfsopsp != NULL) { 102 vfs_freevfsops(pxfs_vfsopsp); 103 } 104 } 105 106 #else 107 108 struct vfsops pxfs_vfsops_v1 = { 109 px_mount, 110 px_unmount, 111 px_root, 112 px_statvfs, 113 px_sync, 114 px_vget, 115 px_mountroot, 116 px_swapvp, 117 px_freevfs 118 }; 119 120 struct vfsops *pxfs_vfsopsp = &pxfs_vfsops_v1; 121 122 #endif // FSI 123 124 static int 125 px_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) 126 { 127 int error; 128 129 ASSERT(uap->flags & MS_GLOBAL); 130 // 131 // "mount -g" mounts use the static form of the 132 // mount method; this method allocates 133 // the pxvfs after determining the fs reference. 134 // 135 error = pxvfs::mount(vfsp, mvp, uap, cr); 136 return (error); 137 } 138 139 static int 140 px_unmount(vfs_t *vfsp, int flags, cred_t *cr) 141 { 142 return (pxvfs::VFSTOPXFS(vfsp)->unmount(flags, cr)); 143 } 144 145 static int 146 px_mountroot(vfs_t *vfsp, enum whymountroot why) 147 { 148 return (pxvfs::VFSTOPXFS(vfsp)->mountroot(why)); 149 } 150 151 static int 152 px_root(vfs_t *vfsp, vnode_t **vpp) 153 { 154 return (pxvfs::VFSTOPXFS(vfsp)->root(vpp)); 155 } 156 157 static int 158 px_statvfs(vfs_t *vfsp, struct statvfs64 *sp) 159 { 160 return (pxvfs::VFSTOPXFS(vfsp)->statvfs(sp)); 161 } 162 163 // 164 // vfsp will be non-NULL if this is a sync in order to unmount one file system. 165 // vfsp will be NULL if this is a sync of all PXFS type file systems. 166 // 167 static int 168 px_sync(vfs_t *vfsp, short flag, cred_t *cr) 169 { 170 if (vfsp != NULL) { 171 return (pxvfs::VFSTOPXFS(vfsp)->sync(flag, cr)); 172 } else { 173 return (pxvfs::sync_all(flag, cr)); 174 } 175 } 176 177 static int 178 px_vget(vfs_t *vfsp, vnode_t **vpp, struct fid *fidp) 179 { 180 return (pxvfs::VFSTOPXFS(vfsp)->vget(vpp, fidp)); 181 } 182 183 static int 184 px_swapvp(vfs_t *vfsp, vnode_t **vpp, char *nm) 185 { 186 return (pxvfs::VFSTOPXFS(vfsp)->swapvp(vpp, nm)); 187 } 188 189 static void 190 px_freevfs(vfs_t *vfsp) 191 { 192 delete pxvfs::VFSTOPXFS(vfsp); 193 } 194