Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Nov 2011 14:06:14 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 201164 for review
Message-ID:  <201111041406.pA4E6ETi062802@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@201164?ac=10

Change 201164 by jhb@jhb_fiver on 2011/11/04 14:06:10

	Create kern_posix_fadvise() and expose kern_posix_fallocate() and use those
	to implement the compat32 wrappers.

Affected files ...

.. //depot/projects/fadvise/sys/compat/freebsd32/freebsd32_misc.c#7 edit
.. //depot/projects/fadvise/sys/kern/vfs_syscalls.c#14 edit
.. //depot/projects/fadvise/sys/sys/syscallsubr.h#2 edit

Differences ...

==== //depot/projects/fadvise/sys/compat/freebsd32/freebsd32_misc.c#7 (text+ko) ====

@@ -2828,23 +2828,16 @@
 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));
 }

==== //depot/projects/fadvise/sys/kern/vfs_syscalls.c#14 (text+ko) ====

@@ -4753,7 +4753,7 @@
 	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,7 @@
  * 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 +4863,9 @@
 	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 +4880,7 @@
 		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 +4900,11 @@
 		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 +4915,17 @@
 		 */
 		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 +4941,15 @@
 		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 +4966,7 @@
 		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 +4975,9 @@
 	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));
+}

==== //depot/projects/fadvise/sys/sys/syscallsubr.h#2 (text+ko) ====

@@ -153,6 +153,8 @@
 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_fallocate(struct thread *td, int fd, off_t offset, off_t len);
+int	kern_posix_fadvise(struct thread td, int fd, off_t offset, off_t len, int advice);
 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201111041406.pA4E6ETi062802>