aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/super.c
diff options
context:
space:
mode:
authorBenjamin Marzinski <bmarzins@redhat.com>2014-11-13 21:42:04 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2014-11-17 05:36:39 -0500
commit2e60d7683c8d2ea21317f6d9f4cd3bf5428ce162 (patch)
treefc7900ad18814d1ea46879f93eab063ff5754d1e /fs/gfs2/super.c
parent48b6bca6b7b8309697fc8a101793befe92d249d9 (diff)
GFS2: update freeze code to use freeze/thaw_super on all nodes
The current gfs2 freezing code is considerably more complicated than it should be because it doesn't use the vfs freezing code on any node except the one that begins the freeze. This is because it needs to acquire a cluster glock before calling the vfs code to prevent a deadlock, and without the new freeze_super and thaw_super hooks, that was impossible. To deal with the issue, gfs2 had to do some hacky locking tricks to make sure that a frozen node couldn't be holding on a lock it needed to do the unfreeze ioctl. This patch makes use of the new hooks to simply the gfs2 locking code. Now, all the nodes in the cluster freeze and thaw in exactly the same way. Every node in the cluster caches the freeze glock in the shared state. The new freeze_super hook allows the freezing node to grab this freeze glock in the exclusive state without first calling the vfs freeze_super function. All the nodes in the cluster see this lock change, and call the vfs freeze_super function. The vfs locking code guarantees that the nodes can't get stuck holding the glocks necessary to unfreeze the system. To unfreeze, the freezing node uses the new thaw_super hook to drop the freeze glock. Again, all the nodes notice this, reacquire the glock in shared mode and call the vfs thaw_super function. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/super.c')
-rw-r--r--fs/gfs2/super.c112
1 files changed, 75 insertions, 37 deletions
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index a346f56c4c6d..5b327f837de7 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -26,6 +26,7 @@
26#include <linux/wait.h> 26#include <linux/wait.h>
27#include <linux/writeback.h> 27#include <linux/writeback.h>
28#include <linux/backing-dev.h> 28#include <linux/backing-dev.h>
29#include <linux/kernel.h>
29 30
30#include "gfs2.h" 31#include "gfs2.h"
31#include "incore.h" 32#include "incore.h"
@@ -399,7 +400,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
399{ 400{
400 struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); 401 struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
401 struct gfs2_glock *j_gl = ip->i_gl; 402 struct gfs2_glock *j_gl = ip->i_gl;
402 struct gfs2_holder thaw_gh; 403 struct gfs2_holder freeze_gh;
403 struct gfs2_log_header_host head; 404 struct gfs2_log_header_host head;
404 int error; 405 int error;
405 406
@@ -408,7 +409,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
408 return error; 409 return error;
409 410
410 error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 0, 411 error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 0,
411 &thaw_gh); 412 &freeze_gh);
412 if (error) 413 if (error)
413 goto fail_threads; 414 goto fail_threads;
414 415
@@ -434,13 +435,13 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
434 435
435 set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); 436 set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
436 437
437 gfs2_glock_dq_uninit(&thaw_gh); 438 gfs2_glock_dq_uninit(&freeze_gh);
438 439
439 return 0; 440 return 0;
440 441
441fail: 442fail:
442 thaw_gh.gh_flags |= GL_NOCACHE; 443 freeze_gh.gh_flags |= GL_NOCACHE;
443 gfs2_glock_dq_uninit(&thaw_gh); 444 gfs2_glock_dq_uninit(&freeze_gh);
444fail_threads: 445fail_threads:
445 kthread_stop(sdp->sd_quotad_process); 446 kthread_stop(sdp->sd_quotad_process);
446 kthread_stop(sdp->sd_logd_process); 447 kthread_stop(sdp->sd_logd_process);
@@ -580,14 +581,15 @@ int gfs2_statfs_sync(struct super_block *sb, int type)
580 struct buffer_head *m_bh, *l_bh; 581 struct buffer_head *m_bh, *l_bh;
581 int error; 582 int error;
582 583
584 sb_start_write(sb);
583 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, 585 error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
584 &gh); 586 &gh);
585 if (error) 587 if (error)
586 return error; 588 goto out;
587 589
588 error = gfs2_meta_inode_buffer(m_ip, &m_bh); 590 error = gfs2_meta_inode_buffer(m_ip, &m_bh);
589 if (error) 591 if (error)
590 goto out; 592 goto out_unlock;
591 593
592 spin_lock(&sdp->sd_statfs_spin); 594 spin_lock(&sdp->sd_statfs_spin);
593 gfs2_statfs_change_in(m_sc, m_bh->b_data + 595 gfs2_statfs_change_in(m_sc, m_bh->b_data +
@@ -615,8 +617,10 @@ out_bh2:
615 brelse(l_bh); 617 brelse(l_bh);
616out_bh: 618out_bh:
617 brelse(m_bh); 619 brelse(m_bh);
618out: 620out_unlock:
619 gfs2_glock_dq_uninit(&gh); 621 gfs2_glock_dq_uninit(&gh);
622out:
623 sb_end_write(sb);
620 return error; 624 return error;
621} 625}
622 626
@@ -643,14 +647,8 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
643 struct lfcc *lfcc; 647 struct lfcc *lfcc;
644 LIST_HEAD(list); 648 LIST_HEAD(list);
645 struct gfs2_log_header_host lh; 649 struct gfs2_log_header_host lh;
646 struct gfs2_inode *dip = GFS2_I(sdp->sd_root_dir->d_inode);
647 int error; 650 int error;
648 651
649 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0,
650 &sdp->sd_freeze_root_gh);
651 if (error)
652 return error;
653 atomic_set(&sdp->sd_frozen_root, 1);
654 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { 652 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
655 lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL); 653 lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL);
656 if (!lfcc) { 654 if (!lfcc) {
@@ -692,11 +690,6 @@ out:
692 gfs2_glock_dq_uninit(&lfcc->gh); 690 gfs2_glock_dq_uninit(&lfcc->gh);
693 kfree(lfcc); 691 kfree(lfcc);
694 } 692 }
695 if (error) {
696 atomic_dec(&sdp->sd_frozen_root);
697 wait_event(sdp->sd_frozen_root_wait, atomic_read(&sdp->sd_frozen_root) == 0);
698 gfs2_glock_dq_uninit(&sdp->sd_freeze_root_gh);
699 }
700 return error; 693 return error;
701} 694}
702 695
@@ -834,18 +827,14 @@ out:
834 827
835static int gfs2_make_fs_ro(struct gfs2_sbd *sdp) 828static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
836{ 829{
837 struct gfs2_holder thaw_gh; 830 struct gfs2_holder freeze_gh;
838 int error; 831 int error;
839 832
840 error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, GL_NOCACHE, 833 error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, GL_NOCACHE,
841 &thaw_gh); 834 &freeze_gh);
842 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) 835 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
843 return error; 836 return error;
844 837
845 down_write(&sdp->sd_log_flush_lock);
846 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
847 up_write(&sdp->sd_log_flush_lock);
848
849 kthread_stop(sdp->sd_quotad_process); 838 kthread_stop(sdp->sd_quotad_process);
850 kthread_stop(sdp->sd_logd_process); 839 kthread_stop(sdp->sd_logd_process);
851 840
@@ -853,11 +842,16 @@ static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
853 gfs2_quota_sync(sdp->sd_vfs, 0); 842 gfs2_quota_sync(sdp->sd_vfs, 0);
854 gfs2_statfs_sync(sdp->sd_vfs, 0); 843 gfs2_statfs_sync(sdp->sd_vfs, 0);
855 844
845 down_write(&sdp->sd_log_flush_lock);
846 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
847 up_write(&sdp->sd_log_flush_lock);
848
856 gfs2_log_flush(sdp, NULL, SHUTDOWN_FLUSH); 849 gfs2_log_flush(sdp, NULL, SHUTDOWN_FLUSH);
850 wait_event(sdp->sd_reserving_log_wait, atomic_read(&sdp->sd_reserving_log) == 0);
857 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks); 851 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
858 852
859 if (thaw_gh.gh_gl) 853 if (freeze_gh.gh_gl)
860 gfs2_glock_dq_uninit(&thaw_gh); 854 gfs2_glock_dq_uninit(&freeze_gh);
861 855
862 gfs2_quota_cleanup(sdp); 856 gfs2_quota_cleanup(sdp);
863 857
@@ -943,11 +937,41 @@ static int gfs2_sync_fs(struct super_block *sb, int wait)
943 struct gfs2_sbd *sdp = sb->s_fs_info; 937 struct gfs2_sbd *sdp = sb->s_fs_info;
944 938
945 gfs2_quota_sync(sb, -1); 939 gfs2_quota_sync(sb, -1);
946 if (wait && sdp && !atomic_read(&sdp->sd_log_freeze)) 940 if (wait && sdp)
947 gfs2_log_flush(sdp, NULL, NORMAL_FLUSH); 941 gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
948 return 0; 942 return 0;
949} 943}
950 944
945void gfs2_freeze_func(struct work_struct *work)
946{
947 int error;
948 struct gfs2_holder freeze_gh;
949 struct gfs2_sbd *sdp = container_of(work, struct gfs2_sbd, sd_freeze_work);
950 struct super_block *sb = sdp->sd_vfs;
951
952 atomic_inc(&sb->s_active);
953 error = gfs2_glock_nq_init(sdp->sd_freeze_gl, LM_ST_SHARED, 0,
954 &freeze_gh);
955 if (error) {
956 printk(KERN_INFO "GFS2: couln't get freeze lock : %d\n", error);
957 gfs2_assert_withdraw(sdp, 0);
958 }
959 else {
960 atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
961 error = thaw_super(sb);
962 if (error) {
963 printk(KERN_INFO "GFS2: couldn't thaw filesystem: %d\n",
964 error);
965 gfs2_assert_withdraw(sdp, 0);
966 }
967 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
968 freeze_gh.gh_flags |= GL_NOCACHE;
969 gfs2_glock_dq_uninit(&freeze_gh);
970 }
971 deactivate_super(sb);
972 return;
973}
974
951/** 975/**
952 * gfs2_freeze - prevent further writes to the filesystem 976 * gfs2_freeze - prevent further writes to the filesystem
953 * @sb: the VFS structure for the filesystem 977 * @sb: the VFS structure for the filesystem
@@ -957,10 +981,16 @@ static int gfs2_sync_fs(struct super_block *sb, int wait)
957static int gfs2_freeze(struct super_block *sb) 981static int gfs2_freeze(struct super_block *sb)
958{ 982{
959 struct gfs2_sbd *sdp = sb->s_fs_info; 983 struct gfs2_sbd *sdp = sb->s_fs_info;
960 int error; 984 int error = 0;
961 985
962 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) 986 mutex_lock(&sdp->sd_freeze_mutex);
963 return -EINVAL; 987 if (atomic_read(&sdp->sd_freeze_state) != SFS_UNFROZEN)
988 goto out;
989
990 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) {
991 error = -EINVAL;
992 goto out;
993 }
964 994
965 for (;;) { 995 for (;;) {
966 error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh); 996 error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh);
@@ -980,7 +1010,10 @@ static int gfs2_freeze(struct super_block *sb)
980 fs_err(sdp, "retrying...\n"); 1010 fs_err(sdp, "retrying...\n");
981 msleep(1000); 1011 msleep(1000);
982 } 1012 }
983 return 0; 1013 error = 0;
1014out:
1015 mutex_unlock(&sdp->sd_freeze_mutex);
1016 return error;
984} 1017}
985 1018
986/** 1019/**
@@ -993,10 +1026,15 @@ static int gfs2_unfreeze(struct super_block *sb)
993{ 1026{
994 struct gfs2_sbd *sdp = sb->s_fs_info; 1027 struct gfs2_sbd *sdp = sb->s_fs_info;
995 1028
1029 mutex_lock(&sdp->sd_freeze_mutex);
1030 if (atomic_read(&sdp->sd_freeze_state) != SFS_FROZEN ||
1031 sdp->sd_freeze_gh.gh_gl == NULL) {
1032 mutex_unlock(&sdp->sd_freeze_mutex);
1033 return 0;
1034 }
1035
996 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); 1036 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
997 atomic_dec(&sdp->sd_frozen_root); 1037 mutex_unlock(&sdp->sd_freeze_mutex);
998 wait_event(sdp->sd_frozen_root_wait, atomic_read(&sdp->sd_frozen_root) == 0);
999 gfs2_glock_dq_uninit(&sdp->sd_freeze_root_gh);
1000 return 0; 1038 return 0;
1001} 1039}
1002 1040
@@ -1618,8 +1656,8 @@ const struct super_operations gfs2_super_ops = {
1618 .evict_inode = gfs2_evict_inode, 1656 .evict_inode = gfs2_evict_inode,
1619 .put_super = gfs2_put_super, 1657 .put_super = gfs2_put_super,
1620 .sync_fs = gfs2_sync_fs, 1658 .sync_fs = gfs2_sync_fs,
1621 .freeze_fs = gfs2_freeze, 1659 .freeze_super = gfs2_freeze,
1622 .unfreeze_fs = gfs2_unfreeze, 1660 .thaw_super = gfs2_unfreeze,
1623 .statfs = gfs2_statfs, 1661 .statfs = gfs2_statfs,
1624 .remount_fs = gfs2_remount_fs, 1662 .remount_fs = gfs2_remount_fs,
1625 .drop_inode = gfs2_drop_inode, 1663 .drop_inode = gfs2_drop_inode,