diff options
author | Chris Mason <clm@fb.com> | 2015-01-21 20:45:25 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-01-21 20:45:25 -0500 |
commit | d3541834884f042aaaab1d6c0610cdc3488028e4 (patch) | |
tree | d6f8f0ac6c98b1f996dfcaae5df0ba33a6fa5251 /fs | |
parent | ce93ec548cfa02f9cd6b70d546d5f36f4d160f57 (diff) | |
parent | 1d4c08e0a60be356134d0c466744d0d4e16ebab0 (diff) |
Merge branch 'fix/find-item-path-leak' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux into for-linus
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/backref.c | 28 | ||||
-rw-r--r-- | fs/btrfs/backref.h | 3 | ||||
-rw-r--r-- | fs/btrfs/ctree.c | 18 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 15 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 10 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 10 | ||||
-rw-r--r-- | fs/btrfs/tree-log.c | 11 |
7 files changed, 46 insertions, 49 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index 8729cf68d2fe..f55721ff9385 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c | |||
@@ -1246,25 +1246,6 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans, | |||
1246 | return ret; | 1246 | return ret; |
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | /* | ||
1250 | * this makes the path point to (inum INODE_ITEM ioff) | ||
1251 | */ | ||
1252 | int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, | ||
1253 | struct btrfs_path *path) | ||
1254 | { | ||
1255 | struct btrfs_key key; | ||
1256 | return btrfs_find_item(fs_root, path, inum, ioff, | ||
1257 | BTRFS_INODE_ITEM_KEY, &key); | ||
1258 | } | ||
1259 | |||
1260 | static int inode_ref_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, | ||
1261 | struct btrfs_path *path, | ||
1262 | struct btrfs_key *found_key) | ||
1263 | { | ||
1264 | return btrfs_find_item(fs_root, path, inum, ioff, | ||
1265 | BTRFS_INODE_REF_KEY, found_key); | ||
1266 | } | ||
1267 | |||
1268 | int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, | 1249 | int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid, |
1269 | u64 start_off, struct btrfs_path *path, | 1250 | u64 start_off, struct btrfs_path *path, |
1270 | struct btrfs_inode_extref **ret_extref, | 1251 | struct btrfs_inode_extref **ret_extref, |
@@ -1374,7 +1355,8 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path, | |||
1374 | btrfs_tree_read_unlock_blocking(eb); | 1355 | btrfs_tree_read_unlock_blocking(eb); |
1375 | free_extent_buffer(eb); | 1356 | free_extent_buffer(eb); |
1376 | } | 1357 | } |
1377 | ret = inode_ref_info(parent, 0, fs_root, path, &found_key); | 1358 | ret = btrfs_find_item(fs_root, path, parent, 0, |
1359 | BTRFS_INODE_REF_KEY, &found_key); | ||
1378 | if (ret > 0) | 1360 | if (ret > 0) |
1379 | ret = -ENOENT; | 1361 | ret = -ENOENT; |
1380 | if (ret) | 1362 | if (ret) |
@@ -1727,8 +1709,10 @@ static int iterate_inode_refs(u64 inum, struct btrfs_root *fs_root, | |||
1727 | struct btrfs_key found_key; | 1709 | struct btrfs_key found_key; |
1728 | 1710 | ||
1729 | while (!ret) { | 1711 | while (!ret) { |
1730 | ret = inode_ref_info(inum, parent ? parent+1 : 0, fs_root, path, | 1712 | ret = btrfs_find_item(fs_root, path, inum, |
1731 | &found_key); | 1713 | parent ? parent + 1 : 0, BTRFS_INODE_REF_KEY, |
1714 | &found_key); | ||
1715 | |||
1732 | if (ret < 0) | 1716 | if (ret < 0) |
1733 | break; | 1717 | break; |
1734 | if (ret) { | 1718 | if (ret) { |
diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h index 2a1ac6bfc724..9c41fbac3009 100644 --- a/fs/btrfs/backref.h +++ b/fs/btrfs/backref.h | |||
@@ -32,9 +32,6 @@ struct inode_fs_paths { | |||
32 | typedef int (iterate_extent_inodes_t)(u64 inum, u64 offset, u64 root, | 32 | typedef int (iterate_extent_inodes_t)(u64 inum, u64 offset, u64 root, |
33 | void *ctx); | 33 | void *ctx); |
34 | 34 | ||
35 | int inode_item_info(u64 inum, u64 ioff, struct btrfs_root *fs_root, | ||
36 | struct btrfs_path *path); | ||
37 | |||
38 | int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, | 35 | int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, |
39 | struct btrfs_path *path, struct btrfs_key *found_key, | 36 | struct btrfs_path *path, struct btrfs_key *found_key, |
40 | u64 *flags); | 37 | u64 *flags); |
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 97a98fc07cfc..f64471e95e33 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -2617,32 +2617,24 @@ static int key_search(struct extent_buffer *b, struct btrfs_key *key, | |||
2617 | return 0; | 2617 | return 0; |
2618 | } | 2618 | } |
2619 | 2619 | ||
2620 | int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path, | 2620 | int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, |
2621 | u64 iobjectid, u64 ioff, u8 key_type, | 2621 | u64 iobjectid, u64 ioff, u8 key_type, |
2622 | struct btrfs_key *found_key) | 2622 | struct btrfs_key *found_key) |
2623 | { | 2623 | { |
2624 | int ret; | 2624 | int ret; |
2625 | struct btrfs_key key; | 2625 | struct btrfs_key key; |
2626 | struct extent_buffer *eb; | 2626 | struct extent_buffer *eb; |
2627 | struct btrfs_path *path; | 2627 | |
2628 | ASSERT(path); | ||
2629 | ASSERT(found_key); | ||
2628 | 2630 | ||
2629 | key.type = key_type; | 2631 | key.type = key_type; |
2630 | key.objectid = iobjectid; | 2632 | key.objectid = iobjectid; |
2631 | key.offset = ioff; | 2633 | key.offset = ioff; |
2632 | 2634 | ||
2633 | if (found_path == NULL) { | ||
2634 | path = btrfs_alloc_path(); | ||
2635 | if (!path) | ||
2636 | return -ENOMEM; | ||
2637 | } else | ||
2638 | path = found_path; | ||
2639 | |||
2640 | ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); | 2635 | ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); |
2641 | if ((ret < 0) || (found_key == NULL)) { | 2636 | if (ret < 0) |
2642 | if (path != found_path) | ||
2643 | btrfs_free_path(path); | ||
2644 | return ret; | 2637 | return ret; |
2645 | } | ||
2646 | 2638 | ||
2647 | eb = path->nodes[0]; | 2639 | eb = path->nodes[0]; |
2648 | if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { | 2640 | if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8c63419a7f70..8d486603e8a3 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -1630,6 +1630,8 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, | |||
1630 | bool check_ref) | 1630 | bool check_ref) |
1631 | { | 1631 | { |
1632 | struct btrfs_root *root; | 1632 | struct btrfs_root *root; |
1633 | struct btrfs_path *path; | ||
1634 | struct btrfs_key key; | ||
1633 | int ret; | 1635 | int ret; |
1634 | 1636 | ||
1635 | if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) | 1637 | if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) |
@@ -1669,8 +1671,17 @@ again: | |||
1669 | if (ret) | 1671 | if (ret) |
1670 | goto fail; | 1672 | goto fail; |
1671 | 1673 | ||
1672 | ret = btrfs_find_item(fs_info->tree_root, NULL, BTRFS_ORPHAN_OBJECTID, | 1674 | path = btrfs_alloc_path(); |
1673 | location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL); | 1675 | if (!path) { |
1676 | ret = -ENOMEM; | ||
1677 | goto fail; | ||
1678 | } | ||
1679 | key.objectid = BTRFS_ORPHAN_OBJECTID; | ||
1680 | key.type = BTRFS_ORPHAN_ITEM_KEY; | ||
1681 | key.offset = location->objectid; | ||
1682 | |||
1683 | ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0); | ||
1684 | btrfs_free_path(path); | ||
1674 | if (ret < 0) | 1685 | if (ret < 0) |
1675 | goto fail; | 1686 | goto fail; |
1676 | if (ret == 0) | 1687 | if (ret == 0) |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8bf326affb94..370f23416080 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -5009,6 +5009,7 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
5009 | struct btrfs_root *new_root; | 5009 | struct btrfs_root *new_root; |
5010 | struct btrfs_root_ref *ref; | 5010 | struct btrfs_root_ref *ref; |
5011 | struct extent_buffer *leaf; | 5011 | struct extent_buffer *leaf; |
5012 | struct btrfs_key key; | ||
5012 | int ret; | 5013 | int ret; |
5013 | int err = 0; | 5014 | int err = 0; |
5014 | 5015 | ||
@@ -5019,9 +5020,12 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
5019 | } | 5020 | } |
5020 | 5021 | ||
5021 | err = -ENOENT; | 5022 | err = -ENOENT; |
5022 | ret = btrfs_find_item(root->fs_info->tree_root, path, | 5023 | key.objectid = BTRFS_I(dir)->root->root_key.objectid; |
5023 | BTRFS_I(dir)->root->root_key.objectid, | 5024 | key.type = BTRFS_ROOT_REF_KEY; |
5024 | location->objectid, BTRFS_ROOT_REF_KEY, NULL); | 5025 | key.offset = location->objectid; |
5026 | |||
5027 | ret = btrfs_search_slot(NULL, root->fs_info->tree_root, &key, path, | ||
5028 | 0, 0); | ||
5025 | if (ret) { | 5029 | if (ret) { |
5026 | if (ret < 0) | 5030 | if (ret < 0) |
5027 | err = ret; | 5031 | err = ret; |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 9e1569ffbf6e..53575a45f7d1 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -520,6 +520,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, | |||
520 | struct inode_fs_paths *ipath = NULL; | 520 | struct inode_fs_paths *ipath = NULL; |
521 | struct btrfs_root *local_root; | 521 | struct btrfs_root *local_root; |
522 | struct btrfs_key root_key; | 522 | struct btrfs_key root_key; |
523 | struct btrfs_key key; | ||
523 | 524 | ||
524 | root_key.objectid = root; | 525 | root_key.objectid = root; |
525 | root_key.type = BTRFS_ROOT_ITEM_KEY; | 526 | root_key.type = BTRFS_ROOT_ITEM_KEY; |
@@ -530,7 +531,14 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, | |||
530 | goto err; | 531 | goto err; |
531 | } | 532 | } |
532 | 533 | ||
533 | ret = inode_item_info(inum, 0, local_root, swarn->path); | 534 | /* |
535 | * this makes the path point to (inum INODE_ITEM ioff) | ||
536 | */ | ||
537 | key.objectid = inum; | ||
538 | key.type = BTRFS_INODE_ITEM_KEY; | ||
539 | key.offset = 0; | ||
540 | |||
541 | ret = btrfs_search_slot(NULL, local_root, &key, swarn->path, 0, 0); | ||
534 | if (ret) { | 542 | if (ret) { |
535 | btrfs_release_path(swarn->path); | 543 | btrfs_release_path(swarn->path); |
536 | goto err; | 544 | goto err; |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 9a02da16f2be..25a1c363a5f4 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -1254,13 +1254,14 @@ out: | |||
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | static int insert_orphan_item(struct btrfs_trans_handle *trans, | 1256 | static int insert_orphan_item(struct btrfs_trans_handle *trans, |
1257 | struct btrfs_root *root, u64 offset) | 1257 | struct btrfs_root *root, u64 ino) |
1258 | { | 1258 | { |
1259 | int ret; | 1259 | int ret; |
1260 | ret = btrfs_find_item(root, NULL, BTRFS_ORPHAN_OBJECTID, | 1260 | |
1261 | offset, BTRFS_ORPHAN_ITEM_KEY, NULL); | 1261 | ret = btrfs_insert_orphan_item(trans, root, ino); |
1262 | if (ret > 0) | 1262 | if (ret == -EEXIST) |
1263 | ret = btrfs_insert_orphan_item(trans, root, offset); | 1263 | ret = 0; |
1264 | |||
1264 | return ret; | 1265 | return ret; |
1265 | } | 1266 | } |
1266 | 1267 | ||