^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) * slot_map.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2002, 2004 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <cluster/masklog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "ocfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "dlmglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "extent_map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "heartbeat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "slot_map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "super.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "sysfile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "ocfs2_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "buffer_head_io.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ocfs2_slot {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int sl_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int sl_node_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct ocfs2_slot_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int si_extended;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int si_slots_per_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct inode *si_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned int si_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct buffer_head **si_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int si_num_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ocfs2_slot si_slots[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int __ocfs2_node_num_to_slot(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static void ocfs2_invalidate_slot(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int slot_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) BUG_ON((slot_num < 0) || (slot_num >= si->si_num_slots));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) si->si_slots[slot_num].sl_valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void ocfs2_set_slot(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int slot_num, unsigned int node_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) BUG_ON((slot_num < 0) || (slot_num >= si->si_num_slots));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) si->si_slots[slot_num].sl_valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) si->si_slots[slot_num].sl_node_num = node_num;
^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) /* This version is for the extended slot map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static void ocfs2_update_slot_info_extended(struct ocfs2_slot_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int b, i, slotno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct ocfs2_slot_map_extended *se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) slotno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) for (b = 0; b < si->si_blocks; b++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) se = (struct ocfs2_slot_map_extended *)si->si_bh[b]->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) for (i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) (i < si->si_slots_per_block) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) (slotno < si->si_num_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) i++, slotno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (se->se_slots[i].es_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ocfs2_set_slot(si, slotno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) le32_to_cpu(se->se_slots[i].es_node_num));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ocfs2_invalidate_slot(si, slotno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Post the slot information on disk into our slot_info struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * Must be protected by osb_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static void ocfs2_update_slot_info_old(struct ocfs2_slot_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct ocfs2_slot_map *sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) sm = (struct ocfs2_slot_map *)si->si_bh[0]->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) for (i = 0; i < si->si_num_slots; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (le16_to_cpu(sm->sm_slots[i]) == (u16)OCFS2_INVALID_SLOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ocfs2_invalidate_slot(si, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ocfs2_set_slot(si, i, le16_to_cpu(sm->sm_slots[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void ocfs2_update_slot_info(struct ocfs2_slot_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * The slot data will have been refreshed when ocfs2_super_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * was taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (si->si_extended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) ocfs2_update_slot_info_extended(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ocfs2_update_slot_info_old(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int ocfs2_refresh_slot_info(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct ocfs2_slot_info *si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (si == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) BUG_ON(si->si_blocks == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) BUG_ON(si->si_bh == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) trace_ocfs2_refresh_slot_info(si->si_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * We pass -1 as blocknr because we expect all of si->si_bh to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * be !NULL. Thus, ocfs2_read_blocks() will ignore blocknr. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * this is not true, the read of -1 (UINT64_MAX) will fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) ret = ocfs2_read_blocks(INODE_CACHE(si->si_inode), -1, si->si_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) si->si_bh, OCFS2_BH_IGNORE_CACHE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ocfs2_update_slot_info(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* post the our slot info stuff into it's destination bh and write it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void ocfs2_update_disk_slot_extended(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int slot_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct buffer_head **bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int blkind = slot_num / si->si_slots_per_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) int slotno = slot_num % si->si_slots_per_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct ocfs2_slot_map_extended *se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) BUG_ON(blkind >= si->si_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) se = (struct ocfs2_slot_map_extended *)si->si_bh[blkind]->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) se->se_slots[slotno].es_valid = si->si_slots[slot_num].sl_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (si->si_slots[slot_num].sl_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) se->se_slots[slotno].es_node_num =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) cpu_to_le32(si->si_slots[slot_num].sl_node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *bh = si->si_bh[blkind];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static void ocfs2_update_disk_slot_old(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int slot_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct buffer_head **bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct ocfs2_slot_map *sm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) sm = (struct ocfs2_slot_map *)si->si_bh[0]->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) for (i = 0; i < si->si_num_slots; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (si->si_slots[i].sl_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) sm->sm_slots[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) cpu_to_le16(si->si_slots[i].sl_node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) sm->sm_slots[i] = cpu_to_le16(OCFS2_INVALID_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) *bh = si->si_bh[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int ocfs2_update_disk_slot(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int slot_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (si->si_extended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ocfs2_update_disk_slot_extended(si, slot_num, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ocfs2_update_disk_slot_old(si, slot_num, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) status = ocfs2_write_block(osb, bh, INODE_CACHE(si->si_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * Calculate how many bytes are needed by the slot map. Returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * an error if the slot map file is too small.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int ocfs2_slot_map_physical_size(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) unsigned long long *bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) unsigned long long bytes_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (ocfs2_uses_extended_slot_map(osb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) bytes_needed = osb->max_slots *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) sizeof(struct ocfs2_extended_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) bytes_needed = osb->max_slots * sizeof(__le16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (bytes_needed > i_size_read(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) mlog(ML_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) "Slot map file is too small! (size %llu, needed %llu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) i_size_read(inode), bytes_needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *bytes = bytes_needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* try to find global node in the slot info. Returns -ENOENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * if nothing is found. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int __ocfs2_node_num_to_slot(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) unsigned int node_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int i, ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) for(i = 0; i < si->si_num_slots; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (si->si_slots[i].sl_valid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) (node_num == si->si_slots[i].sl_node_num)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ret = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int __ocfs2_find_empty_slot(struct ocfs2_slot_info *si,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int preferred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int i, ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if ((preferred >= 0) && (preferred < si->si_num_slots)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!si->si_slots[preferred].sl_valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) !si->si_slots[preferred].sl_node_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ret = preferred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) for(i = 0; i < si->si_num_slots; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (!si->si_slots[i].sl_valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) !si->si_slots[i].sl_node_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ret = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int ocfs2_node_num_to_slot(struct ocfs2_super *osb, unsigned int node_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct ocfs2_slot_info *si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) slot = __ocfs2_node_num_to_slot(si, node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int ocfs2_slot_to_node_num_locked(struct ocfs2_super *osb, int slot_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) unsigned int *node_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct ocfs2_slot_info *si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) assert_spin_locked(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) BUG_ON(slot_num < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) BUG_ON(slot_num >= osb->max_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (!si->si_slots[slot_num].sl_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) *node_num = si->si_slots[slot_num].sl_node_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static void __ocfs2_free_slot_info(struct ocfs2_slot_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (si == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) iput(si->si_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (si->si_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) for (i = 0; i < si->si_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (si->si_bh[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) brelse(si->si_bh[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) si->si_bh[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) kfree(si->si_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) kfree(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int ocfs2_clear_slot(struct ocfs2_super *osb, int slot_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct ocfs2_slot_info *si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (si == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ocfs2_invalidate_slot(si, slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return ocfs2_update_disk_slot(osb, osb->slot_info, slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int ocfs2_map_slot_buffers(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct ocfs2_slot_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) u64 blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) unsigned long long blocks, bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) status = ocfs2_slot_map_physical_size(osb, si->si_inode, &bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) blocks = ocfs2_blocks_for_bytes(si->si_inode->i_sb, bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) BUG_ON(blocks > UINT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) si->si_blocks = blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (!si->si_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (si->si_extended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) si->si_slots_per_block =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) (osb->sb->s_blocksize /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) sizeof(struct ocfs2_extended_slot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) si->si_slots_per_block = osb->sb->s_blocksize / sizeof(__le16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* The size checks above should ensure this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) BUG_ON((osb->max_slots / si->si_slots_per_block) > blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) trace_ocfs2_map_slot_buffers(bytes, si->si_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) si->si_bh = kcalloc(si->si_blocks, sizeof(struct buffer_head *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (!si->si_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) for (i = 0; i < si->si_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) status = ocfs2_extent_map_get_blocks(si->si_inode, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) &blkno, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) trace_ocfs2_map_slot_buffers_block((unsigned long long)blkno, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) bh = NULL; /* Acquire a fresh bh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) status = ocfs2_read_blocks(INODE_CACHE(si->si_inode), blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 1, &bh, OCFS2_BH_IGNORE_CACHE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) goto bail;
^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) si->si_bh[i] = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int ocfs2_init_slot_info(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct ocfs2_slot_info *si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) si = kzalloc(struct_size(si, si_slots, osb->max_slots), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (!si) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) si->si_extended = ocfs2_uses_extended_slot_map(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) si->si_num_slots = osb->max_slots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) inode = ocfs2_get_system_file_inode(osb, SLOT_MAP_SYSTEM_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) OCFS2_INVALID_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) si->si_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) status = ocfs2_map_slot_buffers(osb, si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto bail;
^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) osb->slot_info = (struct ocfs2_slot_info *)si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) __ocfs2_free_slot_info(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) void ocfs2_free_slot_info(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct ocfs2_slot_info *si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) osb->slot_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) __ocfs2_free_slot_info(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) int ocfs2_find_slot(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct ocfs2_slot_info *si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ocfs2_update_slot_info(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (ocfs2_mount_local(osb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* use slot 0 directly in local mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) slot = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) /* search for ourselves first and take the slot if it already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * exists. Perhaps we need to mark this in a variable for our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) * own journal recovery? Possibly not, though we certainly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * need to warn to the user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) slot = __ocfs2_node_num_to_slot(si, osb->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (slot < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* if no slot yet, then just take 1st available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) slot = __ocfs2_find_empty_slot(si, osb->preferred_slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (slot < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) mlog(ML_ERROR, "no free slots available!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) printk(KERN_INFO "ocfs2: Slot %d on device (%s) was "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) "already allocated to this node!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) slot, osb->dev_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) ocfs2_set_slot(si, slot, osb->node_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) osb->slot_num = slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) trace_ocfs2_find_slot(osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) status = ocfs2_update_disk_slot(osb, si, osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * if write block failed, invalidate slot to avoid overwrite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * slot during dismount in case another node rightly has mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ocfs2_invalidate_slot(si, osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) osb->slot_num = OCFS2_INVALID_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return status;
^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) void ocfs2_put_slot(struct ocfs2_super *osb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) int status, slot_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct ocfs2_slot_info *si = osb->slot_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (!si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) spin_lock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ocfs2_update_slot_info(si);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) slot_num = osb->slot_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ocfs2_invalidate_slot(si, osb->slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) osb->slot_num = OCFS2_INVALID_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) spin_unlock(&osb->osb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) status = ocfs2_update_disk_slot(osb, si, slot_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) mlog_errno(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) ocfs2_free_slot_info(osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }