Revert "nilfs2: propagate directory read errors from nilfs_find_entry()"

This reverts commit b3a475e970.
This commit is contained in:
Ksawlii 2024-11-24 00:22:51 +01:00
parent 62d9425e52
commit 3d2f22dcfc
3 changed files with 37 additions and 54 deletions

View file

@ -331,8 +331,6 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx)
* returns the page in which the entry was found, and the entry itself
* (as a parameter - res_dir). Page is returned mapped and unlocked.
* Entry is guaranteed to be valid.
*
* On failure, returns an error pointer and the caller should ignore res_page.
*/
struct nilfs_dir_entry *
nilfs_find_entry(struct inode *dir, const struct qstr *qstr,
@ -360,24 +358,22 @@ nilfs_find_entry(struct inode *dir, const struct qstr *qstr,
do {
char *kaddr = nilfs_get_page(dir, n, &page);
if (IS_ERR(kaddr))
return ERR_CAST(kaddr);
de = (struct nilfs_dir_entry *)kaddr;
kaddr += nilfs_last_byte(dir, n) - reclen;
while ((char *)de <= kaddr) {
if (de->rec_len == 0) {
nilfs_error(dir->i_sb,
"zero-length directory entry");
nilfs_put_page(page);
goto out;
if (!IS_ERR(kaddr)) {
de = (struct nilfs_dir_entry *)kaddr;
kaddr += nilfs_last_byte(dir, n) - reclen;
while ((char *) de <= kaddr) {
if (de->rec_len == 0) {
nilfs_error(dir->i_sb,
"zero-length directory entry");
nilfs_put_page(page);
goto out;
}
if (nilfs_match(namelen, name, de))
goto found;
de = nilfs_next_entry(de);
}
if (nilfs_match(namelen, name, de))
goto found;
de = nilfs_next_entry(de);
nilfs_put_page(page);
}
nilfs_put_page(page);
if (++n >= npages)
n = 0;
/* next page is past the blocks we've got */
@ -390,7 +386,7 @@ nilfs_find_entry(struct inode *dir, const struct qstr *qstr,
}
} while (n != start);
out:
return ERR_PTR(-ENOENT);
return NULL;
found:
*res_page = page;
@ -435,19 +431,19 @@ fail:
return NULL;
}
int nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr, ino_t *ino)
ino_t nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr)
{
ino_t res = 0;
struct nilfs_dir_entry *de;
struct page *page;
de = nilfs_find_entry(dir, qstr, &page);
if (IS_ERR(de))
return PTR_ERR(de);
*ino = le64_to_cpu(de->inode);
kunmap(page);
put_page(page);
return 0;
if (de) {
res = le64_to_cpu(de->inode);
kunmap(page);
put_page(page);
}
return res;
}
/* Releases the page */

View file

@ -55,20 +55,12 @@ nilfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
{
struct inode *inode;
ino_t ino;
int res;
if (dentry->d_name.len > NILFS_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG);
res = nilfs_inode_by_name(dir, &dentry->d_name, &ino);
if (res) {
if (res != -ENOENT)
return ERR_PTR(res);
inode = NULL;
} else {
inode = nilfs_iget(dir->i_sb, NILFS_I(dir)->i_root, ino);
}
ino = nilfs_inode_by_name(dir, &dentry->d_name);
inode = ino ? nilfs_iget(dir->i_sb, NILFS_I(dir)->i_root, ino) : NULL;
return d_splice_alias(inode, dentry);
}
@ -272,11 +264,10 @@ static int nilfs_do_unlink(struct inode *dir, struct dentry *dentry)
struct page *page;
int err;
err = -ENOENT;
de = nilfs_find_entry(dir, &dentry->d_name, &page);
if (IS_ERR(de)) {
err = PTR_ERR(de);
if (!de)
goto out;
}
inode = d_inode(dentry);
err = -EIO;
@ -370,11 +361,10 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (unlikely(err))
return err;
err = -ENOENT;
old_de = nilfs_find_entry(old_dir, &old_dentry->d_name, &old_page);
if (IS_ERR(old_de)) {
err = PTR_ERR(old_de);
if (!old_de)
goto out;
}
if (S_ISDIR(old_inode->i_mode)) {
err = -EIO;
@ -391,12 +381,10 @@ static int nilfs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (dir_de && !nilfs_empty_dir(new_inode))
goto out_dir;
new_de = nilfs_find_entry(new_dir, &new_dentry->d_name,
&new_page);
if (IS_ERR(new_de)) {
err = PTR_ERR(new_de);
err = -ENOENT;
new_de = nilfs_find_entry(new_dir, &new_dentry->d_name, &new_page);
if (!new_de)
goto out_dir;
}
nilfs_set_link(new_dir, new_de, new_page, old_inode);
nilfs_mark_inode_dirty(new_dir);
new_inode->i_ctime = current_time(new_inode);
@ -450,15 +438,14 @@ out:
*/
static struct dentry *nilfs_get_parent(struct dentry *child)
{
ino_t ino;
int res;
unsigned long ino;
struct inode *inode;
struct qstr dotdot = QSTR_INIT("..", 2);
struct nilfs_root *root;
res = nilfs_inode_by_name(d_inode(child), &dotdot, &ino);
if (res)
return ERR_PTR(res);
ino = nilfs_inode_by_name(d_inode(child), &dotdot);
if (!ino)
return ERR_PTR(-ENOENT);
root = NILFS_I(d_inode(child))->i_root;

View file

@ -233,7 +233,7 @@ static inline __u32 nilfs_mask_flags(umode_t mode, __u32 flags)
/* dir.c */
extern int nilfs_add_link(struct dentry *, struct inode *);
int nilfs_inode_by_name(struct inode *dir, const struct qstr *qstr, ino_t *ino);
extern ino_t nilfs_inode_by_name(struct inode *, const struct qstr *);
extern int nilfs_make_empty(struct inode *, struct inode *);
extern struct nilfs_dir_entry *
nilfs_find_entry(struct inode *, const struct qstr *, struct page **);