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