15eb563f5SRyusuke Konishi /* 25eb563f5SRyusuke Konishi * mdt.h - NILFS meta data file prototype and definitions 35eb563f5SRyusuke Konishi * 45eb563f5SRyusuke Konishi * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 55eb563f5SRyusuke Konishi * 65eb563f5SRyusuke Konishi * This program is free software; you can redistribute it and/or modify 75eb563f5SRyusuke Konishi * it under the terms of the GNU General Public License as published by 85eb563f5SRyusuke Konishi * the Free Software Foundation; either version 2 of the License, or 95eb563f5SRyusuke Konishi * (at your option) any later version. 105eb563f5SRyusuke Konishi * 115eb563f5SRyusuke Konishi * This program is distributed in the hope that it will be useful, 125eb563f5SRyusuke Konishi * but WITHOUT ANY WARRANTY; without even the implied warranty of 135eb563f5SRyusuke Konishi * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 145eb563f5SRyusuke Konishi * GNU General Public License for more details. 155eb563f5SRyusuke Konishi * 165eb563f5SRyusuke Konishi * You should have received a copy of the GNU General Public License 175eb563f5SRyusuke Konishi * along with this program; if not, write to the Free Software 185eb563f5SRyusuke Konishi * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 195eb563f5SRyusuke Konishi * 205eb563f5SRyusuke Konishi * Written by Ryusuke Konishi <ryusuke@osrg.net> 215eb563f5SRyusuke Konishi */ 225eb563f5SRyusuke Konishi 235eb563f5SRyusuke Konishi #ifndef _NILFS_MDT_H 245eb563f5SRyusuke Konishi #define _NILFS_MDT_H 255eb563f5SRyusuke Konishi 265eb563f5SRyusuke Konishi #include <linux/buffer_head.h> 275eb563f5SRyusuke Konishi #include <linux/blockgroup_lock.h> 285eb563f5SRyusuke Konishi #include "nilfs.h" 295eb563f5SRyusuke Konishi #include "page.h" 305eb563f5SRyusuke Konishi 31ebdfed4dSRyusuke Konishi struct nilfs_shadow_map { 32ebdfed4dSRyusuke Konishi struct nilfs_bmap_store bmap_store; 33ebdfed4dSRyusuke Konishi struct address_space frozen_data; 34ebdfed4dSRyusuke Konishi struct address_space frozen_btnodes; 35ebdfed4dSRyusuke Konishi struct list_head frozen_buffers; 36ebdfed4dSRyusuke Konishi }; 37ebdfed4dSRyusuke Konishi 385eb563f5SRyusuke Konishi /** 395eb563f5SRyusuke Konishi * struct nilfs_mdt_info - on-memory private data of meta data files 405eb563f5SRyusuke Konishi * @mi_sem: reader/writer semaphore for meta data operations 415eb563f5SRyusuke Konishi * @mi_bgl: per-blockgroup locking 425eb563f5SRyusuke Konishi * @mi_entry_size: size of an entry 435eb563f5SRyusuke Konishi * @mi_first_entry_offset: offset to the first entry 445eb563f5SRyusuke Konishi * @mi_entries_per_block: number of entries in a block 45db38d5adSRyusuke Konishi * @mi_palloc_cache: persistent object allocator cache 46ebdfed4dSRyusuke Konishi * @mi_shadow: shadow of bmap and page caches 475eb563f5SRyusuke Konishi * @mi_blocks_per_group: number of blocks in a group 485eb563f5SRyusuke Konishi * @mi_blocks_per_desc_block: number of blocks per descriptor block 495eb563f5SRyusuke Konishi */ 505eb563f5SRyusuke Konishi struct nilfs_mdt_info { 515eb563f5SRyusuke Konishi struct rw_semaphore mi_sem; 525eb563f5SRyusuke Konishi struct blockgroup_lock *mi_bgl; 535eb563f5SRyusuke Konishi unsigned mi_entry_size; 545eb563f5SRyusuke Konishi unsigned mi_first_entry_offset; 555eb563f5SRyusuke Konishi unsigned long mi_entries_per_block; 56db38d5adSRyusuke Konishi struct nilfs_palloc_cache *mi_palloc_cache; 57ebdfed4dSRyusuke Konishi struct nilfs_shadow_map *mi_shadow; 585eb563f5SRyusuke Konishi unsigned long mi_blocks_per_group; 595eb563f5SRyusuke Konishi unsigned long mi_blocks_per_desc_block; 605eb563f5SRyusuke Konishi }; 615eb563f5SRyusuke Konishi 625eb563f5SRyusuke Konishi static inline struct nilfs_mdt_info *NILFS_MDT(const struct inode *inode) 635eb563f5SRyusuke Konishi { 645eb563f5SRyusuke Konishi return inode->i_private; 655eb563f5SRyusuke Konishi } 665eb563f5SRyusuke Konishi 675eb563f5SRyusuke Konishi /* Default GFP flags using highmem */ 685eb563f5SRyusuke Konishi #define NILFS_MDT_GFP (__GFP_WAIT | __GFP_IO | __GFP_HIGHMEM) 695eb563f5SRyusuke Konishi 705eb563f5SRyusuke Konishi int nilfs_mdt_get_block(struct inode *, unsigned long, int, 715eb563f5SRyusuke Konishi void (*init_block)(struct inode *, 725eb563f5SRyusuke Konishi struct buffer_head *, void *), 735eb563f5SRyusuke Konishi struct buffer_head **); 745eb563f5SRyusuke Konishi int nilfs_mdt_delete_block(struct inode *, unsigned long); 755eb563f5SRyusuke Konishi int nilfs_mdt_forget_block(struct inode *, unsigned long); 765eb563f5SRyusuke Konishi int nilfs_mdt_mark_block_dirty(struct inode *, unsigned long); 775eb563f5SRyusuke Konishi int nilfs_mdt_fetch_dirty(struct inode *); 785eb563f5SRyusuke Konishi 79f1e89c86SRyusuke Konishi int nilfs_mdt_init(struct inode *inode, gfp_t gfp_mask, size_t objsz); 805eb563f5SRyusuke Konishi void nilfs_mdt_set_entry_size(struct inode *, unsigned, unsigned); 815eb563f5SRyusuke Konishi 82ebdfed4dSRyusuke Konishi int nilfs_mdt_setup_shadow_map(struct inode *inode, 83ebdfed4dSRyusuke Konishi struct nilfs_shadow_map *shadow); 84ebdfed4dSRyusuke Konishi int nilfs_mdt_save_to_shadow_map(struct inode *inode); 85ebdfed4dSRyusuke Konishi void nilfs_mdt_restore_from_shadow_map(struct inode *inode); 86ebdfed4dSRyusuke Konishi void nilfs_mdt_clear_shadow_map(struct inode *inode); 87b1f6a4f2SRyusuke Konishi int nilfs_mdt_freeze_buffer(struct inode *inode, struct buffer_head *bh); 88b1f6a4f2SRyusuke Konishi struct buffer_head *nilfs_mdt_get_frozen_buffer(struct inode *inode, 89b1f6a4f2SRyusuke Konishi struct buffer_head *bh); 905eb563f5SRyusuke Konishi 915eb563f5SRyusuke Konishi #define nilfs_mdt_mark_buffer_dirty(bh) nilfs_mark_buffer_dirty(bh) 925eb563f5SRyusuke Konishi 935eb563f5SRyusuke Konishi static inline void nilfs_mdt_mark_dirty(struct inode *inode) 945eb563f5SRyusuke Konishi { 955eb563f5SRyusuke Konishi if (!test_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state)) 965eb563f5SRyusuke Konishi set_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state); 975eb563f5SRyusuke Konishi } 985eb563f5SRyusuke Konishi 995eb563f5SRyusuke Konishi static inline void nilfs_mdt_clear_dirty(struct inode *inode) 1005eb563f5SRyusuke Konishi { 1015eb563f5SRyusuke Konishi clear_bit(NILFS_I_DIRTY, &NILFS_I(inode)->i_state); 1025eb563f5SRyusuke Konishi } 1035eb563f5SRyusuke Konishi 1045eb563f5SRyusuke Konishi static inline __u64 nilfs_mdt_cno(struct inode *inode) 1055eb563f5SRyusuke Konishi { 106*0ef28f9aSRyusuke Konishi return ((struct the_nilfs *)inode->i_sb->s_fs_info)->ns_cno; 1075eb563f5SRyusuke Konishi } 1085eb563f5SRyusuke Konishi 1095eb563f5SRyusuke Konishi #define nilfs_mdt_bgl_lock(inode, bg) \ 1105eb563f5SRyusuke Konishi (&NILFS_MDT(inode)->mi_bgl->locks[(bg) & (NR_BG_LOCKS-1)].lock) 1115eb563f5SRyusuke Konishi 1125eb563f5SRyusuke Konishi #endif /* _NILFS_MDT_H */ 113