hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/fs/btrfs/inode-map.c
....@@ -11,6 +11,7 @@
1111 #include "free-space-cache.h"
1212 #include "inode-map.h"
1313 #include "transaction.h"
14
+#include "delalloc-space.h"
1415
1516 static void fail_caching_thread(struct btrfs_root *root)
1617 {
....@@ -106,7 +107,7 @@
106107
107108 if (last != (u64)-1 && last + 1 != key.objectid) {
108109 __btrfs_add_free_space(fs_info, ctl, last + 1,
109
- key.objectid - last - 1);
110
+ key.objectid - last - 1, 0);
110111 wake_up(&root->ino_cache_wait);
111112 }
112113
....@@ -117,7 +118,7 @@
117118
118119 if (last < root->highest_objectid - 1) {
119120 __btrfs_add_free_space(fs_info, ctl, last + 1,
120
- root->highest_objectid - last - 1);
121
+ root->highest_objectid - last - 1, 0);
121122 }
122123
123124 spin_lock(&root->ino_cache_lock);
....@@ -174,7 +175,9 @@
174175 ret = btrfs_find_free_objectid(root, &objectid);
175176 if (!ret && objectid <= BTRFS_LAST_FREE_OBJECTID) {
176177 __btrfs_add_free_space(fs_info, ctl, objectid,
177
- BTRFS_LAST_FREE_OBJECTID - objectid + 1);
178
+ BTRFS_LAST_FREE_OBJECTID - objectid + 1,
179
+ 0);
180
+ wake_up(&root->ino_cache_wait);
178181 }
179182
180183 tsk = kthread_run(caching_kthread, root, "btrfs-ino-cache-%llu",
....@@ -219,7 +222,7 @@
219222 return;
220223 again:
221224 if (root->ino_cache_state == BTRFS_CACHE_FINISHED) {
222
- __btrfs_add_free_space(fs_info, pinned, objectid, 1);
225
+ __btrfs_add_free_space(fs_info, pinned, objectid, 1, 0);
223226 } else {
224227 down_write(&fs_info->commit_root_sem);
225228 spin_lock(&root->ino_cache_lock);
....@@ -232,7 +235,7 @@
232235
233236 start_caching(root);
234237
235
- __btrfs_add_free_space(fs_info, pinned, objectid, 1);
238
+ __btrfs_add_free_space(fs_info, pinned, objectid, 1, 0);
236239
237240 up_write(&fs_info->commit_root_sem);
238241 }
....@@ -279,7 +282,7 @@
279282 spin_unlock(rbroot_lock);
280283 if (count)
281284 __btrfs_add_free_space(root->fs_info, ctl,
282
- info->offset, count);
285
+ info->offset, count, 0);
283286 kmem_cache_free(btrfs_free_space_cachep, info);
284287 }
285288 }
....@@ -434,7 +437,7 @@
434437 * 1 item for free space object
435438 * 3 items for pre-allocation
436439 */
437
- trans->bytes_reserved = btrfs_calc_trans_metadata_size(fs_info, 10);
440
+ trans->bytes_reserved = btrfs_calc_insert_metadata_size(fs_info, 10);
438441 ret = btrfs_block_rsv_add(root, trans->block_rsv,
439442 trans->bytes_reserved,
440443 BTRFS_RESERVE_NO_FLUSH);
....@@ -492,7 +495,8 @@
492495 /* Just to make sure we have enough space */
493496 prealloc += 8 * PAGE_SIZE;
494497
495
- ret = btrfs_delalloc_reserve_space(inode, &data_reserved, 0, prealloc);
498
+ ret = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved, 0,
499
+ prealloc);
496500 if (ret)
497501 goto out_put;
498502
....@@ -512,67 +516,12 @@
512516 trace_btrfs_space_reservation(fs_info, "ino_cache", trans->transid,
513517 trans->bytes_reserved, 0);
514518 btrfs_block_rsv_release(fs_info, trans->block_rsv,
515
- trans->bytes_reserved);
519
+ trans->bytes_reserved, NULL);
516520 out:
517521 trans->block_rsv = rsv;
518522 trans->bytes_reserved = num_bytes;
519523
520524 btrfs_free_path(path);
521525 extent_changeset_free(data_reserved);
522
- return ret;
523
-}
524
-
525
-int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid)
526
-{
527
- struct btrfs_path *path;
528
- int ret;
529
- struct extent_buffer *l;
530
- struct btrfs_key search_key;
531
- struct btrfs_key found_key;
532
- int slot;
533
-
534
- path = btrfs_alloc_path();
535
- if (!path)
536
- return -ENOMEM;
537
-
538
- search_key.objectid = BTRFS_LAST_FREE_OBJECTID;
539
- search_key.type = -1;
540
- search_key.offset = (u64)-1;
541
- ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
542
- if (ret < 0)
543
- goto error;
544
- BUG_ON(ret == 0); /* Corruption */
545
- if (path->slots[0] > 0) {
546
- slot = path->slots[0] - 1;
547
- l = path->nodes[0];
548
- btrfs_item_key_to_cpu(l, &found_key, slot);
549
- *objectid = max_t(u64, found_key.objectid,
550
- BTRFS_FIRST_FREE_OBJECTID - 1);
551
- } else {
552
- *objectid = BTRFS_FIRST_FREE_OBJECTID - 1;
553
- }
554
- ret = 0;
555
-error:
556
- btrfs_free_path(path);
557
- return ret;
558
-}
559
-
560
-int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid)
561
-{
562
- int ret;
563
- mutex_lock(&root->objectid_mutex);
564
-
565
- if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) {
566
- btrfs_warn(root->fs_info,
567
- "the objectid of root %llu reaches its highest value",
568
- root->root_key.objectid);
569
- ret = -ENOSPC;
570
- goto out;
571
- }
572
-
573
- *objectid = ++root->highest_objectid;
574
- ret = 0;
575
-out:
576
- mutex_unlock(&root->objectid_mutex);
577526 return ret;
578527 }