Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Persistent object (dat entry/disk inode) allocator/deallocator
0004  *
0005  * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * Originally written by Koji Sato.
0008  * Two allocators were unified by Ryusuke Konishi and Amagai Yoshiji.
0009  */
0010 
0011 #ifndef _NILFS_ALLOC_H
0012 #define _NILFS_ALLOC_H
0013 
0014 #include <linux/types.h>
0015 #include <linux/buffer_head.h>
0016 #include <linux/fs.h>
0017 
0018 /**
0019  * nilfs_palloc_entries_per_group - get the number of entries per group
0020  * @inode: inode of metadata file using this allocator
0021  *
0022  * The number of entries per group is defined by the number of bits
0023  * that a bitmap block can maintain.
0024  */
0025 static inline unsigned long
0026 nilfs_palloc_entries_per_group(const struct inode *inode)
0027 {
0028     return 1UL << (inode->i_blkbits + 3 /* log2(8 = CHAR_BITS) */);
0029 }
0030 
0031 int nilfs_palloc_init_blockgroup(struct inode *, unsigned int);
0032 int nilfs_palloc_get_entry_block(struct inode *, __u64, int,
0033                  struct buffer_head **);
0034 void *nilfs_palloc_block_get_entry(const struct inode *, __u64,
0035                    const struct buffer_head *, void *);
0036 
0037 int nilfs_palloc_count_max_entries(struct inode *, u64, u64 *);
0038 
0039 /**
0040  * nilfs_palloc_req - persistent allocator request and reply
0041  * @pr_entry_nr: entry number (vblocknr or inode number)
0042  * @pr_desc_bh: buffer head of the buffer containing block group descriptors
0043  * @pr_bitmap_bh: buffer head of the buffer containing a block group bitmap
0044  * @pr_entry_bh: buffer head of the buffer containing translation entries
0045  */
0046 struct nilfs_palloc_req {
0047     __u64 pr_entry_nr;
0048     struct buffer_head *pr_desc_bh;
0049     struct buffer_head *pr_bitmap_bh;
0050     struct buffer_head *pr_entry_bh;
0051 };
0052 
0053 int nilfs_palloc_prepare_alloc_entry(struct inode *,
0054                      struct nilfs_palloc_req *);
0055 void nilfs_palloc_commit_alloc_entry(struct inode *,
0056                      struct nilfs_palloc_req *);
0057 void nilfs_palloc_abort_alloc_entry(struct inode *, struct nilfs_palloc_req *);
0058 void nilfs_palloc_commit_free_entry(struct inode *, struct nilfs_palloc_req *);
0059 int nilfs_palloc_prepare_free_entry(struct inode *, struct nilfs_palloc_req *);
0060 void nilfs_palloc_abort_free_entry(struct inode *, struct nilfs_palloc_req *);
0061 int nilfs_palloc_freev(struct inode *, __u64 *, size_t);
0062 
0063 #define nilfs_set_bit_atomic        ext2_set_bit_atomic
0064 #define nilfs_clear_bit_atomic      ext2_clear_bit_atomic
0065 #define nilfs_find_next_zero_bit    find_next_zero_bit_le
0066 #define nilfs_find_next_bit     find_next_bit_le
0067 
0068 /**
0069  * struct nilfs_bh_assoc - block offset and buffer head association
0070  * @blkoff: block offset
0071  * @bh: buffer head
0072  */
0073 struct nilfs_bh_assoc {
0074     unsigned long blkoff;
0075     struct buffer_head *bh;
0076 };
0077 
0078 /**
0079  * struct nilfs_palloc_cache - persistent object allocator cache
0080  * @lock: cache protecting lock
0081  * @prev_desc: blockgroup descriptors cache
0082  * @prev_bitmap: blockgroup bitmap cache
0083  * @prev_entry: translation entries cache
0084  */
0085 struct nilfs_palloc_cache {
0086     spinlock_t lock;
0087     struct nilfs_bh_assoc prev_desc;
0088     struct nilfs_bh_assoc prev_bitmap;
0089     struct nilfs_bh_assoc prev_entry;
0090 };
0091 
0092 void nilfs_palloc_setup_cache(struct inode *inode,
0093                   struct nilfs_palloc_cache *cache);
0094 void nilfs_palloc_clear_cache(struct inode *inode);
0095 void nilfs_palloc_destroy_cache(struct inode *inode);
0096 
0097 #endif  /* _NILFS_ALLOC_H */