Skip to content

Commit 26dfdd8

Browse files
committed
nilfs2: add read ahead mode to nilfs_btnode_submit_block
This adds mode argument to nilfs_btnode_submit_block() function and allows it to issue a read-ahead request. An optional submit_ptr argument is also added to store the actual block address for which bio is sent. submit_ptr is used for a series of read-ahead requests, and helps to decide if each requested block is continous to the previous one on disk. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent f8e6cc0 commit 26dfdd8

4 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎fs/nilfs2/btnode.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr)
9696
}
9797

9898
int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
99-
sector_t pblocknr, struct buffer_head **pbh)
99+
sector_t pblocknr, int mode,
100+
struct buffer_head **pbh, sector_t *submit_ptr)
100101
{
101102
struct buffer_head *bh;
102103
struct inode *inode = NILFS_BTNC_I(btnc);
@@ -127,7 +128,16 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
127128
}
128129
}
129130
}
130-
lock_buffer(bh);
131+
132+
if (mode == READA) {
133+
if (pblocknr != *submit_ptr + 1 || !trylock_buffer(bh)) {
134+
err = -EBUSY; /* internal code */
135+
brelse(bh);
136+
goto out_locked;
137+
}
138+
} else { /* mode == READ */
139+
lock_buffer(bh);
140+
}
131141
if (buffer_uptodate(bh)) {
132142
unlock_buffer(bh);
133143
err = -EEXIST; /* internal code */
@@ -138,8 +148,9 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
138148
bh->b_blocknr = pblocknr; /* set block address for read */
139149
bh->b_end_io = end_buffer_read_sync;
140150
get_bh(bh);
141-
submit_bh(READ, bh);
151+
submit_bh(mode, bh);
142152
bh->b_blocknr = blocknr; /* set back to the given block address */
153+
*submit_ptr = pblocknr;
143154
err = 0;
144155
found:
145156
*pbh = bh;

‎fs/nilfs2/btnode.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ void nilfs_btnode_cache_init(struct address_space *, struct backing_dev_info *);
4242
void nilfs_btnode_cache_clear(struct address_space *);
4343
struct buffer_head *nilfs_btnode_create_block(struct address_space *btnc,
4444
__u64 blocknr);
45-
int nilfs_btnode_submit_block(struct address_space *, __u64, sector_t,
46-
struct buffer_head **);
45+
int nilfs_btnode_submit_block(struct address_space *, __u64, sector_t, int,
46+
struct buffer_head **, sector_t *);
4747
void nilfs_btnode_delete(struct buffer_head *);
4848
int nilfs_btnode_prepare_change_key(struct address_space *,
4949
struct nilfs_btnode_chkey_ctxt *);

‎fs/nilfs2/btree.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ static int nilfs_btree_get_block(const struct nilfs_bmap *btree, __u64 ptr,
7171
{
7272
struct address_space *btnc = &NILFS_BMAP_I(btree)->i_btnode_cache;
7373
struct buffer_head *bh;
74+
sector_t pbn = 0;
7475
int err;
7576

76-
err = nilfs_btnode_submit_block(btnc, ptr, 0, bhp);
77+
err = nilfs_btnode_submit_block(btnc, ptr, pbn, READ, bhp, &pbn);
7778
if (err)
7879
return err == -EEXIST ? 0 : err;
7980

‎fs/nilfs2/gcinode.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
151151
int nilfs_gccache_submit_read_node(struct inode *inode, sector_t pbn,
152152
__u64 vbn, struct buffer_head **out_bh)
153153
{
154-
int ret = nilfs_btnode_submit_block(&NILFS_I(inode)->i_btnode_cache,
155-
vbn ? : pbn, pbn, out_bh);
154+
int ret;
155+
156+
ret = nilfs_btnode_submit_block(&NILFS_I(inode)->i_btnode_cache,
157+
vbn ? : pbn, pbn, READ, out_bh, &pbn);
156158
if (ret == -EEXIST) /* internal code (cache hit) */
157159
ret = 0;
158160
return ret;

0 commit comments

Comments
 (0)