Fri Jan 27 10:47:54 2017 UTC ()
Run vflush() when going from read/write to read only.


(hannken)
diff -r1.52 -r1.53 src/sys/fs/tmpfs/tmpfs.h
diff -r1.68 -r1.69 src/sys/fs/tmpfs/tmpfs_vfsops.c

cvs diff -r1.52 -r1.53 src/sys/fs/tmpfs/tmpfs.h (expand / switch to context diff)
--- src/sys/fs/tmpfs/tmpfs.h 2015/07/06 10:07:12 1.52
+++ src/sys/fs/tmpfs/tmpfs.h 2017/01/27 10:47:54 1.53
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs.h,v 1.52 2015/07/06 10:07:12 hannken Exp $	*/
+/*	$NetBSD: tmpfs.h,v 1.53 2017/01/27 10:47:54 hannken Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -216,6 +216,9 @@
 	uint64_t		tm_mem_limit;
 	uint64_t		tm_bytes_used;
 	kmutex_t		tm_acc_lock;
+
+	/* Read-only indicator. */
+	bool			tm_rdonly;
 
 	/* Pointer to the root inode. */
 	tmpfs_node_t *		tm_root;

cvs diff -r1.68 -r1.69 src/sys/fs/tmpfs/tmpfs_vfsops.c (expand / switch to context diff)
--- src/sys/fs/tmpfs/tmpfs_vfsops.c 2016/08/26 21:44:24 1.68
+++ src/sys/fs/tmpfs/tmpfs_vfsops.c 2017/01/27 10:47:54 1.69
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vfsops.c,v 1.68 2016/08/26 21:44:24 dholland Exp $	*/
+/*	$NetBSD: tmpfs_vfsops.c,v 1.69 2017/01/27 10:47:54 hannken 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.68 2016/08/26 21:44:24 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.69 2017/01/27 10:47:54 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -92,7 +92,7 @@
 	struct vnode *vp;
 	uint64_t memlimit;
 	ino_t nodes;
-	int error;
+	int error, flags;
 	bool set_memlimit;
 	bool set_nodes;
 
@@ -160,6 +160,20 @@
 		tmp = VFS_TO_TMPFS(mp);
 		if (set_nodes && nodes < tmp->tm_nodes_cnt)
 			return EBUSY;
+		if (!tmp->tm_rdonly && (mp->mnt_flag & MNT_RDONLY)) {
+			/* Changing from read/write to read-only. */
+			flags = WRITECLOSE;
+			if ((mp->mnt_flag & MNT_FORCE))
+				flags |= FORCECLOSE;
+			error = vflush(mp, NULL, flags);
+			if (error)
+				return error;
+			tmp->tm_rdonly = true;
+		}
+		if (tmp->tm_rdonly && (mp->mnt_flag & IMNT_WANTRDWR)) {
+			/* Changing from read-only to read/write. */
+			tmp->tm_rdonly = false;
+		}
 		if (set_memlimit) {
 			if ((error = tmpfs_mntmem_set(tmp, memlimit)) != 0)
 				return error;
@@ -178,6 +192,8 @@
 	if (tmp == NULL)
 		return ENOMEM;
 
+	if ((mp->mnt_flag & MNT_RDONLY))
+		tmp->tm_rdonly = true;
 	tmp->tm_nodes_max = nodes;
 	tmp->tm_nodes_cnt = 0;
 	LIST_INIT(&tmp->tm_nodes);