opensolaris_kobj.c (218665) | opensolaris_kobj.c (241896) |
---|---|
1/*- 2 * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c 218665 2011-02-13 19:46:55Z marcel $"); | 28__FBSDID("$FreeBSD: head/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c 241896 2012-10-22 17:50:54Z kib $"); |
29 30#include <sys/types.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/kthread.h> 35#include <sys/namei.h> 36#include <sys/proc.h> --- 27 unchanged lines hidden (view full) --- 64} 65 66static void * 67kobj_open_file_vnode(const char *file) 68{ 69 struct thread *td = curthread; 70 struct filedesc *fd; 71 struct nameidata nd; | 29 30#include <sys/types.h> 31#include <sys/systm.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/kthread.h> 35#include <sys/namei.h> 36#include <sys/proc.h> --- 27 unchanged lines hidden (view full) --- 64} 65 66static void * 67kobj_open_file_vnode(const char *file) 68{ 69 struct thread *td = curthread; 70 struct filedesc *fd; 71 struct nameidata nd; |
72 int error, flags, vfslocked; | 72 int error, flags; |
73 74 fd = td->td_proc->p_fd; 75 FILEDESC_XLOCK(fd); 76 if (fd->fd_rdir == NULL) { 77 fd->fd_rdir = rootvnode; 78 vref(fd->fd_rdir); 79 } 80 if (fd->fd_cdir == NULL) { 81 fd->fd_cdir = rootvnode; 82 vref(fd->fd_cdir); 83 } 84 FILEDESC_XUNLOCK(fd); 85 86 flags = FREAD | O_NOFOLLOW; | 73 74 fd = td->td_proc->p_fd; 75 FILEDESC_XLOCK(fd); 76 if (fd->fd_rdir == NULL) { 77 fd->fd_rdir = rootvnode; 78 vref(fd->fd_rdir); 79 } 80 if (fd->fd_cdir == NULL) { 81 fd->fd_cdir = rootvnode; 82 vref(fd->fd_cdir); 83 } 84 FILEDESC_XUNLOCK(fd); 85 86 flags = FREAD | O_NOFOLLOW; |
87 NDINIT(&nd, LOOKUP, MPSAFE, UIO_SYSSPACE, file, td); | 87 NDINIT(&nd, LOOKUP, 0, UIO_SYSSPACE, file, td); |
88 error = vn_open_cred(&nd, &flags, 0, 0, curthread->td_ucred, NULL); 89 if (error != 0) 90 return (NULL); | 88 error = vn_open_cred(&nd, &flags, 0, 0, curthread->td_ucred, NULL); 89 if (error != 0) 90 return (NULL); |
91 vfslocked = NDHASGIANT(&nd); | |
92 NDFREE(&nd, NDF_ONLY_PNBUF); 93 /* We just unlock so we hold a reference. */ 94 VOP_UNLOCK(nd.ni_vp, 0); | 91 NDFREE(&nd, NDF_ONLY_PNBUF); 92 /* We just unlock so we hold a reference. */ 93 VOP_UNLOCK(nd.ni_vp, 0); |
95 VFS_UNLOCK_GIANT(vfslocked); | |
96 return (nd.ni_vp); 97} 98 99static void * 100kobj_open_file_loader(const char *file) 101{ 102 103 return (preload_search_by_name(file)); --- 21 unchanged lines hidden (view full) --- 125 return (out); 126} 127 128static int 129kobj_get_filesize_vnode(struct _buf *file, uint64_t *size) 130{ 131 struct vnode *vp = file->ptr; 132 struct vattr va; | 94 return (nd.ni_vp); 95} 96 97static void * 98kobj_open_file_loader(const char *file) 99{ 100 101 return (preload_search_by_name(file)); --- 21 unchanged lines hidden (view full) --- 123 return (out); 124} 125 126static int 127kobj_get_filesize_vnode(struct _buf *file, uint64_t *size) 128{ 129 struct vnode *vp = file->ptr; 130 struct vattr va; |
133 int error, vfslocked; | 131 int error; |
134 | 132 |
135 vfslocked = VFS_LOCK_GIANT(vp->v_mount); | |
136 vn_lock(vp, LK_SHARED | LK_RETRY); 137 error = VOP_GETATTR(vp, &va, curthread->td_ucred); 138 VOP_UNLOCK(vp, 0); 139 if (error == 0) 140 *size = (uint64_t)va.va_size; | 133 vn_lock(vp, LK_SHARED | LK_RETRY); 134 error = VOP_GETATTR(vp, &va, curthread->td_ucred); 135 VOP_UNLOCK(vp, 0); 136 if (error == 0) 137 *size = (uint64_t)va.va_size; |
141 VFS_UNLOCK_GIANT(vfslocked); | |
142 return (error); 143} 144 145static int 146kobj_get_filesize_loader(struct _buf *file, uint64_t *size) 147{ 148 void *ptr; 149 --- 16 unchanged lines hidden (view full) --- 166 167int 168kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off) 169{ 170 struct vnode *vp = file->ptr; 171 struct thread *td = curthread; 172 struct uio auio; 173 struct iovec aiov; | 138 return (error); 139} 140 141static int 142kobj_get_filesize_loader(struct _buf *file, uint64_t *size) 143{ 144 void *ptr; 145 --- 16 unchanged lines hidden (view full) --- 162 163int 164kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off) 165{ 166 struct vnode *vp = file->ptr; 167 struct thread *td = curthread; 168 struct uio auio; 169 struct iovec aiov; |
174 int error, vfslocked; | 170 int error; |
175 176 bzero(&aiov, sizeof(aiov)); 177 bzero(&auio, sizeof(auio)); 178 179 aiov.iov_base = buf; 180 aiov.iov_len = size; 181 182 auio.uio_iov = &aiov; 183 auio.uio_offset = (off_t)off; 184 auio.uio_segflg = UIO_SYSSPACE; 185 auio.uio_rw = UIO_READ; 186 auio.uio_iovcnt = 1; 187 auio.uio_resid = size; 188 auio.uio_td = td; 189 | 171 172 bzero(&aiov, sizeof(aiov)); 173 bzero(&auio, sizeof(auio)); 174 175 aiov.iov_base = buf; 176 aiov.iov_len = size; 177 178 auio.uio_iov = &aiov; 179 auio.uio_offset = (off_t)off; 180 auio.uio_segflg = UIO_SYSSPACE; 181 auio.uio_rw = UIO_READ; 182 auio.uio_iovcnt = 1; 183 auio.uio_resid = size; 184 auio.uio_td = td; 185 |
190 vfslocked = VFS_LOCK_GIANT(vp->v_mount); | |
191 vn_lock(vp, LK_SHARED | LK_RETRY); 192 error = VOP_READ(vp, &auio, IO_UNIT | IO_SYNC, td->td_ucred); 193 VOP_UNLOCK(vp, 0); | 186 vn_lock(vp, LK_SHARED | LK_RETRY); 187 error = VOP_READ(vp, &auio, IO_UNIT | IO_SYNC, td->td_ucred); 188 VOP_UNLOCK(vp, 0); |
194 VFS_UNLOCK_GIANT(vfslocked); | |
195 return (error != 0 ? -1 : size - auio.uio_resid); 196} 197 198int 199kobj_read_file_loader(struct _buf *file, char *buf, unsigned size, unsigned off) 200{ 201 char *ptr; 202 --- 13 unchanged lines hidden (view full) --- 216 else 217 return (kobj_read_file_loader(file, buf, size, off)); 218} 219 220void 221kobj_close_file(struct _buf *file) 222{ 223 | 189 return (error != 0 ? -1 : size - auio.uio_resid); 190} 191 192int 193kobj_read_file_loader(struct _buf *file, char *buf, unsigned size, unsigned off) 194{ 195 char *ptr; 196 --- 13 unchanged lines hidden (view full) --- 210 else 211 return (kobj_read_file_loader(file, buf, size, off)); 212} 213 214void 215kobj_close_file(struct _buf *file) 216{ 217 |
224 if (file->mounted) { 225 struct vnode *vp = file->ptr; 226 struct thread *td = curthread; 227 int vfslocked; 228 229 vfslocked = VFS_LOCK_GIANT(vp->v_mount); 230 vn_close(vp, FREAD, td->td_ucred, td); 231 VFS_UNLOCK_GIANT(vfslocked); 232 } | 218 if (file->mounted) 219 vn_close(file->ptr, FREAD, curthread->td_ucred, curthread); |
233 kmem_free(file, sizeof(*file)); 234} | 220 kmem_free(file, sizeof(*file)); 221} |