Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70622a20 authored by Ryusuke Konishi's avatar Ryusuke Konishi
Browse files

nilfs2: insert cache operation in palloc get block routines



This implements cache operation in get block routines of palloc code:
nilfs_palloc_get_desc_block(), nilfs_palloc_get_bitmap_block(), and
nilfs_palloc_get_entry_block().

This will complete the palloc cache.

Signed-off-by: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
parent 49fa7a59
Loading
Loading
Loading
Loading
+54 −8
Original line number Original line Diff line number Diff line
@@ -142,29 +142,75 @@ static void nilfs_palloc_desc_block_init(struct inode *inode,
	}
	}
}
}


static int nilfs_palloc_get_block(struct inode *inode, unsigned long blkoff,
				  int create,
				  void (*init_block)(struct inode *,
						     struct buffer_head *,
						     void *),
				  struct buffer_head **bhp,
				  struct nilfs_bh_assoc *prev,
				  spinlock_t *lock)
{
	int ret;

	spin_lock(lock);
	if (prev->bh && blkoff == prev->blkoff) {
		get_bh(prev->bh);
		*bhp = prev->bh;
		spin_unlock(lock);
		return 0;
	}
	spin_unlock(lock);

	ret = nilfs_mdt_get_block(inode, blkoff, create, init_block, bhp);
	if (!ret) {
		spin_lock(lock);
		/*
		 * The following code must be safe for change of the
		 * cache contents during the get block call.
		 */
		brelse(prev->bh);
		get_bh(*bhp);
		prev->bh = *bhp;
		prev->blkoff = blkoff;
		spin_unlock(lock);
	}
	return ret;
}

static int nilfs_palloc_get_desc_block(struct inode *inode,
static int nilfs_palloc_get_desc_block(struct inode *inode,
				       unsigned long group,
				       unsigned long group,
				       int create, struct buffer_head **bhp)
				       int create, struct buffer_head **bhp)
{
{
	return nilfs_mdt_get_block(inode,
	struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache;

	return nilfs_palloc_get_block(inode,
				      nilfs_palloc_desc_blkoff(inode, group),
				      nilfs_palloc_desc_blkoff(inode, group),
				   create, nilfs_palloc_desc_block_init, bhp);
				      create, nilfs_palloc_desc_block_init,
				      bhp, &cache->prev_desc, &cache->lock);
}
}


static int nilfs_palloc_get_bitmap_block(struct inode *inode,
static int nilfs_palloc_get_bitmap_block(struct inode *inode,
					 unsigned long group,
					 unsigned long group,
					 int create, struct buffer_head **bhp)
					 int create, struct buffer_head **bhp)
{
{
	return nilfs_mdt_get_block(inode,
	struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache;

	return nilfs_palloc_get_block(inode,
				      nilfs_palloc_bitmap_blkoff(inode, group),
				      nilfs_palloc_bitmap_blkoff(inode, group),
				   create, NULL, bhp);
				      create, NULL, bhp,
				      &cache->prev_bitmap, &cache->lock);
}
}


int nilfs_palloc_get_entry_block(struct inode *inode, __u64 nr,
int nilfs_palloc_get_entry_block(struct inode *inode, __u64 nr,
				 int create, struct buffer_head **bhp)
				 int create, struct buffer_head **bhp)
{
{
	return nilfs_mdt_get_block(inode, nilfs_palloc_entry_blkoff(inode, nr),
	struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache;
				   create, NULL, bhp);

	return nilfs_palloc_get_block(inode,
				      nilfs_palloc_entry_blkoff(inode, nr),
				      create, NULL, bhp,
				      &cache->prev_entry, &cache->lock);
}
}


static struct nilfs_palloc_group_desc *
static struct nilfs_palloc_group_desc *