Module Name:    src
Committed By:   snj
Date:           Mon May  9 19:45:00 UTC 2016

Modified Files:
        src/sys/fs/tmpfs [netbsd-7]: tmpfs_vfsops.c tmpfs_vnops.c

Log Message:
Pull up following revision(s) (requested by joerg in ticket #1163):
        sys/fs/tmpfs/tmpfs_vfsops.c: revision 1.66, 1.67
        sys/fs/tmpfs/tmpfs_vnops.c: revision 1.124
Only recheck size/node limits on update mounts, if there actually have
been specified.
--
Implement most of mount -ur functionality for tmpfs. Remaining issue is
the question who is responsible for syncing pending writes, but the
functionality is good enough for serving as read-only chroot base in
bulk builds.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.63.2.1 src/sys/fs/tmpfs/tmpfs_vfsops.c
cvs rdiff -u -r1.120.2.1 -r1.120.2.2 src/sys/fs/tmpfs/tmpfs_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/fs/tmpfs/tmpfs_vfsops.c
diff -u src/sys/fs/tmpfs/tmpfs_vfsops.c:1.63 src/sys/fs/tmpfs/tmpfs_vfsops.c:1.63.2.1
--- src/sys/fs/tmpfs/tmpfs_vfsops.c:1.63	Tue Jun 10 16:10:59 2014
+++ src/sys/fs/tmpfs/tmpfs_vfsops.c	Mon May  9 19:45:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vfsops.c,v 1.63 2014/06/10 16:10:59 martin Exp $	*/
+/*	$NetBSD: tmpfs_vfsops.c,v 1.63.2.1 2016/05/09 19:45:00 snj Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.63 2014/06/10 16:10:59 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.63.2.1 2016/05/09 19:45:00 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -102,6 +102,8 @@ tmpfs_mount(struct mount *mp, const char
 	uint64_t memlimit;
 	ino_t nodes;
 	int error;
+	bool set_memlimit;
+	bool set_nodes;
 
 	if (args == NULL)
 		return EINVAL;
@@ -146,26 +148,33 @@ tmpfs_mount(struct mount *mp, const char
 	/* Get the memory usage limit for this file-system. */
 	if (args->ta_size_max < PAGE_SIZE) {
 		memlimit = UINT64_MAX;
+		set_memlimit = false;
 	} else {
 		memlimit = args->ta_size_max;
+		set_memlimit = true;
 	}
 	KASSERT(memlimit > 0);
 
 	if (args->ta_nodes_max <= 3) {
 		nodes = 3 + (memlimit / 1024);
+		set_nodes = false;
 	} else {
 		nodes = args->ta_nodes_max;
+		set_nodes = true;
 	}
 	nodes = MIN(nodes, INT_MAX);
 	KASSERT(nodes >= 3);
 
 	if (mp->mnt_flag & MNT_UPDATE) {
 		tmp = VFS_TO_TMPFS(mp);
-		if (nodes < tmp->tm_nodes_cnt)
+		if (set_nodes && nodes < tmp->tm_nodes_cnt)
 			return EBUSY;
-		if ((error = tmpfs_mntmem_set(tmp, memlimit)) != 0)
-			return error;
-		tmp->tm_nodes_max = nodes;
+		if (set_memlimit) {
+			if ((error = tmpfs_mntmem_set(tmp, memlimit)) != 0)
+				return error;
+		}
+		if (set_nodes)
+			tmp->tm_nodes_max = nodes;
 		root = tmp->tm_root;
 		root->tn_uid = args->ta_root_uid;
 		root->tn_gid = args->ta_root_gid;
@@ -205,7 +214,7 @@ tmpfs_mount(struct mount *mp, const char
 	mp->mnt_stat.f_namemax = TMPFS_MAXNAMLEN;
 	mp->mnt_fs_bshift = PAGE_SHIFT;
 	mp->mnt_dev_bshift = DEV_BSHIFT;
-	mp->mnt_iflag |= IMNT_MPSAFE;
+	mp->mnt_iflag |= IMNT_MPSAFE | IMNT_CAN_RWTORO;
 	vfs_getnewfsid(mp);
 
 	error = set_statvfs_info(path, UIO_USERSPACE, "tmpfs", UIO_SYSSPACE,

Index: src/sys/fs/tmpfs/tmpfs_vnops.c
diff -u src/sys/fs/tmpfs/tmpfs_vnops.c:1.120.2.1 src/sys/fs/tmpfs/tmpfs_vnops.c:1.120.2.2
--- src/sys/fs/tmpfs/tmpfs_vnops.c:1.120.2.1	Mon Dec 22 02:05:08 2014
+++ src/sys/fs/tmpfs/tmpfs_vnops.c	Mon May  9 19:45:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vnops.c,v 1.120.2.1 2014/12/22 02:05:08 msaitoh Exp $	*/
+/*	$NetBSD: tmpfs_vnops.c,v 1.120.2.2 2016/05/09 19:45:00 snj Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.120.2.1 2014/12/22 02:05:08 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.120.2.2 2016/05/09 19:45:00 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -589,6 +589,11 @@ tmpfs_write(void *v)
 
 	KASSERT(VOP_ISLOCKED(vp));
 
+	if ((vp->v_mount->mnt_flag & MNT_RDONLY) != 0) {
+		error = EROFS;
+		goto out;
+	}
+
 	node = VP_TO_TMPFS_NODE(vp);
 	oldsize = node->tn_size;
 
@@ -1267,6 +1272,11 @@ tmpfs_putpages(void *v)
 		return 0;
 	}
 
+	if ((vp->v_mount->mnt_flag & MNT_RDONLY) != 0) {
+		mutex_exit(vp->v_interlock);
+		return EROFS;
+	}
+
 	node = VP_TO_TMPFS_NODE(vp);
 	uobj = node->tn_spec.tn_reg.tn_aobj;
 

Reply via email to