Source-Changes-HG archive

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

[src/trunk]: src/sys/kern - Make the fstrans mount info part of the per-lwp s...



details:   https://anonhg.NetBSD.org/src/rev/c94c96907835
branches:  trunk
changeset: 997074:c94c96907835
user:      hannken <hannken%NetBSD.org@localhost>
date:      Wed Feb 20 10:09:45 2019 +0000

description:
- Make the fstrans mount info part of the per-lwp state and replace
  most accesses to the mount with fstrans mount info.

- Add "fmi_gone" to be true after unmount and add a counter of
  outstanding mount infos so fstrans_clear_lwp_info() only runs
  if there may be something to do.

- Move lookup of base mounts into per-lwp state.

- Keep a list of valid mounts for DIAGNOSTIC checks.

diffstat:

 sys/kern/vfs_trans.c |  338 +++++++++++++++++++++++++++++++-------------------
 1 files changed, 209 insertions(+), 129 deletions(-)

diffs (truncated from 699 to 300 lines):

diff -r 65528c82f1e2 -r c94c96907835 sys/kern/vfs_trans.c
--- a/sys/kern/vfs_trans.c      Wed Feb 20 10:08:37 2019 +0000
+++ b/sys/kern/vfs_trans.c      Wed Feb 20 10:09:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_trans.c,v 1.53 2019/02/20 10:08:37 hannken Exp $   */
+/*     $NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $   */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.53 2019/02/20 10:08:37 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.54 2019/02/20 10:09:45 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -68,6 +68,8 @@
        struct fstrans_lwp_info *fli_succ;
        struct lwp *fli_self;
        struct mount *fli_mount;
+       struct mount *fli_alias;
+       struct fstrans_mount_info *fli_mountinfo;
        int fli_trans_cnt;
        int fli_cow_cnt;
        enum fstrans_lock_type fli_lock_type;
@@ -76,8 +78,10 @@
 struct fstrans_mount_info {
        enum fstrans_state fmi_state;
        unsigned int fmi_ref_cnt;
+       bool fmi_gone;
        bool fmi_cow_change;
        LIST_HEAD(, fscow_handler) fmi_cow_handler;
+       struct mount *fmi_mount;
 };
 
 static specificdata_key_t lwp_data_key;        /* Our specific data key. */
@@ -89,23 +93,87 @@
 static pserialize_t fstrans_psz;       /* Pserialize state. */
 static LIST_HEAD(fstrans_lwp_head, fstrans_lwp_info) fstrans_fli_head;
                                        /* List of all fstrans_lwp_info. */
+static int fstrans_gone_count;         /* Number of fstrans_mount_info gone. */
 
-static inline struct mount *fstrans_normalize_mount(struct mount *);
 static void fstrans_lwp_dtor(void *);
-static void fstrans_mount_dtor(struct mount *);
+static void fstrans_mount_dtor(struct fstrans_mount_info *);
 static void fstrans_clear_lwp_info(void);
 static inline struct fstrans_lwp_info *
     fstrans_get_lwp_info(struct mount *, bool);
 static struct fstrans_lwp_info *fstrans_alloc_lwp_info(struct mount *);
 static inline int _fstrans_start(struct mount *, enum fstrans_lock_type, int);
 static bool grant_lock(const enum fstrans_state, const enum fstrans_lock_type);
-static bool state_change_done(const struct mount *);
-static bool cow_state_change_done(const struct mount *);
-static void cow_change_enter(const struct mount *);
-static void cow_change_done(const struct mount *);
+static bool state_change_done(const struct fstrans_mount_info *);
+static bool cow_state_change_done(const struct fstrans_mount_info *);
+static void cow_change_enter(struct fstrans_mount_info *);
+static void cow_change_done(struct fstrans_mount_info *);
 
 extern struct mount *dead_rootmount;
 
+#if defined(DIAGNOSTIC)
+
+struct fstrans_debug_mount {
+       struct mount *fdm_mount;
+       SLIST_ENTRY(fstrans_debug_mount) fdm_list;
+};
+
+static SLIST_HEAD(, fstrans_debug_mount) fstrans_debug_mount_head =
+    SLIST_HEAD_INITIALIZER(fstrans_debug_mount_head);
+
+static void
+fstrans_debug_mount(struct mount *mp)
+{
+       struct fstrans_debug_mount *fdm, *new;
+
+       KASSERT(mutex_owned(&fstrans_mount_lock));
+
+       mutex_exit(&fstrans_mount_lock);
+       new = kmem_alloc(sizeof(*new), KM_SLEEP);
+       new->fdm_mount = mp;
+       mutex_enter(&fstrans_mount_lock);
+
+       SLIST_FOREACH(fdm, &fstrans_debug_mount_head, fdm_list)
+               KASSERT(fdm->fdm_mount != mp);
+       SLIST_INSERT_HEAD(&fstrans_debug_mount_head, new, fdm_list);
+}
+
+static void
+fstrans_debug_unmount(struct mount *mp)
+{
+       struct fstrans_debug_mount *fdm;
+
+       KASSERT(mutex_owned(&fstrans_mount_lock));
+
+       SLIST_FOREACH(fdm, &fstrans_debug_mount_head, fdm_list)
+               if (fdm->fdm_mount == mp)
+                       break;
+       KASSERT(fdm != NULL);
+       SLIST_REMOVE(&fstrans_debug_mount_head, fdm,
+           fstrans_debug_mount, fdm_list);
+       kmem_free(fdm, sizeof(*fdm));
+}
+
+static void
+fstrans_debug_validate_mount(struct mount *mp)
+{
+       struct fstrans_debug_mount *fdm;
+
+       KASSERT(mutex_owned(&fstrans_mount_lock));
+
+       SLIST_FOREACH(fdm, &fstrans_debug_mount_head, fdm_list)
+               if (fdm->fdm_mount == mp)
+                       break;
+       KASSERTMSG(fdm != NULL, "mount %p invalid", mp);
+}
+
+#else /* defined(DIAGNOSTIC) */
+
+#define fstrans_debug_mount(mp)
+#define fstrans_debug_unmount(mp)
+#define fstrans_debug_validate_mount(mp)
+
+#endif  /* defined(DIAGNOSTIC) */
+
 /*
  * Initialize.
  */
@@ -127,21 +195,6 @@
 }
 
 /*
- * Normalize mount.
- * Return mount if file system supports fstrans, NULL otherwise.
- */
-static inline struct mount *
-fstrans_normalize_mount(struct mount *mp)
-{
-
-       while (mp && mp->mnt_lower)
-               mp = mp->mnt_lower;
-       if (mp == NULL)
-               return NULL;
-       return mp;
-}
-
-/*
  * Deallocate lwp state.
  */
 static void
@@ -153,9 +206,11 @@
                KASSERT(fli->fli_trans_cnt == 0);
                KASSERT(fli->fli_cow_cnt == 0);
                if (fli->fli_mount != NULL)
-                       fstrans_mount_dtor(fli->fli_mount);
+                       fstrans_mount_dtor(fli->fli_mountinfo);
                fli_next = fli->fli_succ;
                fli->fli_mount = NULL;
+               fli->fli_alias = NULL;
+               fli->fli_mountinfo = NULL;
                membar_sync();
                fli->fli_self = NULL;
        }
@@ -165,13 +220,11 @@
  * Dereference mount state.
  */
 static void
-fstrans_mount_dtor(struct mount *mp)
+fstrans_mount_dtor(struct fstrans_mount_info *fmi)
 {
-       struct fstrans_mount_info *fmi;
 
        mutex_enter(&fstrans_mount_lock);
 
-       fmi = mp->mnt_transinfo;
        KASSERT(fmi != NULL);
        fmi->fmi_ref_cnt -= 1;
        if (fmi->fmi_ref_cnt > 0) {
@@ -182,11 +235,12 @@
        KASSERT(fmi->fmi_state == FSTRANS_NORMAL);
        KASSERT(LIST_FIRST(&fmi->fmi_cow_handler) == NULL);
 
-       mp->mnt_transinfo = NULL;
+       KASSERT(fstrans_gone_count > 0);
+       fstrans_gone_count -= 1;
 
        mutex_exit(&fstrans_mount_lock);
 
-       kmem_free(mp, sizeof(*mp));
+       kmem_free(fmi->fmi_mount, sizeof(*fmi->fmi_mount));
        kmem_free(fmi, sizeof(*fmi));
 }
 
@@ -201,11 +255,14 @@
        newfmi = kmem_alloc(sizeof(*newfmi), KM_SLEEP);
        newfmi->fmi_state = FSTRANS_NORMAL;
        newfmi->fmi_ref_cnt = 1;
+       newfmi->fmi_gone = false;
        LIST_INIT(&newfmi->fmi_cow_handler);
        newfmi->fmi_cow_change = false;
+       newfmi->fmi_mount = mp;
 
        mutex_enter(&fstrans_mount_lock);
        mp->mnt_transinfo = newfmi;
+       fstrans_debug_mount(mp);
        mutex_exit(&fstrans_mount_lock);
 
        return 0;
@@ -217,10 +274,18 @@
 void
 fstrans_unmount(struct mount *mp)
 {
+       struct fstrans_mount_info *fmi = mp->mnt_transinfo;
 
-       KASSERT(mp->mnt_transinfo != NULL);
+       KASSERT(fmi != NULL);
 
-       fstrans_mount_dtor(mp);
+       mutex_enter(&fstrans_mount_lock);
+       fstrans_debug_unmount(mp);
+       fmi->fmi_gone = true;
+       mp->mnt_transinfo = NULL;
+       fstrans_gone_count += 1;
+       mutex_exit(&fstrans_mount_lock);
+
+       fstrans_mount_dtor(fmi);
 }
 
 /*
@@ -229,19 +294,30 @@
 static void
 fstrans_clear_lwp_info(void)
 {
-       struct fstrans_lwp_info *fli;
+       struct fstrans_lwp_info *head, **p, *fli;
 
        /*
         * Scan our list clearing entries whose mount is gone.
         */
-       for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
+       head = lwp_getspecific(lwp_data_key);
+       for (p = &head; *p; p = &(*p)->fli_succ) {
+               fli = *p;
                if (fli->fli_mount != NULL &&
-                   (fli->fli_mount->mnt_iflag & IMNT_GONE) != 0 &&
+                   fli->fli_mountinfo->fmi_gone &&
                    fli->fli_trans_cnt == 0 && fli->fli_cow_cnt == 0) {
-                       fstrans_mount_dtor(fli->fli_mount);
+                       *p = (*p)->fli_succ;
+                       fstrans_mount_dtor(fli->fli_mountinfo);
                        fli->fli_mount = NULL;
+                       fli->fli_alias = NULL;
+                       fli->fli_mountinfo = NULL;
+                       membar_sync();
+                       fli->fli_self = NULL;
+
+                       if (*p == NULL)
+                               break;
                }
        }
+       lwp_setspecific(lwp_data_key, head);
 }
 
 /*
@@ -250,35 +326,32 @@
 static struct fstrans_lwp_info *
 fstrans_alloc_lwp_info(struct mount *mp)
 {
-       struct fstrans_lwp_info *fli;
+       struct fstrans_lwp_info *fli, *fli2;
        struct fstrans_mount_info *fmi;
 
+       for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
+               if (fli->fli_mount == mp)
+                       return fli;
+       }
+
        /*
         * Try to reuse a cleared entry or allocate a new one.
         */
-       for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
-               KASSERT(fli->fli_mount != mp);
-               if (fli->fli_mount == NULL) {
+       mutex_enter(&fstrans_lock);
+       LIST_FOREACH(fli, &fstrans_fli_head, fli_list) {
+               membar_sync();
+               if (fli->fli_self == NULL) {
+                       KASSERT(fli->fli_mount == NULL);
                        KASSERT(fli->fli_trans_cnt == 0);
                        KASSERT(fli->fli_cow_cnt == 0);
+                       fli->fli_self = curlwp;
+                       fli->fli_succ = lwp_getspecific(lwp_data_key);
+                       lwp_setspecific(lwp_data_key, fli);
                        break;
                }
        }



Home | Main Index | Thread Index | Old Index