^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /* Reiserfs block (de)allocator, bitmap-based. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "reiserfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define PREALLOCATION_SIZE 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* different reiserfs block allocator options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define SB_ALLOC_OPTS(s) (REISERFS_SB(s)->s_alloc_options.bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define _ALLOC_concentrating_formatted_nodes 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define _ALLOC_displacing_large_files 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define _ALLOC_displacing_new_packing_localities 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define _ALLOC_old_hashed_relocation 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define _ALLOC_new_hashed_relocation 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define _ALLOC_skip_busy 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define _ALLOC_displace_based_on_dirid 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define _ALLOC_hashed_formatted_nodes 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define _ALLOC_old_way 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define _ALLOC_hundredth_slices 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define _ALLOC_dirid_groups 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define _ALLOC_oid_groups 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define _ALLOC_packing_groups 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define concentrating_formatted_nodes(s) test_bit(_ALLOC_concentrating_formatted_nodes, &SB_ALLOC_OPTS(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define displacing_large_files(s) test_bit(_ALLOC_displacing_large_files, &SB_ALLOC_OPTS(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define displacing_new_packing_localities(s) test_bit(_ALLOC_displacing_new_packing_localities, &SB_ALLOC_OPTS(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define SET_OPTION(optname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) reiserfs_info(s, "block allocator option \"%s\" is set", #optname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) set_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define TEST_OPTION(optname, s) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static inline void get_bit_address(struct super_block *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) b_blocknr_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned int *bmap_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned int *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * It is in the bitmap block number equal to the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * number divided by the number of bits in a block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *bmap_nr = block >> (s->s_blocksize_bits + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* Within that bitmap block it is located at bit offset *offset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *offset = block & ((s->s_blocksize << 3) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned int bmap, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned int bmap_count = reiserfs_bmap_count(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) reiserfs_error(s, "vs-4010",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) "block number is out of range %lu (%u)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) block, SB_BLOCK_COUNT(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) get_bit_address(s, block, &bmap, &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Old format filesystem? Unlikely, but the bitmaps are all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * up front so we need to account for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (unlikely(test_bit(REISERFS_OLD_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) &REISERFS_SB(s)->s_properties))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (block >= bmap1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) block <= bmap1 + bmap_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) reiserfs_error(s, "vs-4019", "bitmap block %lu(%u) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) "can't be freed or reused",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) block, bmap_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (offset == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) reiserfs_error(s, "vs-4020", "bitmap block %lu(%u) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) "can't be freed or reused",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) block, bmap_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (bmap >= bmap_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) reiserfs_error(s, "vs-4030", "bitmap for requested block "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) "is out of range: block=%lu, bitmap_nr=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) block, bmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) reiserfs_error(s, "vs-4050", "this is root block (%u), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) "it must be busy", SB_ROOT_BLOCK(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Searches in journal structures for a given block number (bmap, off).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * If block is found in reiserfs journal it suggests next free block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * candidate to test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static inline int is_block_in_journal(struct super_block *s, unsigned int bmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int off, int *next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) b_blocknr_t tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (reiserfs_in_journal(s, bmap, off, 1, &tmp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (tmp) { /* hint supplied */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *next = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) PROC_INFO_INC(s, scan_bitmap.in_journal_hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) (*next) = off + 1; /* inc offset to avoid looping. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) PROC_INFO_INC(s, scan_bitmap.in_journal_nohint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) PROC_INFO_INC(s, scan_bitmap.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * Searches for a window of zero bits with given minimum and maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * lengths in one bitmap block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned int bmap_n, int *beg, int boundary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int min, int max, int unfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct super_block *s = th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int end, next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int org = *beg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) RFALSE(bmap_n >= reiserfs_bmap_count(s), "Bitmap %u is out of "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) "range (0..%u)", bmap_n, reiserfs_bmap_count(s) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) PROC_INFO_INC(s, scan_bitmap.bmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!bi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) reiserfs_error(s, "jdm-4055", "NULL bitmap info pointer "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) "for bitmap %d", bmap_n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) bh = reiserfs_read_bitmap_block(s, bmap_n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (bh == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) cont:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (bi->free_count < min) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return 0; /* No free blocks in this bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* search for a first zero bit -- beginning of a window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *beg = reiserfs_find_next_zero_le_bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ((unsigned long *)(bh->b_data), boundary, *beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * search for a zero bit fails or the rest of bitmap block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * cannot contain a zero window of minimum size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (*beg + min > boundary) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (unfm && is_block_in_journal(s, bmap_n, *beg, beg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* first zero bit found; we check next bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) for (end = *beg + 1;; end++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (end >= *beg + max || end >= boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) || reiserfs_test_le_bit(end, bh->b_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) next = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * finding the other end of zero bit window requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * looking into journal structures (in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * searching for free blocks for unformatted nodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (unfm && is_block_in_journal(s, bmap_n, end, &next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * now (*beg) points to beginning of zero bits window,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * (end) points to one bit after the window end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* found window of proper size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (end - *beg >= min) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) reiserfs_prepare_for_journal(s, bh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * try to set all blocks used checking are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * they still free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) for (i = *beg; i < end; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Don't check in journal again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (reiserfs_test_and_set_le_bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) (i, bh->b_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * bit was set by another process while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * we slept in prepare_for_journal()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) PROC_INFO_INC(s, scan_bitmap.stolen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * we can continue with smaller set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * of allocated blocks, if length of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * this set is more or equal to `min'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (i >= *beg + min) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) end = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * otherwise we clear all bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * were set ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) while (--i >= *beg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) reiserfs_clear_le_bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) (i, bh->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) reiserfs_restore_prepared_buffer(s, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) *beg = org;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * Search again in current block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * from beginning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) bi->free_count -= (end - *beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) journal_mark_dirty(th, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* free block count calculation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) PUT_SB_FREE_BLOCKS(s, SB_FREE_BLOCKS(s) - (end - *beg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) journal_mark_dirty(th, SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return end - (*beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) *beg = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int bmap_hash_id(struct super_block *s, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) char *hash_in = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) unsigned bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (id <= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) bm = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) hash_in = (char *)(&id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) hash = keyed_hash(hash_in, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) bm = hash % reiserfs_bmap_count(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (!bm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) bm = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* this can only be true when SB_BMAP_NR = 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (bm >= reiserfs_bmap_count(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) bm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * hashes the id and then returns > 0 if the block group for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * corresponding hash is full
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static inline int block_group_used(struct super_block *s, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int bm = bmap_hash_id(s, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) struct reiserfs_bitmap_info *info = &SB_AP_BITMAP(s)[bm];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * If we don't have cached information on this bitmap block, we're
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * going to have to load it later anyway. Loading it here allows us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * to make a better decision. This favors long-term performance gain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * with a better on-disk layout vs. a short term gain of skipping the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * read and potentially having a bad placement.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (info->free_count == UINT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (info->free_count > ((s->s_blocksize << 3) * 60 / 100)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * the packing is returned in disk byte order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) __le32 reiserfs_choose_packing(struct inode * dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) __le32 packing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (TEST_OPTION(packing_groups, dir->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) u32 parent_dir = le32_to_cpu(INODE_PKEY(dir)->k_dir_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * some versions of reiserfsck expect packing locality 1 to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (parent_dir == 1 || block_group_used(dir->i_sb, parent_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) packing = INODE_PKEY(dir)->k_objectid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) packing = INODE_PKEY(dir)->k_dir_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) packing = INODE_PKEY(dir)->k_objectid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return packing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * Tries to find contiguous zero bit window (given size) in given region of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * bitmap and place new blocks there. Returns number of allocated blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static int scan_bitmap(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) b_blocknr_t * start, b_blocknr_t finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int min, int max, int unfm, sector_t file_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int nr_allocated = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct super_block *s = th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) unsigned int bm, off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) unsigned int end_bm, end_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) unsigned int off_max = s->s_blocksize << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) PROC_INFO_INC(s, scan_bitmap.call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* No point in looking for more free blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (SB_FREE_BLOCKS(s) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) get_bit_address(s, *start, &bm, &off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) get_bit_address(s, finish, &end_bm, &end_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (bm > reiserfs_bmap_count(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (end_bm > reiserfs_bmap_count(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) end_bm = reiserfs_bmap_count(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * When the bitmap is more than 10% free, anyone can allocate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * When it's less than 10% free, only files that already use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * bitmap are allowed. Once we pass 80% full, this restriction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * is lifted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * We do this so that files that grow later still have space close to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * their original allocation. This improves locality, and presumably
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * performance as a result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * This is only an allocation policy and does not make up for getting a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * bad hint. Decent hinting must be implemented for this to work well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (TEST_OPTION(skip_busy, s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) && SB_FREE_BLOCKS(s) > SB_BLOCK_COUNT(s) / 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) for (; bm < end_bm; bm++, off = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if ((off && (!unfm || (file_block != 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) || SB_AP_BITMAP(s)[bm].free_count >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) (s->s_blocksize << 3) / 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) nr_allocated =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) scan_bitmap_block(th, bm, &off, off_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) min, max, unfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (nr_allocated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /* we know from above that start is a reasonable number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) get_bit_address(s, *start, &bm, &off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) for (; bm < end_bm; bm++, off = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) nr_allocated =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) scan_bitmap_block(th, bm, &off, off_max, min, max, unfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (nr_allocated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) goto ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) nr_allocated =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) scan_bitmap_block(th, bm, &off, end_off + 1, min, max, unfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) *start = bm * off_max + off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return nr_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct inode *inode, b_blocknr_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int for_unformatted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct super_block *s = th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct reiserfs_super_block *rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct buffer_head *sbh, *bmbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct reiserfs_bitmap_info *apbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) unsigned int nr, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) PROC_INFO_INC(s, free_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) rs = SB_DISK_SUPER_BLOCK(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) sbh = SB_BUFFER_WITH_SB(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) apbi = SB_AP_BITMAP(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) get_bit_address(s, block, &nr, &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (nr >= reiserfs_bmap_count(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) reiserfs_error(s, "vs-4075", "block %lu is out of range",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) bmbh = reiserfs_read_bitmap_block(s, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!bmbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) reiserfs_prepare_for_journal(s, bmbh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* clear bit for the given block in bit map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (!reiserfs_test_and_clear_le_bit(offset, bmbh->b_data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) reiserfs_error(s, "vs-4080",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) "block %lu: bit already cleared", block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) apbi[nr].free_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) journal_mark_dirty(th, bmbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) brelse(bmbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) reiserfs_prepare_for_journal(s, sbh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /* update super block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) journal_mark_dirty(th, sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (for_unformatted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) int depth = reiserfs_write_unlock_nested(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) dquot_free_block_nodirty(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) reiserfs_write_lock_nested(s, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) void reiserfs_free_block(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) struct inode *inode, b_blocknr_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) int for_unformatted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct super_block *s = th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) RFALSE(!s, "vs-4061: trying to free block on nonexistent device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) if (!is_reusable(s, block, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (block > sb_block_count(REISERFS_SB(s)->s_rs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) reiserfs_error(th->t_super, "bitmap-4072",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) "Trying to free block outside file system "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) "boundaries (%lu > %lu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) block, sb_block_count(REISERFS_SB(s)->s_rs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /* mark it before we clear it, just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) journal_mark_freed(th, s, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) _reiserfs_free_block(th, inode, block, for_unformatted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* preallocated blocks don't need to be run through journal_mark_freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct inode *inode, b_blocknr_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) RFALSE(!th->t_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) "vs-4060: trying to free block on nonexistent device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!is_reusable(th->t_super, block, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) _reiserfs_free_block(th, inode, block, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) static void __discard_prealloc(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct reiserfs_inode_info *ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) unsigned long save = ei->i_prealloc_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int dirty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct inode *inode = &ei->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) #ifdef CONFIG_REISERFS_CHECK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (ei->i_prealloc_count < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) reiserfs_error(th->t_super, "zam-4001",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) "inode has negative prealloc blocks count.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) while (ei->i_prealloc_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) b_blocknr_t block_to_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * reiserfs_free_prealloc_block can drop the write lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * which could allow another caller to free the same block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * We can protect against it by modifying the prealloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * state before calling it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) block_to_free = ei->i_prealloc_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) ei->i_prealloc_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) reiserfs_free_prealloc_block(th, inode, block_to_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) dirty = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (dirty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) reiserfs_update_sd(th, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) ei->i_prealloc_block = save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) list_del_init(&ei->i_prealloc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* FIXME: It should be inline function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) struct reiserfs_inode_info *ei = REISERFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (ei->i_prealloc_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) __discard_prealloc(th, ei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct list_head *plist = &SB_JOURNAL(th->t_super)->j_prealloc_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) while (!list_empty(plist)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct reiserfs_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) ei = list_entry(plist->next, struct reiserfs_inode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) i_prealloc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) #ifdef CONFIG_REISERFS_CHECK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (!ei->i_prealloc_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) reiserfs_error(th->t_super, "zam-4001",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) "inode is in prealloc list but has "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) "no preallocated blocks.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) __discard_prealloc(th, ei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) void reiserfs_init_alloc_options(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) set_bit(_ALLOC_skip_busy, &SB_ALLOC_OPTS(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) set_bit(_ALLOC_dirid_groups, &SB_ALLOC_OPTS(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) set_bit(_ALLOC_packing_groups, &SB_ALLOC_OPTS(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /* block allocator related options are parsed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) int reiserfs_parse_alloc_options(struct super_block *s, char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) char *this_char, *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* clear default settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) REISERFS_SB(s)->s_alloc_options.bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) while ((this_char = strsep(&options, ":")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if ((value = strchr(this_char, '=')) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) *value++ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (!strcmp(this_char, "concentrating_formatted_nodes")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) SET_OPTION(concentrating_formatted_nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) temp = (value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) && *value) ? simple_strtoul(value, &value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 0) : 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (temp <= 0 || temp > 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) REISERFS_SB(s)->s_alloc_options.border = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) REISERFS_SB(s)->s_alloc_options.border =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 100 / temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (!strcmp(this_char, "displacing_large_files")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) SET_OPTION(displacing_large_files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) REISERFS_SB(s)->s_alloc_options.large_file_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) (value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) && *value) ? simple_strtoul(value, &value, 0) : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (!strcmp(this_char, "displacing_new_packing_localities")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) SET_OPTION(displacing_new_packing_localities);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (!strcmp(this_char, "old_hashed_relocation")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) SET_OPTION(old_hashed_relocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (!strcmp(this_char, "new_hashed_relocation")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) SET_OPTION(new_hashed_relocation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (!strcmp(this_char, "dirid_groups")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) SET_OPTION(dirid_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (!strcmp(this_char, "oid_groups")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) SET_OPTION(oid_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (!strcmp(this_char, "packing_groups")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) SET_OPTION(packing_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (!strcmp(this_char, "hashed_formatted_nodes")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) SET_OPTION(hashed_formatted_nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (!strcmp(this_char, "skip_busy")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) SET_OPTION(skip_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (!strcmp(this_char, "hundredth_slices")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) SET_OPTION(hundredth_slices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (!strcmp(this_char, "old_way")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) SET_OPTION(old_way);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) if (!strcmp(this_char, "displace_based_on_dirid")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) SET_OPTION(displace_based_on_dirid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (!strcmp(this_char, "preallocmin")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) REISERFS_SB(s)->s_alloc_options.preallocmin =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) (value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) && *value) ? simple_strtoul(value, &value, 0) : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (!strcmp(this_char, "preallocsize")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) REISERFS_SB(s)->s_alloc_options.preallocsize =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) (value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) && *value) ? simple_strtoul(value, &value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 0) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) PREALLOCATION_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) reiserfs_warning(s, "zam-4001", "unknown option - %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) this_char);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) reiserfs_info(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static void print_sep(struct seq_file *seq, int *first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (!*first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) seq_puts(seq, ":");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) *first = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) void show_alloc_options(struct seq_file *seq, struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) int first = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (SB_ALLOC_OPTS(s) == ((1 << _ALLOC_skip_busy) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) (1 << _ALLOC_dirid_groups) | (1 << _ALLOC_packing_groups)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) seq_puts(seq, ",alloc=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (TEST_OPTION(concentrating_formatted_nodes, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (REISERFS_SB(s)->s_alloc_options.border != 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) seq_printf(seq, "concentrating_formatted_nodes=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 100 / REISERFS_SB(s)->s_alloc_options.border);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) seq_puts(seq, "concentrating_formatted_nodes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (TEST_OPTION(displacing_large_files, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (REISERFS_SB(s)->s_alloc_options.large_file_size != 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) seq_printf(seq, "displacing_large_files=%lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) REISERFS_SB(s)->s_alloc_options.large_file_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) seq_puts(seq, "displacing_large_files");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (TEST_OPTION(displacing_new_packing_localities, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) seq_puts(seq, "displacing_new_packing_localities");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (TEST_OPTION(old_hashed_relocation, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) seq_puts(seq, "old_hashed_relocation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (TEST_OPTION(new_hashed_relocation, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) seq_puts(seq, "new_hashed_relocation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (TEST_OPTION(dirid_groups, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) seq_puts(seq, "dirid_groups");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) if (TEST_OPTION(oid_groups, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) seq_puts(seq, "oid_groups");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) if (TEST_OPTION(packing_groups, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) seq_puts(seq, "packing_groups");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (TEST_OPTION(hashed_formatted_nodes, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) seq_puts(seq, "hashed_formatted_nodes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) if (TEST_OPTION(skip_busy, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) seq_puts(seq, "skip_busy");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (TEST_OPTION(hundredth_slices, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) seq_puts(seq, "hundredth_slices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (TEST_OPTION(old_way, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) seq_puts(seq, "old_way");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (TEST_OPTION(displace_based_on_dirid, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) seq_puts(seq, "displace_based_on_dirid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (REISERFS_SB(s)->s_alloc_options.preallocmin != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) seq_printf(seq, "preallocmin=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) REISERFS_SB(s)->s_alloc_options.preallocmin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (REISERFS_SB(s)->s_alloc_options.preallocsize != 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) print_sep(seq, &first);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) seq_printf(seq, "preallocsize=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) REISERFS_SB(s)->s_alloc_options.preallocsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) static inline void new_hashed_relocation(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) char *hash_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (hint->formatted_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) hash_in = (char *)&hint->key.k_dir_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (!hint->inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /*hint->search_start = hint->beg;*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) hash_in = (char *)&hint->key.k_dir_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) hash_in =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) (char *)(&INODE_PKEY(hint->inode)->k_objectid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) hint->search_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) * Relocation based on dirid, hashing them into a given bitmap block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * files. Formatted nodes are unaffected, a separate policy covers them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) static void dirid_groups(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) __u32 dirid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) int bm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) struct super_block *sb = hint->th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (hint->inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) else if (hint->formatted_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) dirid = hint->key.k_dir_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (dirid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) bm = bmap_hash_id(sb, dirid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) hash = bm * (sb->s_blocksize << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) /* give a portion of the block group to metadata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (hint->inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) hash += sb->s_blocksize / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) hint->search_start = hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * Relocation based on oid, hashing them into a given bitmap block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * files. Formatted nodes are unaffected, a separate policy covers them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) static void oid_groups(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (hint->inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) __u32 oid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) __u32 dirid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) int bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) dirid = le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) * keep the root dir and it's first set of subdirs close to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * the start of the disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (dirid <= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) hash = (hint->inode->i_sb->s_blocksize << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) oid = le32_to_cpu(INODE_PKEY(hint->inode)->k_objectid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) bm = bmap_hash_id(hint->inode->i_sb, oid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) hash = bm * (hint->inode->i_sb->s_blocksize << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) hint->search_start = hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) * returns 1 if it finds an indirect item and gets valid hint info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) * from it, otherwise 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) static int get_left_neighbor(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct treepath *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct item_head *ih;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) int pos_in_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) __le32 *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) * reiserfs code can call this function w/o pointer to path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) * structure supplied; then we rely on supplied search_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (!hint->path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) path = hint->path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) bh = get_last_bh(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) RFALSE(!bh, "green-4002: Illegal path specified to get_left_neighbor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) ih = tp_item_head(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) pos_in_item = path->pos_in_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) item = tp_item_body(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) hint->search_start = bh->b_blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * for indirect item: go to left and look for the first non-hole entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * in the indirect item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (!hint->formatted_node && is_indirect_le_ih(ih)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) if (pos_in_item == I_UNFM_NUM(ih))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) pos_in_item--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) while (pos_in_item >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) int t = get_block_num(item, pos_in_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if (t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) hint->search_start = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) pos_in_item--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) /* does result value fit into specified region? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) * should be, if formatted node, then try to put on first part of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * specified as number of percent with mount option device, else try to put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * on last of device. This is not to say it is good code to do so,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) * but the effect should be measured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) static inline void set_border_in_hint(struct super_block *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) b_blocknr_t border =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) SB_BLOCK_COUNT(s) / REISERFS_SB(s)->s_alloc_options.border;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) if (hint->formatted_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) hint->end = border - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) hint->beg = border;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) static inline void displace_large_file(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) hint->search_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) hint->beg +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_dir_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 4) % (hint->end - hint->beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) hint->search_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) hint->beg +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) keyed_hash((char *)(&INODE_PKEY(hint->inode)->k_objectid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 4) % (hint->end - hint->beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) static inline void hash_formatted_node(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) char *hash_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (!hint->inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) hash_in = (char *)&hint->key.k_dir_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) else if (TEST_OPTION(displace_based_on_dirid, hint->th->t_super))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) hash_in = (char *)(&INODE_PKEY(hint->inode)->k_dir_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) hash_in = (char *)(&INODE_PKEY(hint->inode)->k_objectid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) hint->search_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) hint->beg + keyed_hash(hash_in, 4) % (hint->end - hint->beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) this_blocknr_allocation_would_make_it_a_large_file(reiserfs_blocknr_hint_t *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return hint->block ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) REISERFS_SB(hint->th->t_super)->s_alloc_options.large_file_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) #ifdef DISPLACE_NEW_PACKING_LOCALITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) static inline void displace_new_packing_locality(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) struct in_core_key *key = &hint->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) hint->th->displace_new_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) hint->search_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) hint->beg + keyed_hash((char *)(&key->k_objectid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) 4) % (hint->end - hint->beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) static inline int old_hashed_relocation(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) b_blocknr_t border;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) u32 hash_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) if (hint->formatted_node || hint->inode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) hash_in = le32_to_cpu((INODE_PKEY(hint->inode))->k_dir_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) border =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) hint->beg + (u32) keyed_hash(((char *)(&hash_in)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) 4) % (hint->end - hint->beg - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (border > hint->search_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) hint->search_start = border;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) static inline int old_way(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) b_blocknr_t border;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (hint->formatted_node || hint->inode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) border =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) hint->beg +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) le32_to_cpu(INODE_PKEY(hint->inode)->k_dir_id) % (hint->end -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) hint->beg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (border > hint->search_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) hint->search_start = border;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) static inline void hundredth_slices(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct in_core_key *key = &hint->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) b_blocknr_t slice_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) slice_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) (keyed_hash((char *)(&key->k_dir_id), 4) % 100) * (hint->end / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (slice_start > hint->search_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) || slice_start + (hint->end / 100) <= hint->search_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) hint->search_start = slice_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) static void determine_search_start(reiserfs_blocknr_hint_t * hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) int amount_needed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) struct super_block *s = hint->th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) int unfm_hint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) hint->beg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) hint->end = SB_BLOCK_COUNT(s) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) /* This is former border algorithm. Now with tunable border offset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) if (concentrating_formatted_nodes(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) set_border_in_hint(s, hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) #ifdef DISPLACE_NEW_PACKING_LOCALITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) * whenever we create a new directory, we displace it. At first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) * we will hash for location, later we might look for a moderately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * empty place for it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (displacing_new_packing_localities(s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) && hint->th->displace_new_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) displace_new_packing_locality(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) * we do not continue determine_search_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) * if new packing locality is being displaced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) * all persons should feel encouraged to add more special cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) * here and test them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (displacing_large_files(s) && !hint->formatted_node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) && this_blocknr_allocation_would_make_it_a_large_file(hint)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) displace_large_file(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * if none of our special cases is relevant, use the left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * neighbor in the tree order of the new node we are allocating for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (hint->formatted_node && TEST_OPTION(hashed_formatted_nodes, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) hash_formatted_node(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) unfm_hint = get_left_neighbor(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) * Mimic old block allocator behaviour, that is if VFS allowed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) * preallocation, new blocks are displaced based on directory ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) * Also, if suggested search_start is less than last preallocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) * block, we start searching from it, assuming that HDD dataflow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) * is faster in forward direction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (TEST_OPTION(old_way, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (!hint->formatted_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if (!reiserfs_hashed_relocation(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) old_way(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) else if (!reiserfs_no_unhashed_relocation(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) old_hashed_relocation(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (hint->inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) && hint->search_start <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) REISERFS_I(hint->inode)->i_prealloc_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) hint->search_start =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) REISERFS_I(hint->inode)->i_prealloc_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /* This is an approach proposed by Hans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (TEST_OPTION(hundredth_slices, s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) && !(displacing_large_files(s) && !hint->formatted_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) hundredth_slices(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* old_hashed_relocation only works on unformatted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (!unfm_hint && !hint->formatted_node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) TEST_OPTION(old_hashed_relocation, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) old_hashed_relocation(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) /* new_hashed_relocation works with both formatted/unformatted nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) if ((!unfm_hint || hint->formatted_node) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) TEST_OPTION(new_hashed_relocation, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) new_hashed_relocation(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /* dirid grouping works only on unformatted nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (!unfm_hint && !hint->formatted_node && TEST_OPTION(dirid_groups, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) dirid_groups(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) #ifdef DISPLACE_NEW_PACKING_LOCALITIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (hint->formatted_node && TEST_OPTION(dirid_groups, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) dirid_groups(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) /* oid grouping works only on unformatted nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (!unfm_hint && !hint->formatted_node && TEST_OPTION(oid_groups, s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) oid_groups(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static int determine_prealloc_size(reiserfs_blocknr_hint_t * hint)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) /* make minimum size a mount option and benchmark both ways */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) /* we preallocate blocks only for regular files, specific size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) /* benchmark preallocating always and see what happens */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) hint->prealloc_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) if (!hint->formatted_node && hint->preallocate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (S_ISREG(hint->inode->i_mode) && !IS_PRIVATE(hint->inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) && hint->inode->i_size >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) REISERFS_SB(hint->th->t_super)->s_alloc_options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) preallocmin * hint->inode->i_sb->s_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) hint->prealloc_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) REISERFS_SB(hint->th->t_super)->s_alloc_options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) preallocsize - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) return CARRY_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static inline int allocate_without_wrapping_disk(reiserfs_blocknr_hint_t * hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) b_blocknr_t * new_blocknrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) b_blocknr_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) b_blocknr_t finish, int min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) int amount_needed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) int prealloc_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) int rest = amount_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) int nr_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) while (rest > 0 && start <= finish) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) nr_allocated = scan_bitmap(hint->th, &start, finish, min,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) rest + prealloc_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) !hint->formatted_node, hint->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (nr_allocated == 0) /* no new blocks allocated, return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) /* fill free_blocknrs array first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) while (rest > 0 && nr_allocated > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) *new_blocknrs++ = start++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) rest--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) nr_allocated--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /* do we have something to fill prealloc. array also ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (nr_allocated > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) * it means prealloc_size was greater that 0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) * we do preallocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) list_add(&REISERFS_I(hint->inode)->i_prealloc_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) &SB_JOURNAL(hint->th->t_super)->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) j_prealloc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) REISERFS_I(hint->inode)->i_prealloc_block = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) REISERFS_I(hint->inode)->i_prealloc_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) nr_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) return (amount_needed - rest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static inline int blocknrs_and_prealloc_arrays_from_search_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) (reiserfs_blocknr_hint_t * hint, b_blocknr_t * new_blocknrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) int amount_needed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) struct super_block *s = hint->th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) b_blocknr_t start = hint->search_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) int passno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) int nr_allocated = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) determine_prealloc_size(hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (!hint->formatted_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) int quota_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) #ifdef REISERQUOTA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) reiserfs_debug(s, REISERFS_DEBUG_CODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) "reiserquota: allocating %d blocks id=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) amount_needed, hint->inode->i_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) depth = reiserfs_write_unlock_nested(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) quota_ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) dquot_alloc_block_nodirty(hint->inode, amount_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (quota_ret) { /* Quota exceeded? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) reiserfs_write_lock_nested(s, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) return QUOTA_EXCEEDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (hint->preallocate && hint->prealloc_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) #ifdef REISERQUOTA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) reiserfs_debug(s, REISERFS_DEBUG_CODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) "reiserquota: allocating (prealloc) %d blocks id=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) hint->prealloc_size, hint->inode->i_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) quota_ret = dquot_prealloc_block_nodirty(hint->inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) hint->prealloc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) if (quota_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) hint->preallocate = hint->prealloc_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) /* for unformatted nodes, force large allocations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) reiserfs_write_lock_nested(s, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) switch (passno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) case 0: /* Search from hint->search_start to end of disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) start = hint->search_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) finish = SB_BLOCK_COUNT(s) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) case 1: /* Search from hint->beg to hint->search_start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) start = hint->beg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) finish = hint->search_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) case 2: /* Last chance: Search from 0 to hint->beg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) finish = hint->beg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /* We've tried searching everywhere, not enough space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) /* Free the blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (!hint->formatted_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) #ifdef REISERQUOTA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) reiserfs_debug(s, REISERFS_DEBUG_CODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) "reiserquota: freeing (nospace) %d blocks id=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) amount_needed +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) hint->prealloc_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) nr_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) hint->inode->i_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) /* Free not allocated blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) depth = reiserfs_write_unlock_nested(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) dquot_free_block_nodirty(hint->inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) amount_needed + hint->prealloc_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) nr_allocated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) reiserfs_write_lock_nested(s, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) while (nr_allocated--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) reiserfs_free_block(hint->th, hint->inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) new_blocknrs[nr_allocated],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) !hint->formatted_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) return NO_DISK_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) } while ((nr_allocated += allocate_without_wrapping_disk(hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) new_blocknrs +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) nr_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) start, finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) amount_needed -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) nr_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) hint->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) prealloc_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) < amount_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) if (!hint->formatted_node &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) amount_needed + hint->prealloc_size >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) nr_allocated + REISERFS_I(hint->inode)->i_prealloc_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) /* Some of preallocation blocks were not allocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) #ifdef REISERQUOTA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) reiserfs_debug(s, REISERFS_DEBUG_CODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) "reiserquota: freeing (failed prealloc) %d blocks id=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) amount_needed + hint->prealloc_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) nr_allocated -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) REISERFS_I(hint->inode)->i_prealloc_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) hint->inode->i_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) depth = reiserfs_write_unlock_nested(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) dquot_free_block_nodirty(hint->inode, amount_needed +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) hint->prealloc_size - nr_allocated -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) REISERFS_I(hint->inode)->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) i_prealloc_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) reiserfs_write_lock_nested(s, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return CARRY_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) /* grab new blocknrs from preallocated list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) /* return amount still needed after using them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) static int use_preallocated_list_if_available(reiserfs_blocknr_hint_t * hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) b_blocknr_t * new_blocknrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) int amount_needed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) struct inode *inode = hint->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) if (REISERFS_I(inode)->i_prealloc_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) while (amount_needed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) *new_blocknrs++ = REISERFS_I(inode)->i_prealloc_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) REISERFS_I(inode)->i_prealloc_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) amount_needed--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (REISERFS_I(inode)->i_prealloc_count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) list_del(&REISERFS_I(inode)->i_prealloc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) /* return amount still needed after using preallocated blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) return amount_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *hint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) b_blocknr_t *new_blocknrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) int amount_needed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) /* Amount of blocks we have already reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) int reserved_by_us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) int initial_amount_needed = amount_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) struct super_block *s = hint->th->t_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) /* Check if there is enough space, taking into account reserved space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (SB_FREE_BLOCKS(s) - REISERFS_SB(s)->reserved_blocks <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) amount_needed - reserved_by_us)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) return NO_DISK_SPACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) /* should this be if !hint->inode && hint->preallocate? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) /* do you mean hint->formatted_node can be removed ? - Zam */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) * hint->formatted_node cannot be removed because we try to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) * inode information here, and there is often no inode associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) * metadata allocations - green
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) if (!hint->formatted_node && hint->preallocate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) amount_needed = use_preallocated_list_if_available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) (hint, new_blocknrs, amount_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) * We have all the block numbers we need from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) * prealloc list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (amount_needed == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) return CARRY_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) new_blocknrs += (initial_amount_needed - amount_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) /* find search start and save it in hint structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) determine_search_start(hint, amount_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (hint->search_start >= SB_BLOCK_COUNT(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) hint->search_start = SB_BLOCK_COUNT(s) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) /* allocation itself; fill new_blocknrs and preallocation arrays */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) ret = blocknrs_and_prealloc_arrays_from_search_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) (hint, new_blocknrs, amount_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) * We used prealloc. list to fill (partially) new_blocknrs array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) * If final allocation fails we need to return blocks back to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) * prealloc. list or just free them. -- Zam (I chose second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) * variant)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (ret != CARRY_ON) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) while (amount_needed++ < initial_amount_needed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) reiserfs_free_block(hint->th, hint->inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) *(--new_blocknrs), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) void reiserfs_cache_bitmap_metadata(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) struct reiserfs_bitmap_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) /* The first bit must ALWAYS be 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (!reiserfs_test_le_bit(0, (unsigned long *)bh->b_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) reiserfs_error(sb, "reiserfs-2025", "bitmap block %lu is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) "corrupted: first bit must be 1", bh->b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) info->free_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) while (--cur >= (unsigned long *)bh->b_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) /* 0 and ~0 are special, we can optimize for them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) if (*cur == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) info->free_count += BITS_PER_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) else if (*cur != ~0L) /* A mix, investigate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) info->free_count += BITS_PER_LONG - hweight_long(*cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) unsigned int bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) b_blocknr_t block = (sb->s_blocksize << 3) * bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) struct reiserfs_bitmap_info *info = SB_AP_BITMAP(sb) + bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) * Way old format filesystems had the bitmaps packed up front.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) * I doubt there are any of these left, but just in case...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (unlikely(test_bit(REISERFS_OLD_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) &REISERFS_SB(sb)->s_properties)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) block = REISERFS_SB(sb)->s_sbh->b_blocknr + 1 + bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) else if (bitmap == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) block = (REISERFS_DISK_OFFSET_IN_BYTES >> sb->s_blocksize_bits) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) bh = sb_bread(sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) if (bh == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) reiserfs_warning(sb, "sh-2029: %s: bitmap block (#%u) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) "reading failed", __func__, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) if (buffer_locked(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) PROC_INFO_INC(sb, scan_bitmap.wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) depth = reiserfs_write_unlock_nested(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) __wait_on_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) reiserfs_write_lock_nested(sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) BUG_ON(!buffer_uptodate(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) BUG_ON(atomic_read(&bh->b_count) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) if (info->free_count == UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) reiserfs_cache_bitmap_metadata(sb, bh, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) int reiserfs_init_bitmap_cache(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) struct reiserfs_bitmap_info *bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) unsigned int bmap_nr = reiserfs_bmap_count(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) bitmap = vmalloc(array_size(bmap_nr, sizeof(*bitmap)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) if (bitmap == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) memset(bitmap, 0xff, sizeof(*bitmap) * bmap_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) SB_AP_BITMAP(sb) = bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) void reiserfs_free_bitmap_cache(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) if (SB_AP_BITMAP(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) vfree(SB_AP_BITMAP(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) SB_AP_BITMAP(sb) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }