};
typedef int (*block_call_t) (struct gfs2_inode *ip, struct buffer_head *dibh,
- struct buffer_head *bh, uint64_t *top,
- uint64_t *bottom, unsigned int height,
+ struct buffer_head *bh, u64 *top,
+ u64 *bottom, unsigned int height,
void *data);
struct strip_mine {
*/
static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
- uint64_t block, struct page *page)
+ u64 block, struct page *page)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct inode *inode = &ip->i_inode;
int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
{
struct buffer_head *bh, *dibh;
- uint64_t block = 0;
+ u64 block = 0;
int isdir = gfs2_is_dir(ip);
int error;
gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
if (ip->i_di.di_size) {
- *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) =
+ *(u64 *)(dibh->b_data + sizeof(struct gfs2_dinode)) =
cpu_to_be64(block);
ip->i_di.di_blocks++;
}
gfs2_dinode_out(&ip->i_di, dibh->b_data);
- out_brelse:
+out_brelse:
brelse(dibh);
-
- out:
+out:
up_write(&ip->i_rw_mutex);
-
return error;
}
* Returns: the height the tree should be
*/
-static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
+static unsigned int calc_tree_height(struct gfs2_inode *ip, u64 size)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
- uint64_t *arr;
+ u64 *arr;
unsigned int max, height;
if (ip->i_di.di_size > size)
*
*/
-static void find_metapath(struct gfs2_inode *ip, uint64_t block,
+static void find_metapath(struct gfs2_inode *ip, u64 block,
struct metapath *mp)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
- uint64_t b = block;
+ u64 b = block;
unsigned int i;
for (i = ip->i_di.di_height; i--;)
- mp->mp_list[i] = (__u16)do_div(b, sdp->sd_inptrs);
+ mp->mp_list[i] = do_div(b, sdp->sd_inptrs);
}
static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh,
unsigned int height, struct metapath *mp, int create,
- int *new, uint64_t *block)
+ int *new, u64 *block)
{
int boundary;
- uint64_t *ptr = metapointer(bh, &boundary, height, mp);
+ u64 *ptr = metapointer(bh, &boundary, height, mp);
if (*ptr) {
*block = be64_to_cpu(*ptr);
* gfs2_block_pointers - Map a block from an inode to a disk block
* @inode: The inode
* @lblock: The logical block number
- * @new: Value/Result argument (1 = may create/did create new blocks)
- * @boundary: gets set if we've hit a block boundary
+ * @map_bh: The bh to be mapped
* @mp: metapath to use
*
* Find the block number on the current device which corresponds to an
* Returns: errno
*/
-static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock,
- int *new, u64 *dblock,
- int *boundary,
- struct metapath *mp)
+static int gfs2_block_pointers(struct inode *inode, u64 lblock, int create,
+ struct buffer_head *bh_map, struct metapath *mp,
+ unsigned int maxlen)
{
struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_sbd *sdp = GFS2_SB(inode);
struct buffer_head *bh;
- int create = *new;
unsigned int bsize;
unsigned int height;
unsigned int end_of_metadata;
unsigned int x;
int error = 0;
-
- *new = 0;
- *dblock = 0;
+ int new = 0;
+ u64 dblock = 0;
+ int boundary;
if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip)))
- goto out;
+ return 0;
bsize = gfs2_is_dir(ip) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize;
height = calc_tree_height(ip, (lblock + 1) * bsize);
if (ip->i_di.di_height < height) {
if (!create)
- goto out;
+ return 0;
error = build_height(inode, height);
if (error)
- goto out;
+ return error;
}
find_metapath(ip, lblock, mp);
error = gfs2_meta_inode_buffer(ip, &bh);
if (error)
- goto out;
+ return error;
for (x = 0; x < end_of_metadata; x++) {
- lookup_block(ip, bh, x, mp, create, new, dblock);
+ lookup_block(ip, bh, x, mp, create, &new, &dblock);
brelse(bh);
- if (!*dblock)
- goto out;
+ if (!dblock)
+ return 0;
- error = gfs2_meta_indirect_buffer(ip, x+1, *dblock, *new, &bh);
+ error = gfs2_meta_indirect_buffer(ip, x+1, dblock, new, &bh);
if (error)
- goto out;
+ return error;
}
- *boundary = lookup_block(ip, bh, end_of_metadata, mp, create, new, dblock);
- if (*new) {
- struct buffer_head *dibh;
- error = gfs2_meta_inode_buffer(ip, &dibh);
- if (!error) {
- gfs2_trans_add_bh(ip->i_gl, dibh, 1);
- gfs2_dinode_out(&ip->i_di, dibh->b_data);
- brelse(dibh);
+ boundary = lookup_block(ip, bh, end_of_metadata, mp, create, &new, &dblock);
+ clear_buffer_mapped(bh_map);
+ clear_buffer_new(bh_map);
+ clear_buffer_boundary(bh_map);
+
+ if (dblock) {
+ map_bh(bh_map, inode->i_sb, dblock);
+ if (boundary)
+ set_buffer_boundary(bh);
+ if (new) {
+ struct buffer_head *dibh;
+ error = gfs2_meta_inode_buffer(ip, &dibh);
+ if (!error) {
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
+ gfs2_dinode_out(&ip->i_di, dibh->b_data);
+ brelse(dibh);
+ }
+ set_buffer_new(bh_map);
+ goto out_brelse;
+ }
+ while(--maxlen && !buffer_boundary(bh_map)) {
+ u64 eblock;
+
+ mp->mp_list[end_of_metadata]++;
+ boundary = lookup_block(ip, bh, end_of_metadata, mp, 0, &new, &eblock);
+ if (eblock != ++dblock)
+ break;
+ bh_map->b_size += (1 << inode->i_blkbits);
+ if (boundary)
+ set_buffer_boundary(bh_map);
}
}
- return bh;
-out:
- return ERR_PTR(error);
+out_brelse:
+ brelse(bh);
+ return 0;
}
up_read(&ip->i_rw_mutex);
}
-int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary)
+int gfs2_block_map(struct inode *inode, u64 lblock, int create,
+ struct buffer_head *bh, unsigned int maxlen)
{
struct metapath mp;
- struct buffer_head *bh;
- int create = *new;
+ int ret;
bmap_lock(inode, create);
- bh = gfs2_block_pointers(inode, lblock, new, dblock, boundary, &mp);
+ ret = gfs2_block_pointers(inode, lblock, create, bh, &mp, maxlen);
bmap_unlock(inode, create);
- if (!bh)
- return 0;
- if (IS_ERR(bh))
- return PTR_ERR(bh);
- brelse(bh);
- return 0;
+ return ret;
}
int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen)
{
- struct gfs2_inode *ip = GFS2_I(inode);
- struct gfs2_sbd *sdp = GFS2_SB(inode);
struct metapath mp;
- struct buffer_head *bh;
- int boundary;
+ struct buffer_head bh = { .b_state = 0, .b_blocknr = 0, .b_size = 0 };
+ int ret;
int create = *new;
BUG_ON(!extlen);
BUG_ON(!new);
bmap_lock(inode, create);
- bh = gfs2_block_pointers(inode, lblock, new, dblock, &boundary, &mp);
- *extlen = 1;
-
- if (bh != NULL && !IS_ERR(bh) && *dblock != 0 && *new == 0) {
- u64 tmp_dblock;
- int tmp_new;
- unsigned int nptrs;
- unsigned end_of_metadata = ip->i_di.di_height - 1;
-
- nptrs = (end_of_metadata) ? sdp->sd_inptrs : sdp->sd_diptrs;
- while (++mp.mp_list[end_of_metadata] < nptrs) {
- lookup_block(ip, bh, end_of_metadata, &mp, 0, &tmp_new, &tmp_dblock);
- if (*dblock + *extlen != tmp_dblock)
- break;
- ++*extlen;
- }
- }
+ ret = gfs2_block_pointers(inode, lblock, create, &bh, &mp, *extlen);
bmap_unlock(inode, create);
- if (!bh)
- return 0;
- if (IS_ERR(bh))
- return PTR_ERR(bh);
- brelse(bh);
- return 0;
+ *extlen = bh.b_size >> inode->i_blkbits;
+ *dblock = bh.b_blocknr;
+ if (buffer_new(&bh))
+ *new = 1;
+ else
+ *new = 0;
+ return ret;
}
/**
static int recursive_scan(struct gfs2_inode *ip, struct buffer_head *dibh,
struct metapath *mp, unsigned int height,
- uint64_t block, int first, block_call_t bc,
+ u64 block, int first, block_call_t bc,
void *data)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct buffer_head *bh = NULL;
- uint64_t *top, *bottom;
- uint64_t bn;
+ u64 *top, *bottom;
+ u64 bn;
int error;
int mh_size = sizeof(struct gfs2_meta_header);
if (error)
return error;
- top = (uint64_t *)(bh->b_data + mh_size) +
- ((first) ? mp->mp_list[height] : 0);
+ top = (u64 *)(bh->b_data + mh_size) +
+ (first ? mp->mp_list[height] : 0);
- bottom = (uint64_t *)(bh->b_data + mh_size) + sdp->sd_inptrs;
+ bottom = (u64 *)(bh->b_data + mh_size) + sdp->sd_inptrs;
}
error = bc(ip, dibh, bh, top, bottom, height, data);
break;
}
- out:
+out:
brelse(bh);
-
return error;
}
*/
static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
- struct buffer_head *bh, uint64_t *top, uint64_t *bottom,
+ struct buffer_head *bh, u64 *top, u64 *bottom,
unsigned int height, void *data)
{
struct strip_mine *sm = data;
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrp_list rlist;
- uint64_t bn, bstart;
- uint32_t blen;
- uint64_t *p;
+ u64 bn, bstart;
+ u32 blen;
+ u64 *p;
unsigned int rg_blocks = 0;
int metadata;
unsigned int revokes = 0;
gfs2_trans_end(sdp);
- out_rg_gunlock:
+out_rg_gunlock:
gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs);
-
- out_rlist:
+out_rlist:
gfs2_rlist_free(&rlist);
-
- out:
+out:
gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh);
-
return error;
}
* Returns: errno
*/
-static int do_grow(struct gfs2_inode *ip, uint64_t size)
+static int do_grow(struct gfs2_inode *ip, u64 size)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al;
gfs2_dinode_out(&ip->i_di, dibh->b_data);
brelse(dibh);
- out_end_trans:
+out_end_trans:
gfs2_trans_end(sdp);
-
- out_ipres:
+out_ipres:
gfs2_inplace_release(ip);
-
- out_gunlock_q:
+out_gunlock_q:
gfs2_quota_unlock(ip);
-
- out:
+out:
gfs2_alloc_put(ip);
-
return error;
}
return err;
}
-static int trunc_start(struct gfs2_inode *ip, uint64_t size)
+static int trunc_start(struct gfs2_inode *ip, u64 size)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct buffer_head *dibh;
int error;
error = gfs2_trans_begin(sdp,
- RES_DINODE + ((journaled) ? RES_JDATA : 0), 0);
+ RES_DINODE + (journaled ? RES_JDATA : 0), 0);
if (error)
return error;
error = 1;
} else {
- if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
+ if (size & (u64)(sdp->sd_sb.sb_bsize - 1))
error = gfs2_block_truncate_page(ip->i_inode.i_mapping);
if (!error) {
brelse(dibh);
- out:
+out:
gfs2_trans_end(sdp);
-
return error;
}
-static int trunc_dealloc(struct gfs2_inode *ip, uint64_t size)
+static int trunc_dealloc(struct gfs2_inode *ip, u64 size)
{
unsigned int height = ip->i_di.di_height;
- uint64_t lblock;
+ u64 lblock;
struct metapath mp;
int error;
gfs2_quota_unhold(ip);
- out:
+out:
gfs2_alloc_put(ip);
return error;
}
gfs2_dinode_out(&ip->i_di, dibh->b_data);
brelse(dibh);
- out:
+out:
up_write(&ip->i_rw_mutex);
-
gfs2_trans_end(sdp);
-
return error;
}
* Returns: errno
*/
-static int do_shrink(struct gfs2_inode *ip, uint64_t size)
+static int do_shrink(struct gfs2_inode *ip, u64 size)
{
int error;
* Returns: errno
*/
-int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size)
+int gfs2_truncatei(struct gfs2_inode *ip, u64 size)
{
int error;
* Returns: errno
*/
-int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
+int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
unsigned int len, int *alloc_required)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
- uint64_t lblock, lblock_stop, dblock;
- uint32_t extlen;
+ u64 lblock, lblock_stop, dblock;
+ u32 extlen;
int new = 0;
int error = 0;