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