[PATCH 13/14] Add nfi, txn, and flags to dirent_args

Valerie Aurora val at versity.com
Thu Feb 27 06:16:22 PST 2025


For directory operations like unlink(), rmdir(), and rename(), the
dirent_args struct needs to carry all necessary info down to the btree
iterator operator function. unlink() needs to know whether it is
attempting to remove a directory or a file, so add a flags field to
dirent_args. rmdir() needs to read the dir inode to get the link
count, so add the nfi and txn pointers. rename() needs to know if the
entry is just being moved to different directory, so add a flag.

Signed-off-by: Valerie Aurora <val at versity.com>
---
 shared/dir.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/shared/dir.c b/shared/dir.c
index 87356ed..5589e3f 100644
--- a/shared/dir.c
+++ b/shared/dir.c
@@ -81,10 +81,14 @@ static u64 name_hash(void *name, size_t name_len) {
  * copy in and out any dirent as we work with them.
  */
 struct dirent_args {
+	struct ngnfs_fs_info *nfi;
+	struct ngnfs_transaction *txn;
+	struct ngnfs_inode_txn_ref inode;
 	u64 hash;
 	size_t dent_size;
 	u8 dtype;
 	u64 ino;
+	u8 flags;
 
 	struct ngnfs_dirent dent;
 	u8 __max_name_storage[NGNFS_NAME_MAX - sizeof_field(struct ngnfs_dirent, name)];
@@ -144,12 +148,17 @@ static void fill_dent(__le64 ino, __le64 version, enum ngnfs_dentry_type type, c
 	memcpy(dent->name, name, name_len);
 }
 
-static void init_dirent_args(struct dirent_args *da, char *name, size_t name_len, u64 ino,
-			     mode_t mode)
+static void init_dirent_args(struct ngnfs_fs_info *nfi, struct ngnfs_transaction *txn,
+			     struct dirent_args *da, char *name, size_t name_len, u64 ino,
+			     mode_t mode, int flags)
 {
+	da->nfi = nfi;
+	da->txn = txn;
+
 	da->hash = name_hash(name, name_len);
 	da->dent_size = offsetof(struct ngnfs_dirent, name) + name_len;
 	da->dtype = IFTODT(mode);
+	da->flags = flags;
 
 	fill_dent(cpu_to_le64(ino), 0 /* XXX :/ */, mode_to_type(mode), name, name_len, &da->dent);
 
@@ -288,7 +297,7 @@ int ngnfs_dir_create(struct ngnfs_fs_info *nfi, u64 dir_ino, umode_t mode, char
 
 	ngnfs_txn_init(&op->txn);
 	op->nsec = ktime_to_ns(ktime_get_real());
-	init_dirent_args(&op->da, name, name_len, 0, mode | S_IFREG);
+	init_dirent_args(nfi, &op->txn, &op->da, name, name_len, 0, mode | S_IFREG, 0);
 
 	do {
 		ret = ngnfs_inode_get(nfi, &op->txn, NBF_WRITE, dir_ino, &op->dir)		?:
@@ -331,7 +340,7 @@ int ngnfs_dir_mkdir(struct ngnfs_fs_info *nfi, u64 dir_ino, umode_t mode, char *
 
 	ngnfs_txn_init(&op->txn);
 	op->nsec = ktime_to_ns(ktime_get_real());
-	init_dirent_args(&op->da, name, name_len, 0, mode | S_IFDIR);
+	init_dirent_args(nfi, &op->txn, &op->da, name, name_len, 0, mode | S_IFDIR, 0);
 
 	do {
 		ret = ngnfs_inode_get(nfi, &op->txn, NBF_WRITE, dir_ino, &op->dir)		?:
@@ -579,7 +588,7 @@ static int do_lookup(struct ngnfs_fs_info *nfi, u64 dir_ino, char *name, size_t
 	}
 
 	ngnfs_txn_init(&op->txn);
-	init_dirent_args(da, name, name_len, 0, 0);
+	init_dirent_args(nfi, &op->txn, da, name, name_len, 0, 0, 0);
 	init_dirent_key(&op->key, da->hash);
 	init_dirent_key(&op->last, da->hash | NGNFS_DIRENT_COLL_BIT);
 
-- 
2.48.1




More information about the ngnfs-devel mailing list