- Add conditional VFS Giant locking to getdents_common() (linux ABIs),

ibcs2_getdents(), ibcs2_read(), ogetdirentries(), svr4_sys_getdents(),
  and svr4_sys_getdents64() similar to that in getdirentries().
- Mark ibcs2_getdents(), ibcs2_read(), linux_getdents(), linux_getdents64(),
  linux_readdir(), ogetdirentries(), svr4_sys_getdents(), and
  svr4_sys_getdents64() MPSAFE.
This commit is contained in:
John Baldwin 2006-07-11 20:52:08 +00:00
parent 55e9893a66
commit be5747d5b5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=160276
10 changed files with 63 additions and 33 deletions

View File

@ -169,7 +169,7 @@
87 AUE_SWAPON MNOPROTO { int swapon(char *name); }
88 AUE_REBOOT MSTD { int linux_reboot(l_int magic1, \
l_int magic2, l_uint cmd, void *arg); }
89 AUE_O_GETDENTS STD { int linux_readdir(l_uint fd, \
89 AUE_O_GETDENTS MSTD { int linux_readdir(l_uint fd, \
struct l_dirent *dent, l_uint count); }
90 AUE_MMAP MSTD { int linux_mmap(struct l_mmap_argv *ptr); }
91 AUE_MUNMAP MNOPROTO { int munmap(caddr_t addr, int len); }
@ -246,7 +246,7 @@
140 AUE_LSEEK MSTD { int linux_llseek(l_int fd, l_ulong ohigh, \
l_ulong olow, l_loff_t *res, \
l_uint whence); }
141 AUE_O_GETDENTS STD { int linux_getdents(l_uint fd, void *dent, \
141 AUE_O_GETDENTS MSTD { int linux_getdents(l_uint fd, void *dent, \
l_uint count); }
142 AUE_SELECT MSTD { int linux_select(l_int nfds, \
l_fd_set *readfds, l_fd_set *writefds, \
@ -381,7 +381,7 @@
l_size_t len, u_char *vec); }
219 AUE_MADVISE MNOPROTO { int madvise(void *addr, size_t len, \
int behav); }
220 AUE_O_GETDENTS STD { int linux_getdents64(l_uint fd, \
220 AUE_O_GETDENTS MSTD { int linux_getdents64(l_uint fd, \
void *dirent, l_uint count); }
221 AUE_FCNTL MSTD { int linux_fcntl64(l_uint fd, l_uint cmd, \
uintptr_t arg); }

View File

@ -259,7 +259,17 @@ getdents_common(struct thread *td, struct linux_getdents64_args *args,
struct l_dirent64 linux_dirent64;
int buflen, error, eofflag, nbytes, justone;
u_long *cookies = NULL, *cookiep;
int ncookies;
int ncookies, vfslocked;
nbytes = args->count;
if (nbytes == 1) {
/* readdir(2) case. Always struct dirent. */
if (is64bit)
return (EINVAL);
nbytes = sizeof(linux_dirent);
justone = 1;
} else
justone = 0;
if ((error = getvnode(td->td_proc->p_fd, args->fd, &fp)) != 0)
return (error);
@ -270,23 +280,13 @@ getdents_common(struct thread *td, struct linux_getdents64_args *args,
}
vp = fp->f_vnode;
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (EINVAL);
}
nbytes = args->count;
if (nbytes == 1) {
/* readdir(2) case. Always struct dirent. */
if (is64bit) {
fdrop(fp, td);
return (EINVAL);
}
nbytes = sizeof(linux_dirent);
justone = 1;
} else
justone = 0;
off = fp->f_offset;
buflen = max(LINUX_DIRBLKSIZ, nbytes);
@ -439,6 +439,7 @@ getdents_common(struct thread *td, struct linux_getdents64_args *args,
free(cookies, M_TEMP);
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
free(buf, M_TEMP);
return (error);

View File

@ -240,7 +240,7 @@ svr4_sys_getdents64(td, uap)
struct iovec aiov;
off_t off;
struct svr4_dirent64 svr4_dirent;
int buflen, error, eofflag, nbytes, justone;
int buflen, error, eofflag, nbytes, justone, vfslocked;
u_long *cookies = NULL, *cookiep;
int ncookies;
@ -256,8 +256,9 @@ svr4_sys_getdents64(td, uap)
}
vp = fp->f_vnode;
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (EINVAL);
}
@ -394,6 +395,7 @@ svr4_sys_getdents64(td, uap)
td->td_retval[0] = nbytes - resid;
out:
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
if (cookies)
free(cookies, M_TEMP);
@ -418,7 +420,7 @@ svr4_sys_getdents(td, uap)
struct iovec aiov;
struct svr4_dirent idb;
off_t off; /* true file offset */
int buflen, error, eofflag;
int buflen, error, eofflag, vfslocked;
u_long *cookiebuf = NULL, *cookie;
int ncookies = 0, *retval = td->td_retval;
@ -434,7 +436,9 @@ svr4_sys_getdents(td, uap)
}
vp = fp->f_vnode;
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (EINVAL);
}
@ -524,6 +528,7 @@ svr4_sys_getdents(td, uap)
*retval = uap->nbytes - resid;
out:
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
if (cookiebuf)
free(cookiebuf, M_TEMP);

View File

@ -136,7 +136,7 @@
78 AUE_NULL UNIMPL rfsys
79 AUE_NULL MNOPROTO { int rmdir(char *path); }
80 AUE_NULL MNOPROTO { int mkdir(char *path, int mode); }
81 AUE_NULL STD { int svr4_sys_getdents(int fd, char *buf, \
81 AUE_NULL MSTD { int svr4_sys_getdents(int fd, char *buf, \
int nbytes); }
82 AUE_NULL UNIMPL libattach
83 AUE_NULL UNIMPL libdetach
@ -325,7 +325,7 @@
210 AUE_NULL UNIMPL signotifywait
211 AUE_NULL UNIMPL lwp_sigredirect
212 AUE_NULL UNIMPL lwp_alarm
213 AUE_NULL STD { int svr4_sys_getdents64(int fd, \
213 AUE_NULL MSTD { int svr4_sys_getdents64(int fd, \
struct svr4_dirent64 *dp, int nbytes); }
;213 AUE_NULL UNIMPL getdents64
214 AUE_NULL MSTD { caddr_t svr4_sys_mmap64(void *addr, \

View File

@ -329,7 +329,7 @@ ibcs2_getdents(td, uap)
struct iovec aiov;
struct ibcs2_dirent idb;
off_t off; /* true file offset */
int buflen, error, eofflag;
int buflen, error, eofflag, vfslocked;
u_long *cookies = NULL, *cookiep;
int ncookies;
#define BSD_DIRENT(cp) ((struct dirent *)(cp))
@ -342,7 +342,9 @@ ibcs2_getdents(td, uap)
return (EBADF);
}
vp = fp->f_vnode;
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) { /* XXX vnode readdir op should do this */
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (EINVAL);
}
@ -459,6 +461,7 @@ ibcs2_getdents(td, uap)
td->td_retval[0] = uap->nbytes - resid;
out:
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
if (cookies)
free(cookies, M_TEMP);
@ -484,7 +487,7 @@ ibcs2_read(td, uap)
char name[14];
} idb;
off_t off; /* true file offset */
int buflen, error, eofflag, size;
int buflen, error, eofflag, size, vfslocked;
u_long *cookies = NULL, *cookiep;
int ncookies;
@ -499,7 +502,9 @@ ibcs2_read(td, uap)
return (EBADF);
}
vp = fp->f_vnode;
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return read(td, (struct read_args *)uap);
}
@ -622,6 +627,7 @@ ibcs2_read(td, uap)
td->td_retval[0] = uap->nbytes - resid;
out:
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
if (cookies)
free(cookies, M_TEMP);

View File

@ -39,7 +39,7 @@
1 AUE_EXIT MNOPROTO { void sys_exit(int rval); } exit \
sys_exit_args void
2 AUE_FORK MNOPROTO { int fork(void); }
3 AUE_NULL STD { int ibcs2_read(int fd, char *buf, \
3 AUE_NULL MSTD { int ibcs2_read(int fd, char *buf, \
u_int nbytes); }
4 AUE_NULL MNOPROTO { int write(int fd, char *buf, \
u_int nbytes); }
@ -146,7 +146,7 @@
78 AUE_NULL UNIMPL rfs_rfsys
79 AUE_RMDIR MSTD { int ibcs2_rmdir(char *path); }
80 AUE_MKDIR MSTD { int ibcs2_mkdir(char *path, int mode); }
81 AUE_GETDIRENTRIES STD { int ibcs2_getdents(int fd, char *buf, \
81 AUE_GETDIRENTRIES MSTD { int ibcs2_getdents(int fd, char *buf, \
int nbytes); }
82 AUE_NULL UNIMPL nosys
83 AUE_NULL UNIMPL nosys

View File

@ -169,7 +169,7 @@
87 AUE_SWAPON MNOPROTO { int swapon(char *name); }
88 AUE_REBOOT MSTD { int linux_reboot(l_int magic1, \
l_int magic2, l_uint cmd, void *arg); }
89 AUE_O_GETDENTS STD { int linux_readdir(l_uint fd, \
89 AUE_O_GETDENTS MSTD { int linux_readdir(l_uint fd, \
struct l_dirent *dent, l_uint count); }
90 AUE_MMAP MSTD { int linux_mmap(struct l_mmap_argv *ptr); }
91 AUE_MUNMAP MNOPROTO { int munmap(caddr_t addr, int len); }
@ -248,7 +248,7 @@
140 AUE_LSEEK MSTD { int linux_llseek(l_int fd, l_ulong ohigh, \
l_ulong olow, l_loff_t *res, \
l_uint whence); }
141 AUE_O_GETDENTS STD { int linux_getdents(l_uint fd, void *dent, \
141 AUE_O_GETDENTS MSTD { int linux_getdents(l_uint fd, void *dent, \
l_uint count); }
142 AUE_SELECT MSTD { int linux_select(l_int nfds, \
l_fd_set *readfds, l_fd_set *writefds, \
@ -383,7 +383,7 @@
l_size_t len, u_char *vec); }
219 AUE_MADVISE MNOPROTO { int madvise(void *addr, size_t len, \
int behav); }
220 AUE_O_GETDENTS STD { int linux_getdents64(l_uint fd, \
220 AUE_O_GETDENTS MSTD { int linux_getdents64(l_uint fd, \
void *dirent, l_uint count); }
221 AUE_FCNTL MSTD { int linux_fcntl64(l_uint fd, l_uint cmd, \
l_ulong arg); }

View File

@ -304,7 +304,7 @@
154 AUE_NULL UNIMPL nosys
; 155 is initialized by the NFS code, if present.
155 AUE_NFSSVC MNOIMPL { int nfssvc(int flag, caddr_t argp); }
156 AUE_GETDIRENTRIES COMPAT { int getdirentries(int fd, char *buf, \
156 AUE_GETDIRENTRIES MCOMPAT { int getdirentries(int fd, char *buf, \
u_int count, long *basep); }
157 AUE_STATFS MCOMPAT4 { int statfs(char *path, \
struct ostatfs *buf); }

View File

@ -3569,7 +3569,7 @@ ogetdirentries(td, uap)
struct iovec aiov, kiov;
struct dirent *dp, *edp;
caddr_t dirbuf;
int error, eofflag, readcnt;
int error, eofflag, readcnt, vfslocked;
long loff;
/* XXX arbitrary sanity limit on `count'. */
@ -3583,7 +3583,9 @@ ogetdirentries(td, uap)
}
vp = fp->f_vnode;
unionread:
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (EINVAL);
}
@ -3601,6 +3603,7 @@ ogetdirentries(td, uap)
error = mac_check_vnode_readdir(td->td_ucred, vp);
if (error) {
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (error);
}
@ -3658,15 +3661,19 @@ ogetdirentries(td, uap)
}
VOP_UNLOCK(vp, 0, td);
if (error) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (error);
}
if (uap->count == auio.uio_resid) {
if (union_dircheckp) {
error = union_dircheckp(td, &vp, fp);
if (error == -1)
if (error == -1) {
VFS_UNLOCK_GIANT(vfslocked);
goto unionread;
}
if (error) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (error);
}
@ -3685,10 +3692,12 @@ ogetdirentries(td, uap)
fp->f_data = vp;
fp->f_offset = 0;
vput(tvp);
VFS_UNLOCK_GIANT(vfslocked);
goto unionread;
}
VOP_UNLOCK(vp, 0, td);
}
VFS_UNLOCK_GIANT(vfslocked);
error = copyout(&loff, uap->basep, sizeof(long));
fdrop(fp, td);
td->td_retval[0] = uap->count - auio.uio_resid;

View File

@ -3569,7 +3569,7 @@ ogetdirentries(td, uap)
struct iovec aiov, kiov;
struct dirent *dp, *edp;
caddr_t dirbuf;
int error, eofflag, readcnt;
int error, eofflag, readcnt, vfslocked;
long loff;
/* XXX arbitrary sanity limit on `count'. */
@ -3583,7 +3583,9 @@ ogetdirentries(td, uap)
}
vp = fp->f_vnode;
unionread:
vfslocked = VFS_LOCK_GIANT(vp->v_mount);
if (vp->v_type != VDIR) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (EINVAL);
}
@ -3601,6 +3603,7 @@ ogetdirentries(td, uap)
error = mac_check_vnode_readdir(td->td_ucred, vp);
if (error) {
VOP_UNLOCK(vp, 0, td);
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (error);
}
@ -3658,15 +3661,19 @@ ogetdirentries(td, uap)
}
VOP_UNLOCK(vp, 0, td);
if (error) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (error);
}
if (uap->count == auio.uio_resid) {
if (union_dircheckp) {
error = union_dircheckp(td, &vp, fp);
if (error == -1)
if (error == -1) {
VFS_UNLOCK_GIANT(vfslocked);
goto unionread;
}
if (error) {
VFS_UNLOCK_GIANT(vfslocked);
fdrop(fp, td);
return (error);
}
@ -3685,10 +3692,12 @@ ogetdirentries(td, uap)
fp->f_data = vp;
fp->f_offset = 0;
vput(tvp);
VFS_UNLOCK_GIANT(vfslocked);
goto unionread;
}
VOP_UNLOCK(vp, 0, td);
}
VFS_UNLOCK_GIANT(vfslocked);
error = copyout(&loff, uap->basep, sizeof(long));
fdrop(fp, td);
td->td_retval[0] = uap->count - auio.uio_resid;