^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * localalloc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Node local data allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2002, 2004 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <cluster/masklog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "ocfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "blockcheck.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "dlmglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "journal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "localalloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "suballoc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "sysfile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "ocfs2_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "buffer_head_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define OCFS2_LOCAL_ALLOC(dinode) (&((dinode)->id2.i_lab))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct ocfs2_dinode *alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u32 *numbits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ocfs2_alloc_reservation *resv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct ocfs2_dinode *alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct inode *main_bm_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct buffer_head *main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct ocfs2_alloc_context **ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct inode **bitmap_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct buffer_head **bitmap_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct ocfs2_alloc_context *ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct inode *local_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * ocfs2_la_default_mb() - determine a default size, in megabytes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * the local alloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Generally, we'd like to pick as large a local alloc as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * possible. Performance on large workloads tends to scale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * proportionally to la size. In addition to that, the reservations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * code functions more efficiently as it can reserve more windows for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * Some things work against us when trying to choose a large local alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * - We need to ensure our sizing is picked to leave enough space in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * group descriptors for other allocations (such as block groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * etc). Picking default sizes which are a multiple of 4 could help
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * - block groups are allocated in 2mb and 4mb chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * - Likewise, we don't want to starve other nodes of bits on small
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * file systems. This can easily be taken care of by limiting our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * default to a reasonable size (256M) on larger cluster sizes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * - Some file systems can't support very large sizes - 4k and 8k in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * particular are limited to less than 128 and 256 megabytes respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * The following reference table shows group descriptor and local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * alloc maximums at various cluster sizes (4k blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * csize: 4K group: 126M la: 121M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * csize: 8K group: 252M la: 243M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * csize: 16K group: 504M la: 486M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * csize: 32K group: 1008M la: 972M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * csize: 64K group: 2016M la: 1944M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * csize: 128K group: 4032M la: 3888M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * csize: 256K group: 8064M la: 7776M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * csize: 512K group: 16128M la: 15552M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * csize: 1024K group: 32256M la: 31104M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define OCFS2_LA_MAX_DEFAULT_MB 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define OCFS2_LA_OLD_DEFAULT 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int ocfs2_la_default_mb(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned int la_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned int gd_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int la_max_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned int megs_per_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct super_block *sb = osb->sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) gd_mb = ocfs2_clusters_to_megabytes(osb->sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 8 * ocfs2_group_bitmap_size(sb, 0, osb->s_feature_incompat));
^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) * This takes care of files systems with very small group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * descriptors - 512 byte blocksize at cluster sizes lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * than 16K and also 1k blocksize with 4k cluster size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if ((sb->s_blocksize == 512 && osb->s_clustersize <= 8192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) || (sb->s_blocksize == 1024 && osb->s_clustersize == 4096))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return OCFS2_LA_OLD_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * Leave enough room for some block groups and make the final
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * value we work from a multiple of 4.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) gd_mb -= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) gd_mb &= 0xFFFFFFFB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) la_mb = gd_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Keep window sizes down to a reasonable default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (la_mb > OCFS2_LA_MAX_DEFAULT_MB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * Some clustersize / blocksize combinations will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * given us a larger than OCFS2_LA_MAX_DEFAULT_MB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * default size, but get poor distribution when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * limited to exactly 256 megabytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * As an example, 16K clustersize at 4K blocksize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * gives us a cluster group size of 504M. Paring the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * local alloc size down to 256 however, would give us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * only one window and around 200MB left in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * cluster group. Instead, find the first size below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * 256 which would give us an even distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Larger cluster group sizes actually work out pretty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * well when pared to 256, so we don't have to do this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * for any group that fits more than two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * OCFS2_LA_MAX_DEFAULT_MB windows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (gd_mb > (2 * OCFS2_LA_MAX_DEFAULT_MB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) la_mb = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) unsigned int gd_mult = gd_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) while (gd_mult > 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) gd_mult = gd_mult >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) la_mb = gd_mult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) megs_per_slot = osb->osb_clusters_at_boot / osb->max_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) megs_per_slot = ocfs2_clusters_to_megabytes(osb->sb, megs_per_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Too many nodes, too few disk clusters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (megs_per_slot < la_mb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) la_mb = megs_per_slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* We can't store more bits than we can in a block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) la_max_mb = ocfs2_clusters_to_megabytes(osb->sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ocfs2_local_alloc_size(sb) * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (la_mb > la_max_mb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) la_mb = la_max_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return la_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) void ocfs2_la_set_sizes(struct ocfs2_super *osb, int requested_mb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct super_block *sb = osb->sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) unsigned int la_default_mb = ocfs2_la_default_mb(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned int la_max_mb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) la_max_mb = ocfs2_clusters_to_megabytes(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ocfs2_local_alloc_size(sb) * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) trace_ocfs2_la_set_sizes(requested_mb, la_max_mb, la_default_mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (requested_mb == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* No user request - use defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) osb->local_alloc_default_bits =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ocfs2_megabytes_to_clusters(sb, la_default_mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) } else if (requested_mb > la_max_mb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* Request is too big, we give the maximum available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) osb->local_alloc_default_bits =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ocfs2_megabytes_to_clusters(sb, la_max_mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) osb->local_alloc_default_bits =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ocfs2_megabytes_to_clusters(sb, requested_mb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) osb->local_alloc_bits = osb->local_alloc_default_bits;
^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) static inline int ocfs2_la_state_enabled(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return (osb->local_alloc_state == OCFS2_LA_THROTTLED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) osb->local_alloc_state == OCFS2_LA_ENABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned int num_clusters)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (osb->local_alloc_state == OCFS2_LA_DISABLED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) osb->local_alloc_state == OCFS2_LA_THROTTLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (num_clusters >= osb->local_alloc_default_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) cancel_delayed_work(&osb->la_enable_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) osb->local_alloc_state = OCFS2_LA_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void ocfs2_la_enable_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct ocfs2_super *osb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) container_of(work, struct ocfs2_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) la_enable_wq.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) osb->local_alloc_state = OCFS2_LA_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Tell us whether a given allocation should use the local alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * file. Otherwise, it has to go to the main bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * This function does semi-dirty reads of local alloc size and state!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * This is ok however, as the values are re-checked once under mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int la_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) la_bits = osb->local_alloc_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (!ocfs2_la_state_enabled(osb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* la_bits should be at least twice the size (in clusters) of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * a new block group. We want to be sure block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * allocations go through the local alloc, so allow an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * allocation to take up to half the bitmap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (bits > (la_bits / 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) trace_ocfs2_alloc_should_use_local(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) (unsigned long long)bits, osb->local_alloc_state, la_bits, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) int ocfs2_load_local_alloc(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct ocfs2_dinode *alloc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct buffer_head *alloc_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) u32 num_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct ocfs2_local_alloc *la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (osb->local_alloc_bits == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (osb->local_alloc_bits >= osb->bitmap_cpg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) mlog(ML_NOTICE, "Requested local alloc window %d is larger "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) "than max possible %u. Using defaults.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) osb->local_alloc_bits, (osb->bitmap_cpg - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) osb->local_alloc_bits =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ocfs2_megabytes_to_clusters(osb->sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ocfs2_la_default_mb(osb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* read the alloc off disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) status = ocfs2_read_inode_block_full(inode, &alloc_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) OCFS2_BH_IGNORE_CACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) alloc = (struct ocfs2_dinode *) alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!(le32_to_cpu(alloc->i_flags) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) (OCFS2_LOCAL_ALLOC_FL|OCFS2_BITMAP_FL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) mlog(ML_ERROR, "Invalid local alloc inode, %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) (unsigned long long)OCFS2_I(inode)->ip_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if ((la->la_size == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) (le16_to_cpu(la->la_size) > ocfs2_local_alloc_size(inode->i_sb))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) mlog(ML_ERROR, "Local alloc size is invalid (la_size = %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) le16_to_cpu(la->la_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /* do a little verification. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) num_used = ocfs2_local_alloc_count_bits(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* hopefully the local alloc has always been recovered before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * we load it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (num_used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) || alloc->id1.bitmap1.i_used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) || alloc->id1.bitmap1.i_total
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) || la->la_bm_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) mlog(ML_ERROR, "inconsistent detected, clean journal with"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) " unrecovered local alloc, please run fsck.ocfs2!\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) "found = %u, set = %u, taken = %u, off = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) num_used, le32_to_cpu(alloc->id1.bitmap1.i_used),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) le32_to_cpu(alloc->id1.bitmap1.i_total),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) OCFS2_LOCAL_ALLOC(alloc)->la_bm_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) osb->local_alloc_bh = alloc_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) osb->local_alloc_state = OCFS2_LA_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) brelse(alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) trace_ocfs2_load_local_alloc(osb->local_alloc_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * return any unused bits to the bitmap and write out a clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * local_alloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * local_alloc_bh is optional. If not passed, we will simply use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * one off osb. If you do pass it however, be warned that it *will* be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * returned brelse'd and NULL'd out.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct inode *local_alloc_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) struct buffer_head *main_bm_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct inode *main_bm_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct ocfs2_dinode *alloc_copy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct ocfs2_dinode *alloc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) cancel_delayed_work(&osb->la_enable_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (osb->ocfs2_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) flush_workqueue(osb->ocfs2_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (osb->local_alloc_state == OCFS2_LA_UNUSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) local_alloc_inode =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ocfs2_get_system_file_inode(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) LOCAL_ALLOC_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (!local_alloc_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) status = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) osb->local_alloc_state = OCFS2_LA_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ocfs2_resmap_uninit(&osb->osb_la_resmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) main_bm_inode = ocfs2_get_system_file_inode(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) GLOBAL_BITMAP_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) OCFS2_INVALID_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (!main_bm_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) inode_lock(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto out_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /* WINDOW_MOVE_CREDITS is a bit heavy... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) mlog_errno(PTR_ERR(handle));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) bh = osb->local_alloc_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) alloc = (struct ocfs2_dinode *) bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) alloc_copy = kmemdup(alloc, bh->b_size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (!alloc_copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) bh, OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) goto out_commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ocfs2_clear_local_alloc(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ocfs2_journal_dirty(handle, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) osb->local_alloc_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) osb->local_alloc_state = OCFS2_LA_UNUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) status = ocfs2_sync_local_to_main(osb, handle, alloc_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) main_bm_inode, main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) out_commit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) brelse(main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ocfs2_inode_unlock(main_bm_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) out_mutex:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) inode_unlock(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) iput(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) iput(local_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) kfree(alloc_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * We want to free the bitmap bits outside of any recovery context as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * we'll need a cluster lock to do so, but we must clear the local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * alloc before giving up the recovered nodes journal. To solve this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * we kmalloc a copy of the local alloc before it's change for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * caller to process with ocfs2_complete_local_alloc_recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int slot_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct ocfs2_dinode **alloc_copy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct buffer_head *alloc_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct ocfs2_dinode *alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) trace_ocfs2_begin_local_alloc_recovery(slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) *alloc_copy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) inode = ocfs2_get_system_file_inode(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) LOCAL_ALLOC_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) status = ocfs2_read_inode_block_full(inode, &alloc_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) OCFS2_BH_IGNORE_CACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) *alloc_copy = kmalloc(alloc_bh->b_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (!(*alloc_copy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) memcpy((*alloc_copy), alloc_bh->b_data, alloc_bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) alloc = (struct ocfs2_dinode *) alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ocfs2_clear_local_alloc(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) ocfs2_compute_meta_ecc(osb->sb, alloc_bh->b_data, &alloc->i_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) status = ocfs2_write_block(osb, alloc_bh, INODE_CACHE(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) kfree(*alloc_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) *alloc_copy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) brelse(alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) * Step 2: By now, we've completed the journal recovery, we've stamped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * a clean local alloc on disk and dropped the node out of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * recovery map. Dlm locks will no longer stall, so lets clear out the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * main bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct ocfs2_dinode *alloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct buffer_head *main_bm_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct inode *main_bm_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) main_bm_inode = ocfs2_get_system_file_inode(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) GLOBAL_BITMAP_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) OCFS2_INVALID_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!main_bm_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) goto out;
^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) inode_lock(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) goto out_mutex;
^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) handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) status = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) /* we want the bitmap change to be recorded on disk asap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) handle->h_sync = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) status = ocfs2_sync_local_to_main(osb, handle, alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) main_bm_inode, main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) ocfs2_inode_unlock(main_bm_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) out_mutex:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) inode_unlock(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) brelse(main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) iput(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) ocfs2_init_steal_slots(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * make sure we've got at least bits_wanted contiguous bits in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * local alloc. You lose them when you drop i_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) * We will add ourselves to the transaction passed in, but may start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) * our own in order to shift windows.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) u32 bits_wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct ocfs2_alloc_context *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct ocfs2_dinode *alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct inode *local_alloc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) unsigned int free_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) BUG_ON(!ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) local_alloc_inode =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) ocfs2_get_system_file_inode(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) LOCAL_ALLOC_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (!local_alloc_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) status = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) inode_lock(local_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) * We must double check state and allocator bits because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * another process may have changed them while holding i_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!ocfs2_la_state_enabled(osb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) (bits_wanted > osb->local_alloc_bits)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) status = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) #ifdef CONFIG_OCFS2_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (le32_to_cpu(alloc->id1.bitmap1.i_used) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) ocfs2_local_alloc_count_bits(alloc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) status = ocfs2_error(osb->sb, "local alloc inode %llu says it has %u used bits, but a count shows %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) (unsigned long long)le64_to_cpu(alloc->i_blkno),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) le32_to_cpu(alloc->id1.bitmap1.i_used),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) ocfs2_local_alloc_count_bits(alloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) le32_to_cpu(alloc->id1.bitmap1.i_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (bits_wanted > free_bits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* uhoh, window change time. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) ocfs2_local_alloc_slide_window(osb, local_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (status != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * Under certain conditions, the window slide code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * might have reduced the number of bits available or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) * disabled the local alloc entirely. Re-check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) * here and return -ENOSPC if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) status = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (!ocfs2_la_state_enabled(osb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) le32_to_cpu(alloc->id1.bitmap1.i_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (bits_wanted > free_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) ac->ac_inode = local_alloc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /* We should never use localalloc from another slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) ac->ac_alloc_slot = osb->slot_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ac->ac_which = OCFS2_AC_USE_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) get_bh(osb->local_alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ac->ac_bh = osb->local_alloc_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (status < 0 && local_alloc_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) inode_unlock(local_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) iput(local_alloc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) trace_ocfs2_reserve_local_alloc_bits(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) (unsigned long long)ac->ac_max_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) bits_wanted, osb->slot_num, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) struct ocfs2_alloc_context *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) u32 bits_wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) u32 *bit_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) u32 *num_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) int status, start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) struct inode *local_alloc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) void *bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) struct ocfs2_dinode *alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) struct ocfs2_local_alloc *la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) local_alloc_inode = ac->ac_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) start = ocfs2_local_alloc_find_clear_bits(osb, alloc, &bits_wanted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) ac->ac_resv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (start == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) /* TODO: Shouldn't we just BUG here? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) status = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) bitmap = la->la_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) *bit_off = le32_to_cpu(la->la_bm_off) + start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) *num_bits = bits_wanted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) status = ocfs2_journal_access_di(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) INODE_CACHE(local_alloc_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) osb->local_alloc_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) ocfs2_resmap_claimed_bits(&osb->osb_la_resmap, ac->ac_resv, start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) bits_wanted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) while(bits_wanted--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) ocfs2_set_bit(start++, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) le32_add_cpu(&alloc->id1.bitmap1.i_used, *num_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) ocfs2_journal_dirty(handle, osb->local_alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) int ocfs2_free_local_alloc_bits(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) struct ocfs2_alloc_context *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) u32 bit_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) u32 num_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) int status, start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) u32 clear_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct inode *local_alloc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) void *bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) struct ocfs2_dinode *alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct ocfs2_local_alloc *la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) local_alloc_inode = ac->ac_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) bitmap = la->la_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) start = bit_off - le32_to_cpu(la->la_bm_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) clear_bits = num_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) status = ocfs2_journal_access_di(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) INODE_CACHE(local_alloc_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) osb->local_alloc_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) while (clear_bits--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) ocfs2_clear_bit(start++, bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) le32_add_cpu(&alloc->id1.bitmap1.i_used, -num_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) ocfs2_journal_dirty(handle, osb->local_alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) u32 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) count = memweight(la->la_bitmap, le16_to_cpu(la->la_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) trace_ocfs2_local_alloc_count_bits(count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) struct ocfs2_dinode *alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) u32 *numbits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) struct ocfs2_alloc_reservation *resv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) int numfound = 0, bitoff, left, startoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) int local_resv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) struct ocfs2_alloc_reservation r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) void *bitmap = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) struct ocfs2_reservation_map *resmap = &osb->osb_la_resmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (!alloc->id1.bitmap1.i_total) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) bitoff = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) if (!resv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) local_resv = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) ocfs2_resv_init_once(&r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ocfs2_resv_set_type(&r, OCFS2_RESV_FLAG_TMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) resv = &r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) numfound = *numbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (ocfs2_resmap_resv_bits(resmap, resv, &bitoff, &numfound) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (numfound < *numbits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) *numbits = numfound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * Code error. While reservations are enabled, local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * allocation should _always_ go through them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) BUG_ON(osb->osb_resv_level != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) * Reservations are disabled. Handle this the old way.
^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) bitmap = OCFS2_LOCAL_ALLOC(alloc)->la_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) numfound = bitoff = startoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) left = le32_to_cpu(alloc->id1.bitmap1.i_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) while ((bitoff = ocfs2_find_next_zero_bit(bitmap, left, startoff)) != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (bitoff == left) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) /* mlog(0, "bitoff (%d) == left", bitoff); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) /* mlog(0, "Found a zero: bitoff = %d, startoff = %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) "numfound = %d\n", bitoff, startoff, numfound);*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) /* Ok, we found a zero bit... is it contig. or do we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) * start over?*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (bitoff == startoff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /* we found a zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) numfound++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) startoff++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* got a zero after some ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) numfound = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) startoff = bitoff+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /* we got everything we needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if (numfound == *numbits) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* mlog(0, "Found it all!\n"); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) trace_ocfs2_local_alloc_find_clear_bits_search_bitmap(bitoff, numfound);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (numfound == *numbits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) bitoff = startoff - numfound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) bitoff = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (local_resv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) ocfs2_resv_discard(resmap, resv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) trace_ocfs2_local_alloc_find_clear_bits(*numbits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) le32_to_cpu(alloc->id1.bitmap1.i_total),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) bitoff, numfound);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return bitoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) alloc->id1.bitmap1.i_total = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) alloc->id1.bitmap1.i_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) la->la_bm_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) for(i = 0; i < le16_to_cpu(la->la_size); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) la->la_bitmap[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) /* turn this on and uncomment below to aid debugging window shifts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) static void ocfs2_verify_zero_bits(unsigned long *bitmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) unsigned int start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) unsigned int tmp = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) while(tmp--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (ocfs2_test_bit(start + tmp, bitmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) printk("ocfs2_verify_zero_bits: start = %u, count = "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) "%u\n", start, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) printk("ocfs2_verify_zero_bits: bit %u is set!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) start + tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) * sync the local alloc to main bitmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * assumes you've already locked the main bitmap -- the bitmap inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) * passed is used for caching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) struct ocfs2_dinode *alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) struct inode *main_bm_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct buffer_head *main_bm_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) int bit_off, left, count, start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) u64 la_start_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) u64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) void *bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) trace_ocfs2_sync_local_to_main(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) le32_to_cpu(alloc->id1.bitmap1.i_total),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) le32_to_cpu(alloc->id1.bitmap1.i_used));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) if (!alloc->id1.bitmap1.i_total) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) if (le32_to_cpu(alloc->id1.bitmap1.i_used) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) le32_to_cpu(alloc->id1.bitmap1.i_total)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) la_start_blk = ocfs2_clusters_to_blocks(osb->sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) le32_to_cpu(la->la_bm_off));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) bitmap = la->la_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) start = count = bit_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) left = le32_to_cpu(alloc->id1.bitmap1.i_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) if ((bit_off < left) && (bit_off == start)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) start++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) blkno = la_start_blk +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) ocfs2_clusters_to_blocks(osb->sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) start - count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) trace_ocfs2_sync_local_to_main_free(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) count, start - count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) (unsigned long long)la_start_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) (unsigned long long)blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) status = ocfs2_release_clusters(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) main_bm_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) main_bm_bh, blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (bit_off >= left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) start = bit_off + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) enum ocfs2_la_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) OCFS2_LA_EVENT_SLIDE, /* Normal window slide. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) OCFS2_LA_EVENT_FRAGMENTED, /* The global bitmap has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * enough bits theoretically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * free, but a contiguous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * allocation could not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) OCFS2_LA_EVENT_ENOSPC, /* Global bitmap doesn't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * enough bits free to satisfy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * our request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) #define OCFS2_LA_ENABLE_INTERVAL (30 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) * Given an event, calculate the size of our next local alloc window.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) * This should always be called under i_mutex of the local alloc inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) * so that local alloc disabling doesn't race with processes trying to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) * use the allocator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * Returns the state which the local alloc was left in. This value can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * be ignored by some paths.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) static int ocfs2_recalc_la_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) enum ocfs2_la_event event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) unsigned int bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (osb->local_alloc_state == OCFS2_LA_DISABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) WARN_ON_ONCE(osb->local_alloc_state == OCFS2_LA_DISABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^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) * ENOSPC and fragmentation are treated similarly for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (event == OCFS2_LA_EVENT_ENOSPC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) event == OCFS2_LA_EVENT_FRAGMENTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) * We ran out of contiguous space in the primary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) * bitmap. Drastically reduce the number of bits used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * by local alloc until we have to disable it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) bits = osb->local_alloc_bits >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (bits > ocfs2_megabytes_to_clusters(osb->sb, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) * By setting state to THROTTLED, we'll keep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) * the number of local alloc bits used down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) * until an event occurs which would give us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) * reason to assume the bitmap situation might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) * have changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) osb->local_alloc_state = OCFS2_LA_THROTTLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) osb->local_alloc_bits = bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) osb->local_alloc_state = OCFS2_LA_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) queue_delayed_work(osb->ocfs2_wq, &osb->la_enable_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) OCFS2_LA_ENABLE_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) * Don't increase the size of the local alloc window until we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * know we might be able to fulfill the request. Otherwise, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) * risk bouncing around the global bitmap during periods of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) * low space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (osb->local_alloc_state != OCFS2_LA_THROTTLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) osb->local_alloc_bits = osb->local_alloc_default_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) state = osb->local_alloc_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) struct ocfs2_alloc_context **ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) struct inode **bitmap_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) struct buffer_head **bitmap_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) if (!(*ac)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) retry_enospc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) (*ac)->ac_bits_wanted = osb->local_alloc_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (status == -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_ENOSPC) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) OCFS2_LA_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) ocfs2_free_ac_resource(*ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) memset(*ac, 0, sizeof(struct ocfs2_alloc_context));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) goto retry_enospc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) *bitmap_inode = (*ac)->ac_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) igrab(*bitmap_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) *bitmap_bh = (*ac)->ac_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) get_bh(*bitmap_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if ((status < 0) && *ac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) ocfs2_free_alloc_context(*ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) *ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) * pass it the bitmap lock in lock_bh if you have it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) struct ocfs2_alloc_context *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) u32 cluster_off, cluster_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) struct ocfs2_dinode *alloc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) struct ocfs2_local_alloc *la;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) la = OCFS2_LOCAL_ALLOC(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) trace_ocfs2_local_alloc_new_window(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) le32_to_cpu(alloc->id1.bitmap1.i_total),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) osb->local_alloc_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) /* Instruct the allocation code to try the most recently used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) * cluster group. We'll re-record the group used this pass
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) * below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) ac->ac_last_group = osb->la_last_gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) /* we used the generic suballoc reserve function, but we set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) * everything up nicely, so there's no reason why we can't use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) * the more specific cluster api to claim bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) status = ocfs2_claim_clusters(handle, ac, osb->local_alloc_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) &cluster_off, &cluster_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (status == -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) retry_enospc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) * Note: We could also try syncing the journal here to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) * allow use of any free bits which the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) * transaction can't give us access to. --Mark
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_FRAGMENTED) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) OCFS2_LA_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) ac->ac_bits_wanted = osb->local_alloc_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) status = ocfs2_claim_clusters(handle, ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) osb->local_alloc_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) &cluster_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) &cluster_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) if (status == -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) goto retry_enospc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) * We only shrunk the *minimum* number of in our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) * request - it's entirely possible that the allocator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) * might give us more than we asked for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) if (status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) osb->local_alloc_bits = cluster_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (status != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) osb->la_last_gd = ac->ac_last_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) la->la_bm_off = cpu_to_le32(cluster_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) alloc->id1.bitmap1.i_total = cpu_to_le32(cluster_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) /* just in case... In the future when we find space ourselves,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) * we don't have to get all contiguous -- but we'll have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) * set all previously used bits in bitmap and update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * la_bits_set before setting the bits in the main bitmap. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) alloc->id1.bitmap1.i_used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) memset(OCFS2_LOCAL_ALLOC(alloc)->la_bitmap, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) le16_to_cpu(la->la_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) ocfs2_resmap_restart(&osb->osb_la_resmap, cluster_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) OCFS2_LOCAL_ALLOC(alloc)->la_bitmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) trace_ocfs2_local_alloc_new_window_result(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) OCFS2_LOCAL_ALLOC(alloc)->la_bm_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) le32_to_cpu(alloc->id1.bitmap1.i_total));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) return status;
^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) /* Note that we do *NOT* lock the local alloc inode here as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) * it's been locked already for us. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) struct inode *local_alloc_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) struct buffer_head *main_bm_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) struct inode *main_bm_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) handle_t *handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) struct ocfs2_dinode *alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) struct ocfs2_dinode *alloc_copy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) struct ocfs2_alloc_context *ac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_SLIDE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /* This will lock the main bitmap for us. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) status = ocfs2_local_alloc_reserve_for_window(osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) &ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) &main_bm_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) &main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) if (status != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) status = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) /* We want to clear the local alloc before doing anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * else, so that if we error later during this operation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * local alloc shutdown won't try to double free main bitmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * bits. Make a copy so the sync function knows which bits to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * free. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) alloc_copy = kmemdup(alloc, osb->local_alloc_bh->b_size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (!alloc_copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) status = ocfs2_journal_access_di(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) INODE_CACHE(local_alloc_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) osb->local_alloc_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) OCFS2_JOURNAL_ACCESS_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) ocfs2_clear_local_alloc(alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) ocfs2_journal_dirty(handle, osb->local_alloc_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) status = ocfs2_sync_local_to_main(osb, handle, alloc_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) main_bm_inode, main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) status = ocfs2_local_alloc_new_window(osb, handle, ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if (status != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) goto bail;
^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) atomic_inc(&osb->alloc_stats.moves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) if (handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) ocfs2_commit_trans(osb, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) brelse(main_bm_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) iput(main_bm_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) kfree(alloc_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) ocfs2_free_alloc_context(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)