- Split out a kern_posix_fadvise() from the posix_fadvise() system call so

it can be used by in-kernel consumers.
- Make kern_posix_fallocate() public.
- Use kern_posix_fadvise() and kern_posix_fallocate() to implement the
  freebsd32 wrappers for the two system calls.
This commit is contained in:
John Baldwin 2011-11-14 18:00:15 +00:00
parent c53bbc074e
commit 7edec6214e
3 changed files with 39 additions and 37 deletions

View File

@ -2828,23 +2828,16 @@ int
freebsd32_posix_fallocate(struct thread *td,
struct freebsd32_posix_fallocate_args *uap)
{
struct posix_fallocate_args ap;
ap.fd = uap->fd;
ap.offset = PAIR32TO64(off_t, uap->offset);
ap.len = PAIR32TO64(off_t, uap->len);
return (sys_posix_fallocate(td, &ap));
return (kern_posix_fallocate(td, uap->fd,
PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len)));
}
int
freebsd32_posix_fadvise(struct thread *td,
struct freebsd32_posix_fadvise_args *uap)
{
struct posix_fadvise_args ap;
ap.fd = uap->fd;
ap.offset = PAIR32TO64(off_t, uap->offset);
ap.len = PAIR32TO64(off_t, uap->len);
ap.advice = uap->advice;
return (sys_posix_fadvise(td, &ap));
return (kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
PAIR32TO64(off_t, uap->len), uap->advice));
}

View File

@ -4753,7 +4753,7 @@ out:
return (error);
}
static int
int
kern_posix_fallocate(struct thread *td, int fd, off_t offset, off_t len)
{
struct file *fp;
@ -4855,7 +4855,8 @@ sys_posix_fallocate(struct thread *td, struct posix_fallocate_args *uap)
* region of any current setting.
*/
int
sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
kern_posix_fadvise(struct thread *td, int fd, off_t offset, off_t len,
int advice)
{
struct fadvise_info *fa, *new;
struct file *fp;
@ -4863,10 +4864,9 @@ sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
off_t end;
int error;
if (uap->offset < 0 || uap->len < 0 ||
uap->offset > OFF_MAX - uap->len)
if (offset < 0 || len < 0 || offset > OFF_MAX - len)
return (EINVAL);
switch (uap->advice) {
switch (advice) {
case POSIX_FADV_SEQUENTIAL:
case POSIX_FADV_RANDOM:
case POSIX_FADV_NOREUSE:
@ -4881,7 +4881,7 @@ sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
return (EINVAL);
}
/* XXX: CAP_POSIX_FADVISE? */
error = fget(td, uap->fd, 0, &fp);
error = fget(td, fd, 0, &fp);
if (error != 0)
goto out;
@ -4901,11 +4901,11 @@ sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
error = ENODEV;
goto out;
}
if (uap->len == 0)
if (len == 0)
end = OFF_MAX;
else
end = uap->offset + uap->len - 1;
switch (uap->advice) {
end = offset + len - 1;
switch (advice) {
case POSIX_FADV_SEQUENTIAL:
case POSIX_FADV_RANDOM:
case POSIX_FADV_NOREUSE:
@ -4916,17 +4916,17 @@ sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
*/
mtx_pool_lock(mtxpool_sleep, fp);
fa = fp->f_advice;
if (fa != NULL && fa->fa_advice == uap->advice &&
((fa->fa_start <= end && fa->fa_end >= uap->offset) ||
if (fa != NULL && fa->fa_advice == advice &&
((fa->fa_start <= end && fa->fa_end >= offset) ||
(end != OFF_MAX && fa->fa_start == end + 1) ||
(fa->fa_end != OFF_MAX && fa->fa_end + 1 == uap->offset))) {
if (uap->offset < fa->fa_start)
fa->fa_start = uap->offset;
(fa->fa_end != OFF_MAX && fa->fa_end + 1 == offset))) {
if (offset < fa->fa_start)
fa->fa_start = offset;
if (end > fa->fa_end)
fa->fa_end = end;
} else {
new->fa_advice = uap->advice;
new->fa_start = uap->offset;
new->fa_advice = advice;
new->fa_start = offset;
new->fa_end = end;
fp->f_advice = new;
new = fa;
@ -4942,18 +4942,15 @@ sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
mtx_pool_lock(mtxpool_sleep, fp);
fa = fp->f_advice;
if (fa != NULL) {
if (uap->offset <= fa->fa_start &&
end >= fa->fa_end) {
if (offset <= fa->fa_start && end >= fa->fa_end) {
new = fa;
fp->f_advice = NULL;
} else if (uap->offset <= fa->fa_start &&
end >= fa->fa_start)
} else if (offset <= fa->fa_start &&
end >= fa->fa_start)
fa->fa_start = end + 1;
else if (uap->offset <= fa->fa_end &&
end >= fa->fa_end)
fa->fa_end = uap->offset - 1;
else if (uap->offset >= fa->fa_start &&
end <= fa->fa_end) {
else if (offset <= fa->fa_end && end >= fa->fa_end)
fa->fa_end = offset - 1;
else if (offset >= fa->fa_start && end <= fa->fa_end) {
/*
* If the "normal" region is a middle
* portion of the existing
@ -4970,7 +4967,7 @@ sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
break;
case POSIX_FADV_WILLNEED:
case POSIX_FADV_DONTNEED:
error = VOP_ADVISE(vp, uap->offset, end, uap->advice);
error = VOP_ADVISE(vp, offset, end, advice);
break;
}
out:
@ -4979,3 +4976,11 @@ out:
free(new, M_FADVISE);
return (error);
}
int
sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap)
{
return (kern_posix_fadvise(td, uap->fd, uap->offset, uap->len,
uap->advice));
}

View File

@ -153,6 +153,10 @@ int kern_openat(struct thread *td, int fd, char *path,
int kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg,
int name, u_long flags);
int kern_pipe(struct thread *td, int fildes[2]);
int kern_posix_fadvise(struct thread *td, int fd, off_t offset, off_t len,
int advice);
int kern_posix_fallocate(struct thread *td, int fd, off_t offset,
off_t len);
int kern_preadv(struct thread *td, int fd, struct uio *auio, off_t offset);
int kern_pselect(struct thread *td, int nd, fd_set *in, fd_set *ou,
fd_set *ex, struct timeval *tvp, sigset_t *uset, int abi_nfdbits);