aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2018-03-23 20:54:32 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2018-03-26 11:54:15 -0400
commit72c44e35f02a1cb4032e476c398a7234badcf49f (patch)
treedd99c46c9bbafdd6f381d8b72a8e9abfa9b63a52
parentfa4493f0d9b3ac8f36743f1a26e2318b449ee4c8 (diff)
xfs: clean up xfs_mount allocation and dynamic initializers
Most of the generic data structures embedded in xfs_mount are dynamically initialized immediately after mp is allocated. A few fields are left out and initialized during the xfs_mountfs() sequence, after mp has been attached to the superblock. To clean this up and help prevent premature access of associated fields, refactor xfs_mount allocation and all dependent init calls into a new helper. This self-documents that all low level data structures (i.e., locks, trees, etc.) should be initialized before xfs_mount is attached to the superblock. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/libxfs/xfs_sb.c1
-rw-r--r--fs/xfs/xfs_mount.c2
-rw-r--r--fs/xfs/xfs_super.c39
3 files changed, 29 insertions, 13 deletions
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index a55f7a45fa78..53433cc024fd 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -731,7 +731,6 @@ xfs_sb_mount_common(
731 struct xfs_sb *sbp) 731 struct xfs_sb *sbp)
732{ 732{
733 mp->m_agfrotor = mp->m_agirotor = 0; 733 mp->m_agfrotor = mp->m_agirotor = 0;
734 spin_lock_init(&mp->m_agirotor_lock);
735 mp->m_maxagi = mp->m_sb.sb_agcount; 734 mp->m_maxagi = mp->m_sb.sb_agcount;
736 mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG; 735 mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
737 mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT; 736 mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 6f5a5e6764d8..a901b86772f8 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -817,8 +817,6 @@ xfs_mountfs(
817 /* 817 /*
818 * Allocate and initialize the per-ag data. 818 * Allocate and initialize the per-ag data.
819 */ 819 */
820 spin_lock_init(&mp->m_perag_lock);
821 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
822 error = xfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi); 820 error = xfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi);
823 if (error) { 821 if (error) {
824 xfs_warn(mp, "Failed per-ag init: %d", error); 822 xfs_warn(mp, "Failed per-ag init: %d", error);
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 951271f57d00..612c1d5348b3 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -1579,29 +1579,48 @@ xfs_destroy_percpu_counters(
1579 percpu_counter_destroy(&mp->m_fdblocks); 1579 percpu_counter_destroy(&mp->m_fdblocks);
1580} 1580}
1581 1581
1582STATIC int 1582static struct xfs_mount *
1583xfs_fs_fill_super( 1583xfs_mount_alloc(
1584 struct super_block *sb, 1584 struct super_block *sb)
1585 void *data,
1586 int silent)
1587{ 1585{
1588 struct inode *root; 1586 struct xfs_mount *mp;
1589 struct xfs_mount *mp = NULL;
1590 int flags = 0, error = -ENOMEM;
1591 1587
1592 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL); 1588 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1593 if (!mp) 1589 if (!mp)
1594 goto out; 1590 return NULL;
1595 1591
1592 mp->m_super = sb;
1596 spin_lock_init(&mp->m_sb_lock); 1593 spin_lock_init(&mp->m_sb_lock);
1594 spin_lock_init(&mp->m_agirotor_lock);
1595 INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
1596 spin_lock_init(&mp->m_perag_lock);
1597 mutex_init(&mp->m_growlock); 1597 mutex_init(&mp->m_growlock);
1598 atomic_set(&mp->m_active_trans, 0); 1598 atomic_set(&mp->m_active_trans, 0);
1599 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker); 1599 INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
1600 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker); 1600 INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
1601 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker); 1601 INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
1602 mp->m_kobj.kobject.kset = xfs_kset; 1602 mp->m_kobj.kobject.kset = xfs_kset;
1603 return mp;
1604}
1603 1605
1604 mp->m_super = sb; 1606
1607STATIC int
1608xfs_fs_fill_super(
1609 struct super_block *sb,
1610 void *data,
1611 int silent)
1612{
1613 struct inode *root;
1614 struct xfs_mount *mp = NULL;
1615 int flags = 0, error = -ENOMEM;
1616
1617 /*
1618 * allocate mp and do all low-level struct initializations before we
1619 * attach it to the super
1620 */
1621 mp = xfs_mount_alloc(sb);
1622 if (!mp)
1623 goto out;
1605 sb->s_fs_info = mp; 1624 sb->s_fs_info = mp;
1606 1625
1607 error = xfs_parseargs(mp, (char *)data); 1626 error = xfs_parseargs(mp, (char *)data);