// SPDX-License-Identifier: GPL-2.0-only /* * inode.c - part of tracefs, a pseudo file system for activating tracing * * Based on debugfs by: Greg Kroah-Hartman <greg@kroah.com> * * Copyright (C) 2014 Red Hat Inc, author: Steven Rostedt <srostedt@redhat.com> * * tracefs is the file system that is used by the tracing infrastructure.
*/
/* * Keep track of all tracefs_inodes in order to update their * flags if necessary on a remount.
*/ static DEFINE_SPINLOCK(tracefs_inode_lock); static LIST_HEAD(tracefs_inodes);
name = get_dname(dentry); if (!name) return ERR_PTR(-ENOMEM);
/* * This is a new directory that does not take the default of * the rootfs. It becomes the default permissions for all the * files and directories underneath it.
*/
ti = get_tracefs(inode);
ti->flags |= TRACEFS_INSTANCE_INODE;
ti->private = inode;
/* * The mkdir call can call the generic functions that create * the files within the tracefs system. It is up to the individual * mkdir routine to handle races.
*/
inode_unlock(inode);
ret = tracefs_ops.mkdir(name);
inode_lock(inode);
name = get_dname(dentry); if (!name) return -ENOMEM;
/* * The rmdir call can call the generic functions that create * the files within the tracefs system. It is up to the individual * rmdir routine to handle races. * This time we need to unlock not only the parent (inode) but * also the directory that is being deleted.
*/
inode_unlock(inode);
inode_unlock(d_inode(dentry));
/* * If the root is not the mount point, then check the root's * permissions. If it was never set, then default to the * mount point.
*/ if (root_inode != d_inode(root_inode->i_sb->s_root)) { struct tracefs_inode *rti;
if (!(rti->flags & TRACEFS_UID_PERM_SET))
uid = root_inode->i_uid;
if (!(rti->flags & TRACEFS_GID_PERM_SET))
gid = root_inode->i_gid;
}
/* * If this inode has never been referenced, then update * the permissions to the superblock.
*/ if (!(ti->flags & TRACEFS_UID_PERM_SET))
inode->i_uid = uid;
if (!(ti->flags & TRACEFS_GID_PERM_SET))
inode->i_gid = gid;
}
switch (opt) { case Opt_uid:
opts->uid = result.uid; break; case Opt_gid:
opts->gid = result.gid; break; case Opt_mode:
opts->mode = result.uint_32 & S_IALLUGO; break; /* * We might like to report bad mount options here; * but traditionally tracefs has ignored all mount options
*/
}
if (update_gid) {
ti->flags &= ~TRACEFS_GID_PERM_SET;
ti->vfs_inode.i_gid = fsi->gid;
}
/* * Note, the above ti->vfs_inode updates are * used in eventfs_remount() so they must come * before calling it.
*/ if (ti->flags & TRACEFS_EVENT_INODE)
eventfs_remount(ti, update_uid, update_gid);
}
rcu_read_unlock();
}
/* * This inode is being freed and cannot be used for * eventfs. Clear the flag so that it doesn't call into * eventfs during the remount flag updates. The eventfs_inode * gets freed after an RCU cycle, so the content will still * be safe if the iteration is going on now.
*/
ti->flags &= ~TRACEFS_EVENT_INODE;
/* * It would be cleaner if eventfs had its own dentry ops. * * Note that d_revalidate is called potentially under RCU, * so it can't take the eventfs mutex etc. It's fine - if * we open a file just as it's marked dead, things will * still work just fine, and just see the old stale case.
*/ staticvoid tracefs_d_release(struct dentry *dentry)
{ if (dentry->d_fsdata)
eventfs_d_release(dentry);
}
staticint tracefs_d_delete(conststruct dentry *dentry)
{ /* * We want to keep eventfs dentries around but not tracefs * ones. eventfs dentries have content in d_fsdata. * Use d_fsdata to determine if it's a eventfs dentry or not.
*/ return dentry->d_fsdata == NULL;
}
error = simple_pin_fs(&trace_fs_type, &tracefs_mount,
&tracefs_mount_count); if (error) return ERR_PTR(error);
/* If the parent is not specified, we create it in the root. * We need the root dentry to do this, which is in the super * block. A pointer to that is in the struct vfsmount that we * have around.
*/ if (!parent)
parent = tracefs_mount->mnt_root;
dentry = simple_start_creating(parent, name); if (IS_ERR(dentry))
simple_release_fs(&tracefs_mount, &tracefs_mount_count);
/* Find the inode that this will use for default */ staticstruct inode *instance_inode(struct dentry *parent, struct inode *inode)
{ struct tracefs_inode *ti;
/* If parent is NULL then use root inode */ if (!parent) return d_inode(inode->i_sb->s_root);
/* Find the inode that is flagged as an instance or the root inode */ while (!IS_ROOT(parent)) {
ti = get_tracefs(d_inode(parent)); if (ti->flags & TRACEFS_INSTANCE_INODE) break;
parent = parent->d_parent;
}
return d_inode(parent);
}
/** * tracefs_create_file - create a file in the tracefs filesystem * @name: a pointer to a string containing the name of the file to create. * @mode: the permission that the file should have. * @parent: a pointer to the parent dentry for this file. This should be a * directory dentry if set. If this parameter is NULL, then the * file will be created in the root of the tracefs filesystem. * @data: a pointer to something that the caller will want to get to later * on. The inode.i_private pointer will point to this value on * the open() call. * @fops: a pointer to a struct file_operations that should be used for * this file. * * This is the basic "create a file" function for tracefs. It allows for a * wide range of flexibility in creating a file, or a directory (if you want * to create a directory, the tracefs_create_dir() function is * recommended to be used instead.) * * This function will return a pointer to a dentry if it succeeds. This * pointer must be passed to the tracefs_remove() function when the file is * to be removed (no automatic cleanup happens if your module is unloaded, * you are responsible here.) If an error occurs, %NULL will be returned. * * If tracefs is not enabled in the kernel, the value -%ENODEV will be * returned.
*/ struct dentry *tracefs_create_file(constchar *name, umode_t mode, struct dentry *parent, void *data, conststruct file_operations *fops)
{ struct tracefs_inode *ti; struct dentry *dentry; struct inode *inode;
if (security_locked_down(LOCKDOWN_TRACEFS)) return NULL;
/** * tracefs_create_dir - create a directory in the tracefs filesystem * @name: a pointer to a string containing the name of the directory to * create. * @parent: a pointer to the parent dentry for this file. This should be a * directory dentry if set. If this parameter is NULL, then the * directory will be created in the root of the tracefs filesystem. * * This function creates a directory in tracefs with the given name. * * This function will return a pointer to a dentry if it succeeds. This * pointer must be passed to the tracefs_remove() function when the file is * to be removed. If an error occurs, %NULL will be returned. * * If tracing is not enabled in the kernel, the value -%ENODEV will be * returned.
*/ struct dentry *tracefs_create_dir(constchar *name, struct dentry *parent)
{ if (security_locked_down(LOCKDOWN_TRACEFS)) return NULL;
/** * tracefs_create_instance_dir - create the tracing instances directory * @name: The name of the instances directory to create * @parent: The parent directory that the instances directory will exist * @mkdir: The function to call when a mkdir is performed. * @rmdir: The function to call when a rmdir is performed. * * Only one instances directory is allowed. * * The instances directory is special as it allows for mkdir and rmdir * to be done by userspace. When a mkdir or rmdir is performed, the inode * locks are released and the methods passed in (@mkdir and @rmdir) are * called without locks and with the name of the directory being created * within the instances directory. * * Returns the dentry of the instances directory.
*/
__init struct dentry *tracefs_create_instance_dir(constchar *name, struct dentry *parent, int (*mkdir)(constchar *name), int (*rmdir)(constchar *name))
{ struct dentry *dentry;
/* Only allow one instance of the instances directory. */ if (WARN_ON(tracefs_ops.mkdir || tracefs_ops.rmdir)) return NULL;
dentry = __create_dir(name, parent, &tracefs_instance_dir_inode_operations); if (!dentry) return NULL;
/** * tracefs_remove - recursively removes a directory * @dentry: a pointer to a the dentry of the directory to be removed. * * This function recursively removes a directory tree in tracefs that * was previously created with a call to another tracefs function * (like tracefs_create_file() or variants thereof.)
*/ void tracefs_remove(struct dentry *dentry)
{ if (IS_ERR_OR_NULL(dentry)) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.