^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * dat.c - NILFS disk address translation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written by Koji Sato.
^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/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "nilfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "mdt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "dat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define NILFS_CNO_MIN ((__u64)1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define NILFS_CNO_MAX (~(__u64)0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * struct nilfs_dat_info - on-memory private data of DAT file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @mi: on-memory private data of metadata file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @palloc_cache: persistent object allocator cache of DAT file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @shadow: shadow map of DAT file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct nilfs_dat_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct nilfs_mdt_info mi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct nilfs_palloc_cache palloc_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct nilfs_shadow_map shadow;
^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) static inline struct nilfs_dat_info *NILFS_DAT_I(struct inode *dat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return (struct nilfs_dat_info *)NILFS_MDT(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int nilfs_dat_prepare_entry(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct nilfs_palloc_req *req, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return nilfs_palloc_get_entry_block(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) create, &req->pr_entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static void nilfs_dat_commit_entry(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) mark_buffer_dirty(req->pr_entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) nilfs_mdt_mark_dirty(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) brelse(req->pr_entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void nilfs_dat_abort_entry(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) brelse(req->pr_entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int nilfs_dat_prepare_alloc(struct inode *dat, struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ret = nilfs_palloc_prepare_alloc_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ret = nilfs_dat_prepare_entry(dat, req, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) nilfs_palloc_abort_alloc_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void nilfs_dat_commit_alloc(struct inode *dat, struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) kaddr = kmap_atomic(req->pr_entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) req->pr_entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) entry->de_start = cpu_to_le64(NILFS_CNO_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) entry->de_end = cpu_to_le64(NILFS_CNO_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) entry->de_blocknr = cpu_to_le64(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) nilfs_palloc_commit_alloc_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) nilfs_dat_commit_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void nilfs_dat_abort_alloc(struct inode *dat, struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) nilfs_dat_abort_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) nilfs_palloc_abort_alloc_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static void nilfs_dat_commit_free(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) kaddr = kmap_atomic(req->pr_entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) req->pr_entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) entry->de_start = cpu_to_le64(NILFS_CNO_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) entry->de_end = cpu_to_le64(NILFS_CNO_MIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) entry->de_blocknr = cpu_to_le64(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) nilfs_dat_commit_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) nilfs_palloc_commit_free_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int nilfs_dat_prepare_start(struct inode *dat, struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ret = nilfs_dat_prepare_entry(dat, req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) WARN_ON(ret == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void nilfs_dat_commit_start(struct inode *dat, struct nilfs_palloc_req *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) sector_t blocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) kaddr = kmap_atomic(req->pr_entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) req->pr_entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) entry->de_start = cpu_to_le64(nilfs_mdt_cno(dat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) entry->de_blocknr = cpu_to_le64(blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) nilfs_dat_commit_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int nilfs_dat_prepare_end(struct inode *dat, struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) sector_t blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = nilfs_dat_prepare_entry(dat, req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) WARN_ON(ret == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) kaddr = kmap_atomic(req->pr_entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) req->pr_entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) blocknr = le64_to_cpu(entry->de_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (blocknr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret = nilfs_palloc_prepare_free_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) nilfs_dat_abort_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) void nilfs_dat_commit_end(struct inode *dat, struct nilfs_palloc_req *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int dead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) __u64 start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) sector_t blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) kaddr = kmap_atomic(req->pr_entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) req->pr_entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) end = start = le64_to_cpu(entry->de_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!dead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) end = nilfs_mdt_cno(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) WARN_ON(start > end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) entry->de_end = cpu_to_le64(end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) blocknr = le64_to_cpu(entry->de_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (blocknr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) nilfs_dat_commit_free(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) nilfs_dat_commit_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) void nilfs_dat_abort_end(struct inode *dat, struct nilfs_palloc_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) __u64 start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sector_t blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) kaddr = kmap_atomic(req->pr_entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) req->pr_entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) start = le64_to_cpu(entry->de_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) blocknr = le64_to_cpu(entry->de_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (start == nilfs_mdt_cno(dat) && blocknr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) nilfs_palloc_abort_free_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) nilfs_dat_abort_entry(dat, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int nilfs_dat_prepare_update(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct nilfs_palloc_req *oldreq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct nilfs_palloc_req *newreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ret = nilfs_dat_prepare_end(dat, oldreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ret = nilfs_dat_prepare_alloc(dat, newreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) nilfs_dat_abort_end(dat, oldreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) void nilfs_dat_commit_update(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct nilfs_palloc_req *oldreq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct nilfs_palloc_req *newreq, int dead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) nilfs_dat_commit_end(dat, oldreq, dead);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) nilfs_dat_commit_alloc(dat, newreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) void nilfs_dat_abort_update(struct inode *dat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct nilfs_palloc_req *oldreq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct nilfs_palloc_req *newreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) nilfs_dat_abort_end(dat, oldreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) nilfs_dat_abort_alloc(dat, newreq);
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * nilfs_dat_mark_dirty -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * @dat: DAT file inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * @vblocknr: virtual block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * Return Value: On success, 0 is returned. On error, one of the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * negative error codes is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * %-EIO - I/O error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * %-ENOMEM - Insufficient amount of memory available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int nilfs_dat_mark_dirty(struct inode *dat, __u64 vblocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct nilfs_palloc_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) req.pr_entry_nr = vblocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ret = nilfs_dat_prepare_entry(dat, &req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) nilfs_dat_commit_entry(dat, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * nilfs_dat_freev - free virtual block numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * @dat: DAT file inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * @vblocknrs: array of virtual block numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * @nitems: number of virtual block numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * Description: nilfs_dat_freev() frees the virtual block numbers specified by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * @vblocknrs and @nitems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Return Value: On success, 0 is returned. On error, one of the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * negative error codes is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * %-EIO - I/O error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * %-ENOMEM - Insufficient amount of memory available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * %-ENOENT - The virtual block number have not been allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int nilfs_dat_freev(struct inode *dat, __u64 *vblocknrs, size_t nitems)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return nilfs_palloc_freev(dat, vblocknrs, nitems);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * nilfs_dat_move - change a block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * @dat: DAT file inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * @vblocknr: virtual block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * @blocknr: block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * Description: nilfs_dat_move() changes the block number associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * @vblocknr to @blocknr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * Return Value: On success, 0 is returned. On error, one of the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * negative error codes is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * %-EIO - I/O error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * %-ENOMEM - Insufficient amount of memory available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int nilfs_dat_move(struct inode *dat, __u64 vblocknr, sector_t blocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct buffer_head *entry_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ret = nilfs_palloc_get_entry_block(dat, vblocknr, 0, &entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return ret;
^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) * The given disk block number (blocknr) is not yet written to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * the device at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * To prevent nilfs_dat_translate() from returning the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * uncommitted block number, this makes a copy of the entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * buffer and redirects nilfs_dat_translate() to the copy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!buffer_nilfs_redirected(entry_bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ret = nilfs_mdt_freeze_buffer(dat, entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) brelse(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return ret;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) kaddr = kmap_atomic(entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) entry = nilfs_palloc_block_get_entry(dat, vblocknr, entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (unlikely(entry->de_blocknr == cpu_to_le64(0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) nilfs_crit(dat->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) "%s: invalid vblocknr = %llu, [%llu, %llu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) __func__, (unsigned long long)vblocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) (unsigned long long)le64_to_cpu(entry->de_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) (unsigned long long)le64_to_cpu(entry->de_end));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) brelse(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) WARN_ON(blocknr == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) entry->de_blocknr = cpu_to_le64(blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) mark_buffer_dirty(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) nilfs_mdt_mark_dirty(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) brelse(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * nilfs_dat_translate - translate a virtual block number to a block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * @dat: DAT file inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * @vblocknr: virtual block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * @blocknrp: pointer to a block number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * Description: nilfs_dat_translate() maps the virtual block number @vblocknr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * to the corresponding block number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * Return Value: On success, 0 is returned and the block number associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * with @vblocknr is stored in the place pointed by @blocknrp. On error, one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * of the following negative error codes is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * %-EIO - I/O error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * %-ENOMEM - Insufficient amount of memory available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * %-ENOENT - A block number associated with @vblocknr does not exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int nilfs_dat_translate(struct inode *dat, __u64 vblocknr, sector_t *blocknrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct buffer_head *entry_bh, *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) sector_t blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ret = nilfs_palloc_get_entry_block(dat, vblocknr, 0, &entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!nilfs_doing_gc() && buffer_nilfs_redirected(entry_bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) bh = nilfs_mdt_get_frozen_buffer(dat, entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) WARN_ON(!buffer_uptodate(bh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) brelse(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) entry_bh = bh;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) kaddr = kmap_atomic(entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) entry = nilfs_palloc_block_get_entry(dat, vblocknr, entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) blocknr = le64_to_cpu(entry->de_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (blocknr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) *blocknrp = blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) brelse(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ssize_t nilfs_dat_get_vinfo(struct inode *dat, void *buf, unsigned int visz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) size_t nvi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) struct buffer_head *entry_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct nilfs_dat_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct nilfs_vinfo *vinfo = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) __u64 first, last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) unsigned long entries_per_block = NILFS_MDT(dat)->mi_entries_per_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) int i, j, n, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) for (i = 0; i < nvi; i += n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ret = nilfs_palloc_get_entry_block(dat, vinfo->vi_vblocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 0, &entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) kaddr = kmap_atomic(entry_bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) /* last virtual block number in this block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) first = vinfo->vi_vblocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) do_div(first, entries_per_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) first *= entries_per_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) last = first + entries_per_block - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) for (j = i, n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) j < nvi && vinfo->vi_vblocknr >= first &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) vinfo->vi_vblocknr <= last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) j++, n++, vinfo = (void *)vinfo + visz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) entry = nilfs_palloc_block_get_entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) dat, vinfo->vi_vblocknr, entry_bh, kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) vinfo->vi_start = le64_to_cpu(entry->de_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) vinfo->vi_end = le64_to_cpu(entry->de_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) vinfo->vi_blocknr = le64_to_cpu(entry->de_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) brelse(entry_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return nvi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * nilfs_dat_read - read or get dat inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * @sb: super block instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * @entry_size: size of a dat entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * @raw_inode: on-disk dat inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * @inodep: buffer to store the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int nilfs_dat_read(struct super_block *sb, size_t entry_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct nilfs_inode *raw_inode, struct inode **inodep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static struct lock_class_key dat_lock_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct inode *dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct nilfs_dat_info *di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (entry_size > sb->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) nilfs_err(sb, "too large DAT entry size: %zu bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) } else if (entry_size < NILFS_MIN_DAT_ENTRY_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) nilfs_err(sb, "too small DAT entry size: %zu bytes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) dat = nilfs_iget_locked(sb, NULL, NILFS_DAT_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (unlikely(!dat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (!(dat->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) err = nilfs_mdt_init(dat, NILFS_MDT_GFP, sizeof(*di));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) err = nilfs_palloc_init_blockgroup(dat, entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) di = NILFS_DAT_I(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) lockdep_set_class(&di->mi.mi_sem, &dat_lock_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) nilfs_palloc_setup_cache(dat, &di->palloc_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) nilfs_mdt_setup_shadow_map(dat, &di->shadow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) err = nilfs_read_inode_common(dat, raw_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) unlock_new_inode(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) *inodep = dat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) iget_failed(dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }