Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: preallocate path for snapshot creation at ioctl time

We can also preallocate btrfs_path that's used during pending snapshot
creation and avoid another late ENOMEM failure.

Signed-off-by: David Sterba <dsterba@suse.com>

+8 -6
+3 -1
fs/btrfs/ioctl.c
··· 661 661 662 662 pending_snapshot->root_item = kzalloc(sizeof(struct btrfs_root_item), 663 663 GFP_NOFS); 664 - if (!pending_snapshot->root_item) { 664 + pending_snapshot->path = btrfs_alloc_path(); 665 + if (!pending_snapshot->root_item || !pending_snapshot->path) { 665 666 ret = -ENOMEM; 666 667 goto free_pending; 667 668 } ··· 748 747 wake_up_atomic_t(&root->will_be_snapshoted); 749 748 free_pending: 750 749 kfree(pending_snapshot->root_item); 750 + btrfs_free_path(pending_snapshot->path); 751 751 kfree(pending_snapshot); 752 752 753 753 return ret;
+4 -5
fs/btrfs/transaction.c
··· 1319 1319 u64 root_flags; 1320 1320 uuid_le new_uuid; 1321 1321 1322 - path = btrfs_alloc_path(); 1323 - if (!path) { 1324 - pending->error = -ENOMEM; 1325 - return 0; 1326 - } 1322 + ASSERT(pending->path); 1323 + path = pending->path; 1327 1324 1328 1325 ASSERT(pending->root_item); 1329 1326 new_root_item = pending->root_item; ··· 1558 1561 kfree(new_root_item); 1559 1562 pending->root_item = NULL; 1560 1563 btrfs_free_path(path); 1564 + pending->path = NULL; 1565 + 1561 1566 return ret; 1562 1567 } 1563 1568
+1
fs/btrfs/transaction.h
··· 140 140 struct btrfs_root_item *root_item; 141 141 struct btrfs_root *snap; 142 142 struct btrfs_qgroup_inherit *inherit; 143 + struct btrfs_path *path; 143 144 /* block reservation for the operation */ 144 145 struct btrfs_block_rsv block_rsv; 145 146 u64 qgroup_reserved;