[PATCH 01/23] Improve naming of dtype code
Valerie Aurora
val at versity.com
Fri Apr 4 11:45:17 PDT 2025
To more easily distinguish the POSIX dtype and the persistent dtype
used by ngnfs in its directory entries, name the POSIX dtype
"abi_dtype" and the ngnfs persistent dtype "pers_dtype". Also remove
the unnecessary dtype member of dirent_args, remove the unnecessary
export of ngnfs dtype translation, and fix a latent bug in
update_dir() where the type of the parent directory was used when the
type of the child dentry should have been used (adding a child dir
increases nlink of parent dir).
Signed-off-by: Valerie Aurora <val at versity.com>
---
shared/dir.c | 21 ++++++++++++---------
shared/dir.h | 4 ----
shared/format-block.h | 2 +-
3 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/shared/dir.c b/shared/dir.c
index a0c698f..b642c6e 100644
--- a/shared/dir.c
+++ b/shared/dir.c
@@ -54,7 +54,6 @@ static u64 name_hash(void *name, size_t name_len)
struct dirent_args {
u64 hash;
size_t dent_size;
- u8 dtype;
u64 ino;
struct ngnfs_dirent dent;
@@ -68,8 +67,10 @@ static void init_dirent_key(struct ngnfs_btree_key *key, u64 hash)
};
}
-/* Convert a POSIX file mode to an ngnfs on-disk dirent type */
-static enum ngnfs_dentry_type mode_to_type(umode_t mode)
+/*
+ * Convert a POSIX file mode to an ngnfs persistent dirent type.
+ */
+static enum ngnfs_dentry_type mode_to_pers_type(umode_t mode)
{
#define S_SHIFT 12
static unsigned char mode_types[S_IFMT >> S_SHIFT] = {
@@ -86,8 +87,11 @@ static enum ngnfs_dentry_type mode_to_type(umode_t mode)
#undef S_SHIFT
}
-/* Convert the on-disk ngnfs dirent dtype to the POSIX d_type */
-unsigned int ngnfs_type_to_dtype(enum ngnfs_dentry_type type)
+/*
+ * Convert the persistent ngnfs directory entry type to the POSIX ABI
+ * dtype.
+ */
+static unsigned int pers_dtype_to_abi_dtype(enum ngnfs_dentry_type type)
{
static unsigned char types[] = {
[NGNFS_DT_FIFO] = DT_FIFO,
@@ -110,11 +114,10 @@ static void init_dirent_args(struct dirent_args *da, char *name, size_t name_len
{
da->hash = name_hash(name, name_len);
da->dent_size = offsetof(struct ngnfs_dirent, name) + name_len;
- da->dtype = IFTODT(mode);
da->dent.ino = cpu_to_le64(ino);
da->dent.version = cpu_to_le64(0); /* XXX :/ */
- da->dent.type = mode_to_type(mode);
+ da->dent.pers_dtype = mode_to_pers_type(mode);
da->dent.name_len = name_len;
/* ensure that we're stitching together a contiguous max name buffer */
@@ -150,7 +153,7 @@ static int update_dir(struct ngnfs_txn_block *tblk, struct ngnfs_inode *dir,
s32 delta;
int ret;
- if (S_ISDIR(le32_to_cpu(dir->mode))) {
+ if (da->dent.pers_dtype == NGNFS_DT_DIR) {
delta = posneg * 1;
if ((le32_to_cpu(dir->nlink) + delta >= NGNFS_LINK_MAX)) {
ret = -EMLINK;
@@ -296,7 +299,7 @@ static int fill_dirent_rd(struct ngnfs_btree_key *key, void *val, size_t val_siz
ra->ent->ino = le64_to_cpu(dent->ino);
ra->ent->gen = le64_to_cpu(dent->version);
ra->ent->next_offset = aligned;
- ra->ent->dtype = ngnfs_type_to_dtype(dent->type);
+ ra->ent->dtype = pers_dtype_to_abi_dtype(dent->pers_dtype);
ra->ent->name_len = dent->name_len;
memcpy(ra->ent->name, dent->name, dent->name_len);
ra->ent->name[ra->ent->name_len] = '\0';
diff --git a/shared/dir.h b/shared/dir.h
index b333686..5594162 100644
--- a/shared/dir.h
+++ b/shared/dir.h
@@ -38,8 +38,4 @@ struct ngnfs_readdir_entry {
int ngnfs_dir_readdir(struct ngnfs_fs_info *nfi, u64 dir_ino, u64 pos,
struct ngnfs_readdir_entry *buf, size_t size);
-enum ngnfs_dentry_type;
-
-unsigned int ngnfs_type_to_dtype(enum ngnfs_dentry_type type);
-
#endif
diff --git a/shared/format-block.h b/shared/format-block.h
index 65274e1..95ba9ff 100644
--- a/shared/format-block.h
+++ b/shared/format-block.h
@@ -125,7 +125,7 @@ enum ngnfs_dentry_type {
struct ngnfs_dirent {
__le64 ino;
__le64 version; /* XXX ? */
- __u8 type;
+ __u8 pers_dtype; /* ngnfs persistent directory entry type */
__u8 name_len; /* no null termination */
__u8 name[6]; /* definition pads to alignment, stored can be smaller */
};
--
2.48.1
More information about the ngnfs-devel
mailing list