@@ -522,6 +522,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,
int bitmaps = 0;
int ret = 0;
bool next_page = false;
+ bool out_of_space = false;
root = root->fs_info->tree_root;
@@ -629,6 +630,11 @@ int btrfs_write_out_cache(struct btrfs_root *root,
offset = start_offset;
}
+ if (index > last_index) {
+ out_of_space = true;
+ break;
+ }
+
page = find_get_page(inode->i_mapping, index);
addr = kmap(page);
@@ -732,6 +738,10 @@ int btrfs_write_out_cache(struct btrfs_root *root,
struct btrfs_free_space *entry =
list_entry(pos, struct btrfs_free_space, list);
+ if (index > last_index) {
+ out_of_space = true;
+ break;
+ }
page = find_get_page(inode->i_mapping, index);
addr = kmap(page);
@@ -754,6 +764,14 @@ int btrfs_write_out_cache(struct btrfs_root *root,
index++;
}
+ if (out_of_space) {
+ ret = 0;
+ unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
+ i_size_read(inode) - 1, &cached_state,
+ GFP_NOFS);
+ goto out_free;
+ }
+
/* Zero out the rest of the pages just to make sure */
while (index <= last_index) {
void *addr;