aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/xattr.c
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2012-07-26 06:26:36 -0400
committerSteven Whitehouse <swhiteho@redhat.com>2012-09-24 05:46:53 -0400
commit1f981697432daea3c0abf938b39174dcfb29340e (patch)
treebcb4123f50445ab93d752e925ab88a6cfe6cf8fb /fs/gfs2/xattr.c
parent979570e02981d4a8fc20b3cc8fd651856c98ee9d (diff)
GFS2: Merge two nearly identical xattr functions
There were two functions in the xattr code which were nearly identical, the only difference being that one was copy data into the unstuffed xattrs and the other was copying data out from it. This patch merges the two functions such that the code which deal with iteration over the unstuffed xattrs is no longer duplicated. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/xattr.c')
-rw-r--r--fs/gfs2/xattr.c94
1 files changed, 30 insertions, 64 deletions
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index 27a0b4a901f5..5404ed1582ff 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -448,17 +448,18 @@ ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
448} 448}
449 449
450/** 450/**
451 * ea_get_unstuffed - actually copies the unstuffed data into the 451 * ea_iter_unstuffed - copies the unstuffed xattr data to/from the
452 * request buffer 452 * request buffer
453 * @ip: The GFS2 inode 453 * @ip: The GFS2 inode
454 * @ea: The extended attribute header structure 454 * @ea: The extended attribute header structure
455 * @data: The data to be copied 455 * @din: The data to be copied in
456 * @dout: The data to be copied out (one of din,dout will be NULL)
456 * 457 *
457 * Returns: errno 458 * Returns: errno
458 */ 459 */
459 460
460static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, 461static int gfs2_iter_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
461 char *data) 462 const char *din, char *dout)
462{ 463{
463 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 464 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
464 struct buffer_head **bh; 465 struct buffer_head **bh;
@@ -467,6 +468,8 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
467 __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); 468 __be64 *dataptrs = GFS2_EA2DATAPTRS(ea);
468 unsigned int x; 469 unsigned int x;
469 int error = 0; 470 int error = 0;
471 unsigned char *pos;
472 unsigned cp_size;
470 473
471 bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); 474 bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
472 if (!bh) 475 if (!bh)
@@ -497,12 +500,21 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
497 goto out; 500 goto out;
498 } 501 }
499 502
500 memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header), 503 pos = bh[x]->b_data + sizeof(struct gfs2_meta_header);
501 (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); 504 cp_size = (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize;
502 505
503 amount -= sdp->sd_jbsize; 506 if (dout) {
504 data += sdp->sd_jbsize; 507 memcpy(dout, pos, cp_size);
508 dout += sdp->sd_jbsize;
509 }
510
511 if (din) {
512 gfs2_trans_add_bh(ip->i_gl, bh[x], 1);
513 memcpy(pos, din, cp_size);
514 din += sdp->sd_jbsize;
515 }
505 516
517 amount -= sdp->sd_jbsize;
506 brelse(bh[x]); 518 brelse(bh[x]);
507 } 519 }
508 520
@@ -523,7 +535,7 @@ static int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el,
523 memcpy(data, GFS2_EA2DATA(el->el_ea), len); 535 memcpy(data, GFS2_EA2DATA(el->el_ea), len);
524 return len; 536 return len;
525 } 537 }
526 ret = ea_get_unstuffed(ip, el->el_ea, data); 538 ret = gfs2_iter_unstuffed(ip, el->el_ea, NULL, data);
527 if (ret < 0) 539 if (ret < 0)
528 return ret; 540 return ret;
529 return len; 541 return len;
@@ -1220,69 +1232,23 @@ static int gfs2_xattr_set(struct dentry *dentry, const char *name,
1220 size, flags, type); 1232 size, flags, type);
1221} 1233}
1222 1234
1235
1223static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, 1236static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip,
1224 struct gfs2_ea_header *ea, char *data) 1237 struct gfs2_ea_header *ea, char *data)
1225{ 1238{
1226 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1239 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1227 struct buffer_head **bh;
1228 unsigned int amount = GFS2_EA_DATA_LEN(ea); 1240 unsigned int amount = GFS2_EA_DATA_LEN(ea);
1229 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); 1241 unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize);
1230 __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); 1242 int ret;
1231 unsigned int x;
1232 int error;
1233
1234 bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS);
1235 if (!bh)
1236 return -ENOMEM;
1237
1238 error = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0);
1239 if (error)
1240 goto out;
1241
1242 for (x = 0; x < nptrs; x++) {
1243 error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0,
1244 bh + x);
1245 if (error) {
1246 while (x--)
1247 brelse(bh[x]);
1248 goto fail;
1249 }
1250 dataptrs++;
1251 }
1252
1253 for (x = 0; x < nptrs; x++) {
1254 error = gfs2_meta_wait(sdp, bh[x]);
1255 if (error) {
1256 for (; x < nptrs; x++)
1257 brelse(bh[x]);
1258 goto fail;
1259 }
1260 if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) {
1261 for (; x < nptrs; x++)
1262 brelse(bh[x]);
1263 error = -EIO;
1264 goto fail;
1265 }
1266
1267 gfs2_trans_add_bh(ip->i_gl, bh[x], 1);
1268
1269 memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data,
1270 (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize);
1271
1272 amount -= sdp->sd_jbsize;
1273 data += sdp->sd_jbsize;
1274
1275 brelse(bh[x]);
1276 }
1277 1243
1278out: 1244 ret = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0);
1279 kfree(bh); 1245 if (ret)
1280 return error; 1246 return ret;
1281 1247
1282fail: 1248 ret = gfs2_iter_unstuffed(ip, ea, data, NULL);
1283 gfs2_trans_end(sdp); 1249 gfs2_trans_end(sdp);
1284 kfree(bh); 1250
1285 return error; 1251 return ret;
1286} 1252}
1287 1253
1288int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) 1254int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data)