Module Name:    src
Committed By:   hannken
Date:           Fri Jan 27 10:47:54 UTC 2017

Modified Files:
        src/sys/fs/tmpfs: tmpfs.h tmpfs_vfsops.c

Log Message:
Run vflush() when going from read/write to read only.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/fs/tmpfs/tmpfs.h
cvs rdiff -u -r1.68 -r1.69 src/sys/fs/tmpfs/tmpfs_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/fs/tmpfs/tmpfs.h
diff -u src/sys/fs/tmpfs/tmpfs.h:1.52 src/sys/fs/tmpfs/tmpfs.h:1.53
--- src/sys/fs/tmpfs/tmpfs.h:1.52	Mon Jul  6 10:07:12 2015
+++ src/sys/fs/tmpfs/tmpfs.h	Fri Jan 27 10:47:54 2017
@@ -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.
@@ -217,6 +217,9 @@ typedef struct tmpfs_mount {
 	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;
 

Index: src/sys/fs/tmpfs/tmpfs_vfsops.c
diff -u src/sys/fs/tmpfs/tmpfs_vfsops.c:1.68 src/sys/fs/tmpfs/tmpfs_vfsops.c:1.69
--- src/sys/fs/tmpfs/tmpfs_vfsops.c:1.68	Fri Aug 26 21:44:24 2016
+++ src/sys/fs/tmpfs/tmpfs_vfsops.c	Fri Jan 27 10:47:54 2017
@@ -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 @@ tmpfs_mount(struct mount *mp, const char
 	struct vnode *vp;
 	uint64_t memlimit;
 	ino_t nodes;
-	int error;
+	int error, flags;
 	bool set_memlimit;
 	bool set_nodes;
 
@@ -160,6 +160,20 @@ tmpfs_mount(struct mount *mp, const char
 		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 @@ tmpfs_mount(struct mount *mp, const char
 	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);

Reply via email to