David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 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 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 10 | #include <linux/slab.h> |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/completion.h> |
| 13 | #include <linux/buffer_head.h> |
| 14 | #include <linux/xattr.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 15 | #include <linux/gfs2_ondisk.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 16 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 17 | #include <asm/uaccess.h> |
| 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 "acl.h" |
| 22 | #include "eaops.h" |
| 23 | #include "eattr.h" |
| 24 | #include "glock.h" |
| 25 | #include "inode.h" |
| 26 | #include "meta_io.h" |
| 27 | #include "quota.h" |
| 28 | #include "rgrp.h" |
| 29 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 30 | #include "util.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * ea_calc_size - returns the acutal number of bytes the request will take up |
| 34 | * (not counting any unstuffed data blocks) |
| 35 | * @sdp: |
| 36 | * @er: |
| 37 | * @size: |
| 38 | * |
| 39 | * Returns: 1 if the EA should be stuffed |
| 40 | */ |
| 41 | |
| 42 | static int ea_calc_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er, |
| 43 | unsigned int *size) |
| 44 | { |
| 45 | *size = GFS2_EAREQ_SIZE_STUFFED(er); |
| 46 | if (*size <= sdp->sd_jbsize) |
| 47 | return 1; |
| 48 | |
| 49 | *size = GFS2_EAREQ_SIZE_UNSTUFFED(sdp, er); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int ea_check_size(struct gfs2_sbd *sdp, struct gfs2_ea_request *er) |
| 55 | { |
| 56 | unsigned int size; |
| 57 | |
| 58 | if (er->er_data_len > GFS2_EA_MAX_DATA_LEN) |
| 59 | return -ERANGE; |
| 60 | |
| 61 | ea_calc_size(sdp, er, &size); |
| 62 | |
| 63 | /* This can only happen with 512 byte blocks */ |
| 64 | if (size > sdp->sd_jbsize) |
| 65 | return -ERANGE; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 70 | typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 71 | struct gfs2_ea_header *ea, |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 72 | struct gfs2_ea_header *prev, void *private); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 73 | |
| 74 | static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh, |
| 75 | ea_call_t ea_call, void *data) |
| 76 | { |
| 77 | struct gfs2_ea_header *ea, *prev = NULL; |
| 78 | int error = 0; |
| 79 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 80 | if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_EA)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 81 | return -EIO; |
| 82 | |
| 83 | for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) { |
| 84 | if (!GFS2_EA_REC_LEN(ea)) |
| 85 | goto fail; |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 86 | if (!(bh->b_data <= (char *)ea && (char *)GFS2_EA2NEXT(ea) <= |
| 87 | bh->b_data + bh->b_size)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 88 | goto fail; |
| 89 | if (!GFS2_EATYPE_VALID(ea->ea_type)) |
| 90 | goto fail; |
| 91 | |
| 92 | error = ea_call(ip, bh, ea, prev, data); |
| 93 | if (error) |
| 94 | return error; |
| 95 | |
| 96 | if (GFS2_EA_IS_LAST(ea)) { |
| 97 | if ((char *)GFS2_EA2NEXT(ea) != |
| 98 | bh->b_data + bh->b_size) |
| 99 | goto fail; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return error; |
| 105 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 106 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 107 | gfs2_consist_inode(ip); |
| 108 | return -EIO; |
| 109 | } |
| 110 | |
| 111 | static int ea_foreach(struct gfs2_inode *ip, ea_call_t ea_call, void *data) |
| 112 | { |
| 113 | struct buffer_head *bh, *eabh; |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 114 | __be64 *eablk, *end; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 115 | int error; |
| 116 | |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 117 | error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, &bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 118 | if (error) |
| 119 | return error; |
| 120 | |
| 121 | if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) { |
| 122 | error = ea_foreach_i(ip, bh, ea_call, data); |
| 123 | goto out; |
| 124 | } |
| 125 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 126 | if (gfs2_metatype_check(GFS2_SB(&ip->i_inode), bh, GFS2_METATYPE_IN)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 127 | error = -EIO; |
| 128 | goto out; |
| 129 | } |
| 130 | |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 131 | eablk = (__be64 *)(bh->b_data + sizeof(struct gfs2_meta_header)); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 132 | end = eablk + GFS2_SB(&ip->i_inode)->sd_inptrs; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 133 | |
| 134 | for (; eablk < end; eablk++) { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 135 | u64 bn; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 136 | |
| 137 | if (!*eablk) |
| 138 | break; |
| 139 | bn = be64_to_cpu(*eablk); |
| 140 | |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 141 | error = gfs2_meta_read(ip->i_gl, bn, DIO_WAIT, &eabh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 142 | if (error) |
| 143 | break; |
| 144 | error = ea_foreach_i(ip, eabh, ea_call, data); |
| 145 | brelse(eabh); |
| 146 | if (error) |
| 147 | break; |
| 148 | } |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 149 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 150 | brelse(bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 151 | return error; |
| 152 | } |
| 153 | |
| 154 | struct ea_find { |
| 155 | struct gfs2_ea_request *ef_er; |
| 156 | struct gfs2_ea_location *ef_el; |
| 157 | }; |
| 158 | |
| 159 | static int ea_find_i(struct gfs2_inode *ip, struct buffer_head *bh, |
| 160 | struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, |
| 161 | void *private) |
| 162 | { |
| 163 | struct ea_find *ef = private; |
| 164 | struct gfs2_ea_request *er = ef->ef_er; |
| 165 | |
| 166 | if (ea->ea_type == GFS2_EATYPE_UNUSED) |
| 167 | return 0; |
| 168 | |
| 169 | if (ea->ea_type == er->er_type) { |
| 170 | if (ea->ea_name_len == er->er_name_len && |
| 171 | !memcmp(GFS2_EA2NAME(ea), er->er_name, ea->ea_name_len)) { |
| 172 | struct gfs2_ea_location *el = ef->ef_el; |
| 173 | get_bh(bh); |
| 174 | el->el_bh = bh; |
| 175 | el->el_ea = ea; |
| 176 | el->el_prev = prev; |
| 177 | return 1; |
| 178 | } |
| 179 | } |
| 180 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int gfs2_ea_find(struct gfs2_inode *ip, struct gfs2_ea_request *er, |
| 185 | struct gfs2_ea_location *el) |
| 186 | { |
| 187 | struct ea_find ef; |
| 188 | int error; |
| 189 | |
| 190 | ef.ef_er = er; |
| 191 | ef.ef_el = el; |
| 192 | |
| 193 | memset(el, 0, sizeof(struct gfs2_ea_location)); |
| 194 | |
| 195 | error = ea_foreach(ip, ea_find_i, &ef); |
| 196 | if (error > 0) |
| 197 | return 0; |
| 198 | |
| 199 | return error; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * ea_dealloc_unstuffed - |
| 204 | * @ip: |
| 205 | * @bh: |
| 206 | * @ea: |
| 207 | * @prev: |
| 208 | * @private: |
| 209 | * |
| 210 | * Take advantage of the fact that all unstuffed blocks are |
| 211 | * allocated from the same RG. But watch, this may not always |
| 212 | * be true. |
| 213 | * |
| 214 | * Returns: errno |
| 215 | */ |
| 216 | |
| 217 | static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, |
| 218 | struct gfs2_ea_header *ea, |
| 219 | struct gfs2_ea_header *prev, void *private) |
| 220 | { |
| 221 | int *leave = private; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 222 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 223 | struct gfs2_rgrpd *rgd; |
| 224 | struct gfs2_holder rg_gh; |
| 225 | struct buffer_head *dibh; |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 226 | __be64 *dataptrs; |
| 227 | u64 bn = 0; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 228 | u64 bstart = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 229 | unsigned int blen = 0; |
| 230 | unsigned int blks = 0; |
| 231 | unsigned int x; |
| 232 | int error; |
| 233 | |
| 234 | if (GFS2_EA_IS_STUFFED(ea)) |
| 235 | return 0; |
| 236 | |
| 237 | dataptrs = GFS2_EA2DATAPTRS(ea); |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 238 | for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 239 | if (*dataptrs) { |
| 240 | blks++; |
| 241 | bn = be64_to_cpu(*dataptrs); |
| 242 | } |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 243 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 244 | if (!blks) |
| 245 | return 0; |
| 246 | |
| 247 | rgd = gfs2_blk2rgrpd(sdp, bn); |
| 248 | if (!rgd) { |
| 249 | gfs2_consist_inode(ip); |
| 250 | return -EIO; |
| 251 | } |
| 252 | |
| 253 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &rg_gh); |
| 254 | if (error) |
| 255 | return error; |
| 256 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 257 | error = gfs2_trans_begin(sdp, rgd->rd_ri.ri_length + RES_DINODE + |
| 258 | RES_EATTR + RES_STATFS + RES_QUOTA, blks); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 259 | if (error) |
| 260 | goto out_gunlock; |
| 261 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 262 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 263 | |
| 264 | dataptrs = GFS2_EA2DATAPTRS(ea); |
| 265 | for (x = 0; x < ea->ea_num_ptrs; x++, dataptrs++) { |
| 266 | if (!*dataptrs) |
| 267 | break; |
| 268 | bn = be64_to_cpu(*dataptrs); |
| 269 | |
| 270 | if (bstart + blen == bn) |
| 271 | blen++; |
| 272 | else { |
| 273 | if (bstart) |
| 274 | gfs2_free_meta(ip, bstart, blen); |
| 275 | bstart = bn; |
| 276 | blen = 1; |
| 277 | } |
| 278 | |
| 279 | *dataptrs = 0; |
| 280 | if (!ip->i_di.di_blocks) |
| 281 | gfs2_consist_inode(ip); |
| 282 | ip->i_di.di_blocks--; |
Steven Whitehouse | 9e2dbda | 2006-11-08 15:45:46 -0500 | [diff] [blame] | 283 | gfs2_set_inode_blocks(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 284 | } |
| 285 | if (bstart) |
| 286 | gfs2_free_meta(ip, bstart, blen); |
| 287 | |
| 288 | if (prev && !leave) { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 289 | u32 len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 290 | |
| 291 | len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); |
| 292 | prev->ea_rec_len = cpu_to_be32(len); |
| 293 | |
| 294 | if (GFS2_EA_IS_LAST(ea)) |
| 295 | prev->ea_flags |= GFS2_EAFLAG_LAST; |
| 296 | } else { |
| 297 | ea->ea_type = GFS2_EATYPE_UNUSED; |
| 298 | ea->ea_num_ptrs = 0; |
| 299 | } |
| 300 | |
| 301 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 302 | if (!error) { |
Eric Sandeen | bbb28ab | 2007-01-29 11:11:51 -0600 | [diff] [blame] | 303 | ip->i_inode.i_ctime = CURRENT_TIME_SEC; |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 304 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 305 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 306 | brelse(dibh); |
| 307 | } |
| 308 | |
| 309 | gfs2_trans_end(sdp); |
| 310 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 311 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 312 | gfs2_glock_dq_uninit(&rg_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 313 | return error; |
| 314 | } |
| 315 | |
| 316 | static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh, |
| 317 | struct gfs2_ea_header *ea, |
| 318 | struct gfs2_ea_header *prev, int leave) |
| 319 | { |
| 320 | struct gfs2_alloc *al; |
| 321 | int error; |
| 322 | |
| 323 | al = gfs2_alloc_get(ip); |
| 324 | |
| 325 | error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 326 | if (error) |
| 327 | goto out_alloc; |
| 328 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 329 | error = gfs2_rindex_hold(GFS2_SB(&ip->i_inode), &al->al_ri_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 330 | if (error) |
| 331 | goto out_quota; |
| 332 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 333 | error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error : NULL); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 334 | |
| 335 | gfs2_glock_dq_uninit(&al->al_ri_gh); |
| 336 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 337 | out_quota: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 338 | gfs2_quota_unhold(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 339 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 340 | gfs2_alloc_put(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 341 | return error; |
| 342 | } |
| 343 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 344 | struct ea_list { |
| 345 | struct gfs2_ea_request *ei_er; |
| 346 | unsigned int ei_size; |
| 347 | }; |
| 348 | |
| 349 | static int ea_list_i(struct gfs2_inode *ip, struct buffer_head *bh, |
| 350 | struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, |
| 351 | void *private) |
| 352 | { |
| 353 | struct ea_list *ei = private; |
| 354 | struct gfs2_ea_request *er = ei->ei_er; |
Ryan O'Hara | 639b6d7 | 2006-05-22 10:08:35 -0400 | [diff] [blame] | 355 | unsigned int ea_size = gfs2_ea_strlen(ea); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 356 | |
| 357 | if (ea->ea_type == GFS2_EATYPE_UNUSED) |
| 358 | return 0; |
| 359 | |
| 360 | if (er->er_data_len) { |
Steven Whitehouse | 01eb7c0 | 2006-06-06 17:31:30 -0400 | [diff] [blame] | 361 | char *prefix = NULL; |
| 362 | unsigned int l = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 363 | char c = 0; |
| 364 | |
| 365 | if (ei->ei_size + ea_size > er->er_data_len) |
| 366 | return -ERANGE; |
| 367 | |
Ryan O'Hara | 639b6d7 | 2006-05-22 10:08:35 -0400 | [diff] [blame] | 368 | switch (ea->ea_type) { |
| 369 | case GFS2_EATYPE_USR: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 370 | prefix = "user."; |
| 371 | l = 5; |
Ryan O'Hara | 639b6d7 | 2006-05-22 10:08:35 -0400 | [diff] [blame] | 372 | break; |
| 373 | case GFS2_EATYPE_SYS: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 374 | prefix = "system."; |
| 375 | l = 7; |
Ryan O'Hara | 639b6d7 | 2006-05-22 10:08:35 -0400 | [diff] [blame] | 376 | break; |
| 377 | case GFS2_EATYPE_SECURITY: |
| 378 | prefix = "security."; |
| 379 | l = 9; |
| 380 | break; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 381 | } |
| 382 | |
Steven Whitehouse | 01eb7c0 | 2006-06-06 17:31:30 -0400 | [diff] [blame] | 383 | BUG_ON(l == 0); |
| 384 | |
Steven Whitehouse | 90cdd20 | 2006-05-22 10:36:25 -0400 | [diff] [blame] | 385 | memcpy(er->er_data + ei->ei_size, prefix, l); |
| 386 | memcpy(er->er_data + ei->ei_size + l, GFS2_EA2NAME(ea), |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 387 | ea->ea_name_len); |
Steven Whitehouse | 90cdd20 | 2006-05-22 10:36:25 -0400 | [diff] [blame] | 388 | memcpy(er->er_data + ei->ei_size + ea_size - 1, &c, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | ei->ei_size += ea_size; |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * gfs2_ea_list - |
| 398 | * @ip: |
| 399 | * @er: |
| 400 | * |
| 401 | * Returns: actual size of data on success, -errno on error |
| 402 | */ |
| 403 | |
| 404 | int gfs2_ea_list(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 405 | { |
| 406 | struct gfs2_holder i_gh; |
| 407 | int error; |
| 408 | |
| 409 | if (!er->er_data || !er->er_data_len) { |
| 410 | er->er_data = NULL; |
| 411 | er->er_data_len = 0; |
| 412 | } |
| 413 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 414 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 415 | if (error) |
| 416 | return error; |
| 417 | |
| 418 | if (ip->i_di.di_eattr) { |
| 419 | struct ea_list ei = { .ei_er = er, .ei_size = 0 }; |
| 420 | |
| 421 | error = ea_foreach(ip, ea_list_i, &ei); |
| 422 | if (!error) |
| 423 | error = ei.ei_size; |
| 424 | } |
| 425 | |
| 426 | gfs2_glock_dq_uninit(&i_gh); |
| 427 | |
| 428 | return error; |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * ea_get_unstuffed - actually copies the unstuffed data into the |
| 433 | * request buffer |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 434 | * @ip: The GFS2 inode |
| 435 | * @ea: The extended attribute header structure |
| 436 | * @data: The data to be copied |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 437 | * |
| 438 | * Returns: errno |
| 439 | */ |
| 440 | |
| 441 | static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, |
| 442 | char *data) |
| 443 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 444 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 445 | struct buffer_head **bh; |
| 446 | unsigned int amount = GFS2_EA_DATA_LEN(ea); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 447 | unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 448 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 449 | unsigned int x; |
| 450 | int error = 0; |
| 451 | |
| 452 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_KERNEL); |
| 453 | if (!bh) |
| 454 | return -ENOMEM; |
| 455 | |
| 456 | for (x = 0; x < nptrs; x++) { |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 457 | error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, |
| 458 | bh + x); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 459 | if (error) { |
| 460 | while (x--) |
| 461 | brelse(bh[x]); |
| 462 | goto out; |
| 463 | } |
| 464 | dataptrs++; |
| 465 | } |
| 466 | |
| 467 | for (x = 0; x < nptrs; x++) { |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 468 | error = gfs2_meta_wait(sdp, bh[x]); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 469 | if (error) { |
| 470 | for (; x < nptrs; x++) |
| 471 | brelse(bh[x]); |
| 472 | goto out; |
| 473 | } |
| 474 | if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) { |
| 475 | for (; x < nptrs; x++) |
| 476 | brelse(bh[x]); |
| 477 | error = -EIO; |
| 478 | goto out; |
| 479 | } |
| 480 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 481 | memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header), |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 482 | (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); |
| 483 | |
| 484 | amount -= sdp->sd_jbsize; |
| 485 | data += sdp->sd_jbsize; |
| 486 | |
| 487 | brelse(bh[x]); |
| 488 | } |
| 489 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 490 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 491 | kfree(bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 492 | return error; |
| 493 | } |
| 494 | |
| 495 | int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, |
| 496 | char *data) |
| 497 | { |
| 498 | if (GFS2_EA_IS_STUFFED(el->el_ea)) { |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 499 | memcpy(data, GFS2_EA2DATA(el->el_ea), GFS2_EA_DATA_LEN(el->el_ea)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 500 | return 0; |
| 501 | } else |
| 502 | return ea_get_unstuffed(ip, el->el_ea, data); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * gfs2_ea_get_i - |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 507 | * @ip: The GFS2 inode |
| 508 | * @er: The request structure |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 509 | * |
| 510 | * Returns: actual size of data on success, -errno on error |
| 511 | */ |
| 512 | |
| 513 | int gfs2_ea_get_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 514 | { |
| 515 | struct gfs2_ea_location el; |
| 516 | int error; |
| 517 | |
| 518 | if (!ip->i_di.di_eattr) |
| 519 | return -ENODATA; |
| 520 | |
| 521 | error = gfs2_ea_find(ip, er, &el); |
| 522 | if (error) |
| 523 | return error; |
| 524 | if (!el.el_ea) |
| 525 | return -ENODATA; |
| 526 | |
| 527 | if (er->er_data_len) { |
| 528 | if (GFS2_EA_DATA_LEN(el.el_ea) > er->er_data_len) |
| 529 | error = -ERANGE; |
| 530 | else |
| 531 | error = gfs2_ea_get_copy(ip, &el, er->er_data); |
| 532 | } |
| 533 | if (!error) |
| 534 | error = GFS2_EA_DATA_LEN(el.el_ea); |
| 535 | |
| 536 | brelse(el.el_bh); |
| 537 | |
| 538 | return error; |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * gfs2_ea_get - |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 543 | * @ip: The GFS2 inode |
| 544 | * @er: The request structure |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 545 | * |
| 546 | * Returns: actual size of data on success, -errno on error |
| 547 | */ |
| 548 | |
| 549 | int gfs2_ea_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 550 | { |
| 551 | struct gfs2_holder i_gh; |
| 552 | int error; |
| 553 | |
| 554 | if (!er->er_name_len || |
| 555 | er->er_name_len > GFS2_EA_MAX_NAME_LEN) |
| 556 | return -EINVAL; |
| 557 | if (!er->er_data || !er->er_data_len) { |
| 558 | er->er_data = NULL; |
| 559 | er->er_data_len = 0; |
| 560 | } |
| 561 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 562 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 563 | if (error) |
| 564 | return error; |
| 565 | |
| 566 | error = gfs2_ea_ops[er->er_type]->eo_get(ip, er); |
| 567 | |
| 568 | gfs2_glock_dq_uninit(&i_gh); |
| 569 | |
| 570 | return error; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * ea_alloc_blk - allocates a new block for extended attributes. |
| 575 | * @ip: A pointer to the inode that's getting extended attributes |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 576 | * @bhp: Pointer to pointer to a struct buffer_head |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 577 | * |
| 578 | * Returns: errno |
| 579 | */ |
| 580 | |
| 581 | static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp) |
| 582 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 583 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 584 | struct gfs2_ea_header *ea; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 585 | u64 block; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 586 | |
| 587 | block = gfs2_alloc_meta(ip); |
| 588 | |
| 589 | *bhp = gfs2_meta_new(ip->i_gl, block); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 590 | gfs2_trans_add_bh(ip->i_gl, *bhp, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 591 | gfs2_metatype_set(*bhp, GFS2_METATYPE_EA, GFS2_FORMAT_EA); |
| 592 | gfs2_buffer_clear_tail(*bhp, sizeof(struct gfs2_meta_header)); |
| 593 | |
| 594 | ea = GFS2_EA_BH2FIRST(*bhp); |
| 595 | ea->ea_rec_len = cpu_to_be32(sdp->sd_jbsize); |
| 596 | ea->ea_type = GFS2_EATYPE_UNUSED; |
| 597 | ea->ea_flags = GFS2_EAFLAG_LAST; |
| 598 | ea->ea_num_ptrs = 0; |
| 599 | |
| 600 | ip->i_di.di_blocks++; |
Steven Whitehouse | 9e2dbda | 2006-11-08 15:45:46 -0500 | [diff] [blame] | 601 | gfs2_set_inode_blocks(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * ea_write - writes the request info to an ea, creating new blocks if |
| 608 | * necessary |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 609 | * @ip: inode that is being modified |
| 610 | * @ea: the location of the new ea in a block |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 611 | * @er: the write request |
| 612 | * |
| 613 | * Note: does not update ea_rec_len or the GFS2_EAFLAG_LAST bin of ea_flags |
| 614 | * |
| 615 | * returns : errno |
| 616 | */ |
| 617 | |
| 618 | static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea, |
| 619 | struct gfs2_ea_request *er) |
| 620 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 621 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 622 | |
| 623 | ea->ea_data_len = cpu_to_be32(er->er_data_len); |
| 624 | ea->ea_name_len = er->er_name_len; |
| 625 | ea->ea_type = er->er_type; |
| 626 | ea->__pad = 0; |
| 627 | |
| 628 | memcpy(GFS2_EA2NAME(ea), er->er_name, er->er_name_len); |
| 629 | |
| 630 | if (GFS2_EAREQ_SIZE_STUFFED(er) <= sdp->sd_jbsize) { |
| 631 | ea->ea_num_ptrs = 0; |
| 632 | memcpy(GFS2_EA2DATA(ea), er->er_data, er->er_data_len); |
| 633 | } else { |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 634 | __be64 *dataptr = GFS2_EA2DATAPTRS(ea); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 635 | const char *data = er->er_data; |
| 636 | unsigned int data_len = er->er_data_len; |
| 637 | unsigned int copy; |
| 638 | unsigned int x; |
| 639 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 640 | ea->ea_num_ptrs = DIV_ROUND_UP(er->er_data_len, sdp->sd_jbsize); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 641 | for (x = 0; x < ea->ea_num_ptrs; x++) { |
| 642 | struct buffer_head *bh; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 643 | u64 block; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 644 | int mh_size = sizeof(struct gfs2_meta_header); |
| 645 | |
| 646 | block = gfs2_alloc_meta(ip); |
| 647 | |
| 648 | bh = gfs2_meta_new(ip->i_gl, block); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 649 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 650 | gfs2_metatype_set(bh, GFS2_METATYPE_ED, GFS2_FORMAT_ED); |
| 651 | |
| 652 | ip->i_di.di_blocks++; |
Steven Whitehouse | 9e2dbda | 2006-11-08 15:45:46 -0500 | [diff] [blame] | 653 | gfs2_set_inode_blocks(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 654 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 655 | copy = data_len > sdp->sd_jbsize ? sdp->sd_jbsize : |
| 656 | data_len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 657 | memcpy(bh->b_data + mh_size, data, copy); |
| 658 | if (copy < sdp->sd_jbsize) |
| 659 | memset(bh->b_data + mh_size + copy, 0, |
| 660 | sdp->sd_jbsize - copy); |
| 661 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 662 | *dataptr++ = cpu_to_be64(bh->b_blocknr); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 663 | data += copy; |
| 664 | data_len -= copy; |
| 665 | |
| 666 | brelse(bh); |
| 667 | } |
| 668 | |
| 669 | gfs2_assert_withdraw(sdp, !data_len); |
| 670 | } |
| 671 | |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | typedef int (*ea_skeleton_call_t) (struct gfs2_inode *ip, |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 676 | struct gfs2_ea_request *er, void *private); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 677 | |
| 678 | static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, |
| 679 | unsigned int blks, |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 680 | ea_skeleton_call_t skeleton_call, void *private) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 681 | { |
| 682 | struct gfs2_alloc *al; |
| 683 | struct buffer_head *dibh; |
| 684 | int error; |
| 685 | |
| 686 | al = gfs2_alloc_get(ip); |
| 687 | |
| 688 | error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 689 | if (error) |
| 690 | goto out; |
| 691 | |
Steven Whitehouse | 2933f92 | 2006-11-01 13:23:29 -0500 | [diff] [blame] | 692 | error = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 693 | if (error) |
| 694 | goto out_gunlock_q; |
| 695 | |
| 696 | al->al_requested = blks; |
| 697 | |
| 698 | error = gfs2_inplace_reserve(ip); |
| 699 | if (error) |
| 700 | goto out_gunlock_q; |
| 701 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 702 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 703 | blks + al->al_rgd->rd_ri.ri_length + |
| 704 | RES_DINODE + RES_STATFS + RES_QUOTA, 0); |
| 705 | if (error) |
| 706 | goto out_ipres; |
| 707 | |
| 708 | error = skeleton_call(ip, er, private); |
| 709 | if (error) |
| 710 | goto out_end_trans; |
| 711 | |
| 712 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 713 | if (!error) { |
| 714 | if (er->er_flags & GFS2_ERF_MODE) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 715 | gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 716 | (ip->i_inode.i_mode & S_IFMT) == |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 717 | (er->er_mode & S_IFMT)); |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 718 | ip->i_inode.i_mode = er->er_mode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 719 | } |
Eric Sandeen | bbb28ab | 2007-01-29 11:11:51 -0600 | [diff] [blame] | 720 | ip->i_inode.i_ctime = CURRENT_TIME_SEC; |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 721 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 722 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 723 | brelse(dibh); |
| 724 | } |
| 725 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 726 | out_end_trans: |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 727 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 728 | out_ipres: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 729 | gfs2_inplace_release(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 730 | out_gunlock_q: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 731 | gfs2_quota_unlock(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 732 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 733 | gfs2_alloc_put(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 734 | return error; |
| 735 | } |
| 736 | |
| 737 | static int ea_init_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, |
| 738 | void *private) |
| 739 | { |
| 740 | struct buffer_head *bh; |
| 741 | int error; |
| 742 | |
| 743 | error = ea_alloc_blk(ip, &bh); |
| 744 | if (error) |
| 745 | return error; |
| 746 | |
| 747 | ip->i_di.di_eattr = bh->b_blocknr; |
| 748 | error = ea_write(ip, GFS2_EA_BH2FIRST(bh), er); |
| 749 | |
| 750 | brelse(bh); |
| 751 | |
| 752 | return error; |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * ea_init - initializes a new eattr block |
| 757 | * @ip: |
| 758 | * @er: |
| 759 | * |
| 760 | * Returns: errno |
| 761 | */ |
| 762 | |
| 763 | static int ea_init(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 764 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 765 | unsigned int jbsize = GFS2_SB(&ip->i_inode)->sd_jbsize; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 766 | unsigned int blks = 1; |
| 767 | |
| 768 | if (GFS2_EAREQ_SIZE_STUFFED(er) > jbsize) |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 769 | blks += DIV_ROUND_UP(er->er_data_len, jbsize); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 770 | |
| 771 | return ea_alloc_skeleton(ip, er, blks, ea_init_i, NULL); |
| 772 | } |
| 773 | |
| 774 | static struct gfs2_ea_header *ea_split_ea(struct gfs2_ea_header *ea) |
| 775 | { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 776 | u32 ea_size = GFS2_EA_SIZE(ea); |
Steven Whitehouse | 568f4c9 | 2006-02-27 12:00:42 -0500 | [diff] [blame] | 777 | struct gfs2_ea_header *new = (struct gfs2_ea_header *)((char *)ea + |
| 778 | ea_size); |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 779 | u32 new_size = GFS2_EA_REC_LEN(ea) - ea_size; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 780 | int last = ea->ea_flags & GFS2_EAFLAG_LAST; |
| 781 | |
| 782 | ea->ea_rec_len = cpu_to_be32(ea_size); |
| 783 | ea->ea_flags ^= last; |
| 784 | |
| 785 | new->ea_rec_len = cpu_to_be32(new_size); |
| 786 | new->ea_flags = last; |
| 787 | |
| 788 | return new; |
| 789 | } |
| 790 | |
| 791 | static void ea_set_remove_stuffed(struct gfs2_inode *ip, |
| 792 | struct gfs2_ea_location *el) |
| 793 | { |
| 794 | struct gfs2_ea_header *ea = el->el_ea; |
| 795 | struct gfs2_ea_header *prev = el->el_prev; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 796 | u32 len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 797 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 798 | gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 799 | |
| 800 | if (!prev || !GFS2_EA_IS_STUFFED(ea)) { |
| 801 | ea->ea_type = GFS2_EATYPE_UNUSED; |
| 802 | return; |
| 803 | } else if (GFS2_EA2NEXT(prev) != ea) { |
| 804 | prev = GFS2_EA2NEXT(prev); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 805 | gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), GFS2_EA2NEXT(prev) == ea); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); |
| 809 | prev->ea_rec_len = cpu_to_be32(len); |
| 810 | |
| 811 | if (GFS2_EA_IS_LAST(ea)) |
| 812 | prev->ea_flags |= GFS2_EAFLAG_LAST; |
| 813 | } |
| 814 | |
| 815 | struct ea_set { |
| 816 | int ea_split; |
| 817 | |
| 818 | struct gfs2_ea_request *es_er; |
| 819 | struct gfs2_ea_location *es_el; |
| 820 | |
| 821 | struct buffer_head *es_bh; |
| 822 | struct gfs2_ea_header *es_ea; |
| 823 | }; |
| 824 | |
| 825 | static int ea_set_simple_noalloc(struct gfs2_inode *ip, struct buffer_head *bh, |
| 826 | struct gfs2_ea_header *ea, struct ea_set *es) |
| 827 | { |
| 828 | struct gfs2_ea_request *er = es->es_er; |
| 829 | struct buffer_head *dibh; |
| 830 | int error; |
| 831 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 832 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + 2 * RES_EATTR, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 833 | if (error) |
| 834 | return error; |
| 835 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 836 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 837 | |
| 838 | if (es->ea_split) |
| 839 | ea = ea_split_ea(ea); |
| 840 | |
| 841 | ea_write(ip, ea, er); |
| 842 | |
| 843 | if (es->es_el) |
| 844 | ea_set_remove_stuffed(ip, es->es_el); |
| 845 | |
| 846 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 847 | if (error) |
| 848 | goto out; |
| 849 | |
| 850 | if (er->er_flags & GFS2_ERF_MODE) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 851 | gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 852 | (ip->i_inode.i_mode & S_IFMT) == (er->er_mode & S_IFMT)); |
| 853 | ip->i_inode.i_mode = er->er_mode; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 854 | } |
Eric Sandeen | bbb28ab | 2007-01-29 11:11:51 -0600 | [diff] [blame] | 855 | ip->i_inode.i_ctime = CURRENT_TIME_SEC; |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 856 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 857 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 858 | brelse(dibh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 859 | out: |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 860 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 861 | return error; |
| 862 | } |
| 863 | |
| 864 | static int ea_set_simple_alloc(struct gfs2_inode *ip, |
| 865 | struct gfs2_ea_request *er, void *private) |
| 866 | { |
| 867 | struct ea_set *es = private; |
| 868 | struct gfs2_ea_header *ea = es->es_ea; |
| 869 | int error; |
| 870 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 871 | gfs2_trans_add_bh(ip->i_gl, es->es_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 872 | |
| 873 | if (es->ea_split) |
| 874 | ea = ea_split_ea(ea); |
| 875 | |
| 876 | error = ea_write(ip, ea, er); |
| 877 | if (error) |
| 878 | return error; |
| 879 | |
| 880 | if (es->es_el) |
| 881 | ea_set_remove_stuffed(ip, es->es_el); |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int ea_set_simple(struct gfs2_inode *ip, struct buffer_head *bh, |
| 887 | struct gfs2_ea_header *ea, struct gfs2_ea_header *prev, |
| 888 | void *private) |
| 889 | { |
| 890 | struct ea_set *es = private; |
| 891 | unsigned int size; |
| 892 | int stuffed; |
| 893 | int error; |
| 894 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 895 | stuffed = ea_calc_size(GFS2_SB(&ip->i_inode), es->es_er, &size); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 896 | |
| 897 | if (ea->ea_type == GFS2_EATYPE_UNUSED) { |
| 898 | if (GFS2_EA_REC_LEN(ea) < size) |
| 899 | return 0; |
| 900 | if (!GFS2_EA_IS_STUFFED(ea)) { |
| 901 | error = ea_remove_unstuffed(ip, bh, ea, prev, 1); |
| 902 | if (error) |
| 903 | return error; |
| 904 | } |
| 905 | es->ea_split = 0; |
| 906 | } else if (GFS2_EA_REC_LEN(ea) - GFS2_EA_SIZE(ea) >= size) |
| 907 | es->ea_split = 1; |
| 908 | else |
| 909 | return 0; |
| 910 | |
| 911 | if (stuffed) { |
| 912 | error = ea_set_simple_noalloc(ip, bh, ea, es); |
| 913 | if (error) |
| 914 | return error; |
| 915 | } else { |
| 916 | unsigned int blks; |
| 917 | |
| 918 | es->es_bh = bh; |
| 919 | es->es_ea = ea; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 920 | blks = 2 + DIV_ROUND_UP(es->es_er->er_data_len, |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 921 | GFS2_SB(&ip->i_inode)->sd_jbsize); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 922 | |
| 923 | error = ea_alloc_skeleton(ip, es->es_er, blks, |
| 924 | ea_set_simple_alloc, es); |
| 925 | if (error) |
| 926 | return error; |
| 927 | } |
| 928 | |
| 929 | return 1; |
| 930 | } |
| 931 | |
| 932 | static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er, |
| 933 | void *private) |
| 934 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 935 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 936 | struct buffer_head *indbh, *newbh; |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 937 | __be64 *eablk; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 938 | int error; |
| 939 | int mh_size = sizeof(struct gfs2_meta_header); |
| 940 | |
| 941 | if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 942 | __be64 *end; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 943 | |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 944 | error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, |
| 945 | &indbh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 946 | if (error) |
| 947 | return error; |
| 948 | |
| 949 | if (gfs2_metatype_check(sdp, indbh, GFS2_METATYPE_IN)) { |
| 950 | error = -EIO; |
| 951 | goto out; |
| 952 | } |
| 953 | |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 954 | eablk = (__be64 *)(indbh->b_data + mh_size); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 955 | end = eablk + sdp->sd_inptrs; |
| 956 | |
| 957 | for (; eablk < end; eablk++) |
| 958 | if (!*eablk) |
| 959 | break; |
| 960 | |
| 961 | if (eablk == end) { |
| 962 | error = -ENOSPC; |
| 963 | goto out; |
| 964 | } |
| 965 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 966 | gfs2_trans_add_bh(ip->i_gl, indbh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 967 | } else { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 968 | u64 blk; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 969 | |
| 970 | blk = gfs2_alloc_meta(ip); |
| 971 | |
| 972 | indbh = gfs2_meta_new(ip->i_gl, blk); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 973 | gfs2_trans_add_bh(ip->i_gl, indbh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 974 | gfs2_metatype_set(indbh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); |
| 975 | gfs2_buffer_clear_tail(indbh, mh_size); |
| 976 | |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 977 | eablk = (__be64 *)(indbh->b_data + mh_size); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 978 | *eablk = cpu_to_be64(ip->i_di.di_eattr); |
| 979 | ip->i_di.di_eattr = blk; |
| 980 | ip->i_di.di_flags |= GFS2_DIF_EA_INDIRECT; |
| 981 | ip->i_di.di_blocks++; |
Steven Whitehouse | 9e2dbda | 2006-11-08 15:45:46 -0500 | [diff] [blame] | 982 | gfs2_set_inode_blocks(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 983 | |
| 984 | eablk++; |
| 985 | } |
| 986 | |
| 987 | error = ea_alloc_blk(ip, &newbh); |
| 988 | if (error) |
| 989 | goto out; |
| 990 | |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 991 | *eablk = cpu_to_be64((u64)newbh->b_blocknr); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 992 | error = ea_write(ip, GFS2_EA_BH2FIRST(newbh), er); |
| 993 | brelse(newbh); |
| 994 | if (error) |
| 995 | goto out; |
| 996 | |
| 997 | if (private) |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 998 | ea_set_remove_stuffed(ip, private); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 999 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1000 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1001 | brelse(indbh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1002 | return error; |
| 1003 | } |
| 1004 | |
| 1005 | static int ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er, |
| 1006 | struct gfs2_ea_location *el) |
| 1007 | { |
| 1008 | struct ea_set es; |
| 1009 | unsigned int blks = 2; |
| 1010 | int error; |
| 1011 | |
| 1012 | memset(&es, 0, sizeof(struct ea_set)); |
| 1013 | es.es_er = er; |
| 1014 | es.es_el = el; |
| 1015 | |
| 1016 | error = ea_foreach(ip, ea_set_simple, &es); |
| 1017 | if (error > 0) |
| 1018 | return 0; |
| 1019 | if (error) |
| 1020 | return error; |
| 1021 | |
| 1022 | if (!(ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT)) |
| 1023 | blks++; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1024 | if (GFS2_EAREQ_SIZE_STUFFED(er) > GFS2_SB(&ip->i_inode)->sd_jbsize) |
| 1025 | blks += DIV_ROUND_UP(er->er_data_len, GFS2_SB(&ip->i_inode)->sd_jbsize); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1026 | |
| 1027 | return ea_alloc_skeleton(ip, er, blks, ea_set_block, el); |
| 1028 | } |
| 1029 | |
| 1030 | static int ea_set_remove_unstuffed(struct gfs2_inode *ip, |
| 1031 | struct gfs2_ea_location *el) |
| 1032 | { |
| 1033 | if (el->el_prev && GFS2_EA2NEXT(el->el_prev) != el->el_ea) { |
| 1034 | el->el_prev = GFS2_EA2NEXT(el->el_prev); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1035 | gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1036 | GFS2_EA2NEXT(el->el_prev) == el->el_ea); |
| 1037 | } |
| 1038 | |
| 1039 | return ea_remove_unstuffed(ip, el->el_bh, el->el_ea, el->el_prev,0); |
| 1040 | } |
| 1041 | |
| 1042 | int gfs2_ea_set_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 1043 | { |
| 1044 | struct gfs2_ea_location el; |
| 1045 | int error; |
| 1046 | |
| 1047 | if (!ip->i_di.di_eattr) { |
| 1048 | if (er->er_flags & XATTR_REPLACE) |
| 1049 | return -ENODATA; |
| 1050 | return ea_init(ip, er); |
| 1051 | } |
| 1052 | |
| 1053 | error = gfs2_ea_find(ip, er, &el); |
| 1054 | if (error) |
| 1055 | return error; |
| 1056 | |
| 1057 | if (el.el_ea) { |
| 1058 | if (ip->i_di.di_flags & GFS2_DIF_APPENDONLY) { |
| 1059 | brelse(el.el_bh); |
| 1060 | return -EPERM; |
| 1061 | } |
| 1062 | |
| 1063 | error = -EEXIST; |
| 1064 | if (!(er->er_flags & XATTR_CREATE)) { |
| 1065 | int unstuffed = !GFS2_EA_IS_STUFFED(el.el_ea); |
| 1066 | error = ea_set_i(ip, er, &el); |
| 1067 | if (!error && unstuffed) |
| 1068 | ea_set_remove_unstuffed(ip, &el); |
| 1069 | } |
| 1070 | |
| 1071 | brelse(el.el_bh); |
| 1072 | } else { |
| 1073 | error = -ENODATA; |
| 1074 | if (!(er->er_flags & XATTR_REPLACE)) |
| 1075 | error = ea_set_i(ip, er, NULL); |
| 1076 | } |
| 1077 | |
| 1078 | return error; |
| 1079 | } |
| 1080 | |
| 1081 | int gfs2_ea_set(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 1082 | { |
| 1083 | struct gfs2_holder i_gh; |
| 1084 | int error; |
| 1085 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 1086 | if (!er->er_name_len || er->er_name_len > GFS2_EA_MAX_NAME_LEN) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1087 | return -EINVAL; |
| 1088 | if (!er->er_data || !er->er_data_len) { |
| 1089 | er->er_data = NULL; |
| 1090 | er->er_data_len = 0; |
| 1091 | } |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1092 | error = ea_check_size(GFS2_SB(&ip->i_inode), er); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1093 | if (error) |
| 1094 | return error; |
| 1095 | |
| 1096 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
| 1097 | if (error) |
| 1098 | return error; |
| 1099 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1100 | if (IS_IMMUTABLE(&ip->i_inode)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1101 | error = -EPERM; |
| 1102 | else |
| 1103 | error = gfs2_ea_ops[er->er_type]->eo_set(ip, er); |
| 1104 | |
| 1105 | gfs2_glock_dq_uninit(&i_gh); |
| 1106 | |
| 1107 | return error; |
| 1108 | } |
| 1109 | |
| 1110 | static int ea_remove_stuffed(struct gfs2_inode *ip, struct gfs2_ea_location *el) |
| 1111 | { |
| 1112 | struct gfs2_ea_header *ea = el->el_ea; |
| 1113 | struct gfs2_ea_header *prev = el->el_prev; |
| 1114 | struct buffer_head *dibh; |
| 1115 | int error; |
| 1116 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1117 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1118 | if (error) |
| 1119 | return error; |
| 1120 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1121 | gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1122 | |
| 1123 | if (prev) { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1124 | u32 len; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1125 | |
| 1126 | len = GFS2_EA_REC_LEN(prev) + GFS2_EA_REC_LEN(ea); |
| 1127 | prev->ea_rec_len = cpu_to_be32(len); |
| 1128 | |
| 1129 | if (GFS2_EA_IS_LAST(ea)) |
| 1130 | prev->ea_flags |= GFS2_EAFLAG_LAST; |
| 1131 | } else |
| 1132 | ea->ea_type = GFS2_EATYPE_UNUSED; |
| 1133 | |
| 1134 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 1135 | if (!error) { |
Eric Sandeen | bbb28ab | 2007-01-29 11:11:51 -0600 | [diff] [blame] | 1136 | ip->i_inode.i_ctime = CURRENT_TIME_SEC; |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1137 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 1138 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1139 | brelse(dibh); |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 1140 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1141 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1142 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1143 | |
| 1144 | return error; |
| 1145 | } |
| 1146 | |
| 1147 | int gfs2_ea_remove_i(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 1148 | { |
| 1149 | struct gfs2_ea_location el; |
| 1150 | int error; |
| 1151 | |
| 1152 | if (!ip->i_di.di_eattr) |
| 1153 | return -ENODATA; |
| 1154 | |
| 1155 | error = gfs2_ea_find(ip, er, &el); |
| 1156 | if (error) |
| 1157 | return error; |
| 1158 | if (!el.el_ea) |
| 1159 | return -ENODATA; |
| 1160 | |
| 1161 | if (GFS2_EA_IS_STUFFED(el.el_ea)) |
| 1162 | error = ea_remove_stuffed(ip, &el); |
| 1163 | else |
| 1164 | error = ea_remove_unstuffed(ip, el.el_bh, el.el_ea, el.el_prev, |
| 1165 | 0); |
| 1166 | |
| 1167 | brelse(el.el_bh); |
| 1168 | |
| 1169 | return error; |
| 1170 | } |
| 1171 | |
| 1172 | /** |
| 1173 | * gfs2_ea_remove - sets (or creates or replaces) an extended attribute |
| 1174 | * @ip: pointer to the inode of the target file |
| 1175 | * @er: request information |
| 1176 | * |
| 1177 | * Returns: errno |
| 1178 | */ |
| 1179 | |
| 1180 | int gfs2_ea_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er) |
| 1181 | { |
| 1182 | struct gfs2_holder i_gh; |
| 1183 | int error; |
| 1184 | |
| 1185 | if (!er->er_name_len || er->er_name_len > GFS2_EA_MAX_NAME_LEN) |
| 1186 | return -EINVAL; |
| 1187 | |
| 1188 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); |
| 1189 | if (error) |
| 1190 | return error; |
| 1191 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1192 | if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode)) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1193 | error = -EPERM; |
| 1194 | else |
| 1195 | error = gfs2_ea_ops[er->er_type]->eo_remove(ip, er); |
| 1196 | |
| 1197 | gfs2_glock_dq_uninit(&i_gh); |
| 1198 | |
| 1199 | return error; |
| 1200 | } |
| 1201 | |
| 1202 | static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, |
| 1203 | struct gfs2_ea_header *ea, char *data) |
| 1204 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1205 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1206 | struct buffer_head **bh; |
| 1207 | unsigned int amount = GFS2_EA_DATA_LEN(ea); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 1208 | unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 1209 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1210 | unsigned int x; |
| 1211 | int error; |
| 1212 | |
| 1213 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_KERNEL); |
| 1214 | if (!bh) |
| 1215 | return -ENOMEM; |
| 1216 | |
| 1217 | error = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0); |
| 1218 | if (error) |
| 1219 | goto out; |
| 1220 | |
| 1221 | for (x = 0; x < nptrs; x++) { |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1222 | error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, |
| 1223 | bh + x); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1224 | if (error) { |
| 1225 | while (x--) |
| 1226 | brelse(bh[x]); |
| 1227 | goto fail; |
| 1228 | } |
| 1229 | dataptrs++; |
| 1230 | } |
| 1231 | |
| 1232 | for (x = 0; x < nptrs; x++) { |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1233 | error = gfs2_meta_wait(sdp, bh[x]); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1234 | if (error) { |
| 1235 | for (; x < nptrs; x++) |
| 1236 | brelse(bh[x]); |
| 1237 | goto fail; |
| 1238 | } |
| 1239 | if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) { |
| 1240 | for (; x < nptrs; x++) |
| 1241 | brelse(bh[x]); |
| 1242 | error = -EIO; |
| 1243 | goto fail; |
| 1244 | } |
| 1245 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1246 | gfs2_trans_add_bh(ip->i_gl, bh[x], 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1247 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 1248 | memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1249 | (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); |
| 1250 | |
| 1251 | amount -= sdp->sd_jbsize; |
| 1252 | data += sdp->sd_jbsize; |
| 1253 | |
| 1254 | brelse(bh[x]); |
| 1255 | } |
| 1256 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1257 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1258 | kfree(bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1259 | return error; |
| 1260 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1261 | fail: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1262 | gfs2_trans_end(sdp); |
| 1263 | kfree(bh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1264 | return error; |
| 1265 | } |
| 1266 | |
| 1267 | int gfs2_ea_acl_chmod(struct gfs2_inode *ip, struct gfs2_ea_location *el, |
| 1268 | struct iattr *attr, char *data) |
| 1269 | { |
| 1270 | struct buffer_head *dibh; |
| 1271 | int error; |
| 1272 | |
| 1273 | if (GFS2_EA_IS_STUFFED(el->el_ea)) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1274 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), RES_DINODE + RES_EATTR, 0); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1275 | if (error) |
| 1276 | return error; |
| 1277 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1278 | gfs2_trans_add_bh(ip->i_gl, el->el_bh, 1); |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 1279 | memcpy(GFS2_EA2DATA(el->el_ea), data, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1280 | GFS2_EA_DATA_LEN(el->el_ea)); |
| 1281 | } else |
| 1282 | error = ea_acl_chmod_unstuffed(ip, el->el_ea, data); |
| 1283 | |
| 1284 | if (error) |
| 1285 | return error; |
| 1286 | |
| 1287 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 1288 | if (!error) { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1289 | error = inode_setattr(&ip->i_inode, attr); |
| 1290 | gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1291 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 1292 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1293 | brelse(dibh); |
| 1294 | } |
| 1295 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1296 | gfs2_trans_end(GFS2_SB(&ip->i_inode)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1297 | |
| 1298 | return error; |
| 1299 | } |
| 1300 | |
| 1301 | static int ea_dealloc_indirect(struct gfs2_inode *ip) |
| 1302 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1303 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1304 | struct gfs2_rgrp_list rlist; |
| 1305 | struct buffer_head *indbh, *dibh; |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 1306 | __be64 *eablk, *end; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1307 | unsigned int rg_blocks = 0; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1308 | u64 bstart = 0; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1309 | unsigned int blen = 0; |
| 1310 | unsigned int blks = 0; |
| 1311 | unsigned int x; |
| 1312 | int error; |
| 1313 | |
| 1314 | memset(&rlist, 0, sizeof(struct gfs2_rgrp_list)); |
| 1315 | |
Steven Whitehouse | 7276b3b | 2006-09-21 17:05:23 -0400 | [diff] [blame] | 1316 | error = gfs2_meta_read(ip->i_gl, ip->i_di.di_eattr, DIO_WAIT, &indbh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1317 | if (error) |
| 1318 | return error; |
| 1319 | |
| 1320 | if (gfs2_metatype_check(sdp, indbh, GFS2_METATYPE_IN)) { |
| 1321 | error = -EIO; |
| 1322 | goto out; |
| 1323 | } |
| 1324 | |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 1325 | eablk = (__be64 *)(indbh->b_data + sizeof(struct gfs2_meta_header)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1326 | end = eablk + sdp->sd_inptrs; |
| 1327 | |
| 1328 | for (; eablk < end; eablk++) { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1329 | u64 bn; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1330 | |
| 1331 | if (!*eablk) |
| 1332 | break; |
| 1333 | bn = be64_to_cpu(*eablk); |
| 1334 | |
| 1335 | if (bstart + blen == bn) |
| 1336 | blen++; |
| 1337 | else { |
| 1338 | if (bstart) |
| 1339 | gfs2_rlist_add(sdp, &rlist, bstart); |
| 1340 | bstart = bn; |
| 1341 | blen = 1; |
| 1342 | } |
| 1343 | blks++; |
| 1344 | } |
| 1345 | if (bstart) |
| 1346 | gfs2_rlist_add(sdp, &rlist, bstart); |
| 1347 | else |
| 1348 | goto out; |
| 1349 | |
| 1350 | gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0); |
| 1351 | |
| 1352 | for (x = 0; x < rlist.rl_rgrps; x++) { |
| 1353 | struct gfs2_rgrpd *rgd; |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 1354 | rgd = rlist.rl_ghs[x].gh_gl->gl_object; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1355 | rg_blocks += rgd->rd_ri.ri_length; |
| 1356 | } |
| 1357 | |
| 1358 | error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs); |
| 1359 | if (error) |
| 1360 | goto out_rlist_free; |
| 1361 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 1362 | error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + RES_INDIRECT + |
| 1363 | RES_STATFS + RES_QUOTA, blks); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1364 | if (error) |
| 1365 | goto out_gunlock; |
| 1366 | |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1367 | gfs2_trans_add_bh(ip->i_gl, indbh, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1368 | |
Al Viro | b44b84d | 2006-10-14 10:46:30 -0400 | [diff] [blame] | 1369 | eablk = (__be64 *)(indbh->b_data + sizeof(struct gfs2_meta_header)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1370 | bstart = 0; |
| 1371 | blen = 0; |
| 1372 | |
| 1373 | for (; eablk < end; eablk++) { |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 1374 | u64 bn; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1375 | |
| 1376 | if (!*eablk) |
| 1377 | break; |
| 1378 | bn = be64_to_cpu(*eablk); |
| 1379 | |
| 1380 | if (bstart + blen == bn) |
| 1381 | blen++; |
| 1382 | else { |
| 1383 | if (bstart) |
| 1384 | gfs2_free_meta(ip, bstart, blen); |
| 1385 | bstart = bn; |
| 1386 | blen = 1; |
| 1387 | } |
| 1388 | |
| 1389 | *eablk = 0; |
| 1390 | if (!ip->i_di.di_blocks) |
| 1391 | gfs2_consist_inode(ip); |
| 1392 | ip->i_di.di_blocks--; |
Steven Whitehouse | 9e2dbda | 2006-11-08 15:45:46 -0500 | [diff] [blame] | 1393 | gfs2_set_inode_blocks(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1394 | } |
| 1395 | if (bstart) |
| 1396 | gfs2_free_meta(ip, bstart, blen); |
| 1397 | |
| 1398 | ip->i_di.di_flags &= ~GFS2_DIF_EA_INDIRECT; |
| 1399 | |
| 1400 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 1401 | if (!error) { |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1402 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 1403 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1404 | brelse(dibh); |
| 1405 | } |
| 1406 | |
| 1407 | gfs2_trans_end(sdp); |
| 1408 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1409 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1410 | gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1411 | out_rlist_free: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1412 | gfs2_rlist_free(&rlist); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1413 | out: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1414 | brelse(indbh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1415 | return error; |
| 1416 | } |
| 1417 | |
| 1418 | static int ea_dealloc_block(struct gfs2_inode *ip) |
| 1419 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1420 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1421 | struct gfs2_alloc *al = &ip->i_alloc; |
| 1422 | struct gfs2_rgrpd *rgd; |
| 1423 | struct buffer_head *dibh; |
| 1424 | int error; |
| 1425 | |
| 1426 | rgd = gfs2_blk2rgrpd(sdp, ip->i_di.di_eattr); |
| 1427 | if (!rgd) { |
| 1428 | gfs2_consist_inode(ip); |
| 1429 | return -EIO; |
| 1430 | } |
| 1431 | |
| 1432 | error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, |
| 1433 | &al->al_rgd_gh); |
| 1434 | if (error) |
| 1435 | return error; |
| 1436 | |
Steven Whitehouse | cca195c | 2006-09-05 13:15:18 -0400 | [diff] [blame] | 1437 | error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_DINODE + RES_STATFS + |
| 1438 | RES_QUOTA, 1); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1439 | if (error) |
| 1440 | goto out_gunlock; |
| 1441 | |
| 1442 | gfs2_free_meta(ip, ip->i_di.di_eattr, 1); |
| 1443 | |
| 1444 | ip->i_di.di_eattr = 0; |
| 1445 | if (!ip->i_di.di_blocks) |
| 1446 | gfs2_consist_inode(ip); |
| 1447 | ip->i_di.di_blocks--; |
Steven Whitehouse | 9e2dbda | 2006-11-08 15:45:46 -0500 | [diff] [blame] | 1448 | gfs2_set_inode_blocks(&ip->i_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1449 | |
| 1450 | error = gfs2_meta_inode_buffer(ip, &dibh); |
| 1451 | if (!error) { |
Steven Whitehouse | d4e9c4c | 2006-01-18 11:19:28 +0000 | [diff] [blame] | 1452 | gfs2_trans_add_bh(ip->i_gl, dibh, 1); |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 1453 | gfs2_dinode_out(ip, dibh->b_data); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1454 | brelse(dibh); |
| 1455 | } |
| 1456 | |
| 1457 | gfs2_trans_end(sdp); |
| 1458 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1459 | out_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1460 | gfs2_glock_dq_uninit(&al->al_rgd_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1461 | return error; |
| 1462 | } |
| 1463 | |
| 1464 | /** |
| 1465 | * gfs2_ea_dealloc - deallocate the extended attribute fork |
| 1466 | * @ip: the inode |
| 1467 | * |
| 1468 | * Returns: errno |
| 1469 | */ |
| 1470 | |
| 1471 | int gfs2_ea_dealloc(struct gfs2_inode *ip) |
| 1472 | { |
| 1473 | struct gfs2_alloc *al; |
| 1474 | int error; |
| 1475 | |
| 1476 | al = gfs2_alloc_get(ip); |
| 1477 | |
| 1478 | error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE); |
| 1479 | if (error) |
| 1480 | goto out_alloc; |
| 1481 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 1482 | error = gfs2_rindex_hold(GFS2_SB(&ip->i_inode), &al->al_ri_gh); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1483 | if (error) |
| 1484 | goto out_quota; |
| 1485 | |
| 1486 | error = ea_foreach(ip, ea_dealloc_unstuffed, NULL); |
| 1487 | if (error) |
| 1488 | goto out_rindex; |
| 1489 | |
| 1490 | if (ip->i_di.di_flags & GFS2_DIF_EA_INDIRECT) { |
| 1491 | error = ea_dealloc_indirect(ip); |
| 1492 | if (error) |
| 1493 | goto out_rindex; |
| 1494 | } |
| 1495 | |
| 1496 | error = ea_dealloc_block(ip); |
| 1497 | |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1498 | out_rindex: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1499 | gfs2_glock_dq_uninit(&al->al_ri_gh); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1500 | out_quota: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1501 | gfs2_quota_unhold(ip); |
Steven Whitehouse | a91ea69 | 2006-09-04 12:04:26 -0400 | [diff] [blame] | 1502 | out_alloc: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1503 | gfs2_alloc_put(ip); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1504 | return error; |
| 1505 | } |
| 1506 | |