10 #include <linux/slab.h>
14 #include <linux/xattr.h>
16 #include <asm/uaccess.h>
40 static int ea_calc_size(
struct gfs2_sbd *sdp,
unsigned int nsize,
size_t dsize,
58 static int ea_check_size(
struct gfs2_sbd *sdp,
unsigned int nsize,
size_t dsize)
65 ea_calc_size(sdp, nsize, dsize, &size);
78 static int ea_foreach_i(
struct gfs2_inode *ip,
struct buffer_head *bh,
90 if (!(bh->b_data <= (
char *)ea && (
char *)
GFS2_EA2NEXT(ea) <=
91 bh->b_data + bh->b_size))
96 error = ea_call(ip, bh, ea, prev, data);
102 bh->b_data + bh->b_size)
117 struct buffer_head *bh, *eabh;
126 error = ea_foreach_i(ip, bh, ea_call, data);
136 end = eablk + GFS2_SB(&ip->
i_inode)->sd_inptrs;
138 for (; eablk <
end; eablk++) {
148 error = ea_foreach_i(ip, eabh, ea_call, data);
165 static int ea_find_i(
struct gfs2_inode *ip,
struct buffer_head *bh,
202 error = ea_foreach(ip, ea_find_i, &ef);
224 static int ea_dealloc_unstuffed(
struct gfs2_inode *ip,
struct buffer_head *bh,
228 int *
leave =
private;
232 struct buffer_head *dibh;
236 unsigned int blen = 0;
237 unsigned int blks = 0;
249 for (x = 0; x < ea->
ea_num_ptrs; x++, dataptrs++) {
276 for (x = 0; x < ea->
ea_num_ptrs; x++, dataptrs++) {
281 if (bstart + blen == bn)
291 gfs2_add_inode_blocks(&ip->
i_inode, -1);
296 if (prev && !leave) {
309 error = gfs2_meta_inode_buffer(ip, &dibh);
324 static int ea_remove_unstuffed(
struct gfs2_inode *ip,
struct buffer_head *bh,
338 error = ea_dealloc_unstuffed(ip, bh, ea, prev, (leave) ? &error :
NULL);
350 static inline unsigned int gfs2_ea_strlen(
struct gfs2_ea_header *ea)
364 static int ea_list_i(
struct gfs2_inode *ip,
struct buffer_head *bh,
370 unsigned int ea_size = gfs2_ea_strlen(ea);
393 prefix =
"security.";
440 error = ea_foreach(ip, ea_list_i, &ei);
462 const char *din,
char *
dout)
465 struct buffer_head **bh;
474 bh = kcalloc(nptrs,
sizeof(
struct buffer_head *),
GFP_NOFS);
478 for (x = 0; x < nptrs; x++) {
489 for (x = 0; x < nptrs; x++) {
492 for (; x < nptrs; x++)
497 for (; x < nptrs; x++)
507 memcpy(dout, pos, cp_size);
513 memcpy(pos, din, cp_size);
527 char *data,
size_t size)
538 ret = gfs2_iter_unstuffed(ip, el->
el_ea,
NULL, data);
565 error = gfs2_ea_get_copy(ip, &el, data, len);
585 static int gfs2_xattr_get(
struct dentry *
dentry,
const char *name,
586 void *
buffer,
size_t size,
int type)
597 error = gfs2_ea_find(ip, type, name, &el);
603 error = gfs2_ea_get_copy(ip, &el, buffer, size);
619 static int ea_alloc_blk(
struct gfs2_inode *ip,
struct buffer_head **bhp)
642 gfs2_add_inode_blocks(&ip->
i_inode, 1);
677 const char *data = er->
er_data;
684 struct buffer_head *bh;
697 gfs2_add_inode_blocks(&ip->
i_inode, 1);
701 memcpy(bh->b_data + mh_size, data, copy);
702 if (copy < sdp->sd_jbsize)
703 memset(bh->b_data + mh_size + copy, 0,
726 struct buffer_head *dibh;
733 error = gfs2_quota_lock_check(ip);
742 blks + gfs2_rg_blocks(ip, blks) +
747 error = skeleton_call(ip, er,
private);
751 error = gfs2_meta_inode_buffer(ip, &dibh);
771 struct buffer_head *bh;
774 error = ea_alloc_blk(ip, &bh);
794 static int ea_init(
struct gfs2_inode *ip,
int type,
const char *name,
795 const void *data,
size_t size)
798 unsigned int jbsize = GFS2_SB(&ip->
i_inode)->sd_jbsize;
799 unsigned int blks = 1;
810 return ea_alloc_skeleton(ip, &er, blks, ea_init_i,
NULL);
825 new->ea_flags = last;
830 static void ea_set_remove_stuffed(
struct gfs2_inode *ip,
864 static int ea_set_simple_noalloc(
struct gfs2_inode *ip,
struct buffer_head *bh,
868 struct buffer_head *dibh;
878 ea = ea_split_ea(ea);
880 ea_write(ip, ea, er);
883 ea_set_remove_stuffed(ip, es->
es_el);
885 error = gfs2_meta_inode_buffer(ip, &dibh);
897 static int ea_set_simple_alloc(
struct gfs2_inode *ip,
907 ea = ea_split_ea(ea);
909 error = ea_write(ip, ea, er);
914 ea_set_remove_stuffed(ip, es->
es_el);
919 static int ea_set_simple(
struct gfs2_inode *ip,
struct buffer_head *bh,
923 struct ea_set *es =
private;
928 stuffed = ea_calc_size(GFS2_SB(&ip->
i_inode), es->
es_er->er_name_len,
929 es->
es_er->er_data_len, &size);
935 error = ea_remove_unstuffed(ip, bh, ea, prev, 1);
946 error = ea_set_simple_noalloc(ip, bh, ea, es);
955 GFS2_SB(&ip->
i_inode)->sd_jbsize);
957 error = ea_alloc_skeleton(ip, es->
es_er, blks,
958 ea_set_simple_alloc, es);
970 struct buffer_head *indbh, *newbh;
988 eablk = (
__be64 *)(indbh->b_data + mh_size);
991 for (; eablk <
end; eablk++)
1011 gfs2_buffer_clear_tail(indbh, mh_size);
1013 eablk = (
__be64 *)(indbh->b_data + mh_size);
1017 gfs2_add_inode_blocks(&ip->
i_inode, 1);
1022 error = ea_alloc_blk(ip, &newbh);
1033 ea_set_remove_stuffed(ip,
private);
1040 static int ea_set_i(
struct gfs2_inode *ip,
int type,
const char *name,
1045 unsigned int blks = 2;
1058 error = ea_foreach(ip, ea_set_simple, &es);
1069 return ea_alloc_skeleton(ip, &er, blks, ea_set_block, el);
1072 static int ea_set_remove_unstuffed(
struct gfs2_inode *ip,
1088 struct buffer_head *dibh;
1109 error = gfs2_meta_inode_buffer(ip, &dibh);
1135 static int gfs2_xattr_remove(
struct gfs2_inode *ip,
int type,
const char *name)
1143 error = gfs2_ea_find(ip, type, name, &el);
1150 error = ea_remove_stuffed(ip, &el);
1174 const void *value,
size_t size,
int flags,
int type)
1177 struct gfs2_sbd *sdp = GFS2_SB(inode);
1179 unsigned int namel =
strlen(name);
1188 return gfs2_xattr_remove(ip, type, name);
1190 if (ea_check_size(sdp, namel, size))
1196 return ea_init(ip, type, name, value, size);
1199 error = gfs2_ea_find(ip, type, name, &el);
1212 error = ea_set_i(ip, type, name, value, size, &el);
1213 if (!error && unstuffed)
1214 ea_set_remove_unstuffed(ip, &el);
1223 error = ea_set_i(ip, type, name, value, size,
NULL);
1228 static int gfs2_xattr_set(
struct dentry *dentry,
const char *name,
1229 const void *value,
size_t size,
int flags,
int type)
1236 static int ea_acl_chmod_unstuffed(
struct gfs2_inode *ip,
1248 ret = gfs2_iter_unstuffed(ip, ea, data,
NULL);
1257 struct gfs2_sbd *sdp = GFS2_SB(inode);
1273 error = ea_acl_chmod_unstuffed(ip, el.
el_ea, data);
1285 static int ea_dealloc_indirect(
struct gfs2_inode *ip)
1289 struct buffer_head *indbh, *dibh;
1291 unsigned int rg_blocks = 0;
1293 unsigned int blen = 0;
1294 unsigned int blks = 0;
1316 for (; eablk <
end; eablk++) {
1323 if (bstart + blen == bn)
1340 for (x = 0; x <
rlist.rl_rgrps; x++) {
1342 rgd =
rlist.rl_ghs[
x].gh_gl->gl_object;
1348 goto out_rlist_free;
1361 for (; eablk <
end; eablk++) {
1368 if (bstart + blen == bn)
1378 gfs2_add_inode_blocks(&ip->
i_inode, -1);
1385 error = gfs2_meta_inode_buffer(ip, &dibh);
1403 static int ea_dealloc_block(
struct gfs2_inode *ip)
1407 struct buffer_head *dibh;
1433 gfs2_add_inode_blocks(&ip->
i_inode, -1);
1435 error = gfs2_meta_inode_buffer(ip, &dibh);
1468 error = ea_foreach(ip, ea_dealloc_unstuffed,
NULL);
1473 error = ea_dealloc_indirect(ip);
1478 error = ea_dealloc_block(ip);
1485 static const struct xattr_handler gfs2_xattr_user_handler = {
1488 .get = gfs2_xattr_get,
1489 .set = gfs2_xattr_set,
1492 static const struct xattr_handler gfs2_xattr_security_handler = {
1495 .get = gfs2_xattr_get,
1496 .set = gfs2_xattr_set,
1500 &gfs2_xattr_user_handler,
1501 &gfs2_xattr_security_handler,