Commit b2258094 authored by Ryusuke Konishi's avatar Ryusuke Konishi Committed by Linus Torvalds

nilfs2: get rid of nilfs_palloc_group_is_in()

This unfolds nilfs_palloc_group_is_in() helper function into
nilfs_palloc_freev() function to simplify a range check and an index
calculation repeatedy performed in a loop of the function.
Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 18c41b37
...@@ -672,22 +672,6 @@ void nilfs_palloc_abort_free_entry(struct inode *inode, ...@@ -672,22 +672,6 @@ void nilfs_palloc_abort_free_entry(struct inode *inode,
req->pr_desc_bh = NULL; req->pr_desc_bh = NULL;
} }
/**
* nilfs_palloc_group_is_in - judge if an entry is in a group
* @inode: inode of metadata file using this allocator
* @group: group number
* @nr: serial number of the entry (e.g. inode number)
*/
static int
nilfs_palloc_group_is_in(struct inode *inode, unsigned long group, __u64 nr)
{
__u64 first, last;
first = group * nilfs_palloc_entries_per_group(inode);
last = first + nilfs_palloc_entries_per_group(inode) - 1;
return (nr >= first) && (nr <= last);
}
/** /**
* nilfs_palloc_freev - deallocate a set of persistent objects * nilfs_palloc_freev - deallocate a set of persistent objects
* @inode: inode of metadata file using this allocator * @inode: inode of metadata file using this allocator
...@@ -701,6 +685,8 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems) ...@@ -701,6 +685,8 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
unsigned char *bitmap; unsigned char *bitmap;
void *desc_kaddr, *bitmap_kaddr; void *desc_kaddr, *bitmap_kaddr;
unsigned long group, group_offset; unsigned long group, group_offset;
__u64 group_min_nr;
const unsigned long epg = nilfs_palloc_entries_per_group(inode);
spinlock_t *lock; spinlock_t *lock;
int i, j, n, ret; int i, j, n, ret;
...@@ -715,6 +701,10 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems) ...@@ -715,6 +701,10 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
brelse(desc_bh); brelse(desc_bh);
return ret; return ret;
} }
/* Get the first entry number of the group */
group_min_nr = (__u64)group * epg;
desc_kaddr = kmap(desc_bh->b_page); desc_kaddr = kmap(desc_bh->b_page);
desc = nilfs_palloc_block_get_group_desc( desc = nilfs_palloc_block_get_group_desc(
inode, group, desc_bh, desc_kaddr); inode, group, desc_bh, desc_kaddr);
...@@ -722,10 +712,10 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems) ...@@ -722,10 +712,10 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
bitmap = bitmap_kaddr + bh_offset(bitmap_bh); bitmap = bitmap_kaddr + bh_offset(bitmap_bh);
lock = nilfs_mdt_bgl_lock(inode, group); lock = nilfs_mdt_bgl_lock(inode, group);
for (j = i, n = 0; for (j = i, n = 0;
(j < nitems) && nilfs_palloc_group_is_in(inode, group, j < nitems && entry_nrs[j] >= group_min_nr &&
entry_nrs[j]); entry_nrs[j] < group_min_nr + epg;
j++) { j++) {
nilfs_palloc_group(inode, entry_nrs[j], &group_offset); group_offset = entry_nrs[j] - group_min_nr;
if (!nilfs_clear_bit_atomic(lock, group_offset, if (!nilfs_clear_bit_atomic(lock, group_offset,
bitmap)) { bitmap)) {
nilfs_warning(inode->i_sb, __func__, nilfs_warning(inode->i_sb, __func__,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment