Commit c752666c authored by Steven Whitehouse's avatar Steven Whitehouse

[GFS2] Fix bug in directory code and tidy up

Due to a typo, the dir leaf split operation was (for the first
split in a directory) writing the new hash vaules at the
wrong offset. This is now fixed.

Also some other tidy ups are included:

 - We use GFS2's hash function for dentries (see ops_dentry.c) so that
   we don't have to keep recalculating the hash values.
 - A lot of common code is eliminated between the various directory
   lookup routines.
 - Better error checking on directory lookup (previously different
   routines checked for different errors)
 - The leaf split operation has a couple of redundant operations
   removed from it, so it should be faster.

There is still further scope for further clean ups in the directory
code, and readdir in particular could do with slimming down a bit.
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 419c93e0
This diff is collapsed.
......@@ -27,25 +27,34 @@ typedef int (*gfs2_filldir_t) (void *opaque,
uint64_t offset,
struct gfs2_inum *inum, unsigned int type);
int gfs2_filecmp(struct qstr *file1, char *file2, int len_of_file2);
int gfs2_dirent_alloc(struct gfs2_inode *dip, struct buffer_head *bh,
int name_len, struct gfs2_dirent **dent_out);
int gfs2_dir_search(struct gfs2_inode *dip, struct qstr *filename,
struct gfs2_inum *inum, unsigned int *type);
int gfs2_dir_add(struct gfs2_inode *dip, struct qstr *filename,
struct gfs2_inum *inum, unsigned int type);
int gfs2_dir_del(struct gfs2_inode *dip, struct qstr *filename);
int gfs2_dir_search(struct inode *dir, const struct qstr *filename,
struct gfs2_inum *inum, unsigned int *type);
int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
const struct gfs2_inum *inum, unsigned int type);
int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *filename);
int gfs2_dir_read(struct gfs2_inode *dip, uint64_t * offset, void *opaque,
gfs2_filldir_t filldir);
int gfs2_dir_mvino(struct gfs2_inode *dip, struct qstr *filename,
struct gfs2_inum *new_inum, unsigned int new_type);
gfs2_filldir_t filldir);
int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
struct gfs2_inum *new_inum, unsigned int new_type);
int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip);
int gfs2_diradd_alloc_required(struct gfs2_inode *dip, struct qstr *filename,
int *alloc_required);
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,
struct buffer_head **bhp);
struct buffer_head **bhp);
/* N.B. This probably ought to take inum & type as args as well */
static inline void gfs2_qstr2dirent(const struct qstr *name, u16 reclen, struct gfs2_dirent *dent)
{
dent->de_inum.no_addr = cpu_to_be64(0);
dent->de_inum.no_formal_ino = cpu_to_be64(0);
dent->de_hash = cpu_to_be32(name->hash);
dent->de_rec_len = cpu_to_be16(reclen);
dent->de_name_len = cpu_to_be16(name->len);
dent->de_type = cpu_to_be16(0);
memset(dent->__pad, 0, sizeof(dent->__pad));
memcpy((char*)(dent+1), name->name, name->len);
}
#endif /* __DIR_DOT_H__ */
......@@ -228,12 +228,10 @@ struct inode *gfs2_iget(struct super_block *sb, struct gfs2_inum *inum)
void gfs2_inode_min_init(struct gfs2_inode *ip, unsigned int type)
{
spin_lock(&ip->i_spin);
if (!test_and_set_bit(GIF_MIN_INIT, &ip->i_flags)) {
ip->i_di.di_nlink = 1;
ip->i_di.di_mode = DT2IF(type);
}
spin_unlock(&ip->i_spin);
}
/**
......@@ -257,10 +255,8 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
return -EIO;
}
spin_lock(&ip->i_spin);
gfs2_dinode_in(&ip->i_di, dibh->b_data);
set_bit(GIF_MIN_INIT, &ip->i_flags);
spin_unlock(&ip->i_spin);
brelse(dibh);
......@@ -702,6 +698,16 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
return 0;
}
struct inode *gfs2_lookup_simple(struct inode *dip, const char *name)
{
struct qstr qstr;
qstr.name = name;
qstr.len = strlen(name);
qstr.hash = gfs2_disk_hash(qstr.name, qstr.len);
return gfs2_lookupi(dip, &qstr, 1, NULL);
}
/**
* gfs2_lookupi - Look up a filename in a directory and return its inode
* @d_gh: An initialized holder for the directory glock
......@@ -715,8 +721,9 @@ int gfs2_change_nlink(struct gfs2_inode *ip, int diff)
* Returns: errno
*/
int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
struct inode **inodep)
struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
struct nameidata *nd)
{
struct super_block *sb = dir->i_sb;
struct gfs2_inode *ipp;
......@@ -727,14 +734,14 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
unsigned int type;
struct gfs2_glock *gl;
int error = 0;
*inodep = NULL;
struct inode *inode = NULL;
if (!name->len || name->len > GFS2_FNAMESIZE)
return -ENAMETOOLONG;
return ERR_PTR(-ENAMETOOLONG);
if (gfs2_filecmp(name, ".", 1) ||
(gfs2_filecmp(name, "..", 2) && dir == sb->s_root->d_inode)) {
if ((name->len == 1 && memcmp(name->name, ".", 1) == 0) ||
(name->len == 2 && memcmp(name->name, "..", 2) == 0 &&
dir == sb->s_root->d_inode)) {
gfs2_inode_hold(dip);
ipp = dip;
goto done;
......@@ -742,7 +749,7 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
if (error)
return error;
return ERR_PTR(error);
if (!is_root) {
error = gfs2_repermission(dip->i_vnode, MAY_EXEC, NULL);
......@@ -750,7 +757,7 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
goto out;
}
error = gfs2_dir_search(dip, name, &inum, &type);
error = gfs2_dir_search(dir, name, &inum, &type);
if (error)
goto out;
......@@ -768,13 +775,16 @@ int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
out:
gfs2_glock_dq_uninit(&d_gh);
done:
if (error == -ENOENT)
return NULL;
if (error == 0) {
*inodep = gfs2_ip2v(ipp);
if (!*inodep)
error = -ENOMEM;
inode = gfs2_ip2v(ipp);
gfs2_inode_put(ipp);
if (!inode)
return ERR_PTR(-ENOMEM);
return inode;
}
return error;
return ERR_PTR(error);
}
static int pick_formal_ino_1(struct gfs2_sbd *sdp, uint64_t *formal_ino)
......@@ -918,7 +928,7 @@ static int create_ok(struct gfs2_inode *dip, struct qstr *name,
if (!dip->i_di.di_nlink)
return -EPERM;
error = gfs2_dir_search(dip, name, NULL, NULL);
error = gfs2_dir_search(dip->i_vnode, name, NULL, NULL);
switch (error) {
case -ENOENT:
error = 0;
......@@ -1116,7 +1126,9 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name,
if (error)
goto fail;
error = gfs2_diradd_alloc_required(dip, name, &alloc_required);
error = alloc_required = gfs2_diradd_alloc_required(dip->i_vnode, name);
if (alloc_required < 0)
goto fail;
if (alloc_required) {
error = gfs2_quota_check(dip, dip->i_di.di_uid,
dip->i_di.di_gid);
......@@ -1145,7 +1157,7 @@ static int link_dinode(struct gfs2_inode *dip, struct qstr *name,
goto fail_quota_locks;
}
error = gfs2_dir_add(dip, name, &ip->i_num, IF2DT(ip->i_di.di_mode));
error = gfs2_dir_add(dip->i_vnode, name, &ip->i_num, IF2DT(ip->i_di.di_mode));
if (error)
goto fail_end_trans;
......@@ -1379,12 +1391,14 @@ int gfs2_rmdiri(struct gfs2_inode *dip, struct qstr *name,
dotname.len = 1;
dotname.name = ".";
dotname.hash = gfs2_disk_hash(dotname.name, dotname.len);
error = gfs2_dir_del(ip, &dotname);
if (error)
return error;
dotname.len = 2;
dotname.name = "..";
dotname.hash = gfs2_disk_hash(dotname.name, dotname.len);
error = gfs2_dir_del(ip, &dotname);
if (error)
return error;
......@@ -1439,7 +1453,7 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, struct qstr *name,
if (error)
return error;
error = gfs2_dir_search(dip, name, &inum, &type);
error = gfs2_dir_search(dip->i_vnode, name, &inum, &type);
if (error)
return error;
......@@ -1476,6 +1490,7 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
memset(&dotdot, 0, sizeof(struct qstr));
dotdot.name = "..";
dotdot.len = 2;
dotdot.hash = gfs2_disk_hash(dotdot.name, dotdot.len);
igrab(dir);
......@@ -1489,9 +1504,11 @@ int gfs2_ok_to_move(struct gfs2_inode *this, struct gfs2_inode *to)
break;
}
error = gfs2_lookupi(dir, &dotdot, 1, &tmp);
if (error)
tmp = gfs2_lookupi(dir, &dotdot, 1, NULL);
if (IS_ERR(tmp)) {
error = PTR_ERR(tmp);
break;
}
iput(dir);
dir = tmp;
......
......@@ -44,8 +44,8 @@ void gfs2_inode_destroy(struct gfs2_inode *ip);
int gfs2_inode_dealloc(struct gfs2_sbd *sdp, struct gfs2_unlinked *ul);
int gfs2_change_nlink(struct gfs2_inode *ip, int diff);
int gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
struct inode **ipp);
struct inode *gfs2_lookupi(struct inode *dir, struct qstr *name, int is_root,
struct nameidata *nd);
struct inode *gfs2_createi(struct gfs2_holder *ghs, struct qstr *name,
unsigned int mode);
int gfs2_unlinki(struct gfs2_inode *dip, struct qstr *name,
......@@ -66,17 +66,7 @@ int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr);
int gfs2_repermission(struct inode *inode, int mask, struct nameidata *nd);
static inline int gfs2_lookup_simple(struct inode *dip, char *name,
struct inode **ipp)
{
struct qstr qstr;
int err;
memset(&qstr, 0, sizeof(struct qstr));
qstr.name = name;
qstr.len = strlen(name);
err = gfs2_lookupi(dip, &qstr, 1, ipp);
return err;
}
struct inode *gfs2_lookup_simple(struct inode *dip, const char *name);
#endif /* __INODE_DOT_H__ */
......@@ -64,7 +64,7 @@ void gfs2_inum_in(struct gfs2_inum *no, char *buf)
no->no_addr = be64_to_cpu(str->no_addr);
}
void gfs2_inum_out(struct gfs2_inum *no, char *buf)
void gfs2_inum_out(const struct gfs2_inum *no, char *buf)
{
struct gfs2_inum *str = (struct gfs2_inum *)buf;
......@@ -342,17 +342,6 @@ void gfs2_dirent_print(struct gfs2_dirent *de, char *name)
printk(KERN_INFO " name = %s\n", buf);
}
void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf)
{
struct gfs2_leaf *str = (struct gfs2_leaf *)buf;
gfs2_meta_header_in(&lf->lf_header, buf);
lf->lf_depth = be16_to_cpu(str->lf_depth);
lf->lf_entries = be16_to_cpu(str->lf_entries);
lf->lf_dirent_format = be32_to_cpu(str->lf_dirent_format);
lf->lf_next = be64_to_cpu(str->lf_next);
}
void gfs2_leaf_print(struct gfs2_leaf *lf)
{
gfs2_meta_header_print(&lf->lf_header);
......
......@@ -38,25 +38,26 @@
static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
{
struct dentry *parent = dget_parent(dentry);
struct gfs2_sbd *sdp = parent->d_inode->i_sb->s_fs_info;
struct gfs2_inode *dip = parent->d_inode->u.generic_ip;
struct inode *inode;
struct inode *inode = dentry->d_inode;
struct gfs2_holder d_gh;
struct gfs2_inode *ip;
struct gfs2_inum inum;
unsigned int type;
int error;
lock_kernel();
inode = dentry->d_inode;
if (inode && is_bad_inode(inode))
goto invalid;
if (sdp->sd_args.ar_localcaching)
goto valid;
error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
if (error)
goto fail;
error = gfs2_dir_search(dip, &dentry->d_name, &inum, &type);
error = gfs2_dir_search(parent->d_inode, &dentry->d_name, &inum, &type);
switch (error) {
case 0:
if (!inode)
......@@ -84,7 +85,6 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
gfs2_glock_dq_uninit(&d_gh);
valid:
unlock_kernel();
dput(parent);
return 1;
......@@ -99,7 +99,6 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
}
d_drop(dentry);
unlock_kernel();
dput(parent);
return 0;
......@@ -107,12 +106,18 @@ static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
gfs2_glock_dq_uninit(&d_gh);
fail:
unlock_kernel();
dput(parent);
return 0;
}
static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
{
str->hash = gfs2_disk_hash(str->name, str->len);
return 0;
}
struct dentry_operations gfs2_dops = {
.d_revalidate = gfs2_drevalidate,
.d_hash = gfs2_dhash,
};
......@@ -24,6 +24,7 @@
#include "inode.h"
#include "ops_export.h"
#include "rgrp.h"
#include "util.h"
static struct dentry *gfs2_decode_fh(struct super_block *sb,
__u32 *fh,
......@@ -167,11 +168,15 @@ static struct dentry *gfs2_get_parent(struct dentry *child)
struct qstr dotdot = { .name = "..", .len = 2 };
struct inode *inode;
struct dentry *dentry;
int error;
error = gfs2_lookupi(child->d_inode, &dotdot, 1, &inode);
if (error)
return ERR_PTR(error);
dotdot.hash = gfs2_disk_hash(dotdot.name, dotdot.len);
inode = gfs2_lookupi(child->d_inode, &dotdot, 1, NULL);
if (!inode)
return ERR_PTR(-ENOENT);
if (IS_ERR(inode))
return ERR_PTR(PTR_ERR(inode));
dentry = d_alloc_anon(inode);
if (!dentry) {
......
......@@ -379,11 +379,10 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
goto fail_recoverd;
}
error = gfs2_lookup_simple(sdp->sd_master_dir, "jindex",
&sdp->sd_jindex);
if (error) {
sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
if (IS_ERR(sdp->sd_jindex)) {
fs_err(sdp, "can't lookup journal index: %d\n", error);
return error;
return PTR_ERR(sdp->sd_jindex);
}
ip = sdp->sd_jindex->u.generic_ip;
set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
......@@ -531,26 +530,26 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
goto fail_master;
/* Read in the master inode number inode */
error = gfs2_lookup_simple(sdp->sd_master_dir, "inum",
&sdp->sd_inum_inode);
if (error) {
sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
if (IS_ERR(sdp->sd_inum_inode)) {
error = PTR_ERR(sdp->sd_inum_inode);
fs_err(sdp, "can't read in inum inode: %d\n", error);
goto fail_journal;
}
/* Read in the master statfs inode */
error = gfs2_lookup_simple(sdp->sd_master_dir, "statfs",
&sdp->sd_statfs_inode);
if (error) {
sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
if (IS_ERR(sdp->sd_statfs_inode)) {
error = PTR_ERR(sdp->sd_statfs_inode);
fs_err(sdp, "can't read in statfs inode: %d\n", error);
goto fail_inum;
}
/* Read in the resource index inode */
error = gfs2_lookup_simple(sdp->sd_master_dir, "rindex",
&sdp->sd_rindex);
if (error) {
sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
if (IS_ERR(sdp->sd_rindex)) {
error = PTR_ERR(sdp->sd_rindex);
fs_err(sdp, "can't get resource index inode: %d\n", error);
goto fail_statfs;
}
......@@ -559,9 +558,9 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
/* Read in the quota inode */
error = gfs2_lookup_simple(sdp->sd_master_dir, "quota",
&sdp->sd_quota_inode);
if (error) {
sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
if (IS_ERR(sdp->sd_quota_inode)) {
error = PTR_ERR(sdp->sd_quota_inode);
fs_err(sdp, "can't get quota file inode: %d\n", error);
goto fail_rindex;
}
......@@ -600,36 +599,41 @@ static int init_per_node(struct gfs2_sbd *sdp, int undo)
if (undo)
goto fail_qc_gh;
error = gfs2_lookup_simple(sdp->sd_master_dir, "per_node", &pn);
if (error) {
pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
if (IS_ERR(pn)) {
error = PTR_ERR(pn);
fs_err(sdp, "can't find per_node directory: %d\n", error);
return error;
}
sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
error = gfs2_lookup_simple(pn, buf, &sdp->sd_ir_inode);
if (error) {
sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
if (IS_ERR(sdp->sd_ir_inode)) {
error = PTR_ERR(sdp->sd_ir_inode);
fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
goto fail;
}
sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
error = gfs2_lookup_simple(pn, buf, &sdp->sd_sc_inode);
if (error) {
sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
if (IS_ERR(sdp->sd_sc_inode)) {
error = PTR_ERR(sdp->sd_sc_inode);
fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
goto fail_ir_i;
}
sprintf(buf, "unlinked_tag%u", sdp->sd_jdesc->jd_jid);
error = gfs2_lookup_simple(pn, buf, &sdp->sd_ut_inode);
if (error) {
sdp->sd_ut_inode = gfs2_lookup_simple(pn, buf);
if (IS_ERR(sdp->sd_ut_inode)) {
error = PTR_ERR(sdp->sd_ut_inode);
fs_err(sdp, "can't find local \"ut\" file: %d\n", error);
goto fail_sc_i;
}
sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
error = gfs2_lookup_simple(pn, buf, &sdp->sd_qc_inode);
if (error) {
sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
if (IS_ERR(sdp->sd_qc_inode)) {
error = PTR_ERR(sdp->sd_qc_inode);
fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
goto fail_ut_i;
}
......
......@@ -58,7 +58,6 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
struct gfs2_holder ghs[2];
struct inode *inode;
int new = 1;
int error;
gfs2_holder_init(dip->i_gl, 0, 0, ghs);
......@@ -78,14 +77,16 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
return PTR_ERR(inode);
}
error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode);
if (!error) {
new = 0;
gfs2_holder_uninit(ghs);
break;
} else if (error != -ENOENT) {
gfs2_holder_uninit(ghs);
return error;
inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
if (inode) {
if (!IS_ERR(inode)) {
new = 0;
gfs2_holder_uninit(ghs);
break;
} else {
gfs2_holder_uninit(ghs);
return PTR_ERR(inode);
}
}
}
......@@ -110,17 +111,13 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
struct nameidata *nd)
{
struct gfs2_inode *dip = dir->u.generic_ip;
struct gfs2_sbd *sdp = dip->i_sbd;
struct inode *inode = NULL;
int error;
if (!sdp->sd_args.ar_localcaching)
dentry->d_op = &gfs2_dops;
dentry->d_op = &gfs2_dops;
error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode);
if (error && error != -ENOENT)
return ERR_PTR(error);
inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
if (inode && IS_ERR(inode))
return ERR_PTR(PTR_ERR(inode));
if (inode)
return d_splice_alias(inode, dentry);
......@@ -166,7 +163,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
if (error)
goto out_gunlock;
error = gfs2_dir_search(dip, &dentry->d_name, NULL, NULL);
error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
switch (error) {
case -ENOENT:
break;
......@@ -192,10 +189,10 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
if (ip->i_di.di_nlink == (uint32_t)-1)
goto out_gunlock;
error = gfs2_diradd_alloc_required(dip, &dentry->d_name,
&alloc_required);
if (error)
alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
if (error < 0)
goto out_gunlock;
error = 0;
if (alloc_required) {
struct gfs2_alloc *al = gfs2_alloc_get(dip);
......@@ -228,7 +225,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
goto out_ipres;
}
error = gfs2_dir_add(dip, &dentry->d_name, &ip->i_num,
error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
IF2DT(ip->i_di.di_mode));
if (error)
goto out_end_trans;
......@@ -419,24 +416,24 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
if (!gfs2_assert_withdraw(sdp, !error)) {
struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
struct gfs2_dirent *dent;
gfs2_dirent_alloc(ip, dibh, 1, &dent);
struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
struct qstr str = { .name = ".", .len = 1 };
str.hash = gfs2_disk_hash(str.name, str.len);
gfs2_trans_add_bh(ip->i_gl, dibh, 1);
gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
dent->de_inum = di->di_num; /* already GFS2 endian */
dent->de_hash = gfs2_disk_hash(".", 1);
dent->de_hash = cpu_to_be32(dent->de_hash);
dent->de_type = DT_DIR;
memcpy((char *) (dent + 1), ".", 1);
di->di_entries = cpu_to_be32(1);
gfs2_dirent_alloc(ip, dibh, 2, &dent);
str.name = "..";
str.len = 2;
str.hash = gfs2_disk_hash(str.name, str.len);
dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
dent->de_hash = gfs2_disk_hash("..", 2);
dent->de_hash = cpu_to_be32(dent->de_hash);
dent->de_type = DT_DIR;
memcpy((char *) (dent + 1), "..", 2);
gfs2_dinode_out(&ip->i_di, (char *)di);
......@@ -687,7 +684,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
if (error)
goto out_gunlock;
error = gfs2_dir_search(ndip, &ndentry->d_name, NULL, NULL);
error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
switch (error) {
case -ENOENT:
error = 0;
......@@ -723,10 +720,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
goto out_gunlock;
}
error = gfs2_diradd_alloc_required(ndip, &ndentry->d_name,
&alloc_required);
if (error)
alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
if (error < 0)
goto out_gunlock;
error = 0;
if (alloc_required) {
struct gfs2_alloc *al = gfs2_alloc_get(ndip);
......@@ -777,6 +774,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
struct qstr name;
name.len = 2;
name.name = "..";
name.hash = gfs2_disk_hash(name.name, name.len);
error = gfs2_change_nlink(ndip, +1);
if (error)
......@@ -803,7 +801,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
if (error)
goto out_end_trans;
error = gfs2_dir_add(ndip, &ndentry->d_name, &ip->i_num,
error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
IF2DT(ip->i_di.di_mode));
if (error)
goto out_end_trans;
......
......@@ -299,8 +299,9 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
break;
name.len = sprintf(buf, "journal%u", sdp->sd_journals);
name.hash = gfs2_disk_hash(name.name, name.len);
error = gfs2_dir_search(sdp->sd_jindex->u.generic_ip,
error = gfs2_dir_search(sdp->sd_jindex,
&name, NULL, NULL);
if (error == -ENOENT) {
error = 0;
......@@ -317,8 +318,12 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
if (!jd)
break;
error = gfs2_lookupi(sdp->sd_jindex, &name, 1, &jd->jd_inode);
if (error) {
jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL);
if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
if (!jd->jd_inode)
error = -ENOENT;
else
error = PTR_ERR(jd->jd_inode);
kfree(jd);
break;
}
......
......@@ -411,7 +411,7 @@ struct gfs2_quota_change {
/* Translation functions */
extern void gfs2_inum_in(struct gfs2_inum *no, char *buf);
extern void gfs2_inum_out(struct gfs2_inum *no, char *buf);
extern void gfs2_inum_out(const struct gfs2_inum *no, char *buf);
extern void gfs2_sb_in(struct gfs2_sb *sb, char *buf);
extern void gfs2_rindex_in(struct gfs2_rindex *ri, char *buf);
extern void gfs2_rindex_out(struct gfs2_rindex *ri, char *buf);
......@@ -421,7 +421,6 @@ extern void gfs2_quota_in(struct gfs2_quota *qu, char *buf);
extern void gfs2_quota_out(struct gfs2_quota *qu, char *buf);
extern void gfs2_dinode_in(struct gfs2_dinode *di, char *buf);
extern void gfs2_dinode_out(struct gfs2_dinode *di, char *buf);
extern void gfs2_leaf_in(struct gfs2_leaf *lf, char *buf);
extern void gfs2_ea_header_in(struct gfs2_ea_header *ea, char *buf);
extern void gfs2_ea_header_out(struct gfs2_ea_header *ea, char *buf);
extern void gfs2_log_header_in(struct gfs2_log_header *lh, char *buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment