David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Bob Peterson | da6dd40 | 2007-12-11 18:49:21 -0600 | [diff] [blame] | 3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/completion.h> |
| 14 | #include <linux/buffer_head.h> |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 15 | #include <linux/crc32.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 16 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | f45b7dd | 2006-07-27 13:53:53 -0400 | [diff] [blame] | 17 | #include <linux/bio.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 18 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 19 | |
| 20 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 22 | #include "bmap.h" |
| 23 | #include "dir.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 24 | #include "glock.h" |
| 25 | #include "glops.h" |
| 26 | #include "inode.h" |
| 27 | #include "log.h" |
| 28 | #include "meta_io.h" |
| 29 | #include "quota.h" |
| 30 | #include "recovery.h" |
| 31 | #include "rgrp.h" |
| 32 | #include "super.h" |
| 33 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 34 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 35 | |
Steven Whitehouse | fefc03b | 2008-12-19 15:32:06 +0000 | [diff] [blame^] | 36 | /** |
| 37 | * gfs2_jindex_free - Clear all the journal index information |
| 38 | * @sdp: The GFS2 superblock |
| 39 | * |
| 40 | */ |
| 41 | |
| 42 | void gfs2_jindex_free(struct gfs2_sbd *sdp) |
| 43 | { |
| 44 | struct list_head list, *head; |
| 45 | struct gfs2_jdesc *jd; |
| 46 | struct gfs2_journal_extent *jext; |
| 47 | |
| 48 | spin_lock(&sdp->sd_jindex_spin); |
| 49 | list_add(&list, &sdp->sd_jindex_list); |
| 50 | list_del_init(&sdp->sd_jindex_list); |
| 51 | sdp->sd_journals = 0; |
| 52 | spin_unlock(&sdp->sd_jindex_spin); |
| 53 | |
| 54 | while (!list_empty(&list)) { |
| 55 | jd = list_entry(list.next, struct gfs2_jdesc, jd_list); |
| 56 | head = &jd->extent_list; |
| 57 | while (!list_empty(head)) { |
| 58 | jext = list_entry(head->next, |
| 59 | struct gfs2_journal_extent, |
| 60 | extent_list); |
| 61 | list_del(&jext->extent_list); |
| 62 | kfree(jext); |
| 63 | } |
| 64 | list_del(&jd->jd_list); |
| 65 | iput(jd->jd_inode); |
| 66 | kfree(jd); |
| 67 | } |
| 68 | } |
| 69 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 70 | static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid) |
| 71 | { |
| 72 | struct gfs2_jdesc *jd; |
| 73 | int found = 0; |
| 74 | |
| 75 | list_for_each_entry(jd, head, jd_list) { |
| 76 | if (jd->jd_jid == jid) { |
| 77 | found = 1; |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (!found) |
| 83 | jd = NULL; |
| 84 | |
| 85 | return jd; |
| 86 | } |
| 87 | |
| 88 | struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid) |
| 89 | { |
| 90 | struct gfs2_jdesc *jd; |
| 91 | |
| 92 | spin_lock(&sdp->sd_jindex_spin); |
| 93 | jd = jdesc_find_i(&sdp->sd_jindex_list, jid); |
| 94 | spin_unlock(&sdp->sd_jindex_spin); |
| 95 | |
| 96 | return jd; |
| 97 | } |
| 98 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 99 | int gfs2_jdesc_check(struct gfs2_jdesc *jd) |
| 100 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 101 | struct gfs2_inode *ip = GFS2_I(jd->jd_inode); |
| 102 | struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 103 | int ar; |
| 104 | int error; |
| 105 | |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 106 | if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) || |
| 107 | (ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 108 | gfs2_consist_inode(ip); |
| 109 | return -EIO; |
| 110 | } |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 111 | jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 112 | |
Steven Whitehouse | c9e9888 | 2008-11-04 09:47:33 +0000 | [diff] [blame] | 113 | error = gfs2_write_alloc_required(ip, 0, ip->i_disksize, &ar); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 114 | if (!error && ar) { |
| 115 | gfs2_consist_inode(ip); |
| 116 | error = -EIO; |
| 117 | } |
| 118 | |
| 119 | return error; |
| 120 | } |
| 121 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 122 | /** |
| 123 | * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one |
| 124 | * @sdp: the filesystem |
| 125 | * |
| 126 | * Returns: errno |
| 127 | */ |
| 128 | |
| 129 | int gfs2_make_fs_rw(struct gfs2_sbd *sdp) |
| 130 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 131 | struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 132 | struct gfs2_glock *j_gl = ip->i_gl; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 133 | struct gfs2_holder t_gh; |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 134 | struct gfs2_log_header_host head; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 135 | int error; |
| 136 | |
Steven Whitehouse | 1c0f487 | 2007-01-22 12:10:39 -0500 | [diff] [blame] | 137 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 138 | if (error) |
| 139 | return error; |
| 140 | |
Steven Whitehouse | 1a14d3a | 2006-11-20 10:37:45 -0500 | [diff] [blame] | 141 | j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 142 | |
| 143 | error = gfs2_find_jhead(sdp->sd_jdesc, &head); |
| 144 | if (error) |
| 145 | goto fail; |
| 146 | |
| 147 | if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { |
| 148 | gfs2_consist(sdp); |
| 149 | error = -EIO; |
| 150 | goto fail; |
| 151 | } |
| 152 | |
| 153 | /* Initialize some head of the log stuff */ |
| 154 | sdp->sd_log_sequence = head.lh_sequence + 1; |
| 155 | gfs2_log_pointers_init(sdp, head.lh_blkno); |
| 156 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 157 | error = gfs2_quota_init(sdp); |
| 158 | if (error) |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 159 | goto fail; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 160 | |
| 161 | set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); |
| 162 | |
| 163 | gfs2_glock_dq_uninit(&t_gh); |
| 164 | |
| 165 | return 0; |
| 166 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 167 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 168 | t_gh.gh_flags |= GL_NOCACHE; |
| 169 | gfs2_glock_dq_uninit(&t_gh); |
| 170 | |
| 171 | return error; |
| 172 | } |
| 173 | |
Steven Whitehouse | bb8d8a6 | 2007-06-01 14:11:58 +0100 | [diff] [blame] | 174 | static void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf) |
| 175 | { |
| 176 | const struct gfs2_statfs_change *str = buf; |
| 177 | |
| 178 | sc->sc_total = be64_to_cpu(str->sc_total); |
| 179 | sc->sc_free = be64_to_cpu(str->sc_free); |
| 180 | sc->sc_dinodes = be64_to_cpu(str->sc_dinodes); |
| 181 | } |
| 182 | |
| 183 | static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf) |
| 184 | { |
| 185 | struct gfs2_statfs_change *str = buf; |
| 186 | |
| 187 | str->sc_total = cpu_to_be64(sc->sc_total); |
| 188 | str->sc_free = cpu_to_be64(sc->sc_free); |
| 189 | str->sc_dinodes = cpu_to_be64(sc->sc_dinodes); |
| 190 | } |
| 191 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 192 | int gfs2_statfs_init(struct gfs2_sbd *sdp) |
| 193 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 194 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 195 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 196 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 197 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 198 | struct buffer_head *m_bh, *l_bh; |
| 199 | struct gfs2_holder gh; |
| 200 | int error; |
| 201 | |
| 202 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 203 | &gh); |
| 204 | if (error) |
| 205 | return error; |
| 206 | |
| 207 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
| 208 | if (error) |
| 209 | goto out; |
| 210 | |
| 211 | if (sdp->sd_args.ar_spectator) { |
| 212 | spin_lock(&sdp->sd_statfs_spin); |
| 213 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
| 214 | sizeof(struct gfs2_dinode)); |
| 215 | spin_unlock(&sdp->sd_statfs_spin); |
| 216 | } else { |
| 217 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 218 | if (error) |
| 219 | goto out_m_bh; |
| 220 | |
| 221 | spin_lock(&sdp->sd_statfs_spin); |
| 222 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
| 223 | sizeof(struct gfs2_dinode)); |
| 224 | gfs2_statfs_change_in(l_sc, l_bh->b_data + |
| 225 | sizeof(struct gfs2_dinode)); |
| 226 | spin_unlock(&sdp->sd_statfs_spin); |
| 227 | |
| 228 | brelse(l_bh); |
| 229 | } |
| 230 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 231 | out_m_bh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 232 | brelse(m_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 233 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 234 | gfs2_glock_dq_uninit(&gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 238 | void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free, |
| 239 | s64 dinodes) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 240 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 241 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 242 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 243 | struct buffer_head *l_bh; |
| 244 | int error; |
| 245 | |
| 246 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 247 | if (error) |
| 248 | return; |
| 249 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 250 | gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 251 | |
| 252 | spin_lock(&sdp->sd_statfs_spin); |
| 253 | l_sc->sc_total += total; |
| 254 | l_sc->sc_free += free; |
| 255 | l_sc->sc_dinodes += dinodes; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 256 | gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 257 | spin_unlock(&sdp->sd_statfs_spin); |
| 258 | |
| 259 | brelse(l_bh); |
| 260 | } |
| 261 | |
| 262 | int gfs2_statfs_sync(struct gfs2_sbd *sdp) |
| 263 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 264 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
| 265 | struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode); |
Al Viro | bd209cc | 2006-10-13 23:43:19 -0400 | [diff] [blame] | 266 | struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master; |
| 267 | struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 268 | struct gfs2_holder gh; |
| 269 | struct buffer_head *m_bh, *l_bh; |
| 270 | int error; |
| 271 | |
| 272 | error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, |
| 273 | &gh); |
| 274 | if (error) |
| 275 | return error; |
| 276 | |
| 277 | error = gfs2_meta_inode_buffer(m_ip, &m_bh); |
| 278 | if (error) |
| 279 | goto out; |
| 280 | |
| 281 | spin_lock(&sdp->sd_statfs_spin); |
| 282 | gfs2_statfs_change_in(m_sc, m_bh->b_data + |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 283 | sizeof(struct gfs2_dinode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 284 | if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) { |
| 285 | spin_unlock(&sdp->sd_statfs_spin); |
| 286 | goto out_bh; |
| 287 | } |
| 288 | spin_unlock(&sdp->sd_statfs_spin); |
| 289 | |
| 290 | error = gfs2_meta_inode_buffer(l_ip, &l_bh); |
| 291 | if (error) |
| 292 | goto out_bh; |
| 293 | |
| 294 | error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0); |
| 295 | if (error) |
| 296 | goto out_bh2; |
| 297 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 298 | gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 299 | |
| 300 | spin_lock(&sdp->sd_statfs_spin); |
| 301 | m_sc->sc_total += l_sc->sc_total; |
| 302 | m_sc->sc_free += l_sc->sc_free; |
| 303 | m_sc->sc_dinodes += l_sc->sc_dinodes; |
| 304 | memset(l_sc, 0, sizeof(struct gfs2_statfs_change)); |
| 305 | memset(l_bh->b_data + sizeof(struct gfs2_dinode), |
| 306 | 0, sizeof(struct gfs2_statfs_change)); |
| 307 | spin_unlock(&sdp->sd_statfs_spin); |
| 308 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 309 | gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 310 | gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode)); |
| 311 | |
| 312 | gfs2_trans_end(sdp); |
| 313 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 314 | out_bh2: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 315 | brelse(l_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 316 | out_bh: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 317 | brelse(m_bh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 318 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 319 | gfs2_glock_dq_uninit(&gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 320 | return error; |
| 321 | } |
| 322 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 323 | struct lfcc { |
| 324 | struct list_head list; |
| 325 | struct gfs2_holder gh; |
| 326 | }; |
| 327 | |
| 328 | /** |
| 329 | * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all |
| 330 | * journals are clean |
| 331 | * @sdp: the file system |
| 332 | * @state: the state to put the transaction lock into |
| 333 | * @t_gh: the hold on the transaction lock |
| 334 | * |
| 335 | * Returns: errno |
| 336 | */ |
| 337 | |
Adrian Bunk | 08bc2db | 2006-04-28 10:59:12 -0400 | [diff] [blame] | 338 | static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, |
| 339 | struct gfs2_holder *t_gh) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 340 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 341 | struct gfs2_inode *ip; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 342 | struct gfs2_holder ji_gh; |
| 343 | struct gfs2_jdesc *jd; |
| 344 | struct lfcc *lfcc; |
| 345 | LIST_HEAD(list); |
Al Viro | 5516762 | 2006-10-13 21:47:13 -0400 | [diff] [blame] | 346 | struct gfs2_log_header_host lh; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 347 | int error; |
| 348 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 349 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 350 | lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL); |
| 351 | if (!lfcc) { |
| 352 | error = -ENOMEM; |
| 353 | goto out; |
| 354 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 355 | ip = GFS2_I(jd->jd_inode); |
| 356 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 357 | if (error) { |
| 358 | kfree(lfcc); |
| 359 | goto out; |
| 360 | } |
| 361 | list_add(&lfcc->list, &list); |
| 362 | } |
| 363 | |
| 364 | error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED, |
Steven Whitehouse | 6802e34 | 2008-05-21 17:03:22 +0100 | [diff] [blame] | 365 | GL_NOCACHE, t_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 366 | |
| 367 | list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { |
| 368 | error = gfs2_jdesc_check(jd); |
| 369 | if (error) |
| 370 | break; |
| 371 | error = gfs2_find_jhead(jd, &lh); |
| 372 | if (error) |
| 373 | break; |
| 374 | if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) { |
| 375 | error = -EBUSY; |
| 376 | break; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | if (error) |
| 381 | gfs2_glock_dq_uninit(t_gh); |
| 382 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 383 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 384 | while (!list_empty(&list)) { |
| 385 | lfcc = list_entry(list.next, struct lfcc, list); |
| 386 | list_del(&lfcc->list); |
| 387 | gfs2_glock_dq_uninit(&lfcc->gh); |
| 388 | kfree(lfcc); |
| 389 | } |
| 390 | gfs2_glock_dq_uninit(&ji_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 391 | return error; |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * gfs2_freeze_fs - freezes the file system |
| 396 | * @sdp: the file system |
| 397 | * |
| 398 | * This function flushes data and meta data for all machines by |
| 399 | * aquiring the transaction log exclusively. All journals are |
| 400 | * ensured to be in a clean state as well. |
| 401 | * |
| 402 | * Returns: errno |
| 403 | */ |
| 404 | |
| 405 | int gfs2_freeze_fs(struct gfs2_sbd *sdp) |
| 406 | { |
| 407 | int error = 0; |
| 408 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 409 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 410 | |
| 411 | if (!sdp->sd_freeze_count++) { |
| 412 | error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh); |
| 413 | if (error) |
| 414 | sdp->sd_freeze_count--; |
| 415 | } |
| 416 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 417 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 418 | |
| 419 | return error; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * gfs2_unfreeze_fs - unfreezes the file system |
| 424 | * @sdp: the file system |
| 425 | * |
| 426 | * This function allows the file system to proceed by unlocking |
| 427 | * the exclusively held transaction lock. Other GFS2 nodes are |
| 428 | * now free to acquire the lock shared and go on with their lives. |
| 429 | * |
| 430 | */ |
| 431 | |
| 432 | void gfs2_unfreeze_fs(struct gfs2_sbd *sdp) |
| 433 | { |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 434 | mutex_lock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 435 | |
| 436 | if (sdp->sd_freeze_count && !--sdp->sd_freeze_count) |
| 437 | gfs2_glock_dq_uninit(&sdp->sd_freeze_gh); |
| 438 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 439 | mutex_unlock(&sdp->sd_freeze_lock); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 440 | } |
| 441 | |