aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/xattr.c')
-rw-r--r--fs/ext4/xattr.c112
1 files changed, 59 insertions, 53 deletions
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index fed5b01d7a8d..b4c5aa8489d8 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -92,7 +92,7 @@ static struct buffer_head *ext4_xattr_cache_find(struct inode *,
92 struct mb_cache_entry **); 92 struct mb_cache_entry **);
93static void ext4_xattr_rehash(struct ext4_xattr_header *, 93static void ext4_xattr_rehash(struct ext4_xattr_header *,
94 struct ext4_xattr_entry *); 94 struct ext4_xattr_entry *);
95static int ext4_xattr_list(struct inode *inode, char *buffer, 95static int ext4_xattr_list(struct dentry *dentry, char *buffer,
96 size_t buffer_size); 96 size_t buffer_size);
97 97
98static struct mb_cache *ext4_xattr_cache; 98static struct mb_cache *ext4_xattr_cache;
@@ -140,7 +140,7 @@ ext4_xattr_handler(int name_index)
140ssize_t 140ssize_t
141ext4_listxattr(struct dentry *dentry, char *buffer, size_t size) 141ext4_listxattr(struct dentry *dentry, char *buffer, size_t size)
142{ 142{
143 return ext4_xattr_list(dentry->d_inode, buffer, size); 143 return ext4_xattr_list(dentry, buffer, size);
144} 144}
145 145
146static int 146static int
@@ -227,7 +227,8 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
227 ea_bdebug(bh, "b_count=%d, refcount=%d", 227 ea_bdebug(bh, "b_count=%d, refcount=%d",
228 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 228 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
229 if (ext4_xattr_check_block(bh)) { 229 if (ext4_xattr_check_block(bh)) {
230bad_block: ext4_error(inode->i_sb, __func__, 230bad_block:
231 ext4_error(inode->i_sb,
231 "inode %lu: bad block %llu", inode->i_ino, 232 "inode %lu: bad block %llu", inode->i_ino,
232 EXT4_I(inode)->i_file_acl); 233 EXT4_I(inode)->i_file_acl);
233 error = -EIO; 234 error = -EIO;
@@ -267,7 +268,7 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
267 void *end; 268 void *end;
268 int error; 269 int error;
269 270
270 if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR)) 271 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
271 return -ENODATA; 272 return -ENODATA;
272 error = ext4_get_inode_loc(inode, &iloc); 273 error = ext4_get_inode_loc(inode, &iloc);
273 if (error) 274 if (error)
@@ -325,7 +326,7 @@ ext4_xattr_get(struct inode *inode, int name_index, const char *name,
325} 326}
326 327
327static int 328static int
328ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry, 329ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
329 char *buffer, size_t buffer_size) 330 char *buffer, size_t buffer_size)
330{ 331{
331 size_t rest = buffer_size; 332 size_t rest = buffer_size;
@@ -335,9 +336,10 @@ ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry,
335 ext4_xattr_handler(entry->e_name_index); 336 ext4_xattr_handler(entry->e_name_index);
336 337
337 if (handler) { 338 if (handler) {
338 size_t size = handler->list(inode, buffer, rest, 339 size_t size = handler->list(dentry, buffer, rest,
339 entry->e_name, 340 entry->e_name,
340 entry->e_name_len); 341 entry->e_name_len,
342 handler->flags);
341 if (buffer) { 343 if (buffer) {
342 if (size > rest) 344 if (size > rest)
343 return -ERANGE; 345 return -ERANGE;
@@ -350,8 +352,9 @@ ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry,
350} 352}
351 353
352static int 354static int
353ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) 355ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
354{ 356{
357 struct inode *inode = dentry->d_inode;
355 struct buffer_head *bh = NULL; 358 struct buffer_head *bh = NULL;
356 int error; 359 int error;
357 360
@@ -369,14 +372,14 @@ ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
369 ea_bdebug(bh, "b_count=%d, refcount=%d", 372 ea_bdebug(bh, "b_count=%d, refcount=%d",
370 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 373 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
371 if (ext4_xattr_check_block(bh)) { 374 if (ext4_xattr_check_block(bh)) {
372 ext4_error(inode->i_sb, __func__, 375 ext4_error(inode->i_sb,
373 "inode %lu: bad block %llu", inode->i_ino, 376 "inode %lu: bad block %llu", inode->i_ino,
374 EXT4_I(inode)->i_file_acl); 377 EXT4_I(inode)->i_file_acl);
375 error = -EIO; 378 error = -EIO;
376 goto cleanup; 379 goto cleanup;
377 } 380 }
378 ext4_xattr_cache_insert(bh); 381 ext4_xattr_cache_insert(bh);
379 error = ext4_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size); 382 error = ext4_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size);
380 383
381cleanup: 384cleanup:
382 brelse(bh); 385 brelse(bh);
@@ -385,15 +388,16 @@ cleanup:
385} 388}
386 389
387static int 390static int
388ext4_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) 391ext4_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size)
389{ 392{
393 struct inode *inode = dentry->d_inode;
390 struct ext4_xattr_ibody_header *header; 394 struct ext4_xattr_ibody_header *header;
391 struct ext4_inode *raw_inode; 395 struct ext4_inode *raw_inode;
392 struct ext4_iloc iloc; 396 struct ext4_iloc iloc;
393 void *end; 397 void *end;
394 int error; 398 int error;
395 399
396 if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR)) 400 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
397 return 0; 401 return 0;
398 error = ext4_get_inode_loc(inode, &iloc); 402 error = ext4_get_inode_loc(inode, &iloc);
399 if (error) 403 if (error)
@@ -404,7 +408,7 @@ ext4_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
404 error = ext4_xattr_check_names(IFIRST(header), end); 408 error = ext4_xattr_check_names(IFIRST(header), end);
405 if (error) 409 if (error)
406 goto cleanup; 410 goto cleanup;
407 error = ext4_xattr_list_entries(inode, IFIRST(header), 411 error = ext4_xattr_list_entries(dentry, IFIRST(header),
408 buffer, buffer_size); 412 buffer, buffer_size);
409 413
410cleanup: 414cleanup:
@@ -423,12 +427,12 @@ cleanup:
423 * used / required on success. 427 * used / required on success.
424 */ 428 */
425static int 429static int
426ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 430ext4_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
427{ 431{
428 int i_error, b_error; 432 int i_error, b_error;
429 433
430 down_read(&EXT4_I(inode)->xattr_sem); 434 down_read(&EXT4_I(dentry->d_inode)->xattr_sem);
431 i_error = ext4_xattr_ibody_list(inode, buffer, buffer_size); 435 i_error = ext4_xattr_ibody_list(dentry, buffer, buffer_size);
432 if (i_error < 0) { 436 if (i_error < 0) {
433 b_error = 0; 437 b_error = 0;
434 } else { 438 } else {
@@ -436,11 +440,11 @@ ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
436 buffer += i_error; 440 buffer += i_error;
437 buffer_size -= i_error; 441 buffer_size -= i_error;
438 } 442 }
439 b_error = ext4_xattr_block_list(inode, buffer, buffer_size); 443 b_error = ext4_xattr_block_list(dentry, buffer, buffer_size);
440 if (b_error < 0) 444 if (b_error < 0)
441 i_error = 0; 445 i_error = 0;
442 } 446 }
443 up_read(&EXT4_I(inode)->xattr_sem); 447 up_read(&EXT4_I(dentry->d_inode)->xattr_sem);
444 return i_error + b_error; 448 return i_error + b_error;
445} 449}
446 450
@@ -482,15 +486,16 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
482 ea_bdebug(bh, "refcount now=0; freeing"); 486 ea_bdebug(bh, "refcount now=0; freeing");
483 if (ce) 487 if (ce)
484 mb_cache_entry_free(ce); 488 mb_cache_entry_free(ce);
485 ext4_free_blocks(handle, inode, bh->b_blocknr, 1, 1);
486 get_bh(bh); 489 get_bh(bh);
487 ext4_forget(handle, 1, inode, bh, bh->b_blocknr); 490 ext4_free_blocks(handle, inode, bh, 0, 1,
491 EXT4_FREE_BLOCKS_METADATA |
492 EXT4_FREE_BLOCKS_FORGET);
488 } else { 493 } else {
489 le32_add_cpu(&BHDR(bh)->h_refcount, -1); 494 le32_add_cpu(&BHDR(bh)->h_refcount, -1);
490 error = ext4_handle_dirty_metadata(handle, inode, bh); 495 error = ext4_handle_dirty_metadata(handle, inode, bh);
491 if (IS_SYNC(inode)) 496 if (IS_SYNC(inode))
492 ext4_handle_sync(handle); 497 ext4_handle_sync(handle);
493 vfs_dq_free_block(inode, 1); 498 dquot_free_block(inode, 1);
494 ea_bdebug(bh, "refcount now=%d; releasing", 499 ea_bdebug(bh, "refcount now=%d; releasing",
495 le32_to_cpu(BHDR(bh)->h_refcount)); 500 le32_to_cpu(BHDR(bh)->h_refcount));
496 if (ce) 501 if (ce)
@@ -661,9 +666,8 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
661 atomic_read(&(bs->bh->b_count)), 666 atomic_read(&(bs->bh->b_count)),
662 le32_to_cpu(BHDR(bs->bh)->h_refcount)); 667 le32_to_cpu(BHDR(bs->bh)->h_refcount));
663 if (ext4_xattr_check_block(bs->bh)) { 668 if (ext4_xattr_check_block(bs->bh)) {
664 ext4_error(sb, __func__, 669 ext4_error(sb, "inode %lu: bad block %llu",
665 "inode %lu: bad block %llu", inode->i_ino, 670 inode->i_ino, EXT4_I(inode)->i_file_acl);
666 EXT4_I(inode)->i_file_acl);
667 error = -EIO; 671 error = -EIO;
668 goto cleanup; 672 goto cleanup;
669 } 673 }
@@ -783,8 +787,8 @@ inserted:
783 else { 787 else {
784 /* The old block is released after updating 788 /* The old block is released after updating
785 the inode. */ 789 the inode. */
786 error = -EDQUOT; 790 error = dquot_alloc_block(inode, 1);
787 if (vfs_dq_alloc_block(inode, 1)) 791 if (error)
788 goto cleanup; 792 goto cleanup;
789 error = ext4_journal_get_write_access(handle, 793 error = ext4_journal_get_write_access(handle,
790 new_bh); 794 new_bh);
@@ -832,7 +836,8 @@ inserted:
832 new_bh = sb_getblk(sb, block); 836 new_bh = sb_getblk(sb, block);
833 if (!new_bh) { 837 if (!new_bh) {
834getblk_failed: 838getblk_failed:
835 ext4_free_blocks(handle, inode, block, 1, 1); 839 ext4_free_blocks(handle, inode, 0, block, 1,
840 EXT4_FREE_BLOCKS_METADATA);
836 error = -EIO; 841 error = -EIO;
837 goto cleanup; 842 goto cleanup;
838 } 843 }
@@ -871,13 +876,12 @@ cleanup:
871 return error; 876 return error;
872 877
873cleanup_dquot: 878cleanup_dquot:
874 vfs_dq_free_block(inode, 1); 879 dquot_free_block(inode, 1);
875 goto cleanup; 880 goto cleanup;
876 881
877bad_block: 882bad_block:
878 ext4_error(inode->i_sb, __func__, 883 ext4_error(inode->i_sb, "inode %lu: bad block %llu",
879 "inode %lu: bad block %llu", inode->i_ino, 884 inode->i_ino, EXT4_I(inode)->i_file_acl);
880 EXT4_I(inode)->i_file_acl);
881 goto cleanup; 885 goto cleanup;
882 886
883#undef header 887#undef header
@@ -903,7 +907,7 @@ ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
903 is->s.base = is->s.first = IFIRST(header); 907 is->s.base = is->s.first = IFIRST(header);
904 is->s.here = is->s.first; 908 is->s.here = is->s.first;
905 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size; 909 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
906 if (EXT4_I(inode)->i_state & EXT4_STATE_XATTR) { 910 if (ext4_test_inode_state(inode, EXT4_STATE_XATTR)) {
907 error = ext4_xattr_check_names(IFIRST(header), is->s.end); 911 error = ext4_xattr_check_names(IFIRST(header), is->s.end);
908 if (error) 912 if (error)
909 return error; 913 return error;
@@ -935,10 +939,10 @@ ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
935 header = IHDR(inode, ext4_raw_inode(&is->iloc)); 939 header = IHDR(inode, ext4_raw_inode(&is->iloc));
936 if (!IS_LAST_ENTRY(s->first)) { 940 if (!IS_LAST_ENTRY(s->first)) {
937 header->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC); 941 header->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
938 EXT4_I(inode)->i_state |= EXT4_STATE_XATTR; 942 ext4_set_inode_state(inode, EXT4_STATE_XATTR);
939 } else { 943 } else {
940 header->h_magic = cpu_to_le32(0); 944 header->h_magic = cpu_to_le32(0);
941 EXT4_I(inode)->i_state &= ~EXT4_STATE_XATTR; 945 ext4_clear_inode_state(inode, EXT4_STATE_XATTR);
942 } 946 }
943 return 0; 947 return 0;
944} 948}
@@ -981,17 +985,21 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
981 if (strlen(name) > 255) 985 if (strlen(name) > 255)
982 return -ERANGE; 986 return -ERANGE;
983 down_write(&EXT4_I(inode)->xattr_sem); 987 down_write(&EXT4_I(inode)->xattr_sem);
984 no_expand = EXT4_I(inode)->i_state & EXT4_STATE_NO_EXPAND; 988 no_expand = ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND);
985 EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND; 989 ext4_set_inode_state(inode, EXT4_STATE_NO_EXPAND);
986 990
987 error = ext4_get_inode_loc(inode, &is.iloc); 991 error = ext4_get_inode_loc(inode, &is.iloc);
988 if (error) 992 if (error)
989 goto cleanup; 993 goto cleanup;
990 994
991 if (EXT4_I(inode)->i_state & EXT4_STATE_NEW) { 995 error = ext4_journal_get_write_access(handle, is.iloc.bh);
996 if (error)
997 goto cleanup;
998
999 if (ext4_test_inode_state(inode, EXT4_STATE_NEW)) {
992 struct ext4_inode *raw_inode = ext4_raw_inode(&is.iloc); 1000 struct ext4_inode *raw_inode = ext4_raw_inode(&is.iloc);
993 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size); 1001 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
994 EXT4_I(inode)->i_state &= ~EXT4_STATE_NEW; 1002 ext4_clear_inode_state(inode, EXT4_STATE_NEW);
995 } 1003 }
996 1004
997 error = ext4_xattr_ibody_find(inode, &i, &is); 1005 error = ext4_xattr_ibody_find(inode, &i, &is);
@@ -1013,9 +1021,6 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
1013 if (flags & XATTR_CREATE) 1021 if (flags & XATTR_CREATE)
1014 goto cleanup; 1022 goto cleanup;
1015 } 1023 }
1016 error = ext4_journal_get_write_access(handle, is.iloc.bh);
1017 if (error)
1018 goto cleanup;
1019 if (!value) { 1024 if (!value) {
1020 if (!is.s.not_found) 1025 if (!is.s.not_found)
1021 error = ext4_xattr_ibody_set(handle, inode, &i, &is); 1026 error = ext4_xattr_ibody_set(handle, inode, &i, &is);
@@ -1046,7 +1051,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
1046 ext4_xattr_update_super_block(handle, inode->i_sb); 1051 ext4_xattr_update_super_block(handle, inode->i_sb);
1047 inode->i_ctime = ext4_current_time(inode); 1052 inode->i_ctime = ext4_current_time(inode);
1048 if (!value) 1053 if (!value)
1049 EXT4_I(inode)->i_state &= ~EXT4_STATE_NO_EXPAND; 1054 ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
1050 error = ext4_mark_iloc_dirty(handle, inode, &is.iloc); 1055 error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
1051 /* 1056 /*
1052 * The bh is consumed by ext4_mark_iloc_dirty, even with 1057 * The bh is consumed by ext4_mark_iloc_dirty, even with
@@ -1061,7 +1066,7 @@ cleanup:
1061 brelse(is.iloc.bh); 1066 brelse(is.iloc.bh);
1062 brelse(bs.bh); 1067 brelse(bs.bh);
1063 if (no_expand == 0) 1068 if (no_expand == 0)
1064 EXT4_I(inode)->i_state &= ~EXT4_STATE_NO_EXPAND; 1069 ext4_clear_inode_state(inode, EXT4_STATE_NO_EXPAND);
1065 up_write(&EXT4_I(inode)->xattr_sem); 1070 up_write(&EXT4_I(inode)->xattr_sem);
1066 return error; 1071 return error;
1067} 1072}
@@ -1189,9 +1194,8 @@ retry:
1189 if (!bh) 1194 if (!bh)
1190 goto cleanup; 1195 goto cleanup;
1191 if (ext4_xattr_check_block(bh)) { 1196 if (ext4_xattr_check_block(bh)) {
1192 ext4_error(inode->i_sb, __func__, 1197 ext4_error(inode->i_sb, "inode %lu: bad block %llu",
1193 "inode %lu: bad block %llu", inode->i_ino, 1198 inode->i_ino, EXT4_I(inode)->i_file_acl);
1194 EXT4_I(inode)->i_file_acl);
1195 error = -EIO; 1199 error = -EIO;
1196 goto cleanup; 1200 goto cleanup;
1197 } 1201 }
@@ -1296,6 +1300,8 @@ retry:
1296 1300
1297 /* Remove the chosen entry from the inode */ 1301 /* Remove the chosen entry from the inode */
1298 error = ext4_xattr_ibody_set(handle, inode, &i, is); 1302 error = ext4_xattr_ibody_set(handle, inode, &i, is);
1303 if (error)
1304 goto cleanup;
1299 1305
1300 entry = IFIRST(header); 1306 entry = IFIRST(header);
1301 if (entry_size + EXT4_XATTR_SIZE(size) >= new_extra_isize) 1307 if (entry_size + EXT4_XATTR_SIZE(size) >= new_extra_isize)
@@ -1326,6 +1332,8 @@ retry:
1326 goto cleanup; 1332 goto cleanup;
1327 kfree(b_entry_name); 1333 kfree(b_entry_name);
1328 kfree(buffer); 1334 kfree(buffer);
1335 b_entry_name = NULL;
1336 buffer = NULL;
1329 brelse(is->iloc.bh); 1337 brelse(is->iloc.bh);
1330 kfree(is); 1338 kfree(is);
1331 kfree(bs); 1339 kfree(bs);
@@ -1364,16 +1372,14 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
1364 goto cleanup; 1372 goto cleanup;
1365 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl); 1373 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
1366 if (!bh) { 1374 if (!bh) {
1367 ext4_error(inode->i_sb, __func__, 1375 ext4_error(inode->i_sb, "inode %lu: block %llu read error",
1368 "inode %lu: block %llu read error", inode->i_ino, 1376 inode->i_ino, EXT4_I(inode)->i_file_acl);
1369 EXT4_I(inode)->i_file_acl);
1370 goto cleanup; 1377 goto cleanup;
1371 } 1378 }
1372 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || 1379 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
1373 BHDR(bh)->h_blocks != cpu_to_le32(1)) { 1380 BHDR(bh)->h_blocks != cpu_to_le32(1)) {
1374 ext4_error(inode->i_sb, __func__, 1381 ext4_error(inode->i_sb, "inode %lu: bad block %llu",
1375 "inode %lu: bad block %llu", inode->i_ino, 1382 inode->i_ino, EXT4_I(inode)->i_file_acl);
1376 EXT4_I(inode)->i_file_acl);
1377 goto cleanup; 1383 goto cleanup;
1378 } 1384 }
1379 ext4_xattr_release_block(handle, inode, bh); 1385 ext4_xattr_release_block(handle, inode, bh);
@@ -1498,7 +1504,7 @@ again:
1498 } 1504 }
1499 bh = sb_bread(inode->i_sb, ce->e_block); 1505 bh = sb_bread(inode->i_sb, ce->e_block);
1500 if (!bh) { 1506 if (!bh) {
1501 ext4_error(inode->i_sb, __func__, 1507 ext4_error(inode->i_sb,
1502 "inode %lu: block %lu read error", 1508 "inode %lu: block %lu read error",
1503 inode->i_ino, (unsigned long) ce->e_block); 1509 inode->i_ino, (unsigned long) ce->e_block);
1504 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >= 1510 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=