diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-11-30 11:30:34 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:03:58 -0400 |
commit | 87ee04eb0f2f0c63314cef4a76bd1adac748425e (patch) | |
tree | 2be6218d1d94ec92230be8df8e215691ecd5065d /fs/btrfs/extent-tree.c | |
parent | 00f5c795fca47d038fedd3f0c9311da3be710c9f (diff) |
Btrfs: Add simple stripe size parameter
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 55abdf997ca5..91397e989393 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -932,6 +932,13 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root | |||
932 | return ret ? ret : pending_ret; | 932 | return ret ? ret : pending_ret; |
933 | } | 933 | } |
934 | 934 | ||
935 | static u64 stripe_align(struct btrfs_root *root, u64 val) | ||
936 | { | ||
937 | u64 mask = ((u64)root->stripesize - 1); | ||
938 | u64 ret = (val + mask) & ~mask; | ||
939 | return ret; | ||
940 | } | ||
941 | |||
935 | /* | 942 | /* |
936 | * walks the btree of allocated extents and find a hole of a given size. | 943 | * walks the btree of allocated extents and find a hole of a given size. |
937 | * The key ins is changed to record the hole: | 944 | * The key ins is changed to record the hole: |
@@ -948,8 +955,9 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root | |||
948 | { | 955 | { |
949 | struct btrfs_path *path; | 956 | struct btrfs_path *path; |
950 | struct btrfs_key key; | 957 | struct btrfs_key key; |
951 | int ret; | ||
952 | u64 hole_size = 0; | 958 | u64 hole_size = 0; |
959 | u64 aligned; | ||
960 | int ret; | ||
953 | int slot = 0; | 961 | int slot = 0; |
954 | u64 last_byte = 0; | 962 | u64 last_byte = 0; |
955 | u64 orig_search_start = search_start; | 963 | u64 orig_search_start = search_start; |
@@ -990,6 +998,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root | |||
990 | check_failed: | 998 | check_failed: |
991 | search_start = find_search_start(root, &block_group, search_start, | 999 | search_start = find_search_start(root, &block_group, search_start, |
992 | total_needed, data, full_scan); | 1000 | total_needed, data, full_scan); |
1001 | search_start = stripe_align(root, search_start); | ||
993 | cached_start = search_start; | 1002 | cached_start = search_start; |
994 | btrfs_init_path(path); | 1003 | btrfs_init_path(path); |
995 | ins->objectid = search_start; | 1004 | ins->objectid = search_start; |
@@ -1039,13 +1048,23 @@ check_failed: | |||
1039 | search_start = max(search_start, | 1048 | search_start = max(search_start, |
1040 | block_group->key.objectid); | 1049 | block_group->key.objectid); |
1041 | if (!start_found) { | 1050 | if (!start_found) { |
1042 | ins->objectid = search_start; | 1051 | aligned = stripe_align(root, search_start); |
1043 | ins->offset = search_end - search_start; | 1052 | ins->objectid = aligned; |
1053 | if (aligned >= search_end) { | ||
1054 | ret = -ENOSPC; | ||
1055 | goto error; | ||
1056 | } | ||
1057 | ins->offset = search_end - aligned; | ||
1044 | start_found = 1; | 1058 | start_found = 1; |
1045 | goto check_pending; | 1059 | goto check_pending; |
1046 | } | 1060 | } |
1047 | ins->objectid = last_byte > search_start ? | 1061 | ins->objectid = stripe_align(root, |
1048 | last_byte : search_start; | 1062 | last_byte > search_start ? |
1063 | last_byte : search_start); | ||
1064 | if (search_end <= ins->objectid) { | ||
1065 | ret = -ENOSPC; | ||
1066 | goto error; | ||
1067 | } | ||
1049 | ins->offset = search_end - ins->objectid; | 1068 | ins->offset = search_end - ins->objectid; |
1050 | BUG_ON(ins->objectid >= search_end); | 1069 | BUG_ON(ins->objectid >= search_end); |
1051 | goto check_pending; | 1070 | goto check_pending; |
@@ -1056,9 +1075,10 @@ check_failed: | |||
1056 | start_found) { | 1075 | start_found) { |
1057 | if (last_byte < search_start) | 1076 | if (last_byte < search_start) |
1058 | last_byte = search_start; | 1077 | last_byte = search_start; |
1059 | hole_size = key.objectid - last_byte; | 1078 | aligned = stripe_align(root, last_byte); |
1060 | if (hole_size >= num_bytes) { | 1079 | hole_size = key.objectid - aligned; |
1061 | ins->objectid = last_byte; | 1080 | if (key.objectid > aligned && hole_size >= num_bytes) { |
1081 | ins->objectid = aligned; | ||
1062 | ins->offset = hole_size; | 1082 | ins->offset = hole_size; |
1063 | goto check_pending; | 1083 | goto check_pending; |
1064 | } | 1084 | } |