CVS commit: src/sys/miscfs/fdesc

2021-05-01 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat May  1 15:08:14 UTC 2021

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
Make sure fdesc_lookup() never returns VNON vnodes.

Should fix PR kern/56130 (fdescfs create nodes with wrong major number)


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.134 src/sys/miscfs/fdesc/fdesc_vnops.c:1.135
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.134	Sat Jun 27 17:29:19 2020
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Sat May  1 15:08:14 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.134 2020/06/27 17:29:19 christos Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.135 2021/05/01 15:08:14 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.134 2020/06/27 17:29:19 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.135 2021/05/01 15:08:14 hannken Exp $");
 
 #include 
 #include 
@@ -295,9 +295,20 @@ bad:
 good:
 	KASSERT(ix != -1);
 	error = vcache_get(dvp->v_mount, , sizeof(ix), vpp);
-	if (error == 0 && ix == FD_CTTY)
+	if (error)
+		return error;
+
+	/*
+	 * Prevent returning VNON nodes.
+	 * Operation fdesc_inactive() will reset the type to VNON.
+	 */
+	if (ix == FD_CTTY)
 		(*vpp)->v_type = VCHR;
-	return error;
+	else if (ix >= FD_DESC)
+		(*vpp)->v_type = VREG;
+	KASSERT((*vpp)->v_type != VNON);
+
+	return 0;
 }
 
 int



CVS commit: src/sys/miscfs/fdesc

2014-09-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep  5 10:43:26 UTC 2014

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
The comment about toxicity was correct, restore VNON setting code and
then set the proper type in lookup.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.124 src/sys/miscfs/fdesc/fdesc_vnops.c:1.125
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.124	Fri Sep  5 05:26:16 2014
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Fri Sep  5 06:43:26 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.124 2014/09/05 09:26:16 matt Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.125 2014/09/05 10:43:26 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.124 2014/09/05 09:26:16 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.125 2014/09/05 10:43:26 christos Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -295,6 +295,8 @@ bad:
 good:
 	KASSERT(ix != -1);
 	error = vcache_get(dvp-v_mount, ix, sizeof(ix), vpp);
+	if (error == 0  ix == FD_CTTY)
+		(*vpp)-v_type = VCHR;
 	return error;
 }
 
@@ -838,7 +840,6 @@ fdesc_inactive(void *v)
 		struct vnode *a_vp;
 	} */ *ap = v;
 	struct vnode *vp = ap-a_vp;
-#if 0
 	struct fdescnode *fd = VTOFDESC(vp);
 
 	/*
@@ -847,7 +848,6 @@ fdesc_inactive(void *v)
 	 */
 	if (fd-fd_type == Fctty || fd-fd_type == Fdesc)
 		vp-v_type = VNON;
-#endif
 	VOP_UNLOCK(vp);
 	return (0);
 }



CVS commit: src/sys/miscfs/fdesc

2014-09-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep  4 13:28:54 UTC 2014

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
Well, nasty thing happen if you set /dev/tty to VNON too. Disable for now.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.121 src/sys/miscfs/fdesc/fdesc_vnops.c:1.122
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.121	Fri Jul 25 04:20:52 2014
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Thu Sep  4 09:28:54 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.121 2014/07/25 08:20:52 dholland Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.122 2014/09/04 13:28:54 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.121 2014/07/25 08:20:52 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.122 2014/09/04 13:28:54 christos Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -295,6 +295,7 @@ bad:
 good:
 	KASSERT(ix != -1);
 	error = vcache_get(dvp-v_mount, ix, sizeof(ix), vpp);
+printf(%s, %d: %d %d %p\n, __FILE__, __LINE__, error, ix, vpp);
 	return error;
 }
 
@@ -354,6 +355,7 @@ fdesc_attr(int fd, struct vattr *vap, ka
 			 */
 			vap-va_mode = ~(S_IXUSR|S_IXGRP|S_IXOTH);
 		}
+printf(%s, %d: %d %d\n, __FILE__, __LINE__, error, vap-va_type);
 		break;
 
 	default:
@@ -390,6 +392,7 @@ fdesc_attr(int fd, struct vattr *vap, ka
 		vap-va_flags = stb.st_flags;
 		vap-va_rdev = stb.st_rdev;
 		vap-va_bytes = stb.st_blocks * stb.st_blksize;
+printf(%s, %d: %d %lld\n, __FILE__, __LINE__, error, (long long)vap-va_rdev);
 		break;
 	}
 
@@ -764,10 +767,12 @@ fdesc_ioctl(void *v)
 	} */ *ap = v;
 	int error = EOPNOTSUPP;
 
+printf(%s, %d: ioctl %d\n, __FILE__, __LINE__, VTOFDESC(ap-a_vp)-fd_type);
 	switch (VTOFDESC(ap-a_vp)-fd_type) {
 	case Fctty:
 		error = cdev_ioctl(devctty, ap-a_command, ap-a_data,
 		ap-a_fflag, curlwp);
+printf(%s, %d: ioctl error %d\n, __FILE__, __LINE__, error);
 		break;
 
 	default:
@@ -838,6 +843,7 @@ fdesc_inactive(void *v)
 		struct vnode *a_vp;
 	} */ *ap = v;
 	struct vnode *vp = ap-a_vp;
+#if 0
 	struct fdescnode *fd = VTOFDESC(vp);
 
 	/*
@@ -846,6 +852,7 @@ fdesc_inactive(void *v)
 	 */
 	if (fd-fd_type == Fctty || fd-fd_type == Fdesc)
 		vp-v_type = VNON;
+#endif
 	VOP_UNLOCK(vp);
 	return (0);
 }



CVS commit: src/sys/miscfs/fdesc

2014-09-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep  4 13:29:50 UTC 2014

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
remove debugging.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.122 src/sys/miscfs/fdesc/fdesc_vnops.c:1.123
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.122	Thu Sep  4 09:28:54 2014
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Thu Sep  4 09:29:50 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.122 2014/09/04 13:28:54 christos Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.123 2014/09/04 13:29:50 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.122 2014/09/04 13:28:54 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.123 2014/09/04 13:29:50 christos Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -295,7 +295,6 @@ bad:
 good:
 	KASSERT(ix != -1);
 	error = vcache_get(dvp-v_mount, ix, sizeof(ix), vpp);
-printf(%s, %d: %d %d %p\n, __FILE__, __LINE__, error, ix, vpp);
 	return error;
 }
 
@@ -355,7 +354,6 @@ fdesc_attr(int fd, struct vattr *vap, ka
 			 */
 			vap-va_mode = ~(S_IXUSR|S_IXGRP|S_IXOTH);
 		}
-printf(%s, %d: %d %d\n, __FILE__, __LINE__, error, vap-va_type);
 		break;
 
 	default:
@@ -392,7 +390,6 @@ printf(%s, %d: %d %d\n, __FILE__, __LI
 		vap-va_flags = stb.st_flags;
 		vap-va_rdev = stb.st_rdev;
 		vap-va_bytes = stb.st_blocks * stb.st_blksize;
-printf(%s, %d: %d %lld\n, __FILE__, __LINE__, error, (long long)vap-va_rdev);
 		break;
 	}
 
@@ -767,12 +764,10 @@ fdesc_ioctl(void *v)
 	} */ *ap = v;
 	int error = EOPNOTSUPP;
 
-printf(%s, %d: ioctl %d\n, __FILE__, __LINE__, VTOFDESC(ap-a_vp)-fd_type);
 	switch (VTOFDESC(ap-a_vp)-fd_type) {
 	case Fctty:
 		error = cdev_ioctl(devctty, ap-a_command, ap-a_data,
 		ap-a_fflag, curlwp);
-printf(%s, %d: ioctl error %d\n, __FILE__, __LINE__, error);
 		break;
 
 	default:



CVS commit: src/sys/miscfs/fdesc

2014-09-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Sep  4 00:30:25 UTC 2014

Modified Files:
src/sys/miscfs/fdesc: fdesc_vfsops.c

Log Message:
Fix type of /dev/tty


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/miscfs/fdesc/fdesc_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vfsops.c
diff -u src/sys/miscfs/fdesc/fdesc_vfsops.c:1.89 src/sys/miscfs/fdesc/fdesc_vfsops.c:1.90
--- src/sys/miscfs/fdesc/fdesc_vfsops.c:1.89	Sun Jul 13 07:23:01 2014
+++ src/sys/miscfs/fdesc/fdesc_vfsops.c	Wed Sep  3 20:30:25 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vfsops.c,v 1.89 2014/07/13 11:23:01 hannken Exp $	*/
+/*	$NetBSD: fdesc_vfsops.c,v 1.90 2014/09/04 00:30:25 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1995
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.89 2014/07/13 11:23:01 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.90 2014/09/04 00:30:25 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -202,7 +202,7 @@ fdesc_loadvnode(struct mount *mp, struct
 		break;
 	case FD_CTTY:
 		fd-fd_type = Fctty;
-		vp-v_type = VNON;
+		vp-v_type = VCHR;
 		break;
 	case FD_STDIN:
 		fd-fd_type = Flink;



CVS commit: src/sys/miscfs/fdesc

2014-07-13 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sun Jul 13 11:23:01 UTC 2014

Modified Files:
src/sys/miscfs/fdesc: fdesc.h fdesc_vfsops.c fdesc_vnops.c

Log Message:
Change fdesc from hashlist to vcache.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/miscfs/fdesc/fdesc.h
cvs rdiff -u -r1.88 -r1.89 src/sys/miscfs/fdesc/fdesc_vfsops.c
cvs rdiff -u -r1.119 -r1.120 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc.h
diff -u src/sys/miscfs/fdesc/fdesc.h:1.21 src/sys/miscfs/fdesc/fdesc.h:1.22
--- src/sys/miscfs/fdesc/fdesc.h:1.21	Tue Sep 27 01:22:12 2011
+++ src/sys/miscfs/fdesc/fdesc.h	Sun Jul 13 11:23:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc.h,v 1.21 2011/09/27 01:22:12 christos Exp $	*/
+/*	$NetBSD: fdesc.h,v 1.22 2014/07/13 11:23:01 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -56,11 +56,10 @@ typedef enum {
 } fdntype;
 
 struct fdescnode {
-	LIST_ENTRY(fdescnode) fd_hash;	/* Hash list */
 	struct vnode	*fd_vnode;	/* Back ptr to vnode */
 	fdntype		fd_type;	/* Type of this node */
 	unsigned	fd_fd;		/* Fd to be dup'ed */
-	char		*fd_link;	/* Link to fd/n */
+	const char	*fd_link;	/* Link to fd/n */
 	int		fd_ix;		/* filesystem index */
 };
 

Index: src/sys/miscfs/fdesc/fdesc_vfsops.c
diff -u src/sys/miscfs/fdesc/fdesc_vfsops.c:1.88 src/sys/miscfs/fdesc/fdesc_vfsops.c:1.89
--- src/sys/miscfs/fdesc/fdesc_vfsops.c:1.88	Sun Mar 23 15:21:16 2014
+++ src/sys/miscfs/fdesc/fdesc_vfsops.c	Sun Jul 13 11:23:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vfsops.c,v 1.88 2014/03/23 15:21:16 hannken Exp $	*/
+/*	$NetBSD: fdesc_vfsops.c,v 1.89 2014/07/13 11:23:01 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1995
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.88 2014/03/23 15:21:16 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.89 2014/07/13 11:23:01 hannken Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -78,7 +78,7 @@ int
 fdesc_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
 {
 	struct lwp *l = curlwp;
-	int error = 0;
+	int error = 0, ix;
 	struct vnode *rvp;
 
 	if (mp-mnt_flag  MNT_GETARGS) {
@@ -91,12 +91,11 @@ fdesc_mount(struct mount *mp, const char
 	if (mp-mnt_flag  MNT_UPDATE)
 		return (EOPNOTSUPP);
 
-	error = fdesc_allocvp(Froot, FD_ROOT, mp, rvp);
+	ix = FD_ROOT;
+	error = vcache_get(mp, ix, sizeof(ix), rvp);
 	if (error)
-		return (error);
+		return error;
 
-	rvp-v_type = VDIR;
-	rvp-v_vflag |= VV_ROOT;
 	mp-mnt_stat.f_namemax = FDESC_MAXNAMLEN;
 	mp-mnt_flag |= MNT_LOCAL;
 	mp-mnt_data = rvp;
@@ -104,7 +103,6 @@ fdesc_mount(struct mount *mp, const char
 
 	error = set_statvfs_info(path, UIO_USERSPACE, fdesc, UIO_SYSSPACE,
 	mp-mnt_op-vfs_name, mp, l);
-	VOP_UNLOCK(rvp);
 	return error;
 }
 
@@ -174,6 +172,66 @@ fdesc_vget(struct mount *mp, ino_t ino,
 	return (EOPNOTSUPP);
 }
 
+int
+fdesc_loadvnode(struct mount *mp, struct vnode *vp,
+const void *key, size_t key_len, const void **new_key)
+{
+	int ix;
+	struct fdescnode *fd;
+
+	KASSERT(key_len == sizeof(ix));
+	memcpy(ix, key, key_len);
+
+	fd = kmem_alloc(sizeof(struct fdescnode), KM_SLEEP);
+	fd-fd_fd = -1;
+	fd-fd_link = NULL;
+	fd-fd_ix = ix;
+	fd-fd_vnode = vp;
+	vp-v_tag = VT_FDESC;
+	vp-v_op = fdesc_vnodeop_p;
+	vp-v_data = fd;
+	switch (ix) {
+	case FD_ROOT:
+		fd-fd_type = Froot;
+		vp-v_type = VDIR;
+		vp-v_vflag |= VV_ROOT;
+		break;
+	case FD_DEVFD:
+		fd-fd_type = Fdevfd;
+		vp-v_type = VDIR;
+		break;
+	case FD_CTTY:
+		fd-fd_type = Fctty;
+		vp-v_type = VNON;
+		break;
+	case FD_STDIN:
+		fd-fd_type = Flink;
+		fd-fd_link = fd/0;
+		vp-v_type = VLNK;
+		break;
+	case FD_STDOUT:
+		fd-fd_type = Flink;
+		fd-fd_link = fd/1;
+		vp-v_type = VLNK;
+		break;
+	case FD_STDERR:
+		fd-fd_type = Flink;
+		fd-fd_link = fd/2;
+		vp-v_type = VLNK;
+		break;
+	default:
+		KASSERT(ix = FD_DESC);
+		fd-fd_type = Fdesc;
+		fd-fd_fd = ix - FD_DESC;
+		vp-v_type = VNON;
+		break;
+	}
+	uvm_vnp_setsize(vp, 0);
+	*new_key = fd-fd_ix;
+
+	return 0;
+}
+
 extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
 
 const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
@@ -192,6 +250,7 @@ struct vfsops fdesc_vfsops = {
 	.vfs_statvfs = genfs_statvfs,
 	.vfs_sync = fdesc_sync,
 	.vfs_vget = fdesc_vget,
+	.vfs_loadvnode = fdesc_loadvnode,
 	.vfs_fhtovp = (void *)eopnotsupp,
 	.vfs_vptofh = (void *)eopnotsupp,
 	.vfs_init = fdesc_init,

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.119 src/sys/miscfs/fdesc/fdesc_vnops.c:1.120
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.119	Thu Mar 20 18:04:05 2014
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Sun Jul 13 11:23:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.119 2014/03/20 18:04:05 christos Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.120 2014/07/13 

CVS commit: src/sys/miscfs/fdesc

2014-03-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 20 18:04:05 UTC 2014

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
kill sprintf


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.118 src/sys/miscfs/fdesc/fdesc_vnops.c:1.119
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.118	Thu Feb 27 11:51:38 2014
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Thu Mar 20 14:04:05 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.118 2014/02/27 16:51:38 hannken Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.119 2014/03/20 18:04:05 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.118 2014/02/27 16:51:38 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.119 2014/03/20 18:04:05 christos Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -755,7 +755,8 @@ fdesc_readdir(void *v)
 dt-dt_ff[j]-ff_file == NULL)
 	continue;
 d.d_fileno = j + FD_STDIN;
-d.d_namlen = sprintf(d.d_name, %d, j);
+d.d_namlen = snprintf(d.d_name,
+sizeof(d.d_name), %d, j);
 d.d_type = DT_UNKNOWN;
 break;
 			}



CVS commit: src/sys/miscfs/fdesc

2011-09-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Sep 27 01:22:12 UTC 2011

Modified Files:
src/sys/miscfs/fdesc: fdesc.h fdesc_vfsops.c

Log Message:
define FDESC_MAXNAMLEN and use it.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/miscfs/fdesc/fdesc.h
cvs rdiff -u -r1.85 -r1.86 src/sys/miscfs/fdesc/fdesc_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc.h
diff -u src/sys/miscfs/fdesc/fdesc.h:1.20 src/sys/miscfs/fdesc/fdesc.h:1.21
--- src/sys/miscfs/fdesc/fdesc.h:1.20	Fri Jul 31 15:47:47 2009
+++ src/sys/miscfs/fdesc/fdesc.h	Mon Sep 26 21:22:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc.h,v 1.20 2009/07/31 19:47:47 pooka Exp $	*/
+/*	$NetBSD: fdesc.h,v 1.21 2011/09/27 01:22:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -66,6 +66,8 @@ struct fdescnode {
 
 #define	VTOFDESC(vp) ((struct fdescnode *)(vp)-v_data)
 
+#define FDESC_MAXNAMLEN	255
+
 extern dev_t devctty;
 extern void fdesc_init(void);
 extern void fdesc_done(void);

Index: src/sys/miscfs/fdesc/fdesc_vfsops.c
diff -u src/sys/miscfs/fdesc/fdesc_vfsops.c:1.85 src/sys/miscfs/fdesc/fdesc_vfsops.c:1.86
--- src/sys/miscfs/fdesc/fdesc_vfsops.c:1.85	Thu Jun 24 09:03:12 2010
+++ src/sys/miscfs/fdesc/fdesc_vfsops.c	Mon Sep 26 21:22:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vfsops.c,v 1.85 2010/06/24 13:03:12 hannken Exp $	*/
+/*	$NetBSD: fdesc_vfsops.c,v 1.86 2011/09/27 01:22:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1995
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.85 2010/06/24 13:03:12 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.86 2011/09/27 01:22:12 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -97,7 +97,7 @@ fdesc_mount(struct mount *mp, const char
 
 	rvp-v_type = VDIR;
 	rvp-v_vflag |= VV_ROOT;
-	mp-mnt_stat.f_namemax = MAXNAMLEN;
+	mp-mnt_stat.f_namemax = FDESC_MAXNAMLEN;
 	mp-mnt_flag |= MNT_LOCAL;
 	mp-mnt_data = rvp;
 	vfs_getnewfsid(mp);



CVS commit: src/sys/miscfs/fdesc

2010-07-16 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Fri Jul 16 10:41:12 UTC 2010

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
Use a kmutex to protect the hash chains and always take this mutex
before removing a node from the hash chain.

Release the hash list lock before calling getnewvnode() and check the
hash list again like other file systems do.

Take v_interlock before calling vget().


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.110 src/sys/miscfs/fdesc/fdesc_vnops.c:1.111
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.110	Thu Jun 24 13:03:12 2010
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Fri Jul 16 10:41:12 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.110 2010/06/24 13:03:12 hannken Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.111 2010/07/16 10:41:12 hannken Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.110 2010/06/24 13:03:12 hannken Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.111 2010/07/16 10:41:12 hannken Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -69,9 +69,7 @@
 
 #define cttyvp(p) ((p)-p_lflag  PL_CONTROLT ? (p)-p_session-s_ttyvp : NULL)
 
-#define FDL_WANT	0x01
-#define FDL_LOCKED	0x02
-static int fdcache_lock;
+static kmutex_t fdcache_lock;
 
 dev_t devctty;
 
@@ -187,6 +185,7 @@
 	/* locate the major number */
 	cttymajor = devsw_name2chr(ctty, NULL, 0);
 	devctty = makedev(cttymajor, 0);
+	mutex_init(fdcache_lock, MUTEX_DEFAULT, IPL_NONE);
 	fdhashtbl = hashinit(NFDCACHE, HASH_LIST, true, fdhash);
 }
 
@@ -197,6 +196,7 @@
 fdesc_done(void)
 {
 	hashdone(fdhashtbl, HASH_LIST, fdhash);
+	mutex_destroy(fdcache_lock);
 }
 
 /*
@@ -211,29 +211,36 @@
 
 	fc = FD_NHASH(ix);
 loop:
-	for (fd = fc-lh_first; fd != 0; fd = fd-fd_hash.le_next) {
+	mutex_enter(fdcache_lock);
+	LIST_FOREACH(fd, fc, fd_hash) {
 		if (fd-fd_ix == ix  fd-fd_vnode-v_mount == mp) {
-			if (vget(fd-fd_vnode, LK_EXCLUSIVE))
+			mutex_enter(fd-fd_vnode-v_interlock);
+			mutex_exit(fdcache_lock);
+			if (vget(fd-fd_vnode, LK_INTERLOCK | LK_EXCLUSIVE))
 goto loop;
 			*vpp = fd-fd_vnode;
-			return (error);
+			return 0;
 		}
 	}
-
-	/*
-	 * otherwise lock the array while we call getnewvnode
-	 * since that can block.
-	 */
-	if (fdcache_lock  FDL_LOCKED) {
-		fdcache_lock |= FDL_WANT;
-		(void) tsleep(fdcache_lock, PINOD, fdcache, 0);
-		goto loop;
-	}
-	fdcache_lock |= FDL_LOCKED;
+	mutex_exit(fdcache_lock);
 
 	error = getnewvnode(VT_FDESC, mp, fdesc_vnodeop_p, vpp);
 	if (error)
-		goto out;
+		return error;
+
+	mutex_enter(fdcache_lock);
+	LIST_FOREACH(fd, fc, fd_hash) {
+		if (fd-fd_ix == ix  fd-fd_vnode-v_mount == mp) {
+			/*
+			 * Another thread beat us, push back freshly
+			 * allocated vnode and retry.
+			 */
+			mutex_exit(fdcache_lock);
+			ungetnewvnode(*vpp);
+			goto loop;
+		}
+	}
+
 	fd = malloc(sizeof(struct fdescnode), M_TEMP, M_WAITOK);
 	(*vpp)-v_data = fd;
 	fd-fd_vnode = *vpp;
@@ -244,16 +251,9 @@
 	uvm_vnp_setsize(*vpp, 0);
 	VOP_LOCK(*vpp, LK_EXCLUSIVE);
 	LIST_INSERT_HEAD(fc, fd, fd_hash);
+	mutex_exit(fdcache_lock);
 
-out:;
-	fdcache_lock = ~FDL_LOCKED;
-
-	if (fdcache_lock  FDL_WANT) {
-		fdcache_lock = ~FDL_WANT;
-		wakeup(fdcache_lock);
-	}
-
-	return (error);
+	return 0;
 }
 
 /*
@@ -956,9 +956,11 @@
 	struct vnode *vp = ap-a_vp;
 	struct fdescnode *fd = VTOFDESC(vp);
 
+	mutex_enter(fdcache_lock);
 	LIST_REMOVE(fd, fd_hash);
 	free(vp-v_data, M_TEMP);
 	vp-v_data = 0;
+	mutex_exit(fdcache_lock);
 
 	return (0);
 }



CVS commit: src/sys/miscfs/fdesc

2009-07-31 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jul 31 18:50:58 UTC 2009

Modified Files:
src/sys/miscfs/fdesc: fdesc_vnops.c

Log Message:
Do a name-based search for the ctty major instead of requiring an
external symbol.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/miscfs/fdesc/fdesc_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc_vnops.c
diff -u src/sys/miscfs/fdesc/fdesc_vnops.c:1.107 src/sys/miscfs/fdesc/fdesc_vnops.c:1.108
--- src/sys/miscfs/fdesc/fdesc_vnops.c:1.107	Sun May 24 21:41:26 2009
+++ src/sys/miscfs/fdesc/fdesc_vnops.c	Fri Jul 31 18:50:58 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.107 2009/05/24 21:41:26 ad Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.108 2009/07/31 18:50:58 pooka Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.107 2009/05/24 21:41:26 ad Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vnops.c,v 1.108 2009/07/31 18:50:58 pooka Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -176,8 +176,6 @@
 const struct vnodeopv_desc fdesc_vnodeop_opv_desc =
 	{ fdesc_vnodeop_p, fdesc_vnodeop_entries };
 
-extern const struct cdevsw ctty_cdevsw;
-
 /*
  * Initialise cache headers
  */
@@ -187,7 +185,7 @@
 	int cttymajor;
 
 	/* locate the major number */
-	cttymajor = cdevsw_lookup_major(ctty_cdevsw);
+	cttymajor = devsw_name2chr(ctty, NULL, 0);
 	devctty = makedev(cttymajor, 0);
 	fdhashtbl = hashinit(NFDCACHE, HASH_LIST, true, fdhash);
 }



CVS commit: src/sys/miscfs/fdesc

2009-07-31 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jul 31 19:47:47 UTC 2009

Modified Files:
src/sys/miscfs/fdesc: fdesc.h fdesc_vfsops.c

Log Message:
Get rid of dependency on M_UFSMNT.  Since we need storage only for
one pointer, simply hang that off of mnt_data instead of allocating
storage.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/miscfs/fdesc/fdesc.h
cvs rdiff -u -r1.81 -r1.82 src/sys/miscfs/fdesc/fdesc_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/miscfs/fdesc/fdesc.h
diff -u src/sys/miscfs/fdesc/fdesc.h:1.19 src/sys/miscfs/fdesc/fdesc.h:1.20
--- src/sys/miscfs/fdesc/fdesc.h:1.19	Sat Jun 28 01:34:06 2008
+++ src/sys/miscfs/fdesc/fdesc.h	Fri Jul 31 19:47:47 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc.h,v 1.19 2008/06/28 01:34:06 rumble Exp $	*/
+/*	$NetBSD: fdesc.h,v 1.20 2009/07/31 19:47:47 pooka Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -37,9 +37,6 @@
  */
 
 #ifdef _KERNEL
-struct fdescmount {
-	struct vnode	*f_root;	/* Root node */
-};
 
 #define FD_ROOT		2
 #define FD_DEVFD	3
@@ -67,7 +64,6 @@
 	int		fd_ix;		/* filesystem index */
 };
 
-#define VFSTOFDESC(mp)	((struct fdescmount *)((mp)-mnt_data))
 #define	VTOFDESC(vp) ((struct fdescnode *)(vp)-v_data)
 
 extern dev_t devctty;

Index: src/sys/miscfs/fdesc/fdesc_vfsops.c
diff -u src/sys/miscfs/fdesc/fdesc_vfsops.c:1.81 src/sys/miscfs/fdesc/fdesc_vfsops.c:1.82
--- src/sys/miscfs/fdesc/fdesc_vfsops.c:1.81	Fri Jul 31 18:44:58 2009
+++ src/sys/miscfs/fdesc/fdesc_vfsops.c	Fri Jul 31 19:47:47 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vfsops.c,v 1.81 2009/07/31 18:44:58 pooka Exp $	*/
+/*	$NetBSD: fdesc_vfsops.c,v 1.82 2009/07/31 19:47:47 pooka Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1995
@@ -41,7 +41,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.81 2009/07/31 18:44:58 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: fdesc_vfsops.c,v 1.82 2009/07/31 19:47:47 pooka Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_compat_netbsd.h
@@ -79,7 +79,6 @@
 {
 	struct lwp *l = curlwp;
 	int error = 0;
-	struct fdescmount *fmp;
 	struct vnode *rvp;
 
 	if (mp-mnt_flag  MNT_GETARGS) {
@@ -96,14 +95,11 @@
 	if (error)
 		return (error);
 
-	fmp = (struct fdescmount *)malloc(sizeof(struct fdescmount),
-M_UFSMNT, M_WAITOK);	/* XXX */
 	rvp-v_type = VDIR;
 	rvp-v_vflag |= VV_ROOT;
-	fmp-f_root = rvp;
 	mp-mnt_stat.f_namemax = MAXNAMLEN;
 	mp-mnt_flag |= MNT_LOCAL;
-	mp-mnt_data = fmp;
+	mp-mnt_data = rvp;
 	vfs_getnewfsid(mp);
 
 	error = set_statvfs_info(path, UIO_USERSPACE, fdesc, UIO_SYSSPACE,
@@ -123,7 +119,7 @@
 {
 	int error;
 	int flags = 0;
-	struct vnode *rtvp = VFSTOFDESC(mp)-f_root;
+	struct vnode *rtvp = mp-mnt_data;
 
 	if (mntflags  MNT_FORCE)
 		flags |= FORCECLOSE;
@@ -137,10 +133,6 @@
 	 * Blow it away for future re-use
 	 */
 	vgone(rtvp);
-	/*
-	 * Finally, throw away the fdescmount structure
-	 */
-	free(mp-mnt_data, M_UFSMNT);	/* XXX */
 	mp-mnt_data = NULL;
 
 	return (0);
@@ -154,7 +146,7 @@
 	/*
 	 * Return locked reference to root.
 	 */
-	vp = VFSTOFDESC(mp)-f_root;
+	vp = mp-mnt_data;
 	VREF(vp);
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 	*vpp = vp;