Module Name:    src
Committed By:   hannken
Date:           Wed Mar  1 10:44:47 UTC 2017

Modified Files:
        src/sys/fs/tmpfs: tmpfs.h tmpfs_vfsops.c
        src/sys/kern: vfs_syscalls.c
        src/sys/rump/librump/rumpvfs: rumpfs.c
        src/sys/sys: fstypes.h param.h

Log Message:
Change the protocol to update a mounted file system from read-write
to read-only and vice versa:

- Add an internal flag IMNT_WANTRDONLY.
- Set either IMNT_WANTRDWR or IMNT_WANTRDONLY if going from or to read-only.
- After successfull call to VFS_MOUNT() set or clear MNT_RDONLY.

Adapt tmpfs and rumpfs to the new protocol.  Other file systems will be
updated when they get the IMNT_CAN_RWTORO property.

Welcome to 7.99.64


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/fs/tmpfs/tmpfs.h
cvs rdiff -u -r1.70 -r1.71 src/sys/fs/tmpfs/tmpfs_vfsops.c
cvs rdiff -u -r1.506 -r1.507 src/sys/kern/vfs_syscalls.c
cvs rdiff -u -r1.144 -r1.145 src/sys/rump/librump/rumpvfs/rumpfs.c
cvs rdiff -u -r1.34 -r1.35 src/sys/sys/fstypes.h
cvs rdiff -u -r1.530 -r1.531 src/sys/sys/param.h

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.53 src/sys/fs/tmpfs/tmpfs.h:1.54
--- src/sys/fs/tmpfs/tmpfs.h:1.53	Fri Jan 27 10:47:54 2017
+++ src/sys/fs/tmpfs/tmpfs.h	Wed Mar  1 10:44:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs.h,v 1.53 2017/01/27 10:47:54 hannken Exp $	*/
+/*	$NetBSD: tmpfs.h,v 1.54 2017/03/01 10:44:47 hannken Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -217,9 +217,6 @@ 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.70 src/sys/fs/tmpfs/tmpfs_vfsops.c:1.71
--- src/sys/fs/tmpfs/tmpfs_vfsops.c:1.70	Fri Feb 17 08:31:25 2017
+++ src/sys/fs/tmpfs/tmpfs_vfsops.c	Wed Mar  1 10:44:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: tmpfs_vfsops.c,v 1.70 2017/02/17 08:31:25 hannken Exp $	*/
+/*	$NetBSD: tmpfs_vfsops.c,v 1.71 2017/03/01 10:44:47 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.70 2017/02/17 08:31:25 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.71 2017/03/01 10:44:47 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -160,7 +160,7 @@ 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)) {
+		if ((mp->mnt_iflag & IMNT_WANTRDONLY)) {
 			/* Changing from read/write to read-only. */
 			flags = WRITECLOSE;
 			if ((mp->mnt_flag & MNT_FORCE))
@@ -168,11 +168,6 @@ tmpfs_mount(struct mount *mp, const char
 			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)
@@ -192,8 +187,6 @@ 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);

Index: src/sys/kern/vfs_syscalls.c
diff -u src/sys/kern/vfs_syscalls.c:1.506 src/sys/kern/vfs_syscalls.c:1.507
--- src/sys/kern/vfs_syscalls.c:1.506	Fri Feb 17 08:26:07 2017
+++ src/sys/kern/vfs_syscalls.c	Wed Mar  1 10:44:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_syscalls.c,v 1.506 2017/02/17 08:26:07 hannken Exp $	*/
+/*	$NetBSD: vfs_syscalls.c,v 1.507 2017/03/01 10:44:47 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.506 2017/02/17 08:26:07 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.507 2017/03/01 10:44:47 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_fileassoc.h"
@@ -295,12 +295,14 @@ mount_update(struct lwp *l, struct vnode
 	/*
 	 * Set the mount level flags.
 	 */
-	if (flags & MNT_RDONLY)
-		mp->mnt_flag |= MNT_RDONLY;
-	else if (mp->mnt_flag & MNT_RDONLY)
-		mp->mnt_iflag |= IMNT_WANTRDWR;
+	if ((flags & MNT_RDONLY) != (mp->mnt_flag & MNT_RDONLY)) {
+		if ((flags & MNT_RDONLY))
+			mp->mnt_iflag |= IMNT_WANTRDONLY;
+		else
+			mp->mnt_iflag |= IMNT_WANTRDWR;
+	}
 	mp->mnt_flag &= ~MNT_BASIC_FLAGS;
-	mp->mnt_flag |= flags & MNT_BASIC_FLAGS;
+	mp->mnt_flag |= (flags & ~MNT_RDONLY) & MNT_BASIC_FLAGS;
 	error = VFS_MOUNT(mp, path, data, data_len);
 
 	if (error && data != NULL) {
@@ -321,12 +323,14 @@ mount_update(struct lwp *l, struct vnode
 			error = error2;
 	}
 
-	if (mp->mnt_iflag & IMNT_WANTRDWR)
+	if (error == 0 && (mp->mnt_iflag & IMNT_WANTRDONLY))
+		mp->mnt_flag |= MNT_RDONLY;
+	else if (error == 0 && (mp->mnt_iflag & IMNT_WANTRDWR))
 		mp->mnt_flag &= ~MNT_RDONLY;
 	if (error)
 		mp->mnt_flag = saved_flags;
 	mp->mnt_flag &= ~MNT_OP_FLAGS;
-	mp->mnt_iflag &= ~IMNT_WANTRDWR;
+	mp->mnt_iflag &= ~(IMNT_WANTRDONLY | IMNT_WANTRDWR);
 	if ((mp->mnt_flag & (MNT_RDONLY | MNT_ASYNC)) == 0) {
 		if ((mp->mnt_iflag & IMNT_ONWORKLIST) == 0)
 			vfs_syncer_add_to_worklist(mp);

Index: src/sys/rump/librump/rumpvfs/rumpfs.c
diff -u src/sys/rump/librump/rumpvfs/rumpfs.c:1.144 src/sys/rump/librump/rumpvfs/rumpfs.c:1.145
--- src/sys/rump/librump/rumpvfs/rumpfs.c:1.144	Fri Feb 17 08:31:26 2017
+++ src/sys/rump/librump/rumpvfs/rumpfs.c	Wed Mar  1 10:44:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpfs.c,v 1.144 2017/02/17 08:31:26 hannken Exp $	*/
+/*	$NetBSD: rumpfs.c,v 1.145 2017/03/01 10:44:47 hannken Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.144 2017/02/17 08:31:26 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.145 2017/03/01 10:44:47 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -216,7 +216,6 @@ struct rumpfs_node {
 
 struct rumpfs_mount {
 	struct vnode *rfsmp_rvp;
-	bool rfsmp_rdonly;
 };
 
 #define INO_WHITEOUT 1
@@ -1806,7 +1805,6 @@ rumpfs_mountfs(struct mount *mp)
 	}
 
 	rfsmp->rfsmp_rvp->v_vflag |= VV_ROOT;
-	rfsmp->rfsmp_rdonly = (mp->mnt_flag & MNT_RDONLY) != 0;
 
 	mp->mnt_data = rfsmp;
 	mp->mnt_stat.f_namemax = RUMPFS_MAXNAMLEN;
@@ -1822,14 +1820,13 @@ rumpfs_mountfs(struct mount *mp)
 int
 rumpfs_mount(struct mount *mp, const char *mntpath, void *arg, size_t *alen)
 {
-	struct rumpfs_mount *rfsmp = mp->mnt_data;
 	int error, flags;
 
 	if (mp->mnt_flag & MNT_GETARGS) {
 		return 0;
 	}
 	if (mp->mnt_flag & MNT_UPDATE) {
-		if (!rfsmp->rfsmp_rdonly && (mp->mnt_flag & MNT_RDONLY)) {
+		if ((mp->mnt_iflag & IMNT_WANTRDONLY)) {
 			/* Changing from read/write to read-only. */
 			flags = WRITECLOSE;
 			if ((mp->mnt_flag & MNT_FORCE))
@@ -1837,11 +1834,6 @@ rumpfs_mount(struct mount *mp, const cha
 			error = vflush(mp, NULL, flags);
 			if (error)
 				return error;
-			rfsmp->rfsmp_rdonly = true;
-		}
-		if (rfsmp->rfsmp_rdonly && (mp->mnt_flag & IMNT_WANTRDWR)) {
-			/* Changing from read-only to read/write. */
-			rfsmp->rfsmp_rdonly = false;
 		}
 		return 0;
 	}
@@ -1966,7 +1958,6 @@ int
 rumpfs_mountroot()
 {
 	struct mount *mp;
-	struct rumpfs_mount *rfsmp;
 	int error;
 
 	if ((error = vfs_rootmountalloc(MOUNT_RUMPFS, "rootdev", &mp)) != 0) {
@@ -1984,9 +1975,7 @@ rumpfs_mountroot()
 	if (error)
 		panic("set_statvfs_info failed for rootfs: %d", error);
 
-	rfsmp = mp->mnt_data;
 	mp->mnt_flag &= ~MNT_RDONLY;
-	rfsmp->rfsmp_rdonly = false;
 	vfs_unbusy(mp, false, NULL);
 
 	return 0;

Index: src/sys/sys/fstypes.h
diff -u src/sys/sys/fstypes.h:1.34 src/sys/sys/fstypes.h:1.35
--- src/sys/sys/fstypes.h:1.34	Sat Oct  8 17:28:17 2016
+++ src/sys/sys/fstypes.h	Wed Mar  1 10:44:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fstypes.h,v 1.34 2016/10/08 17:28:17 ast Exp $	*/
+/*	$NetBSD: fstypes.h,v 1.35 2017/03/01 10:44:47 hannken Exp $	*/
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -216,6 +216,7 @@ typedef struct fhandle	fhandle_t;
 #define	IMNT_GONE	0x00000001	/* filesystem is gone.. */
 #define	IMNT_UNMOUNT	0x00000002	/* unmount in progress */
 #define	IMNT_WANTRDWR	0x00000004	/* upgrade to read/write requested */
+#define	IMNT_WANTRDONLY	0x00000008	/* upgrade to readonly requested */
 #define	IMNT_DTYPE	0x00000040	/* returns d_type fields */
 #define	IMNT_HAS_TRANS	0x00000080	/* supports transactions */
 #define	IMNT_MPSAFE	0x00000100	/* file system code MP safe */
@@ -270,6 +271,7 @@ typedef struct fhandle	fhandle_t;
 	"\11IMNT_MPSAFE" \
 	"\10IMNT_HAS_TRANS" \
 	"\07IMNT_DTYPE" \
+	"\04IMNT_WANTRDONLY" \
 	"\03IMNT_WANTRDWR" \
 	"\02IMNT_UNMOUNT" \
 	"\01IMNT_GONE"

Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.530 src/sys/sys/param.h:1.531
--- src/sys/sys/param.h:1.530	Mon Feb 27 21:33:47 2017
+++ src/sys/sys/param.h	Wed Mar  1 10:44:47 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: param.h,v 1.530 2017/02/27 21:33:47 jdolecek Exp $	*/
+/*	$NetBSD: param.h,v 1.531 2017/03/01 10:44:47 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -67,7 +67,7 @@
  *	2.99.9		(299000900)
  */
 
-#define	__NetBSD_Version__	799006300	/* NetBSD 7.99.63 */
+#define	__NetBSD_Version__	799006400	/* NetBSD 7.99.64 */
 
 #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
     (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)

Reply via email to