Messages in this thread | | | Date | Wed, 31 Jan 2024 08:14:49 -0500 | From | Steven Rostedt <> | Subject | Re: [PATCH 5/6] eventfs: get rid of dentry pointers without refcounts |
| |
On Wed, 31 Jan 2024 07:57:40 -0500 Steven Rostedt <rostedt@goodmis.org> wrote:
> static int instance_rmdir(const char *name) > { > struct trace_array *tr; > int ret; > > mutex_lock(&event_mutex);
Note, event_mutex prevents dynamic events from being created. No kprobe can be added while the event_mutex is held (not to be confused with eventfs_mutex).
> mutex_lock(&trace_types_lock); > > ret = -ENODEV; > tr = trace_array_find(name); > if (tr) > ret = __remove_instance(tr); > > mutex_unlock(&trace_types_lock); > mutex_unlock(&event_mutex); > > return ret; > }
And
static int instance_mkdir(const char *name) { struct trace_array *tr; int ret;
mutex_lock(&event_mutex); mutex_lock(&trace_types_lock);
ret = -EEXIST; if (trace_array_find(name)) goto out_unlock;
tr = trace_array_create(name);
ret = PTR_ERR_OR_ZERO(tr);
out_unlock: mutex_unlock(&trace_types_lock); mutex_unlock(&event_mutex); return ret; }
The above functions would have been basically what would have been called if I had created:
echo foo >> make_instance echo '!foo' >> remove_instance
In fact, IIRC, I did do the above first, and then moved that code into mkdir/rmdir. Such that the tracefs mkdir and rmdir were just helpers and not real "mkdir" and "rmdir" routines. This isn't in git history because it was done only on my local repository.
If you also notice, tracefs only allows mkdir/rmdir to be assigned to one directory. Once it is assigned, no other directories can have mkdir rmdir functionality.
/sys/kernel/tracing/instances
is the *only* directory that can have mkdir rmdir on it.
__init struct dentry *tracefs_create_instance_dir(const char *name, struct dentry *parent, int (*mkdir)(const char *name), int (*rmdir)(const char *name)) { struct dentry *dentry;
/* Only allow one instance of the instances directory. */ if (WARN_ON(tracefs_ops.mkdir || tracefs_ops.rmdir)) return NULL;
And IIRC, Al told me that if I released the locks, it's up to the above functions to prevent the races from occurring. That is, no file can be created or remove when the mkdir and rmdir are running. Which the event_mutex prevents.
Basically, I freeze external file creation and deletion within tracefs/eventfs when the above mkdir/rmdir is being executed, and prevent rmdir if any file within it is open.
-- Steve
| |