always dget the parent and always dput it

This commit is contained in:
Isabella Bosia
2025-12-02 10:30:02 +00:00
parent cc79221543
commit 43450dff76

View File

@@ -901,6 +901,7 @@ static ssize_t file_write_iter(struct kiocb* iocb, struct iov_iter* from) {
// shared functionality of ternfs_flush and ternfs_link // shared functionality of ternfs_flush and ternfs_link
// takes the file we're trying to flush/link, the directory we're going to put it in, and a name/len pair to assign // takes the file we're trying to flush/link, the directory we're going to put it in, and a name/len pair to assign
// note: caller must take care of dget_parent/dput
static int flush_and_link(struct ternfs_inode *enode, struct dentry *parent, const char *name, size_t name_len) { static int flush_and_link(struct ternfs_inode *enode, struct dentry *parent, const char *name, size_t name_len) {
BUG_ON(!inode_is_locked(&enode->inode)); BUG_ON(!inode_is_locked(&enode->inode));
@@ -953,10 +954,7 @@ static int flush_and_link(struct ternfs_inode *enode, struct dentry *parent, con
// expire the directory listing -- we know for a fact that it // expire the directory listing -- we know for a fact that it
// is wrong, it now contains this file. // is wrong, it now contains this file.
{ WRITE_ONCE(TERNFS_I(d_inode(parent))->dir.mtime_expiry, 0);
WRITE_ONCE(TERNFS_I(d_inode(parent))->dir.mtime_expiry, 0);
dput(parent);
}
out: out:
if (err) { if (err) {
@@ -1008,7 +1006,13 @@ int ternfs_file_flush(struct ternfs_inode* enode, struct dentry* dentry) {
goto out; goto out;
} }
err = flush_and_link(enode, dentry->d_parent, dentry->d_name.name, dentry->d_name.len);
struct dentry *parent = dget_parent(dentry);
err = flush_and_link(enode, parent, dentry->d_name.name, dentry->d_name.len);
if (parent)
dput(parent);
out: out:
inode_unlock(&enode->inode); inode_unlock(&enode->inode);
@@ -1051,6 +1055,9 @@ int ternfs_link(struct dentry* old_dentry, struct inode* dir, struct dentry* new
err = flush_and_link(enode, parent, new_dentry->d_name.name, new_dentry->d_name.len); err = flush_and_link(enode, parent, new_dentry->d_name.name, new_dentry->d_name.len);
out: out:
if (parent)
dput(parent);
return err; return err;
} }