Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Change the protocol to update a mounted file system from...



details:   https://anonhg.NetBSD.org/src/rev/609b75fdbc9b
branches:  trunk
changeset: 351849:609b75fdbc9b
user:      hannken <hannken%NetBSD.org@localhost>
date:      Wed Mar 01 10:44:47 2017 +0000

description:
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

diffstat:

 sys/fs/tmpfs/tmpfs.h              |   5 +----
 sys/fs/tmpfs/tmpfs_vfsops.c       |  13 +++----------
 sys/kern/vfs_syscalls.c           |  22 +++++++++++++---------
 sys/rump/librump/rumpvfs/rumpfs.c |  17 +++--------------
 sys/sys/fstypes.h                 |   4 +++-
 sys/sys/param.h                   |   4 ++--
 6 files changed, 25 insertions(+), 40 deletions(-)

diffs (245 lines):

diff -r 8b1a53f72303 -r 609b75fdbc9b sys/fs/tmpfs/tmpfs.h
--- a/sys/fs/tmpfs/tmpfs.h      Wed Mar 01 10:43:37 2017 +0000
+++ b/sys/fs/tmpfs/tmpfs.h      Wed Mar 01 10:44:47 2017 +0000
@@ -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 @@
        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;
 
diff -r 8b1a53f72303 -r 609b75fdbc9b sys/fs/tmpfs/tmpfs_vfsops.c
--- a/sys/fs/tmpfs/tmpfs_vfsops.c       Wed Mar 01 10:43:37 2017 +0000
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c       Wed Mar 01 10:44:47 2017 +0000
@@ -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 @@
                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 @@
                        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 @@
        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);
diff -r 8b1a53f72303 -r 609b75fdbc9b sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c   Wed Mar 01 10:43:37 2017 +0000
+++ b/sys/kern/vfs_syscalls.c   Wed Mar 01 10:44:47 2017 +0000
@@ -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 @@
        /*
         * 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 @@
                        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);
diff -r 8b1a53f72303 -r 609b75fdbc9b sys/rump/librump/rumpvfs/rumpfs.c
--- a/sys/rump/librump/rumpvfs/rumpfs.c Wed Mar 01 10:43:37 2017 +0000
+++ b/sys/rump/librump/rumpvfs/rumpfs.c Wed Mar 01 10:44:47 2017 +0000
@@ -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_mount {
        struct vnode *rfsmp_rvp;
-       bool rfsmp_rdonly;
 };
 
 #define INO_WHITEOUT 1
@@ -1806,7 +1805,6 @@
        }
 
        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 @@
 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 @@
                        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 @@
 rumpfs_mountroot()
 {
        struct mount *mp;
-       struct rumpfs_mount *rfsmp;
        int error;
 
        if ((error = vfs_rootmountalloc(MOUNT_RUMPFS, "rootdev", &mp)) != 0) {
@@ -1984,9 +1975,7 @@
        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;
diff -r 8b1a53f72303 -r 609b75fdbc9b sys/sys/fstypes.h
--- a/sys/sys/fstypes.h Wed Mar 01 10:43:37 2017 +0000
+++ b/sys/sys/fstypes.h Wed Mar 01 10:44:47 2017 +0000
@@ -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 @@
 #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 @@
        "\11IMNT_MPSAFE" \
        "\10IMNT_HAS_TRANS" \
        "\07IMNT_DTYPE" \
+       "\04IMNT_WANTRDONLY" \
        "\03IMNT_WANTRDWR" \
        "\02IMNT_UNMOUNT" \
        "\01IMNT_GONE"
diff -r 8b1a53f72303 -r 609b75fdbc9b sys/sys/param.h
--- a/sys/sys/param.h   Wed Mar 01 10:43:37 2017 +0000
+++ b/sys/sys/param.h   Wed Mar 01 10:44:47 2017 +0000
@@ -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__)



Home | Main Index | Thread Index | Old Index