[PATCH 2/2] Add rpdfs_rmdir()
Valerie Aurora <[email protected]> Tue, 24 Feb 2026 17:41:57 +0100
| Newsgroups | dev.linux.lists.rpdfs-devel |
|---|---|
| Message-ID | <[email protected]> |
Copied from rpdfs_rename() and the extra bits removed. Signed-off-by: Valerie Aurora <[email protected]> --- fs/rpdfs/dir.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/fs/rpdfs/dir.c b/fs/rpdfs/dir.c index 9b33453ad5f6..cff995a7618c 100644 --- a/fs/rpdfs/dir.c +++ b/fs/rpdfs/dir.c @@ -541,6 +541,56 @@ static int rpdfs_unlink(struct inode *dir, struct dentry *dentry) return ret; } +static int rpdfs_rmdir(struct inode *dir, struct dentry *dentry) +{ + struct rpdfs_fs_info *rfi = RPDFS_INODE_FS(dir); + struct inode *inode = d_inode(dentry); + struct key_dent *kd = NULL; + DECLARE_RPDFS_TXN(txn); + int ret; + + kd = alloc_key_dent(dentry, inode); + if (!kd) { + ret = -ENOMEM; + goto out; + } + + /* prepare all the blocks in the txn */ + do { + ret = rpdfs_inode_txn_prepare(rfi, &txn, dir, RBAF_WRITE) ?: + rpdfs_inode_txn_prepare(rfi, &txn, inode, RBAF_WRITE) ?: + prepare_remove_entry(rfi, &txn, dir, kd); + } while (rpdfs_txn_retry(rfi, &txn, &ret)); + if (ret < 0) + goto out; + + /* apply changes to block structures */ + apply_remove_entry(rfi, &txn, dir, kd); + + /* update vfs inodes: first dir sizes and times */ + i_size_write(dir, i_size_read(dir) - dentry->d_name.len); + inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); + + /* now inode nlink and times */ + if (inode->i_nlink < 2) + pr_warn("deleting dir %.*s with link count %d < 2", + dentry->d_name.len, dentry->d_name.name, inode->i_nlink); + else + clear_nlink(inode); + inode_set_ctime_current(inode); + + /* update block storage of vfs inodes */ + rpdfs_inode_txn_update(rfi, &txn, dir); + rpdfs_inode_txn_update(rfi, &txn, inode); + + ret = 0; +out: + rpdfs_txn_reset(rfi, &txn); + kfree(kd); + + return ret; +} + /* * The vfs has verified the cached directories. Our inode refresh will * fail if the inodes have been reused, so we don't have to test if @@ -731,6 +781,7 @@ const struct inode_operations rpdfs_dir_iops = { .mkdir = rpdfs_mkdir, .rename = rpdfs_rename, .unlink = rpdfs_unlink, + .rmdir = rpdfs_rmdir, }; const struct file_operations rpdfs_dir_fops = { -- 2.49.0