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

View file

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