Skip to content

Commit

Permalink
ocfs2: Take the inode out of the metadata read/write paths.
Browse files Browse the repository at this point in the history
We are really passing the inode into the ocfs2_read/write_blocks()
functions to get at the metadata cache.  This commit passes the cache
directly into the metadata block functions, divorcing them from the
inode.

Signed-off-by: Joel Becker <[email protected]>
  • Loading branch information
Joel Becker committed Sep 4, 2009
1 parent 6e5a3d7 commit 8cb471e
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 134 deletions.
13 changes: 7 additions & 6 deletions fs/ocfs2/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ int ocfs2_read_extent_block(struct inode *inode, u64 eb_blkno,
int rc;
struct buffer_head *tmp = *bh;

rc = ocfs2_read_block(inode, eb_blkno, &tmp,
rc = ocfs2_read_block(INODE_CACHE(inode), eb_blkno, &tmp,
ocfs2_validate_extent_block);

/* If ocfs2_read_block() got us a new bh, pass it up. */
Expand Down Expand Up @@ -949,7 +949,8 @@ static int ocfs2_create_new_meta_bhs(struct ocfs2_super *osb,
mlog_errno(status);
goto bail;
}
ocfs2_set_new_buffer_uptodate(inode, bhs[i]);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode),
bhs[i]);

status = ocfs2_journal_access_eb(handle, inode, bhs[i],
OCFS2_JOURNAL_ACCESS_CREATE);
Expand Down Expand Up @@ -2559,7 +2560,7 @@ static void ocfs2_unlink_path(struct inode *inode, handle_t *handle,
le16_to_cpu(el->l_next_free_rec));

ocfs2_journal_dirty(handle, bh);
ocfs2_remove_from_cache(inode, bh);
ocfs2_remove_from_cache(INODE_CACHE(inode), bh);
continue;
}

Expand All @@ -2572,7 +2573,7 @@ static void ocfs2_unlink_path(struct inode *inode, handle_t *handle,
if (ret)
mlog_errno(ret);

ocfs2_remove_from_cache(inode, bh);
ocfs2_remove_from_cache(INODE_CACHE(inode), bh);
}
}

Expand Down Expand Up @@ -6010,7 +6011,7 @@ int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb,
tl->tl_used = 0;

ocfs2_compute_meta_ecc(osb->sb, tl_bh->b_data, &di->i_check);
status = ocfs2_write_block(osb, tl_bh, tl_inode);
status = ocfs2_write_block(osb, tl_bh, INODE_CACHE(tl_inode));
if (status < 0) {
mlog_errno(status);
goto bail;
Expand Down Expand Up @@ -6719,7 +6720,7 @@ static int ocfs2_trim_tree(struct inode *inode, struct ocfs2_path *path,

mlog(0, "deleting this extent block.\n");

ocfs2_remove_from_cache(inode, bh);
ocfs2_remove_from_cache(INODE_CACHE(inode), bh);

BUG_ON(ocfs2_rec_clusters(el, &el->l_recs[0]));
BUG_ON(le32_to_cpu(el->l_recs[0].e_cpos));
Expand Down
47 changes: 24 additions & 23 deletions fs/ocfs2/buffer_head_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ enum ocfs2_state_bits {
BUFFER_FNS(NeedsValidate, needs_validate);

int ocfs2_write_block(struct ocfs2_super *osb, struct buffer_head *bh,
struct inode *inode)
struct ocfs2_caching_info *ci)
{
int ret = 0;

mlog_entry("(bh->b_blocknr = %llu, inode=%p)\n",
(unsigned long long)bh->b_blocknr, inode);
mlog_entry("(bh->b_blocknr = %llu, ci=%p)\n",
(unsigned long long)bh->b_blocknr, ci);

BUG_ON(bh->b_blocknr < OCFS2_SUPER_BLOCK_BLKNO);
BUG_ON(buffer_jbd(bh));
Expand All @@ -70,7 +70,7 @@ int ocfs2_write_block(struct ocfs2_super *osb, struct buffer_head *bh,
goto out;
}

mutex_lock(&OCFS2_I(inode)->ip_io_mutex);
ocfs2_metadata_cache_io_lock(ci);

lock_buffer(bh);
set_buffer_uptodate(bh);
Expand All @@ -85,7 +85,7 @@ int ocfs2_write_block(struct ocfs2_super *osb, struct buffer_head *bh,
wait_on_buffer(bh);

if (buffer_uptodate(bh)) {
ocfs2_set_buffer_uptodate(inode, bh);
ocfs2_set_buffer_uptodate(ci, bh);
} else {
/* We don't need to remove the clustered uptodate
* information for this bh as it's not marked locally
Expand All @@ -94,7 +94,7 @@ int ocfs2_write_block(struct ocfs2_super *osb, struct buffer_head *bh,
put_bh(bh);
}

mutex_unlock(&OCFS2_I(inode)->ip_io_mutex);
ocfs2_metadata_cache_io_unlock(ci);
out:
mlog_exit(ret);
return ret;
Expand Down Expand Up @@ -177,19 +177,20 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
return status;
}

int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
struct buffer_head *bhs[], int flags,
int (*validate)(struct super_block *sb,
struct buffer_head *bh))
{
int status = 0;
int i, ignore_cache = 0;
struct buffer_head *bh;
struct super_block *sb = ocfs2_metadata_cache_get_super(ci);

mlog_entry("(inode=%p, block=(%llu), nr=(%d), flags=%d)\n",
inode, (unsigned long long)block, nr, flags);
mlog_entry("(ci=%p, block=(%llu), nr=(%d), flags=%d)\n",
ci, (unsigned long long)block, nr, flags);

BUG_ON(!inode);
BUG_ON(!ci);
BUG_ON((flags & OCFS2_BH_READAHEAD) &&
(flags & OCFS2_BH_IGNORE_CACHE));

Expand All @@ -212,12 +213,12 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
goto bail;
}

mutex_lock(&OCFS2_I(inode)->ip_io_mutex);
ocfs2_metadata_cache_io_lock(ci);
for (i = 0 ; i < nr ; i++) {
if (bhs[i] == NULL) {
bhs[i] = sb_getblk(inode->i_sb, block++);
bhs[i] = sb_getblk(sb, block++);
if (bhs[i] == NULL) {
mutex_unlock(&OCFS2_I(inode)->ip_io_mutex);
ocfs2_metadata_cache_io_unlock(ci);
status = -EIO;
mlog_errno(status);
goto bail;
Expand Down Expand Up @@ -250,11 +251,11 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
* before our is-it-in-flight check.
*/

if (!ignore_cache && !ocfs2_buffer_uptodate(inode, bh)) {
if (!ignore_cache && !ocfs2_buffer_uptodate(ci, bh)) {
mlog(ML_UPTODATE,
"bh (%llu), inode %llu not uptodate\n",
"bh (%llu), owner %llu not uptodate\n",
(unsigned long long)bh->b_blocknr,
(unsigned long long)OCFS2_I(inode)->ip_blkno);
(unsigned long long)ocfs2_metadata_cache_owner(ci));
/* We're using ignore_cache here to say
* "go to disk" */
ignore_cache = 1;
Expand Down Expand Up @@ -283,7 +284,7 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
* previously submitted request than we are
* done here. */
if ((flags & OCFS2_BH_READAHEAD)
&& ocfs2_buffer_read_ahead(inode, bh))
&& ocfs2_buffer_read_ahead(ci, bh))
continue;

lock_buffer(bh);
Expand All @@ -305,7 +306,7 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
* buffer lock. */
if (!(flags & OCFS2_BH_IGNORE_CACHE)
&& !(flags & OCFS2_BH_READAHEAD)
&& ocfs2_buffer_uptodate(inode, bh)) {
&& ocfs2_buffer_uptodate(ci, bh)) {
unlock_buffer(bh);
continue;
}
Expand All @@ -327,7 +328,7 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,

if (!(flags & OCFS2_BH_READAHEAD)) {
/* We know this can't have changed as we hold the
* inode sem. Avoid doing any work on the bh if the
* owner sem. Avoid doing any work on the bh if the
* journal has it. */
if (!buffer_jbd(bh))
wait_on_buffer(bh);
Expand All @@ -351,7 +352,7 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
* that better not have changed */
BUG_ON(buffer_jbd(bh));
clear_buffer_needs_validate(bh);
status = validate(inode->i_sb, bh);
status = validate(sb, bh);
if (status) {
put_bh(bh);
bhs[i] = NULL;
Expand All @@ -363,9 +364,9 @@ int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
/* Always set the buffer in the cache, even if it was
* a forced read, or read-ahead which hasn't yet
* completed. */
ocfs2_set_buffer_uptodate(inode, bh);
ocfs2_set_buffer_uptodate(ci, bh);
}
mutex_unlock(&OCFS2_I(inode)->ip_io_mutex);
ocfs2_metadata_cache_io_unlock(ci);

mlog(ML_BH_IO, "block=(%llu), nr=(%d), cached=%s, flags=0x%x\n",
(unsigned long long)block, nr,
Expand Down Expand Up @@ -399,7 +400,7 @@ static void ocfs2_check_super_or_backup(struct super_block *sb,

/*
* Write super block and backups doesn't need to collaborate with journal,
* so we don't need to lock ip_io_mutex and inode doesn't need to bea passed
* so we don't need to lock ip_io_mutex and ci doesn't need to bea passed
* into this function.
*/
int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
Expand Down
8 changes: 4 additions & 4 deletions fs/ocfs2/buffer_head_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ocfs2_end_buffer_io_sync(struct buffer_head *bh,

int ocfs2_write_block(struct ocfs2_super *osb,
struct buffer_head *bh,
struct inode *inode);
struct ocfs2_caching_info *ci);
int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
unsigned int nr, struct buffer_head *bhs[]);

Expand All @@ -44,7 +44,7 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
* be set even for a READAHEAD call, as it marks the buffer for later
* validation.
*/
int ocfs2_read_blocks(struct inode *inode, u64 block, int nr,
int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
struct buffer_head *bhs[], int flags,
int (*validate)(struct super_block *sb,
struct buffer_head *bh));
Expand All @@ -55,7 +55,7 @@ int ocfs2_write_super_or_backup(struct ocfs2_super *osb,
#define OCFS2_BH_IGNORE_CACHE 1
#define OCFS2_BH_READAHEAD 8

static inline int ocfs2_read_block(struct inode *inode, u64 off,
static inline int ocfs2_read_block(struct ocfs2_caching_info *ci, u64 off,
struct buffer_head **bh,
int (*validate)(struct super_block *sb,
struct buffer_head *bh))
Expand All @@ -68,7 +68,7 @@ static inline int ocfs2_read_block(struct inode *inode, u64 off,
goto bail;
}

status = ocfs2_read_blocks(inode, off, 1, bh, 0, validate);
status = ocfs2_read_blocks(ci, off, 1, bh, 0, validate);

bail:
return status;
Expand Down
23 changes: 13 additions & 10 deletions fs/ocfs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ static int ocfs2_read_dir_block_direct(struct inode *dir, u64 phys,
int ret;
struct buffer_head *tmp = *bh;

ret = ocfs2_read_block(dir, phys, &tmp, ocfs2_validate_dir_block);
ret = ocfs2_read_block(INODE_CACHE(dir), phys, &tmp,
ocfs2_validate_dir_block);
if (ret) {
mlog_errno(ret);
goto out;
Expand Down Expand Up @@ -622,7 +623,8 @@ static int ocfs2_read_dx_root(struct inode *dir, struct ocfs2_dinode *di,
u64 blkno = le64_to_cpu(di->i_dx_root);
struct buffer_head *tmp = *dx_root_bh;

ret = ocfs2_read_block(dir, blkno, &tmp, ocfs2_validate_dx_root);
ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp,
ocfs2_validate_dx_root);

/* If ocfs2_read_block() got us a new bh, pass it up. */
if (!ret && !*dx_root_bh)
Expand Down Expand Up @@ -662,7 +664,8 @@ static int ocfs2_read_dx_leaf(struct inode *dir, u64 blkno,
int ret;
struct buffer_head *tmp = *dx_leaf_bh;

ret = ocfs2_read_block(dir, blkno, &tmp, ocfs2_validate_dx_leaf);
ret = ocfs2_read_block(INODE_CACHE(dir), blkno, &tmp,
ocfs2_validate_dx_leaf);

/* If ocfs2_read_block() got us a new bh, pass it up. */
if (!ret && !*dx_leaf_bh)
Expand All @@ -680,7 +683,7 @@ static int ocfs2_read_dx_leaves(struct inode *dir, u64 start, int num,
{
int ret;

ret = ocfs2_read_blocks(dir, start, num, dx_leaf_bhs, 0,
ret = ocfs2_read_blocks(INODE_CACHE(dir), start, num, dx_leaf_bhs, 0,
ocfs2_validate_dx_leaf);
if (ret)
mlog_errno(ret);
Expand Down Expand Up @@ -2332,7 +2335,7 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb,
goto bail;
}

ocfs2_set_new_buffer_uptodate(inode, new_bh);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh);

status = ocfs2_journal_access_db(handle, inode, new_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
Expand Down Expand Up @@ -2418,7 +2421,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
ret = -EIO;
goto out;
}
ocfs2_set_new_buffer_uptodate(dir, dx_root_bh);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dx_root_bh);

ret = ocfs2_journal_access_dr(handle, dir, dx_root_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
Expand Down Expand Up @@ -2495,7 +2498,7 @@ static int ocfs2_dx_dir_format_cluster(struct ocfs2_super *osb,
}
dx_leaves[i] = bh;

ocfs2_set_new_buffer_uptodate(dir, bh);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), bh);

ret = ocfs2_journal_access_dl(handle, dir, bh,
OCFS2_JOURNAL_ACCESS_CREATE);
Expand Down Expand Up @@ -3005,7 +3008,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
goto out_commit;
}

ocfs2_set_new_buffer_uptodate(dir, dirdata_bh);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), dirdata_bh);

ret = ocfs2_journal_access_db(handle, dir, dirdata_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
Expand Down Expand Up @@ -3387,7 +3390,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
goto bail;
}

ocfs2_set_new_buffer_uptodate(dir, new_bh);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(dir), new_bh);

status = ocfs2_journal_access_db(handle, dir, new_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
Expand Down Expand Up @@ -4565,7 +4568,7 @@ int ocfs2_dx_dir_truncate(struct inode *dir, struct buffer_head *di_bh)
goto out;
}

ocfs2_remove_from_cache(dir, dx_root_bh);
ocfs2_remove_from_cache(INODE_CACHE(dir), dx_root_bh);
out:
ocfs2_schedule_truncate_log_flush(osb, 1);
ocfs2_run_deallocs(osb, &dealloc);
Expand Down
2 changes: 1 addition & 1 deletion fs/ocfs2/dlmglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ static int ocfs2_inode_lock_update(struct inode *inode,

/* This will discard any caching information we might have had
* for the inode metadata. */
ocfs2_metadata_cache_purge(inode);
ocfs2_metadata_cache_purge(INODE_CACHE(inode));

ocfs2_extent_map_trunc(inode, 0);

Expand Down
4 changes: 2 additions & 2 deletions fs/ocfs2/extent_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,8 @@ int ocfs2_read_virt_blocks(struct inode *inode, u64 v_block, int nr,
BUG_ON(bhs[done + i]->b_blocknr != (p_block + i));
}

rc = ocfs2_read_blocks(inode, p_block, count, bhs + done,
flags, validate);
rc = ocfs2_read_blocks(INODE_CACHE(inode), p_block, count,
bhs + done, flags, validate);
if (rc) {
mlog_errno(rc);
break;
Expand Down
Loading

0 comments on commit 8cb471e

Please sign in to comment.