Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 149565
b: refs/heads/master
c: d4b9615
h: refs/heads/master
i:
  149563: a3f441a
v: v3
  • Loading branch information
Ryusuke Konishi committed Jun 10, 2009
1 parent 8b033a2 commit a3f39af
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 235 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 3033342a0b76048e32ce1faebfa85cf8f1aa93b5
refs/heads/master: d4b961576df2769b936bd967b01e8c607c3c9ad8
181 changes: 52 additions & 129 deletions trunk/fs/nilfs2/bmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,26 @@
#include "dat.h"
#include "alloc.h"

static struct inode *nilfs_bmap_get_dat(const struct nilfs_bmap *bmap)
{
return nilfs_dat_inode(NILFS_I_NILFS(bmap->b_inode));
}

int nilfs_bmap_lookup_at_level(struct nilfs_bmap *bmap, __u64 key, int level,
__u64 *ptrp)
{
__u64 ptr;
sector_t blocknr;
int ret;

down_read(&bmap->b_sem);
ret = bmap->b_ops->bop_lookup(bmap, key, level, ptrp);
if (ret < 0)
goto out;
if (bmap->b_pops->bpop_translate != NULL) {
ret = bmap->b_pops->bpop_translate(bmap, *ptrp, &ptr);
if (ret < 0)
goto out;
*ptrp = ptr;
if (NILFS_BMAP_USE_VBN(bmap)) {
ret = nilfs_dat_translate(nilfs_bmap_get_dat(bmap), *ptrp,
&blocknr);
if (!ret)
*ptrp = blocknr;
}

out:
Expand Down Expand Up @@ -442,11 +447,6 @@ __u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *bmap, __u64 key)
return NILFS_BMAP_INVALID_PTR;
}

static struct inode *nilfs_bmap_get_dat(const struct nilfs_bmap *bmap)
{
return nilfs_dat_inode(NILFS_I_NILFS(bmap->b_inode));
}

#define NILFS_BMAP_GROUP_DIV 8
__u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
{
Expand All @@ -459,20 +459,20 @@ __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *bmap)
(entries_per_group / NILFS_BMAP_GROUP_DIV);
}

static int nilfs_bmap_prepare_alloc_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
int nilfs_bmap_prepare_alloc_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
return nilfs_dat_prepare_alloc(nilfs_bmap_get_dat(bmap), &req->bpr_req);
}

static void nilfs_bmap_commit_alloc_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
void nilfs_bmap_commit_alloc_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
nilfs_dat_commit_alloc(nilfs_bmap_get_dat(bmap), &req->bpr_req);
}

static void nilfs_bmap_abort_alloc_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
void nilfs_bmap_abort_alloc_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
nilfs_dat_abort_alloc(nilfs_bmap_get_dat(bmap), &req->bpr_req);
}
Expand All @@ -489,26 +489,21 @@ int nilfs_bmap_start_v(struct nilfs_bmap *bmap, union nilfs_bmap_ptr_req *req,
return ret;
}

static int nilfs_bmap_prepare_end_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
int nilfs_bmap_prepare_end_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
return nilfs_dat_prepare_end(nilfs_bmap_get_dat(bmap), &req->bpr_req);
}

static void nilfs_bmap_commit_end_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
nilfs_dat_commit_end(nilfs_bmap_get_dat(bmap), &req->bpr_req, 0);
}

static void nilfs_bmap_commit_end_vmdt(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
void nilfs_bmap_commit_end_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
nilfs_dat_commit_end(nilfs_bmap_get_dat(bmap), &req->bpr_req, 1);
nilfs_dat_commit_end(nilfs_bmap_get_dat(bmap), &req->bpr_req,
bmap->b_ptr_type == NILFS_BMAP_PTR_VS);
}

static void nilfs_bmap_abort_end_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
void nilfs_bmap_abort_end_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
nilfs_dat_abort_end(nilfs_bmap_get_dat(bmap), &req->bpr_req);
}
Expand All @@ -524,116 +519,44 @@ int nilfs_bmap_mark_dirty(const struct nilfs_bmap *bmap, __u64 vblocknr)
return nilfs_dat_mark_dirty(nilfs_bmap_get_dat(bmap), vblocknr);
}

int nilfs_bmap_prepare_update(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *oldreq,
union nilfs_bmap_ptr_req *newreq)
int nilfs_bmap_prepare_update_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *oldreq,
union nilfs_bmap_ptr_req *newreq)
{
struct inode *dat = nilfs_bmap_get_dat(bmap);
int ret;

ret = bmap->b_pops->bpop_prepare_end_ptr(bmap, oldreq);
ret = nilfs_dat_prepare_end(dat, &oldreq->bpr_req);
if (ret < 0)
return ret;
ret = bmap->b_pops->bpop_prepare_alloc_ptr(bmap, newreq);
ret = nilfs_dat_prepare_alloc(dat, &newreq->bpr_req);
if (ret < 0)
bmap->b_pops->bpop_abort_end_ptr(bmap, oldreq);
nilfs_dat_abort_end(dat, &oldreq->bpr_req);

return ret;
}

void nilfs_bmap_commit_update(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *oldreq,
union nilfs_bmap_ptr_req *newreq)
{
bmap->b_pops->bpop_commit_end_ptr(bmap, oldreq);
bmap->b_pops->bpop_commit_alloc_ptr(bmap, newreq);
}

void nilfs_bmap_abort_update(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *oldreq,
union nilfs_bmap_ptr_req *newreq)
{
bmap->b_pops->bpop_abort_end_ptr(bmap, oldreq);
bmap->b_pops->bpop_abort_alloc_ptr(bmap, newreq);
}

static int nilfs_bmap_translate_v(const struct nilfs_bmap *bmap, __u64 ptr,
__u64 *ptrp)
void nilfs_bmap_commit_update_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *oldreq,
union nilfs_bmap_ptr_req *newreq)
{
sector_t blocknr;
int ret;

ret = nilfs_dat_translate(nilfs_bmap_get_dat(bmap), ptr, &blocknr);
if (ret < 0)
return ret;
if (ptrp != NULL)
*ptrp = blocknr;
return 0;
}
struct inode *dat = nilfs_bmap_get_dat(bmap);

static int nilfs_bmap_prepare_alloc_p(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
/* ignore target ptr */
req->bpr_ptr = bmap->b_last_allocated_ptr++;
return 0;
nilfs_dat_commit_end(dat, &oldreq->bpr_req,
bmap->b_ptr_type == NILFS_BMAP_PTR_VS);
nilfs_dat_commit_alloc(dat, &newreq->bpr_req);
}

static void nilfs_bmap_commit_alloc_p(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
void nilfs_bmap_abort_update_v(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *oldreq,
union nilfs_bmap_ptr_req *newreq)
{
/* do nothing */
}
struct inode *dat = nilfs_bmap_get_dat(bmap);

static void nilfs_bmap_abort_alloc_p(struct nilfs_bmap *bmap,
union nilfs_bmap_ptr_req *req)
{
bmap->b_last_allocated_ptr--;
nilfs_dat_abort_end(dat, &oldreq->bpr_req);
nilfs_dat_abort_alloc(dat, &newreq->bpr_req);
}

static const struct nilfs_bmap_ptr_operations nilfs_bmap_ptr_ops_v = {
.bpop_prepare_alloc_ptr = nilfs_bmap_prepare_alloc_v,
.bpop_commit_alloc_ptr = nilfs_bmap_commit_alloc_v,
.bpop_abort_alloc_ptr = nilfs_bmap_abort_alloc_v,
.bpop_prepare_end_ptr = nilfs_bmap_prepare_end_v,
.bpop_commit_end_ptr = nilfs_bmap_commit_end_v,
.bpop_abort_end_ptr = nilfs_bmap_abort_end_v,

.bpop_translate = nilfs_bmap_translate_v,
};

static const struct nilfs_bmap_ptr_operations nilfs_bmap_ptr_ops_vmdt = {
.bpop_prepare_alloc_ptr = nilfs_bmap_prepare_alloc_v,
.bpop_commit_alloc_ptr = nilfs_bmap_commit_alloc_v,
.bpop_abort_alloc_ptr = nilfs_bmap_abort_alloc_v,
.bpop_prepare_end_ptr = nilfs_bmap_prepare_end_v,
.bpop_commit_end_ptr = nilfs_bmap_commit_end_vmdt,
.bpop_abort_end_ptr = nilfs_bmap_abort_end_v,

.bpop_translate = nilfs_bmap_translate_v,
};

static const struct nilfs_bmap_ptr_operations nilfs_bmap_ptr_ops_p = {
.bpop_prepare_alloc_ptr = nilfs_bmap_prepare_alloc_p,
.bpop_commit_alloc_ptr = nilfs_bmap_commit_alloc_p,
.bpop_abort_alloc_ptr = nilfs_bmap_abort_alloc_p,
.bpop_prepare_end_ptr = NULL,
.bpop_commit_end_ptr = NULL,
.bpop_abort_end_ptr = NULL,

.bpop_translate = NULL,
};

static const struct nilfs_bmap_ptr_operations nilfs_bmap_ptr_ops_gc = {
.bpop_prepare_alloc_ptr = NULL,
.bpop_commit_alloc_ptr = NULL,
.bpop_abort_alloc_ptr = NULL,
.bpop_prepare_end_ptr = NULL,
.bpop_commit_end_ptr = NULL,
.bpop_abort_end_ptr = NULL,

.bpop_translate = NULL,
};

static struct lock_class_key nilfs_bmap_dat_lock_key;

/**
Expand All @@ -660,20 +583,20 @@ int nilfs_bmap_read(struct nilfs_bmap *bmap, struct nilfs_inode *raw_inode)
bmap->b_inode = &NILFS_BMAP_I(bmap)->vfs_inode;
switch (bmap->b_inode->i_ino) {
case NILFS_DAT_INO:
bmap->b_pops = &nilfs_bmap_ptr_ops_p;
bmap->b_last_allocated_key = 0; /* XXX: use macro */
bmap->b_ptr_type = NILFS_BMAP_PTR_P;
bmap->b_last_allocated_key = 0;
bmap->b_last_allocated_ptr = NILFS_BMAP_NEW_PTR_INIT;
lockdep_set_class(&bmap->b_sem, &nilfs_bmap_dat_lock_key);
break;
case NILFS_CPFILE_INO:
case NILFS_SUFILE_INO:
bmap->b_pops = &nilfs_bmap_ptr_ops_vmdt;
bmap->b_last_allocated_key = 0; /* XXX: use macro */
bmap->b_ptr_type = NILFS_BMAP_PTR_VS;
bmap->b_last_allocated_key = 0;
bmap->b_last_allocated_ptr = NILFS_BMAP_INVALID_PTR;
break;
default:
bmap->b_pops = &nilfs_bmap_ptr_ops_v;
bmap->b_last_allocated_key = 0; /* XXX: use macro */
bmap->b_ptr_type = NILFS_BMAP_PTR_VM;
bmap->b_last_allocated_key = 0;
bmap->b_last_allocated_ptr = NILFS_BMAP_INVALID_PTR;
break;
}
Expand Down Expand Up @@ -705,7 +628,7 @@ void nilfs_bmap_init_gc(struct nilfs_bmap *bmap)
memset(&bmap->b_u, 0, NILFS_BMAP_SIZE);
init_rwsem(&bmap->b_sem);
bmap->b_inode = &NILFS_BMAP_I(bmap)->vfs_inode;
bmap->b_pops = &nilfs_bmap_ptr_ops_gc;
bmap->b_ptr_type = NILFS_BMAP_PTR_U;
bmap->b_last_allocated_key = 0;
bmap->b_last_allocated_ptr = NILFS_BMAP_INVALID_PTR;
bmap->b_state = 0;
Expand Down
Loading

0 comments on commit a3f39af

Please sign in to comment.