svn commit: r271489 - in head/sys: kern ofed/include/linux opencrypto sys

John Baldwin jhb at FreeBSD.org
Fri Sep 12 21:29:13 UTC 2014


Author: jhb
Date: Fri Sep 12 21:29:10 2014
New Revision: 271489
URL: http://svnweb.freebsd.org/changeset/base/271489

Log:
  Fix various issues with invalid file operations:
  - Add invfo_rdwr() (for read and write), invfo_ioctl(), invfo_poll(),
    and invfo_kqfilter() for use by file types that do not support the
    respective operations.  Home-grown versions of invfo_poll() were
    universally broken (they returned an errno value, invfo_poll()
    uses poll_no_poll() to return an appropriate event mask).  Home-grown
    ioctl routines also tended to return an incorrect errno (invfo_ioctl
    returns ENOTTY).
  - Use the invfo_*() functions instead of local versions for
    unsupported file operations.
  - Reorder fileops members to match the order in the structure definition
    to make it easier to spot missing members.
  - Add several missing methods to linuxfileops used by the OFED shim
    layer: fo_write(), fo_truncate(), fo_kqfilter(), and fo_stat().  Most
    of these used invfo_*(), but a dummy fo_stat() implementation was
    added.

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/kern/kern_event.c
  head/sys/kern/sys_procdesc.c
  head/sys/kern/tty_pts.c
  head/sys/kern/uipc_mqueue.c
  head/sys/kern/uipc_sem.c
  head/sys/kern/uipc_shm.c
  head/sys/ofed/include/linux/linux_compat.c
  head/sys/opencrypto/cryptodev.c
  head/sys/sys/file.h

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/kern_descrip.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -3941,6 +3941,14 @@ struct fileops badfileops = {
 };
 
 int
+invfo_rdwr(struct file *fp, struct uio *uio, struct ucred *active_cred,
+    int flags, struct thread *td)
+{
+
+	return (EOPNOTSUPP);
+}
+
+int
 invfo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
     struct thread *td)
 {
@@ -3949,6 +3957,29 @@ invfo_truncate(struct file *fp, off_t le
 }
 
 int
+invfo_ioctl(struct file *fp, u_long com, void *data,
+    struct ucred *active_cred, struct thread *td)
+{
+
+	return (ENOTTY);
+}
+
+int
+invfo_poll(struct file *fp, int events, struct ucred *active_cred,
+    struct thread *td)
+{
+
+	return (poll_no_poll(events));
+}
+
+int
+invfo_kqfilter(struct file *fp, struct knote *kn)
+{
+
+	return (EINVAL);
+}
+
+int
 invfo_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
     struct thread *td)
 {

Modified: head/sys/kern/kern_event.c
==============================================================================
--- head/sys/kern/kern_event.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/kern_event.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -109,9 +109,6 @@ static void 	kqueue_wakeup(struct kqueue
 static struct filterops *kqueue_fo_find(int filt);
 static void	kqueue_fo_release(int filt);
 
-static fo_rdwr_t	kqueue_read;
-static fo_rdwr_t	kqueue_write;
-static fo_truncate_t	kqueue_truncate;
 static fo_ioctl_t	kqueue_ioctl;
 static fo_poll_t	kqueue_poll;
 static fo_kqfilter_t	kqueue_kqfilter;
@@ -119,9 +116,9 @@ static fo_stat_t	kqueue_stat;
 static fo_close_t	kqueue_close;
 
 static struct fileops kqueueops = {
-	.fo_read = kqueue_read,
-	.fo_write = kqueue_write,
-	.fo_truncate = kqueue_truncate,
+	.fo_read = invfo_rdwr,
+	.fo_write = invfo_rdwr,
+	.fo_truncate = invfo_truncate,
 	.fo_ioctl = kqueue_ioctl,
 	.fo_poll = kqueue_poll,
 	.fo_kqfilter = kqueue_kqfilter,
@@ -1602,35 +1599,6 @@ done_nl:
 	return (error);
 }
 
-/*
- * XXX
- * This could be expanded to call kqueue_scan, if desired.
- */
-/*ARGSUSED*/
-static int
-kqueue_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
-	int flags, struct thread *td)
-{
-	return (ENXIO);
-}
-
-/*ARGSUSED*/
-static int
-kqueue_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
-	 int flags, struct thread *td)
-{
-	return (ENXIO);
-}
-
-/*ARGSUSED*/
-static int
-kqueue_truncate(struct file *fp, off_t length, struct ucred *active_cred,
-	struct thread *td)
-{
-
-	return (EINVAL);
-}
-
 /*ARGSUSED*/
 static int
 kqueue_ioctl(struct file *fp, u_long cmd, void *data,

Modified: head/sys/kern/sys_procdesc.c
==============================================================================
--- head/sys/kern/sys_procdesc.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/sys_procdesc.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -87,28 +87,22 @@ FEATURE(process_descriptors, "Process De
 
 static uma_zone_t procdesc_zone;
 
-static fo_rdwr_t	procdesc_read;
-static fo_rdwr_t	procdesc_write;
-static fo_truncate_t	procdesc_truncate;
-static fo_ioctl_t	procdesc_ioctl;
 static fo_poll_t	procdesc_poll;
 static fo_kqfilter_t	procdesc_kqfilter;
 static fo_stat_t	procdesc_stat;
 static fo_close_t	procdesc_close;
-static fo_chmod_t	procdesc_chmod;
-static fo_chown_t	procdesc_chown;
 
 static struct fileops procdesc_ops = {
-	.fo_read = procdesc_read,
-	.fo_write = procdesc_write,
-	.fo_truncate = procdesc_truncate,
-	.fo_ioctl = procdesc_ioctl,
+	.fo_read = invfo_rdwr,
+	.fo_write = invfo_rdwr,
+	.fo_truncate = invfo_truncate,
+	.fo_ioctl = invfo_ioctl,
 	.fo_poll = procdesc_poll,
 	.fo_kqfilter = procdesc_kqfilter,
 	.fo_stat = procdesc_stat,
 	.fo_close = procdesc_close,
-	.fo_chmod = procdesc_chmod,
-	.fo_chown = procdesc_chown,
+	.fo_chmod = invfo_chmod,
+	.fo_chown = invfo_chown,
 	.fo_sendfile = invfo_sendfile,
 	.fo_flags = DFLAG_PASSABLE,
 };
@@ -413,38 +407,6 @@ procdesc_close(struct file *fp, struct t
 }
 
 static int
-procdesc_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
-    int flags, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-procdesc_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
-    int flags, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-procdesc_truncate(struct file *fp, off_t length, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-procdesc_ioctl(struct file *fp, u_long com, void *data,
-    struct ucred *active_cred, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
 procdesc_poll(struct file *fp, int events, struct ucred *active_cred,
     struct thread *td)
 {
@@ -569,18 +531,3 @@ procdesc_stat(struct file *fp, struct st
 	return (0);
 }
 
-static int
-procdesc_chmod(struct file *fp, mode_t mode, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-procdesc_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}

Modified: head/sys/kern/tty_pts.c
==============================================================================
--- head/sys/kern/tty_pts.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/tty_pts.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -253,14 +253,6 @@ done:	ttydisc_rint_done(tp);
 }
 
 static int
-ptsdev_truncate(struct file *fp, off_t length, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EINVAL);
-}
-
-static int
 ptsdev_ioctl(struct file *fp, u_long cmd, void *data,
     struct ucred *active_cred, struct thread *td)
 {
@@ -591,7 +583,7 @@ ptsdev_close(struct file *fp, struct thr
 static struct fileops ptsdev_ops = {
 	.fo_read	= ptsdev_read,
 	.fo_write	= ptsdev_write,
-	.fo_truncate	= ptsdev_truncate,
+	.fo_truncate	= invfo_truncate,
 	.fo_ioctl	= ptsdev_ioctl,
 	.fo_poll	= ptsdev_poll,
 	.fo_kqfilter	= ptsdev_kqfilter,

Modified: head/sys/kern/uipc_mqueue.c
==============================================================================
--- head/sys/kern/uipc_mqueue.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/uipc_mqueue.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -2418,35 +2418,6 @@ mq_proc_exit(void *arg __unused, struct 
 }
 
 static int
-mqf_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
-	int flags, struct thread *td)
-{
-	return (EOPNOTSUPP);
-}
-
-static int
-mqf_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
-	int flags, struct thread *td)
-{
-	return (EOPNOTSUPP);
-}
-
-static int
-mqf_truncate(struct file *fp, off_t length, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EINVAL);
-}
-
-static int
-mqf_ioctl(struct file *fp, u_long cmd, void *data,
-	struct ucred *active_cred, struct thread *td)
-{
-	return (ENOTTY);
-}
-
-static int
 mqf_poll(struct file *fp, int events, struct ucred *active_cred,
 	struct thread *td)
 {
@@ -2601,16 +2572,16 @@ filt_mqwrite(struct knote *kn, long hint
 }
 
 static struct fileops mqueueops = {
-	.fo_read		= mqf_read,
-	.fo_write		= mqf_write,
-	.fo_truncate		= mqf_truncate,
-	.fo_ioctl		= mqf_ioctl,
+	.fo_read		= invfo_rdwr,
+	.fo_write		= invfo_rdwr,
+	.fo_truncate		= invfo_truncate,
+	.fo_ioctl		= invfo_ioctl,
 	.fo_poll		= mqf_poll,
 	.fo_kqfilter		= mqf_kqfilter,
 	.fo_stat		= mqf_stat,
+	.fo_close		= mqf_close,
 	.fo_chmod		= mqf_chmod,
 	.fo_chown		= mqf_chown,
-	.fo_close		= mqf_close,
 	.fo_sendfile		= invfo_sendfile,
 };
 

Modified: head/sys/kern/uipc_sem.c
==============================================================================
--- head/sys/kern/uipc_sem.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/uipc_sem.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -126,12 +126,6 @@ static int	ksem_module_init(void);
 static int	ksem_remove(char *path, Fnv32_t fnv, struct ucred *ucred);
 static int	sem_modload(struct module *module, int cmd, void *arg);
 
-static fo_rdwr_t	ksem_read;
-static fo_rdwr_t	ksem_write;
-static fo_truncate_t	ksem_truncate;
-static fo_ioctl_t	ksem_ioctl;
-static fo_poll_t	ksem_poll;
-static fo_kqfilter_t	ksem_kqfilter;
 static fo_stat_t	ksem_stat;
 static fo_close_t	ksem_closef;
 static fo_chmod_t	ksem_chmod;
@@ -139,12 +133,12 @@ static fo_chown_t	ksem_chown;
 
 /* File descriptor operations. */
 static struct fileops ksem_ops = {
-	.fo_read = ksem_read,
-	.fo_write = ksem_write,
-	.fo_truncate = ksem_truncate,
-	.fo_ioctl = ksem_ioctl,
-	.fo_poll = ksem_poll,
-	.fo_kqfilter = ksem_kqfilter,
+	.fo_read = invfo_rdwr,
+	.fo_write = invfo_rdwr,
+	.fo_truncate = invfo_truncate,
+	.fo_ioctl = invfo_ioctl,
+	.fo_poll = invfo_poll,
+	.fo_kqfilter = invfo_kqfilter,
 	.fo_stat = ksem_stat,
 	.fo_close = ksem_closef,
 	.fo_chmod = ksem_chmod,
@@ -156,53 +150,6 @@ static struct fileops ksem_ops = {
 FEATURE(posix_sem, "POSIX semaphores");
 
 static int
-ksem_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
-    int flags, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-ksem_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
-    int flags, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-ksem_truncate(struct file *fp, off_t length, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EINVAL);
-}
-
-static int
-ksem_ioctl(struct file *fp, u_long com, void *data,
-    struct ucred *active_cred, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-ksem_poll(struct file *fp, int events, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-ksem_kqfilter(struct file *fp, struct knote *kn)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
 ksem_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
     struct thread *td)
 {

Modified: head/sys/kern/uipc_shm.c
==============================================================================
--- head/sys/kern/uipc_shm.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/kern/uipc_shm.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -120,9 +120,6 @@ static int	shm_dotruncate(struct shmfd *
 static fo_rdwr_t	shm_read;
 static fo_rdwr_t	shm_write;
 static fo_truncate_t	shm_truncate;
-static fo_ioctl_t	shm_ioctl;
-static fo_poll_t	shm_poll;
-static fo_kqfilter_t	shm_kqfilter;
 static fo_stat_t	shm_stat;
 static fo_close_t	shm_close;
 static fo_chmod_t	shm_chmod;
@@ -134,9 +131,9 @@ static struct fileops shm_ops = {
 	.fo_read = shm_read,
 	.fo_write = shm_write,
 	.fo_truncate = shm_truncate,
-	.fo_ioctl = shm_ioctl,
-	.fo_poll = shm_poll,
-	.fo_kqfilter = shm_kqfilter,
+	.fo_ioctl = invfo_ioctl,
+	.fo_poll = invfo_poll,
+	.fo_kqfilter = invfo_kqfilter,
 	.fo_stat = shm_stat,
 	.fo_close = shm_close,
 	.fo_chmod = shm_chmod,
@@ -355,29 +352,6 @@ shm_truncate(struct file *fp, off_t leng
 }
 
 static int
-shm_ioctl(struct file *fp, u_long com, void *data,
-    struct ucred *active_cred, struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-shm_poll(struct file *fp, int events, struct ucred *active_cred,
-    struct thread *td)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
-shm_kqfilter(struct file *fp, struct knote *kn)
-{
-
-	return (EOPNOTSUPP);
-}
-
-static int
 shm_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
     struct thread *td)
 {

Modified: head/sys/ofed/include/linux/linux_compat.c
==============================================================================
--- head/sys/ofed/include/linux/linux_compat.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/ofed/include/linux/linux_compat.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -568,11 +568,23 @@ linux_file_ioctl(struct file *fp, u_long
 	return (error);
 }
 
+static int
+linux_file_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
+    struct thread *td)
+{
+
+	return (EOPNOTSUPP);
+}
+
 struct fileops linuxfileops = {
 	.fo_read = linux_file_read,
+	.fo_write = invfo_rdwr,
+	.fo_truncate = invfo_truncate,
+	.fo_ioctl = linux_file_ioctl,
 	.fo_poll = linux_file_poll,
+	.fo_kqfilter = invfo_kqfilter,
+	.fo_stat = linux_file_stat,
 	.fo_close = linux_file_close,
-	.fo_ioctl = linux_file_ioctl,
 	.fo_chmod = invfo_chmod,
 	.fo_chown = invfo_chown,
 	.fo_sendfile = invfo_sendfile,

Modified: head/sys/opencrypto/cryptodev.c
==============================================================================
--- head/sys/opencrypto/cryptodev.c	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/opencrypto/cryptodev.c	Fri Sep 12 21:29:10 2014	(r271489)
@@ -281,25 +281,19 @@ struct fcrypt {
 	int		sesn;
 };
 
-static	int cryptof_rw(struct file *fp, struct uio *uio,
-		    struct ucred *cred, int flags, struct thread *);
-static	int cryptof_truncate(struct file *, off_t, struct ucred *,
-		    struct thread *);
 static	int cryptof_ioctl(struct file *, u_long, void *,
 		    struct ucred *, struct thread *);
-static	int cryptof_poll(struct file *, int, struct ucred *, struct thread *);
-static	int cryptof_kqfilter(struct file *, struct knote *);
 static	int cryptof_stat(struct file *, struct stat *,
 		    struct ucred *, struct thread *);
 static	int cryptof_close(struct file *, struct thread *);
 
 static struct fileops cryptofops = {
-    .fo_read = cryptof_rw,
-    .fo_write = cryptof_rw,
-    .fo_truncate = cryptof_truncate,
+    .fo_read = invfo_rdwr,
+    .fo_write = invfo_rdwr,
+    .fo_truncate = invfo_truncate,
     .fo_ioctl = cryptof_ioctl,
-    .fo_poll = cryptof_poll,
-    .fo_kqfilter = cryptof_kqfilter,
+    .fo_poll = invfo_poll,
+    .fo_kqfilter = invfo_kqfilter,
     .fo_stat = cryptof_stat,
     .fo_close = cryptof_close,
     .fo_chmod = invfo_chmod,
@@ -320,29 +314,6 @@ static	int cryptodev_op(struct csession 
 static	int cryptodev_key(struct crypt_kop *);
 static	int cryptodev_find(struct crypt_find_op *);
 
-static int
-cryptof_rw(
-	struct file *fp,
-	struct uio *uio,
-	struct ucred *active_cred,
-	int flags,
-	struct thread *td)
-{
-
-	return (EIO);
-}
-
-static int
-cryptof_truncate(
-	struct file *fp,
-	off_t length,
-	struct ucred *active_cred,
-	struct thread *td)
-{
-
-	return (EINVAL);
-}
-
 /*
  * Check a crypto identifier to see if it requested
  * a software device/driver.  This can be done either
@@ -961,26 +932,6 @@ cryptodev_find(struct crypt_find_op *fin
 
 /* ARGSUSED */
 static int
-cryptof_poll(
-	struct file *fp,
-	int events,
-	struct ucred *active_cred,
-	struct thread *td)
-{
-
-	return (0);
-}
-
-/* ARGSUSED */
-static int
-cryptof_kqfilter(struct file *fp, struct knote *kn)
-{
-
-	return (0);
-}
-
-/* ARGSUSED */
-static int
 cryptof_stat(
 	struct file *fp,
 	struct stat *sb,

Modified: head/sys/sys/file.h
==============================================================================
--- head/sys/sys/file.h	Fri Sep 12 21:20:36 2014	(r271488)
+++ head/sys/sys/file.h	Fri Sep 12 21:29:10 2014	(r271489)
@@ -231,10 +231,14 @@ int fget_write(struct thread *td, int fd
     struct file **fpp);
 int _fdrop(struct file *fp, struct thread *td);
 
+fo_rdwr_t	invfo_rdwr;
+fo_truncate_t	invfo_truncate;
+fo_ioctl_t	invfo_ioctl;
+fo_poll_t	invfo_poll;
+fo_kqfilter_t	invfo_kqfilter;
 fo_chmod_t	invfo_chmod;
 fo_chown_t	invfo_chown;
 fo_sendfile_t	invfo_sendfile;
-fo_truncate_t	invfo_truncate;
 
 fo_sendfile_t	vn_sendfile;
 fo_seek_t	vn_seek;


More information about the svn-src-all mailing list