summaryrefslogtreecommitdiffstats
path: root/fs/gfs2/trans.c
diff options
context:
space:
mode:
authorBenjamin Marzinski <bmarzins@redhat.com>2014-05-01 23:26:55 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2014-05-14 05:04:34 -0400
commit24972557b12ce8fd5b6c6847d0e2ee1837ddc13b (patch)
treefb82edff8bfab9d4d1c4df6dd7784dd3c9f85c1b /fs/gfs2/trans.c
parent5a7c6690c2759d686d2c299402327e92ed92ab6c (diff)
GFS2: remove transaction glock
GFS2 has a transaction glock, which must be grabbed for every transaction, whose purpose is to deal with freezing the filesystem. Aside from this involving a large amount of locking, it is very easy to make the current fsfreeze code hang on unfreezing. This patch rewrites how gfs2 handles freezing the filesystem. The transaction glock is removed. In it's place is a freeze glock, which is cached (but not held) in a shared state by every node in the cluster when the filesystem is mounted. This lock only needs to be grabbed on freezing, and actions which need to be safe from freezing, like recovery. When a node wants to freeze the filesystem, it grabs this glock exclusively. When the freeze glock state changes on the nodes (either from shared to unlocked, or shared to exclusive), the filesystem does a special log flush. gfs2_log_flush() does all the work for flushing out the and shutting down the incore log, and then it tries to grab the freeze glock in a shared state again. Since the filesystem is stuck in gfs2_log_flush, no new transaction can start, and nothing can be written to disk. Unfreezing the filesytem simply involes dropping the freeze glock, allowing gfs2_log_flush() to grab and then release the shared lock, so it is cached for next time. However, in order for the unfreezing ioctl to occur, gfs2 needs to get a shared lock on the filesystem root directory inode to check permissions. If that glock has already been grabbed exclusively, fsfreeze will be unable to get the shared lock and unfreeze the filesystem. In order to allow the unfreeze, this patch makes gfs2 grab a shared lock on the filesystem root directory during the freeze, and hold it until it unfreezes the filesystem. The functions which need to grab a shared lock in order to allow the unfreeze ioctl to be issued now use the lock grabbed by the freeze code instead. The freeze and unfreeze code take care to make sure that this shared lock will not be dropped while another process is using it. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/trans.c')
-rw-r--r--fs/gfs2/trans.c44
1 files changed, 6 insertions, 38 deletions
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index bead90d27bad..0546ab4e28e8 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -48,6 +48,7 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
48 tr->tr_blocks = blocks; 48 tr->tr_blocks = blocks;
49 tr->tr_revokes = revokes; 49 tr->tr_revokes = revokes;
50 tr->tr_reserved = 1; 50 tr->tr_reserved = 1;
51 tr->tr_alloced = 1;
51 if (blocks) 52 if (blocks)
52 tr->tr_reserved += 6 + blocks; 53 tr->tr_reserved += 6 + blocks;
53 if (revokes) 54 if (revokes)
@@ -57,48 +58,22 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
57 INIT_LIST_HEAD(&tr->tr_buf); 58 INIT_LIST_HEAD(&tr->tr_buf);
58 59
59 sb_start_intwrite(sdp->sd_vfs); 60 sb_start_intwrite(sdp->sd_vfs);
60 gfs2_holder_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &tr->tr_t_gh);
61
62 error = gfs2_glock_nq(&tr->tr_t_gh);
63 if (error)
64 goto fail_holder_uninit;
65 61
66 error = gfs2_log_reserve(sdp, tr->tr_reserved); 62 error = gfs2_log_reserve(sdp, tr->tr_reserved);
67 if (error) 63 if (error)
68 goto fail_gunlock; 64 goto fail;
69 65
70 current->journal_info = tr; 66 current->journal_info = tr;
71 67
72 return 0; 68 return 0;
73 69
74fail_gunlock: 70fail:
75 gfs2_glock_dq(&tr->tr_t_gh);
76
77fail_holder_uninit:
78 sb_end_intwrite(sdp->sd_vfs); 71 sb_end_intwrite(sdp->sd_vfs);
79 gfs2_holder_uninit(&tr->tr_t_gh);
80 kfree(tr); 72 kfree(tr);
81 73
82 return error; 74 return error;
83} 75}
84 76
85/**
86 * gfs2_log_release - Release a given number of log blocks
87 * @sdp: The GFS2 superblock
88 * @blks: The number of blocks
89 *
90 */
91
92static void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
93{
94
95 atomic_add(blks, &sdp->sd_log_blks_free);
96 trace_gfs2_log_blocks(sdp, blks);
97 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
98 sdp->sd_jdesc->jd_blocks);
99 up_read(&sdp->sd_log_flush_lock);
100}
101
102static void gfs2_print_trans(const struct gfs2_trans *tr) 77static void gfs2_print_trans(const struct gfs2_trans *tr)
103{ 78{
104 pr_warn("Transaction created at: %pSR\n", (void *)tr->tr_ip); 79 pr_warn("Transaction created at: %pSR\n", (void *)tr->tr_ip);
@@ -119,11 +94,8 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
119 94
120 if (!tr->tr_touched) { 95 if (!tr->tr_touched) {
121 gfs2_log_release(sdp, tr->tr_reserved); 96 gfs2_log_release(sdp, tr->tr_reserved);
122 if (tr->tr_t_gh.gh_gl) { 97 if (tr->tr_alloced)
123 gfs2_glock_dq(&tr->tr_t_gh);
124 gfs2_holder_uninit(&tr->tr_t_gh);
125 kfree(tr); 98 kfree(tr);
126 }
127 sb_end_intwrite(sdp->sd_vfs); 99 sb_end_intwrite(sdp->sd_vfs);
128 return; 100 return;
129 } 101 }
@@ -137,16 +109,12 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
137 gfs2_print_trans(tr); 109 gfs2_print_trans(tr);
138 110
139 gfs2_log_commit(sdp, tr); 111 gfs2_log_commit(sdp, tr);
140 if (tr->tr_t_gh.gh_gl) { 112 if (tr->tr_alloced && !tr->tr_attached)
141 gfs2_glock_dq(&tr->tr_t_gh);
142 gfs2_holder_uninit(&tr->tr_t_gh);
143 if (!tr->tr_attached)
144 kfree(tr); 113 kfree(tr);
145 }
146 up_read(&sdp->sd_log_flush_lock); 114 up_read(&sdp->sd_log_flush_lock);
147 115
148 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) 116 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
149 gfs2_log_flush(sdp, NULL); 117 gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
150 sb_end_intwrite(sdp->sd_vfs); 118 sb_end_intwrite(sdp->sd_vfs);
151} 119}
152 120