/*
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
- * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
-#include <asm/semaphore.h>
+#include <linux/gfs2_ondisk.h>
+#include <linux/crc32.h>
#include "gfs2.h"
+#include "lm_interface.h"
+#include "incore.h"
#include "bmap.h"
#include "glock.h"
#include "inode.h"
-#include "jdata.h"
#include "meta_io.h"
#include "page.h"
#include "quota.h"
#include "rgrp.h"
#include "trans.h"
+#include "dir.h"
+#include "util.h"
/* This doesn't need to be that large as max 64 bit pointers in a 4k
* block is 512, so __u16 is fine for that. It saves stack space to
unsigned int sm_height;
};
-/**
- * @gfs2_unstuffer_sync - Synchronously unstuff a dinode
- * @ip:
- * @dibh:
- * @block:
- * @private:
- *
- * Cheat and use a metadata buffer instead of a data page.
- *
- * Returns: errno
- */
-
-int gfs2_unstuffer_sync(struct gfs2_inode *ip, struct buffer_head *dibh,
- uint64_t block, void *private)
-{
- struct buffer_head *bh;
- int error;
-
- bh = gfs2_meta_new(ip->i_gl, block);
-
- gfs2_buffer_copy_tail(bh, 0, dibh, sizeof(struct gfs2_dinode));
-
- set_buffer_dirty(bh);
- error = sync_dirty_buffer(bh);
-
- brelse(bh);
-
- return error;
-}
-
/**
* gfs2_unstuff_dinode - Unstuff a dinode when the data has grown too big
* @ip: The GFS2 inode to unstuff
{
struct buffer_head *bh, *dibh;
uint64_t block = 0;
- int journaled = gfs2_is_jdata(ip);
+ int isdir = gfs2_is_dir(ip);
int error;
down_write(&ip->i_rw_mutex);
/* Get a free block, fill it with the stuffed data,
and write it out to disk */
- if (journaled) {
+ if (isdir) {
block = gfs2_alloc_meta(ip);
- error = gfs2_jdata_get_buffer(ip, block, 1, &bh);
+ error = gfs2_dir_get_new_buffer(ip, block, &bh);
if (error)
goto out_brelse;
gfs2_buffer_copy_tail(bh,
/* Set up the pointer to the new block */
- gfs2_trans_add_bh(ip->i_gl, dibh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
if (ip->i_di.di_size) {
- *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block);
+ *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) =
+ cpu_to_be64(block);
ip->i_di.di_blocks++;
}
static unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
uint64_t *arr;
unsigned int max, height;
if (ip->i_di.di_size > size)
size = ip->i_di.di_size;
- if (gfs2_is_jdata(ip)) {
+ if (gfs2_is_dir(ip)) {
arr = sdp->sd_jheightsize;
max = sdp->sd_max_jheight;
} else {
* @ip: The GFS2 inode
* @height: The height to build to
*
- * This routine makes sure that the metadata tree is tall enough to hold
- * "size" bytes of data.
*
* Returns: errno
*/
-static int build_height(struct gfs2_inode *ip, int height)
+static int build_height(struct inode *inode, unsigned height)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
- struct buffer_head *bh, *dibh;
- uint64_t block = 0, *bp;
- unsigned int x;
- int new_block;
+ struct gfs2_inode *ip = GFS2_I(inode);
+ unsigned new_height = height - ip->i_di.di_height;
+ struct buffer_head *dibh;
+ struct buffer_head *blocks[GFS2_MAX_META_HEIGHT];
int error;
+ u64 *bp;
+ u64 bn;
+ unsigned n;
- while (ip->i_di.di_height < height) {
- error = gfs2_meta_inode_buffer(ip, &dibh);
- if (error)
- return error;
-
- new_block = 0;
- bp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode));
- for (x = 0; x < sdp->sd_diptrs; x++, bp++)
- if (*bp) {
- new_block = 1;
- break;
- }
-
- if (new_block) {
- /* Get a new block, fill it with the old direct
- pointers, and write it out */
+ if (height <= ip->i_di.di_height)
+ return 0;
- block = gfs2_alloc_meta(ip);
+ error = gfs2_meta_inode_buffer(ip, &dibh);
+ if (error)
+ return error;
- bh = gfs2_meta_new(ip->i_gl, block);
- gfs2_trans_add_bh(ip->i_gl, bh);
- gfs2_metatype_set(bh,
- GFS2_METATYPE_IN,
+ for(n = 0; n < new_height; n++) {
+ bn = gfs2_alloc_meta(ip);
+ blocks[n] = gfs2_meta_new(ip->i_gl, bn);
+ gfs2_trans_add_bh(ip->i_gl, blocks[n], 1);
+ }
+
+ n = 0;
+ bn = blocks[0]->b_blocknr;
+ if (new_height > 1) {
+ for(; n < new_height-1; n++) {
+ gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN,
GFS2_FORMAT_IN);
- gfs2_buffer_copy_tail(bh,
- sizeof(struct gfs2_meta_header),
- dibh, sizeof(struct gfs2_dinode));
-
- brelse(bh);
+ gfs2_buffer_clear_tail(blocks[n],
+ sizeof(struct gfs2_meta_header));
+ bp = (u64 *)(blocks[n]->b_data +
+ sizeof(struct gfs2_meta_header));
+ *bp = cpu_to_be64(blocks[n+1]->b_blocknr);
+ brelse(blocks[n]);
+ blocks[n] = NULL;
}
-
- /* Set up the new direct pointer and write it out to disk */
-
- gfs2_trans_add_bh(ip->i_gl, dibh);
-
- gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
-
- if (new_block) {
- *(uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode)) = cpu_to_be64(block);
- ip->i_di.di_blocks++;
- }
-
- ip->i_di.di_height++;
-
- gfs2_dinode_out(&ip->i_di, dibh->b_data);
- brelse(dibh);
}
-
- return 0;
+ gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN, GFS2_FORMAT_IN);
+ gfs2_buffer_copy_tail(blocks[n], sizeof(struct gfs2_meta_header),
+ dibh, sizeof(struct gfs2_dinode));
+ brelse(blocks[n]);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
+ gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
+ bp = (u64 *)(dibh->b_data + sizeof(struct gfs2_dinode));
+ *bp = cpu_to_be64(bn);
+ ip->i_di.di_height += new_height;
+ ip->i_di.di_blocks += new_height;
+ gfs2_dinode_out(&ip->i_di, dibh->b_data);
+ brelse(dibh);
+ return error;
}
/**
*
*/
-static void find_metapath(struct gfs2_inode *ip, uint64_t block, struct metapath *mp)
+static void find_metapath(struct gfs2_inode *ip, uint64_t block,
+ struct metapath *mp)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
uint64_t b = block;
unsigned int i;
* metadata tree.
*/
-static inline uint64_t *metapointer(struct buffer_head *bh,
- unsigned int height, struct metapath *mp)
+static inline u64 *metapointer(struct buffer_head *bh, int *boundary,
+ unsigned int height, const struct metapath *mp)
{
unsigned int head_size = (height > 0) ?
sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_dinode);
-
- return ((uint64_t *)(bh->b_data + head_size)) + mp->mp_list[height];
+ u64 *ptr;
+ *boundary = 0;
+ ptr = ((u64 *)(bh->b_data + head_size)) + mp->mp_list[height];
+ if (ptr + 1 == (u64*)(bh->b_data + bh->b_size))
+ *boundary = 1;
+ return ptr;
}
/**
*
*/
-static void lookup_block(struct gfs2_inode *ip, struct buffer_head *bh,
- unsigned int height, struct metapath *mp, int create,
- int *new, uint64_t *block)
+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)
{
- uint64_t *ptr = metapointer(bh, height, mp);
+ int boundary;
+ uint64_t *ptr = metapointer(bh, &boundary, height, mp);
if (*ptr) {
*block = be64_to_cpu(*ptr);
- return;
+ return boundary;
}
*block = 0;
if (!create)
- return;
+ return 0;
- if (height == ip->i_di.di_height - 1 &&
- !gfs2_is_jdata(ip))
+ if (height == ip->i_di.di_height - 1 && !gfs2_is_dir(ip))
*block = gfs2_alloc_data(ip);
else
*block = gfs2_alloc_meta(ip);
- gfs2_trans_add_bh(ip->i_gl, bh);
+ gfs2_trans_add_bh(ip->i_gl, bh, 1);
*ptr = cpu_to_be64(*block);
ip->i_di.di_blocks++;
*new = 1;
+ return 0;
}
/**
- * gfs2_block_map - Map a block from an inode to a disk block
- * @ip: The GFS2 inode
+ * 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)
- * @dblock: the disk block number of the start of an extent
- * @extlen: the size of the extent
+ * @boundary: gets set if we've hit a block boundary
+ * @mp: metapath to use
*
* Find the block number on the current device which corresponds to an
* inode's block. If the block had to be created, "new" will be set.
* Returns: errno
*/
-int gfs2_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
- uint64_t *dblock, uint32_t *extlen)
+static struct buffer_head *gfs2_block_pointers(struct inode *inode, u64 lblock,
+ int *new, u64 *dblock,
+ int *boundary,
+ struct metapath *mp)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_inode *ip = GFS2_I(inode);
+ struct gfs2_sbd *sdp = GFS2_SB(inode);
struct buffer_head *bh;
- struct metapath mp;
int create = *new;
unsigned int bsize;
unsigned int height;
*new = 0;
*dblock = 0;
- if (extlen)
- *extlen = 0;
-
- if (create)
- down_write(&ip->i_rw_mutex);
- else
- down_read(&ip->i_rw_mutex);
if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip)))
goto out;
- bsize = (gfs2_is_jdata(ip)) ? sdp->sd_jbsize : sdp->sd_sb.sb_bsize;
+ 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;
- error = build_height(ip, height);
+ error = build_height(inode, height);
if (error)
goto out;
}
- find_metapath(ip, lblock, &mp);
+ find_metapath(ip, lblock, mp);
end_of_metadata = ip->i_di.di_height - 1;
error = gfs2_meta_inode_buffer(ip, &bh);
goto out;
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;
goto out;
}
- lookup_block(ip, bh, end_of_metadata, &mp, create, new, dblock);
-
- if (extlen && *dblock) {
- *extlen = 1;
-
- if (!*new) {
- uint64_t tmp_dblock;
- int tmp_new;
- unsigned int nptrs;
-
- 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)++;
- }
- }
- }
-
- brelse(bh);
-
+ *boundary = lookup_block(ip, bh, end_of_metadata, mp, create, new, dblock);
if (*new) {
- error = gfs2_meta_inode_buffer(ip, &bh);
+ struct buffer_head *dibh;
+ error = gfs2_meta_inode_buffer(ip, &dibh);
if (!error) {
- gfs2_trans_add_bh(ip->i_gl, bh);
- gfs2_dinode_out(&ip->i_di, bh->b_data);
- brelse(bh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
+ gfs2_dinode_out(&ip->i_di, dibh->b_data);
+ brelse(dibh);
}
}
+ return bh;
+out:
+ return ERR_PTR(error);
+}
- out:
+
+static inline void bmap_lock(struct inode *inode, int create)
+{
+ struct gfs2_inode *ip = GFS2_I(inode);
+ if (create)
+ down_write(&ip->i_rw_mutex);
+ else
+ down_read(&ip->i_rw_mutex);
+}
+
+static inline void bmap_unlock(struct inode *inode, int create)
+{
+ struct gfs2_inode *ip = GFS2_I(inode);
if (create)
up_write(&ip->i_rw_mutex);
else
up_read(&ip->i_rw_mutex);
+}
- return error;
+int gfs2_block_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, int *boundary)
+{
+ struct metapath mp;
+ struct buffer_head *bh;
+ int create = *new;
+
+ bmap_lock(inode, create);
+ bh = gfs2_block_pointers(inode, lblock, new, dblock, boundary, &mp);
+ bmap_unlock(inode, create);
+ if (!bh)
+ return 0;
+ if (IS_ERR(bh))
+ return PTR_ERR(bh);
+ brelse(bh);
+ return 0;
+}
+
+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;
+ int create = *new;
+
+ BUG_ON(!extlen);
+ BUG_ON(!dblock);
+ BUG_ON(!new);
+
+ bmap_lock(inode, create);
+ bh = gfs2_block_pointers(inode, lblock, new, dblock, &boundary, &mp);
+ *extlen = 1;
+
+ if (bh && !IS_ERR(bh) && *dblock && !*new) {
+ 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)++;
+ }
+ }
+ bmap_unlock(inode, create);
+ if (!bh)
+ return 0;
+ if (IS_ERR(bh))
+ return PTR_ERR(bh);
+ brelse(bh);
+ return 0;
}
/**
uint64_t block, int first, block_call_t bc,
void *data)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct buffer_head *bh = NULL;
uint64_t *top, *bottom;
uint64_t bn;
struct buffer_head *bh, uint64_t *top, uint64_t *bottom,
unsigned int height, void *data)
{
- struct strip_mine *sm = (struct strip_mine *)data;
- struct gfs2_sbd *sdp = ip->i_sbd;
+ 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;
sm->sm_first = 0;
}
- metadata = (height != ip->i_di.di_height - 1) || gfs2_is_jdata(ip);
+ metadata = (height != ip->i_di.di_height - 1);
if (metadata)
revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs;
for (x = 0; x < rlist.rl_rgrps; x++) {
struct gfs2_rgrpd *rgd;
- rgd = get_gl2rgd(rlist.rl_ghs[x].gh_gl);
+ rgd = rlist.rl_ghs[x].gh_gl->gl_object;
rg_blocks += rgd->rd_ri.ri_length;
}
down_write(&ip->i_rw_mutex);
- gfs2_trans_add_bh(ip->i_gl, dibh);
- gfs2_trans_add_bh(ip->i_gl, bh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
+ gfs2_trans_add_bh(ip->i_gl, bh, 1);
bstart = 0;
blen = 0;
static int do_grow(struct gfs2_inode *ip, uint64_t size)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al;
struct buffer_head *dibh;
unsigned int h;
h = calc_tree_height(ip, size);
if (ip->i_di.di_height < h) {
down_write(&ip->i_rw_mutex);
- error = build_height(ip, h);
+ error = build_height(&ip->i_inode, h);
up_write(&ip->i_rw_mutex);
if (error)
goto out_end_trans;
if (error)
goto out_end_trans;
- gfs2_trans_add_bh(ip->i_gl, dibh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_dinode_out(&ip->i_di, dibh->b_data);
brelse(dibh);
return error;
}
-static int truncator_journaled(struct gfs2_inode *ip, uint64_t size)
+static int trunc_start(struct gfs2_inode *ip, uint64_t size)
{
- uint64_t lbn, dbn;
- uint32_t off;
- struct buffer_head *bh;
- int new = 0;
- int error;
-
- lbn = size;
- off = do_div(lbn, ip->i_sbd->sd_jbsize);
-
- error = gfs2_block_map(ip, lbn, &new, &dbn, NULL);
- if (error || !dbn)
- return error;
-
- error = gfs2_jdata_get_buffer(ip, dbn, 0, &bh);
- if (error)
- return error;
-
- gfs2_trans_add_bh(ip->i_gl, bh);
- gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header) + off);
-
- brelse(bh);
-
- return 0;
-}
-
-static int trunc_start(struct gfs2_inode *ip, uint64_t size,
- gfs2_truncator_t truncator)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct buffer_head *dibh;
int journaled = gfs2_is_jdata(ip);
int error;
if (gfs2_is_stuffed(ip)) {
ip->i_di.di_size = size;
ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
- gfs2_trans_add_bh(ip->i_gl, dibh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_dinode_out(&ip->i_di, dibh->b_data);
gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode) + size);
error = 1;
} else {
- if (journaled) {
- uint64_t junk = size;
- /* we're just interested in the modulus */
- if (do_div(junk, sdp->sd_jbsize))
- error = truncator_journaled(ip, size);
- } else if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
- error = truncator(ip, size);
+ if (size & (uint64_t)(sdp->sd_sb.sb_bsize - 1))
+ error = gfs2_block_truncate_page(ip->i_inode.i_mapping);
if (!error) {
ip->i_di.di_size = size;
ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
ip->i_di.di_flags |= GFS2_DIF_TRUNC_IN_PROG;
- gfs2_trans_add_bh(ip->i_gl, dibh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_dinode_out(&ip->i_di, dibh->b_data);
}
}
if (!size)
lblock = 0;
- else if (gfs2_is_jdata(ip)) {
- lblock = size - 1;
- do_div(lblock, ip->i_sbd->sd_jbsize);
- } else
- lblock = (size - 1) >> ip->i_sbd->sd_sb.sb_bsize_shift;
+ else
+ lblock = (size - 1) >> GFS2_SB(&ip->i_inode)->sd_sb.sb_bsize_shift;
find_metapath(ip, lblock, &mp);
gfs2_alloc_get(ip);
static int trunc_end(struct gfs2_inode *ip)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct buffer_head *dibh;
int error;
ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
ip->i_di.di_flags &= ~GFS2_DIF_TRUNC_IN_PROG;
- gfs2_trans_add_bh(ip->i_gl, dibh);
+ gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_dinode_out(&ip->i_di, dibh->b_data);
brelse(dibh);
* Returns: errno
*/
-static int do_shrink(struct gfs2_inode *ip, uint64_t size,
- gfs2_truncator_t truncator)
+static int do_shrink(struct gfs2_inode *ip, uint64_t size)
{
int error;
- error = trunc_start(ip, size, truncator);
+ error = trunc_start(ip, size);
if (error < 0)
return error;
if (error > 0)
}
/**
- * gfs2_truncatei - make a file a give size
+ * gfs2_truncatei - make a file a given size
* @ip: the inode
* @size: the size to make the file
* @truncator: function to truncate the last partial block
* Returns: errno
*/
-int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size,
- gfs2_truncator_t truncator)
+int gfs2_truncatei(struct gfs2_inode *ip, uint64_t size)
{
int error;
- if (gfs2_assert_warn(ip->i_sbd, S_ISREG(ip->i_di.di_mode)))
+ if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), S_ISREG(ip->i_di.di_mode)))
return -EINVAL;
if (size > ip->i_di.di_size)
error = do_grow(ip, size);
else
- error = do_shrink(ip, size, truncator);
+ error = do_shrink(ip, size);
return error;
}
void gfs2_write_calc_reserv(struct gfs2_inode *ip, unsigned int len,
unsigned int *data_blocks, unsigned int *ind_blocks)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
unsigned int tmp;
- if (gfs2_is_jdata(ip)) {
- *data_blocks = DIV_RU(len, sdp->sd_jbsize) + 2;
+ if (gfs2_is_dir(ip)) {
+ *data_blocks = DIV_ROUND_UP(len, sdp->sd_jbsize) + 2;
*ind_blocks = 3 * (sdp->sd_max_jheight - 1);
} else {
*data_blocks = (len >> sdp->sd_sb.sb_bsize_shift) + 3;
}
for (tmp = *data_blocks; tmp > sdp->sd_diptrs;) {
- tmp = DIV_RU(tmp, sdp->sd_inptrs);
+ tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs);
*ind_blocks += tmp;
}
}
int gfs2_write_alloc_required(struct gfs2_inode *ip, uint64_t offset,
unsigned int len, int *alloc_required)
{
- struct gfs2_sbd *sdp = ip->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
uint64_t lblock, lblock_stop, dblock;
uint32_t extlen;
int new = 0;
return 0;
}
- if (gfs2_is_jdata(ip)) {
+ if (gfs2_is_dir(ip)) {
unsigned int bsize = sdp->sd_jbsize;
lblock = offset;
do_div(lblock, bsize);
}
for (; lblock < lblock_stop; lblock += extlen) {
- error = gfs2_block_map(ip, lblock, &new, &dblock, &extlen);
+ error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen);
if (error)
return error;
return 0;
}
-/**
- * do_gfm - Copy out the dinode/indirect blocks of a file
- * @ip: the file
- * @dibh: the dinode buffer
- * @bh: the indirect buffer we're looking at
- * @top: the first pointer in the block
- * @bottom: one more than the last pointer in the block
- * @height: the height the block is at
- * @data: a pointer to a struct gfs2_user_buffer structure
- *
- * If this is a journaled file, copy out the data too.
- *
- * Returns: errno
- */
-
-static int do_gfm(struct gfs2_inode *ip, struct buffer_head *dibh,
- struct buffer_head *bh, uint64_t *top, uint64_t *bottom,
- unsigned int height, void *data)
-{
- struct gfs2_user_buffer *ub = (struct gfs2_user_buffer *)data;
- int error;
-
- error = gfs2_add_bh_to_ub(ub, bh);
- if (error)
- return error;
-
- if (!S_ISDIR(ip->i_di.di_mode) ||
- height + 1 != ip->i_di.di_height)
- return 0;
-
- for (; top < bottom; top++)
- if (*top) {
- struct buffer_head *data_bh;
-
- error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*top),
- DIO_START | DIO_WAIT,
- &data_bh);
- if (error)
- return error;
-
- error = gfs2_add_bh_to_ub(ub, data_bh);
-
- brelse(data_bh);
-
- if (error)
- return error;
- }
-
- return 0;
-}
-
-/**
- * gfs2_get_file_meta - return all the metadata for a file
- * @ip: the file
- * @ub: the structure representing the meta
- *
- * Returns: errno
- */
-
-int gfs2_get_file_meta(struct gfs2_inode *ip, struct gfs2_user_buffer *ub)
-{
- int error;
-
- if (gfs2_is_stuffed(ip)) {
- struct buffer_head *dibh;
- error = gfs2_meta_inode_buffer(ip, &dibh);
- if (!error) {
- error = gfs2_add_bh_to_ub(ub, dibh);
- brelse(dibh);
- }
- } else {
- struct metapath mp;
- find_metapath(ip, 0, &mp);
- error = recursive_scan(ip, NULL, &mp, 0, 0, 1, do_gfm, ub);
- }
-
- return error;
-}
-