Skip to content

Commit

Permalink
dentry: Rework dentry references and destruction
Browse files Browse the repository at this point in the history
Now dentries default to d_ref = 0, and there's a way to lock references
out.

Signed-off-by: Pedro Falcato <[email protected]>
  • Loading branch information
heatd committed Aug 3, 2024
1 parent cf39338 commit 7cefbb0
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 132 deletions.
6 changes: 6 additions & 0 deletions kernel/include/onyx/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
#define atomic_and_relaxed(var, mask) (__atomic_and_fetch(&(var), mask, __ATOMIC_RELAXED))
#define atomic_or_relaxed(var, mask) (__atomic_or_fetch(&(var), mask, __ATOMIC_RELAXED))

#define cmpxchg(ptr, old, new) \
({ \
__auto_type __old = (old); \
__atomic_compare_exchange_n(ptr, &__old, new, false, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); \
__old; \
})
#endif
12 changes: 7 additions & 5 deletions kernel/include/onyx/dentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct dentry_operations
int (*d_revalidate)(struct dentry *, unsigned int flags);
};

#define D_REF_LOCKED (1UL << 63)

struct dentry
{
unsigned long d_ref;
Expand Down Expand Up @@ -66,8 +68,8 @@ struct dentry
struct dentry *dentry_open(char *path, struct dentry *base);
struct dentry *dentry_mount(const char *mountpoint, struct inode *inode);
void dentry_init();
void dentry_put(struct dentry *d);
void dentry_get(struct dentry *d);
void dput(struct dentry *d);
void dget(struct dentry *d);
struct inode;
struct dentry *dentry_create(const char *name, struct inode *inode, struct dentry *parent,
u16 flags
Expand Down Expand Up @@ -128,13 +130,13 @@ class auto_dentry
void ref() const
{
if (d)
dentry_get(d);
dget(d);
}

void unref() const
{
if (d)
dentry_put(d);
dput(d);
}

public:
Expand All @@ -147,7 +149,7 @@ class auto_dentry
~auto_dentry()
{
if (d)
dentry_put(d);
dput(d);
}

auto_dentry &operator=(const auto_dentry &rhs)
Expand Down
4 changes: 2 additions & 2 deletions kernel/include/onyx/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ struct path

static inline void path_get(struct path *p)
{
dentry_get(p->dentry);
dget(p->dentry);
mnt_get(p->mount);
}

static inline void path_put(struct path *p)
{
if (p->dentry)
dentry_put(p->dentry);
dput(p->dentry);
if (p->mount)
mnt_put(p->mount);
}
Expand Down
Loading

0 comments on commit 7cefbb0

Please sign in to comment.