diff options
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r-- | fs/btrfs/ioctl.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index a8577a7f26ab..4de7ef6f8603 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -239,7 +239,13 @@ static noinline int create_subvol(struct btrfs_root *root, | |||
239 | u64 index = 0; | 239 | u64 index = 0; |
240 | unsigned long nr = 1; | 240 | unsigned long nr = 1; |
241 | 241 | ||
242 | ret = btrfs_check_metadata_free_space(root); | 242 | /* |
243 | * 1 - inode item | ||
244 | * 2 - refs | ||
245 | * 1 - root item | ||
246 | * 2 - dir items | ||
247 | */ | ||
248 | ret = btrfs_reserve_metadata_space(root, 6); | ||
243 | if (ret) | 249 | if (ret) |
244 | return ret; | 250 | return ret; |
245 | 251 | ||
@@ -340,6 +346,9 @@ fail: | |||
340 | err = btrfs_commit_transaction(trans, root); | 346 | err = btrfs_commit_transaction(trans, root); |
341 | if (err && !ret) | 347 | if (err && !ret) |
342 | ret = err; | 348 | ret = err; |
349 | |||
350 | btrfs_unreserve_metadata_space(root, 6); | ||
351 | btrfs_btree_balance_dirty(root, nr); | ||
343 | return ret; | 352 | return ret; |
344 | } | 353 | } |
345 | 354 | ||
@@ -355,19 +364,27 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, | |||
355 | if (!root->ref_cows) | 364 | if (!root->ref_cows) |
356 | return -EINVAL; | 365 | return -EINVAL; |
357 | 366 | ||
358 | ret = btrfs_check_metadata_free_space(root); | 367 | /* |
368 | * 1 - inode item | ||
369 | * 2 - refs | ||
370 | * 1 - root item | ||
371 | * 2 - dir items | ||
372 | */ | ||
373 | ret = btrfs_reserve_metadata_space(root, 6); | ||
359 | if (ret) | 374 | if (ret) |
360 | goto fail_unlock; | 375 | goto fail_unlock; |
361 | 376 | ||
362 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); | 377 | pending_snapshot = kzalloc(sizeof(*pending_snapshot), GFP_NOFS); |
363 | if (!pending_snapshot) { | 378 | if (!pending_snapshot) { |
364 | ret = -ENOMEM; | 379 | ret = -ENOMEM; |
380 | btrfs_unreserve_metadata_space(root, 6); | ||
365 | goto fail_unlock; | 381 | goto fail_unlock; |
366 | } | 382 | } |
367 | pending_snapshot->name = kmalloc(namelen + 1, GFP_NOFS); | 383 | pending_snapshot->name = kmalloc(namelen + 1, GFP_NOFS); |
368 | if (!pending_snapshot->name) { | 384 | if (!pending_snapshot->name) { |
369 | ret = -ENOMEM; | 385 | ret = -ENOMEM; |
370 | kfree(pending_snapshot); | 386 | kfree(pending_snapshot); |
387 | btrfs_unreserve_metadata_space(root, 6); | ||
371 | goto fail_unlock; | 388 | goto fail_unlock; |
372 | } | 389 | } |
373 | memcpy(pending_snapshot->name, name, namelen); | 390 | memcpy(pending_snapshot->name, name, namelen); |