From 99da41eaf5e30c8a5fbe82dfce8adb148ce86e96 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 13 Jun 2013 12:07:36 -0700 Subject: [PATCH] hammer2 - pfsmount -> clustermount separation part 1 * Start working on turning the hammer2_pfsmount structure into an abstracted PFS 'cluster' structure. * Move hammer2_inode's allocation infrastructure to the pmp (except for the super-root inode which has no pmp). It was previously hmp-centric. --- sys/vfs/hammer2/hammer2.h | 13 +++++++------ sys/vfs/hammer2/hammer2_chain.c | 8 ++++---- sys/vfs/hammer2/hammer2_inode.c | 33 +++++++++++++++++++++++--------- sys/vfs/hammer2/hammer2_vfsops.c | 4 ++-- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/sys/vfs/hammer2/hammer2.h b/sys/vfs/hammer2/hammer2.h index 55a14380d4..e17fdc359d 100644 --- a/sys/vfs/hammer2/hammer2.h +++ b/sys/vfs/hammer2/hammer2.h @@ -309,7 +309,7 @@ struct hammer2_inode { typedef struct hammer2_inode hammer2_inode_t; #define HAMMER2_INODE_MODIFIED 0x0001 -#define HAMMER2_INODE_UNUSED0002 0x0002 +#define HAMMER2_INODE_SROOT 0x0002 /* kmalloc special case */ #define HAMMER2_INODE_RENAME_INPROG 0x0004 #define HAMMER2_INODE_ONRBTREE 0x0008 @@ -398,10 +398,6 @@ struct hammer2_mount { int pmp_count; /* PFS mounts backed by us */ TAILQ_ENTRY(hammer2_mount) mntentry; /* hammer2_mntlist */ - struct malloc_type *minode; - int ninodes; - int maxinodes; - struct malloc_type *mchain; int nipstacks; int maxipstacks; @@ -428,7 +424,11 @@ struct hammer2_mount { typedef struct hammer2_mount hammer2_mount_t; /* - * Per-PFS mount structure for device (aka vp->v_mount) + * HAMMER2 PFS mount point structure (aka vp->v_mount->mnt_data). + * + * This structure represents a cluster mount and not necessarily a + * PFS under a specific device mount (HMP). The distinction is important + * because the elements backing a cluster mount can change on the fly. */ struct hammer2_pfsmount { struct mount *mp; /* kernel mount */ @@ -439,6 +439,7 @@ struct hammer2_pfsmount { ccms_domain_t ccms_dom; struct netexport export; /* nfs export */ int ronly; /* read-only mount */ + struct malloc_type *minode; struct malloc_type *mmsg; kdmsg_iocom_t iocom; struct spinlock inum_spin; /* inumber lookup */ diff --git a/sys/vfs/hammer2/hammer2_chain.c b/sys/vfs/hammer2/hammer2_chain.c index eaf55b5d46..a3b2450828 100644 --- a/sys/vfs/hammer2/hammer2_chain.c +++ b/sys/vfs/hammer2/hammer2_chain.c @@ -426,7 +426,7 @@ hammer2_chain_lastdrop(hammer2_chain_t *chain) break; case HAMMER2_BREF_TYPE_INODE: if (chain->data) { - kfree(chain->data, hmp->minode); + kfree(chain->data, hmp->mchain); chain->data = NULL; } break; @@ -670,7 +670,7 @@ hammer2_chain_lock(hammer2_chain_t *chain, int how) KKASSERT(chain->bytes == sizeof(chain->data->ipdata)); atomic_set_int(&chain->flags, HAMMER2_CHAIN_EMBEDDED); chain->data = kmalloc(sizeof(chain->data->ipdata), - hmp->minode, M_WAITOK | M_ZERO); + hmp->mchain, M_WAITOK | M_ZERO); bcopy(bdata, &chain->data->ipdata, chain->bytes); bqrelse(chain->bp); chain->bp = NULL; @@ -2096,7 +2096,7 @@ hammer2_chain_create(hammer2_trans_t *trans, hammer2_chain_t **parentp, KKASSERT(bytes == HAMMER2_INODE_BYTES); atomic_set_int(&chain->flags, HAMMER2_CHAIN_EMBEDDED); chain->data = kmalloc(sizeof(chain->data->ipdata), - hmp->minode, M_WAITOK | M_ZERO); + hmp->mchain, M_WAITOK | M_ZERO); break; case HAMMER2_BREF_TYPE_INDIRECT: panic("hammer2_chain_create: cannot be used to" @@ -2633,7 +2633,7 @@ hammer2_chain_dup_fixup(hammer2_chain_t *ochain, hammer2_chain_t *nchain) KKASSERT(nchain->data == NULL); atomic_set_int(&nchain->flags, HAMMER2_CHAIN_EMBEDDED); nchain->data = kmalloc(sizeof(nchain->data->ipdata), - ochain->hmp->minode, M_WAITOK | M_ZERO); + ochain->hmp->mchain, M_WAITOK | M_ZERO); nchain->data->ipdata = ochain->data->ipdata; break; case HAMMER2_BREF_TYPE_FREEMAP_LEAF: diff --git a/sys/vfs/hammer2/hammer2_inode.c b/sys/vfs/hammer2/hammer2_inode.c index be3294b775..cdf59608a8 100644 --- a/sys/vfs/hammer2/hammer2_inode.c +++ b/sys/vfs/hammer2/hammer2_inode.c @@ -230,6 +230,7 @@ void hammer2_inode_drop(hammer2_inode_t *ip) { hammer2_mount_t *hmp; + hammer2_pfsmount_t *pmp; hammer2_inode_t *pip; u_int refs; @@ -243,8 +244,9 @@ hammer2_inode_drop(hammer2_inode_t *ip) * * NOTE: The super-root inode has no pmp. */ - if (ip->pmp) - spin_lock(&ip->pmp->inum_spin); + pmp = ip->pmp; + if (pmp) + spin_lock(&pmp->inum_spin); if (atomic_cmpset_int(&ip->refs, 1, 0)) { KKASSERT(ip->topo_cst.count == 0); @@ -252,16 +254,16 @@ hammer2_inode_drop(hammer2_inode_t *ip) atomic_clear_int(&ip->flags, HAMMER2_INODE_ONRBTREE); RB_REMOVE(hammer2_inode_tree, - &ip->pmp->inum_tree, - ip); + &pmp->inum_tree, ip); } - if (ip->pmp) - spin_unlock(&ip->pmp->inum_spin); + if (pmp) + spin_unlock(&pmp->inum_spin); hmp = ip->hmp; ip->hmp = NULL; pip = ip->pip; ip->pip = NULL; + ip->pmp = NULL; /* * Cleaning out ip->chain isn't entirely @@ -274,11 +276,19 @@ hammer2_inode_drop(hammer2_inode_t *ip) * dispose of our implied reference from * ip->pip. We can simply loop on it. */ - kfree(ip, hmp->minode); + if (pmp) { + KKASSERT((ip->flags & + HAMMER2_INODE_SROOT) == 0); + kfree(ip, pmp->minode); + } else { + KKASSERT(ip->flags & + HAMMER2_INODE_SROOT); + kfree(ip, hmp->mchain); + } ip = pip; /* continue with pip (can be NULL) */ } else { - if (ip->pmp) + if (pmp) spin_unlock(&ip->pmp->inum_spin); } } else { @@ -473,7 +483,12 @@ again: /* * We couldn't find the inode number, create a new inode. */ - nip = kmalloc(sizeof(*nip), hmp->minode, M_WAITOK | M_ZERO); + if (pmp) { + nip = kmalloc(sizeof(*nip), pmp->minode, M_WAITOK | M_ZERO); + } else { + nip = kmalloc(sizeof(*nip), hmp->mchain, M_WAITOK | M_ZERO); + nip->flags = HAMMER2_INODE_SROOT; + } nip->inum = chain->data->ipdata.inum; hammer2_inode_repoint(nip, NULL, chain); nip->pip = dip; /* can be NULL */ diff --git a/sys/vfs/hammer2/hammer2_vfsops.c b/sys/vfs/hammer2/hammer2_vfsops.c index 074ee2ef21..cb3f365854 100644 --- a/sys/vfs/hammer2/hammer2_vfsops.c +++ b/sys/vfs/hammer2/hammer2_vfsops.c @@ -372,6 +372,7 @@ hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data, * From this point on we have to call hammer2_unmount() on failure. */ pmp = kmalloc(sizeof(*pmp), M_HAMMER2, M_WAITOK | M_ZERO); + kmalloc_create(&pmp->minode, "HAMMER2-inodes"); mp->mnt_data = (qaddr_t)pmp; pmp->mp = mp; @@ -389,7 +390,6 @@ hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data, hmp = kmalloc(sizeof(*hmp), M_HAMMER2, M_WAITOK | M_ZERO); hmp->ronly = ronly; hmp->devvp = devvp; - kmalloc_create(&hmp->minode, "HAMMER2-inodes"); kmalloc_create(&hmp->mchain, "HAMMER2-chains"); TAILQ_INSERT_TAIL(&hammer2_mntlist, hmp, mntentry); } @@ -737,11 +737,11 @@ hammer2_vfs_unmount(struct mount *mp, int mntflags) mp->mnt_data = NULL; kmalloc_destroy(&pmp->mmsg); + kmalloc_destroy(&pmp->minode); kfree(pmp, M_HAMMER2); if (hmp->pmp_count == 0) { TAILQ_REMOVE(&hammer2_mntlist, hmp, mntentry); - kmalloc_destroy(&hmp->minode); kmalloc_destroy(&hmp->mchain); kfree(hmp, M_HAMMER2); } -- 2.41.0