Commit 0f6fa8ca authored by Bob Peterson's avatar Bob Peterson Committed by Luis Henriques

GFS2: Make rename not save dirent location

commit 19aeb5a6 upstream.

This patch fixes a regression in the patch "GFS2: Remember directory
insert point", commit 2b47dad8.
The problem had to do with the rename function: The function found
space for the new dirent, and remembered that location. But then the
old dirent was removed, which often moved the eligible location for
the renamed dirent. Putting the new dirent at the saved location
caused file system corruption.

This patch adds a new "save_loc" variable to struct gfs2_diradd.
If 1, the dirent location is saved. If 0, the dirent location is not
saved and the buffer_head is released as per previous behavior.
Signed-off-by: default avatarBob Peterson <rpeterso@redhat.com>
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent e11323e2
...@@ -2100,8 +2100,13 @@ int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name, ...@@ -2100,8 +2100,13 @@ int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name,
} }
if (IS_ERR(dent)) if (IS_ERR(dent))
return PTR_ERR(dent); return PTR_ERR(dent);
if (da->save_loc) {
da->bh = bh; da->bh = bh;
da->dent = dent; da->dent = dent;
} else {
brelse(bh);
}
return 0; return 0;
} }
...@@ -23,6 +23,7 @@ struct gfs2_diradd { ...@@ -23,6 +23,7 @@ struct gfs2_diradd {
unsigned nr_blocks; unsigned nr_blocks;
struct gfs2_dirent *dent; struct gfs2_dirent *dent;
struct buffer_head *bh; struct buffer_head *bh;
int save_loc;
}; };
extern struct inode *gfs2_dir_search(struct inode *dir, extern struct inode *gfs2_dir_search(struct inode *dir,
......
...@@ -600,7 +600,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, ...@@ -600,7 +600,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
int error, free_vfs_inode = 0; int error, free_vfs_inode = 0;
u32 aflags = 0; u32 aflags = 0;
unsigned blocks = 1; unsigned blocks = 1;
struct gfs2_diradd da = { .bh = NULL, }; struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
if (!name->len || name->len > GFS2_FNAMESIZE) if (!name->len || name->len > GFS2_FNAMESIZE)
return -ENAMETOOLONG; return -ENAMETOOLONG;
...@@ -897,7 +897,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, ...@@ -897,7 +897,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_holder ghs[2]; struct gfs2_holder ghs[2];
struct buffer_head *dibh; struct buffer_head *dibh;
struct gfs2_diradd da = { .bh = NULL, }; struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
int error; int error;
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
...@@ -1335,7 +1335,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, ...@@ -1335,7 +1335,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
struct gfs2_rgrpd *nrgd; struct gfs2_rgrpd *nrgd;
unsigned int num_gh; unsigned int num_gh;
int dir_rename = 0; int dir_rename = 0;
struct gfs2_diradd da = { .nr_blocks = 0, }; struct gfs2_diradd da = { .nr_blocks = 0, .save_loc = 0, };
unsigned int x; unsigned int x;
int error; int error;
......
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