Skip to content

Commit

Permalink
GFS2: Clean up dir hash table reading
Browse files Browse the repository at this point in the history
Since there is now only a single caller to gfs2_dir_read_data()
and it has a number of constant arguments, we can factor
those out. Also some tests relating to the inode size were
being done twice.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
  • Loading branch information
Steven Whitehouse committed Oct 21, 2011
1 parent fd11e15 commit 4c28d33
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions fs/gfs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,15 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
return error;
}

static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf,
u64 offset, unsigned int size)
static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, __be64 *buf,
unsigned int size)
{
struct buffer_head *dibh;
int error;

error = gfs2_meta_inode_buffer(ip, &dibh);
if (!error) {
offset += sizeof(struct gfs2_dinode);
memcpy(buf, dibh->b_data + offset, size);
memcpy(buf, dibh->b_data + sizeof(struct gfs2_dinode), size);
brelse(dibh);
}

Expand All @@ -261,38 +260,27 @@ static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf,
* gfs2_dir_read_data - Read a data from a directory inode
* @ip: The GFS2 Inode
* @buf: The buffer to place result into
* @offset: File offset to begin jdata_readng from
* @size: Amount of data to transfer
*
* Returns: The amount of data actually copied or the error
*/
static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset,
unsigned int size, unsigned ra)
static int gfs2_dir_read_data(struct gfs2_inode *ip, __be64 *buf,
unsigned int size)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
u64 lblock, dblock;
u32 extlen = 0;
unsigned int o;
int copied = 0;
int error = 0;
u64 disksize = i_size_read(&ip->i_inode);

if (offset >= disksize)
return 0;

if (offset + size > disksize)
size = disksize - offset;

if (!size)
return 0;

if (gfs2_is_stuffed(ip))
return gfs2_dir_read_stuffed(ip, buf, offset, size);
return gfs2_dir_read_stuffed(ip, buf, size);

if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip)))
return -EINVAL;

lblock = offset;
lblock = 0;
o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header);

while (copied < size) {
Expand All @@ -311,8 +299,6 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset,
if (error || !dblock)
goto fail;
BUG_ON(extlen < 1);
if (!ra)
extlen = 1;
bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
} else {
error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh);
Expand All @@ -328,7 +314,7 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf, u64 offset,
extlen--;
memcpy(buf, bh->b_data + o, amount);
brelse(bh);
buf += amount;
buf += (amount/sizeof(__be64));
copied += amount;
lblock++;
o = sizeof(struct gfs2_meta_header);
Expand Down Expand Up @@ -371,7 +357,7 @@ static __be64 *gfs2_dir_get_hash_table(struct gfs2_inode *ip)
if (hc == NULL)
return ERR_PTR(-ENOMEM);

ret = gfs2_dir_read_data(ip, (char *)hc, 0, hsize, 1);
ret = gfs2_dir_read_data(ip, hc, hsize);
if (ret < 0) {
kfree(hc);
return ERR_PTR(ret);
Expand Down

0 comments on commit 4c28d33

Please sign in to comment.