From 4b5001196a469819f97ba8f50be2e3bcd8cfcfd1 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sun, 23 Aug 2020 21:05:39 +0000 Subject: [PATCH] vfs: convert nameiop into an enum While here change the field size from long to int and move it into the gap next to cn_flags. Shrinks struct componentname from 64 to 56 bytes on amd64. --- sys/kern/vfs_lookup.c | 4 ---- sys/sys/namei.h | 13 ++++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index e38b02e9652..4e5f4427c76 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -484,10 +484,6 @@ namei(struct nameidata *ndp) td = cnp->cn_thread; ndp->ni_cnd.cn_cred = ndp->ni_cnd.cn_thread->td_ucred; KASSERT(cnp->cn_cred && td->td_proc, ("namei: bad cred/proc")); - KASSERT((cnp->cn_nameiop & (~OPMASK)) == 0, - ("namei: nameiop contaminated with flags")); - KASSERT((cnp->cn_flags & OPMASK) == 0, - ("namei: flags contaminated with nameiops")); KASSERT((cnp->cn_flags & NAMEI_INTERNAL_FLAGS) == 0, ("namei: unexpected flags: %" PRIx64 "\n", cnp->cn_flags & NAMEI_INTERNAL_FLAGS)); diff --git a/sys/sys/namei.h b/sys/sys/namei.h index 479fbace1bd..862139181c0 100644 --- a/sys/sys/namei.h +++ b/sys/sys/namei.h @@ -40,14 +40,16 @@ #include #include +enum nameiop { LOOKUP, CREATE, DELETE, RENAME }; + struct componentname { /* * Arguments to lookup. */ - u_long cn_nameiop; /* namei operation */ u_int64_t cn_flags; /* flags to namei */ struct thread *cn_thread;/* thread requesting lookup */ struct ucred *cn_cred; /* credentials */ + enum nameiop cn_nameiop; /* namei operation */ int cn_lkflags; /* Lock flags LK_EXCLUSIVE or LK_SHARED */ /* * Shared between lookup and commit routines. @@ -115,13 +117,10 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status, struct pwd **pwdp); /* - * namei operations + * Flags for namei. + * + * If modifying the list make sure to check whether NDVALIDATE needs updating. */ -#define LOOKUP 0 /* perform name lookup only */ -#define CREATE 1 /* setup for file creation */ -#define DELETE 2 /* setup for file deletion */ -#define RENAME 3 /* setup for file renaming */ -#define OPMASK 3 /* mask for operation */ /* * namei operational modifier flags, stored in ni_cnd.flags */