xref: /OK3568_Linux_fs/kernel/fs/nilfs2/alloc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * alloc.h - persistent object (dat entry/disk inode) allocator/deallocator
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Originally written by Koji Sato.
8*4882a593Smuzhiyun  * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #ifndef _NILFS_ALLOC_H
12*4882a593Smuzhiyun #define _NILFS_ALLOC_H
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #include <linux/types.h>
15*4882a593Smuzhiyun #include <linux/buffer_head.h>
16*4882a593Smuzhiyun #include <linux/fs.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /**
19*4882a593Smuzhiyun  * nilfs_palloc_entries_per_group - get the number of entries per group
20*4882a593Smuzhiyun  * @inode: inode of metadata file using this allocator
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * The number of entries per group is defined by the number of bits
23*4882a593Smuzhiyun  * that a bitmap block can maintain.
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun static inline unsigned long
nilfs_palloc_entries_per_group(const struct inode * inode)26*4882a593Smuzhiyun nilfs_palloc_entries_per_group(const struct inode *inode)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun 	return 1UL << (inode->i_blkbits + 3 /* log2(8 = CHAR_BITS) */);
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun int nilfs_palloc_init_blockgroup(struct inode *, unsigned int);
32*4882a593Smuzhiyun int nilfs_palloc_get_entry_block(struct inode *, __u64, int,
33*4882a593Smuzhiyun 				 struct buffer_head **);
34*4882a593Smuzhiyun void *nilfs_palloc_block_get_entry(const struct inode *, __u64,
35*4882a593Smuzhiyun 				   const struct buffer_head *, void *);
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun int nilfs_palloc_count_max_entries(struct inode *, u64, u64 *);
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /**
40*4882a593Smuzhiyun  * nilfs_palloc_req - persistent allocator request and reply
41*4882a593Smuzhiyun  * @pr_entry_nr: entry number (vblocknr or inode number)
42*4882a593Smuzhiyun  * @pr_desc_bh: buffer head of the buffer containing block group descriptors
43*4882a593Smuzhiyun  * @pr_bitmap_bh: buffer head of the buffer containing a block group bitmap
44*4882a593Smuzhiyun  * @pr_entry_bh: buffer head of the buffer containing translation entries
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun struct nilfs_palloc_req {
47*4882a593Smuzhiyun 	__u64 pr_entry_nr;
48*4882a593Smuzhiyun 	struct buffer_head *pr_desc_bh;
49*4882a593Smuzhiyun 	struct buffer_head *pr_bitmap_bh;
50*4882a593Smuzhiyun 	struct buffer_head *pr_entry_bh;
51*4882a593Smuzhiyun };
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun int nilfs_palloc_prepare_alloc_entry(struct inode *,
54*4882a593Smuzhiyun 				     struct nilfs_palloc_req *);
55*4882a593Smuzhiyun void nilfs_palloc_commit_alloc_entry(struct inode *,
56*4882a593Smuzhiyun 				     struct nilfs_palloc_req *);
57*4882a593Smuzhiyun void nilfs_palloc_abort_alloc_entry(struct inode *, struct nilfs_palloc_req *);
58*4882a593Smuzhiyun void nilfs_palloc_commit_free_entry(struct inode *, struct nilfs_palloc_req *);
59*4882a593Smuzhiyun int nilfs_palloc_prepare_free_entry(struct inode *, struct nilfs_palloc_req *);
60*4882a593Smuzhiyun void nilfs_palloc_abort_free_entry(struct inode *, struct nilfs_palloc_req *);
61*4882a593Smuzhiyun int nilfs_palloc_freev(struct inode *, __u64 *, size_t);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun #define nilfs_set_bit_atomic		ext2_set_bit_atomic
64*4882a593Smuzhiyun #define nilfs_clear_bit_atomic		ext2_clear_bit_atomic
65*4882a593Smuzhiyun #define nilfs_find_next_zero_bit	find_next_zero_bit_le
66*4882a593Smuzhiyun #define nilfs_find_next_bit		find_next_bit_le
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /**
69*4882a593Smuzhiyun  * struct nilfs_bh_assoc - block offset and buffer head association
70*4882a593Smuzhiyun  * @blkoff: block offset
71*4882a593Smuzhiyun  * @bh: buffer head
72*4882a593Smuzhiyun  */
73*4882a593Smuzhiyun struct nilfs_bh_assoc {
74*4882a593Smuzhiyun 	unsigned long blkoff;
75*4882a593Smuzhiyun 	struct buffer_head *bh;
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun /**
79*4882a593Smuzhiyun  * struct nilfs_palloc_cache - persistent object allocator cache
80*4882a593Smuzhiyun  * @lock: cache protecting lock
81*4882a593Smuzhiyun  * @prev_desc: blockgroup descriptors cache
82*4882a593Smuzhiyun  * @prev_bitmap: blockgroup bitmap cache
83*4882a593Smuzhiyun  * @prev_entry: translation entries cache
84*4882a593Smuzhiyun  */
85*4882a593Smuzhiyun struct nilfs_palloc_cache {
86*4882a593Smuzhiyun 	spinlock_t lock;
87*4882a593Smuzhiyun 	struct nilfs_bh_assoc prev_desc;
88*4882a593Smuzhiyun 	struct nilfs_bh_assoc prev_bitmap;
89*4882a593Smuzhiyun 	struct nilfs_bh_assoc prev_entry;
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun void nilfs_palloc_setup_cache(struct inode *inode,
93*4882a593Smuzhiyun 			      struct nilfs_palloc_cache *cache);
94*4882a593Smuzhiyun void nilfs_palloc_clear_cache(struct inode *inode);
95*4882a593Smuzhiyun void nilfs_palloc_destroy_cache(struct inode *inode);
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun #endif	/* _NILFS_ALLOC_H */
98