Commit 61e085a8 authored by Steven Whitehouse's avatar Steven Whitehouse
Browse files

[GFS2] Tidy up dir code as per Christoph Hellwig's comments



1. Comment whitespace fix
2. Removed unused header files from dir.c
3. Split the gfs2_dir_get_buffer() function into two functions

Cc: Christoph Hellwig <hch@infradead.org>
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 1e09ae54
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, gfs2_unstuffer_t unstuffer,
		if (isdir) {
			block = gfs2_alloc_meta(ip);

			error = gfs2_dir_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,
+75 −69
Original line number Diff line number Diff line
@@ -42,10 +42,10 @@
 *
 * When the dirents are in leaves, the actual contents of the directory file are
 * used as an array of 64-bit block pointers pointing to the leaf blocks. The
* dirents are NOT in the directory file itself. There can be more than one block
* pointer in the array that points to the same leaf. In fact, when a directory
* is first converted from linear to exhash, all of the pointers point to the
* same leaf.
 * dirents are NOT in the directory file itself. There can be more than one
 * block pointer in the array that points to the same leaf. In fact, when a
 * directory is first converted from linear to exhash, all of the pointers
 * point to the same leaf.
 *
 * When a leaf is completely full, the size of the hash table can be
 * doubled unless it is already at the maximum size which is hard coded into
@@ -56,13 +56,11 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
#include <linux/sort.h>
#include <linux/gfs2_ondisk.h>
#include <linux/crc32.h>
#include <linux/vmalloc.h>
#include <asm/semaphore.h>

#include "gfs2.h"
#include "lm_interface.h"
@@ -92,34 +90,37 @@ typedef int (*leaf_call_t) (struct gfs2_inode *dip,
			    uint32_t index, uint32_t len, uint64_t leaf_no,
			    void *data);

int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new,

int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block,
			    struct buffer_head **bhp)
{
	struct buffer_head *bh;
	int error = 0;

	if (new) {
	bh = gfs2_meta_new(ip->i_gl, block);
	gfs2_trans_add_bh(ip->i_gl, bh, 1);
	gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD);
	gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
	} else {
		error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT,
				       &bh);
	*bhp = bh;
	return 0;
}

static int gfs2_dir_get_existing_buffer(struct gfs2_inode *ip, uint64_t block,
					struct buffer_head **bhp)
{
	struct buffer_head *bh;
	int error;

	error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT, &bh);
	if (error)
		return error;
	if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) {
		brelse(bh);
		return -EIO;
	}
	}

	*bhp = bh;
	return 0;
}



static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf,
				  unsigned int offset, unsigned int size)
                               
@@ -205,9 +206,11 @@ static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
				goto fail;
		}

		error = gfs2_dir_get_buffer(ip, dblock,
					    (amount == sdp->sd_jbsize) ?
					    1 : new, &bh);
		if (amount == sdp->sd_jbsize || new)
			error = gfs2_dir_get_new_buffer(ip, dblock, &bh);
		else
			error = gfs2_dir_get_existing_buffer(ip, dblock, &bh);

		if (error)
			goto fail;

@@ -321,7 +324,10 @@ static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf,
			gfs2_meta_ra(ip->i_gl, dblock, extlen);

		if (dblock) {
			error = gfs2_dir_get_buffer(ip, dblock, new, &bh);
			if (new)
				error = gfs2_dir_get_new_buffer(ip, dblock, &bh);
			else
				error = gfs2_dir_get_existing_buffer(ip, dblock, &bh);
			if (error)
				goto fail;
			dblock++;
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip);

int gfs2_diradd_alloc_required(struct inode *dir,
			       const struct qstr *filename);
int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new,
int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, uint64_t block,
			    struct buffer_head **bhp);

static inline uint32_t gfs2_disk_hash(const char *data, int len)