^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * inode.c - basic inode and dentry operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on sysfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * configfs Copyright (C) 2005 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Please see Documentation/filesystems/configfs.rst for more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/configfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "configfs_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static struct lock_class_key default_group_class[MAX_LOCK_DEPTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static const struct address_space_operations configfs_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .readpage = simple_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .write_begin = simple_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .write_end = simple_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static const struct inode_operations configfs_inode_operations ={
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .setattr = configfs_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int configfs_setattr(struct dentry * dentry, struct iattr * iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct inode * inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct configfs_dirent * sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct iattr * sd_iattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned int ia_valid = iattr->ia_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (!sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) sd_iattr = sd->s_iattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!sd_iattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* setting attributes for the first time, allocate now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!sd_iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* assign default attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) sd_iattr->ia_mode = sd->s_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) sd_iattr->ia_uid = GLOBAL_ROOT_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) sd_iattr->ia_gid = GLOBAL_ROOT_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) sd_iattr->ia_atime = sd_iattr->ia_mtime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) sd_iattr->ia_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) sd->s_iattr = sd_iattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* attributes were changed atleast once in past */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) error = simple_setattr(dentry, iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (ia_valid & ATTR_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) sd_iattr->ia_uid = iattr->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (ia_valid & ATTR_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) sd_iattr->ia_gid = iattr->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (ia_valid & ATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) sd_iattr->ia_atime = iattr->ia_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (ia_valid & ATTR_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) sd_iattr->ia_mtime = iattr->ia_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (ia_valid & ATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) sd_iattr->ia_ctime = iattr->ia_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (ia_valid & ATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) umode_t mode = iattr->ia_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) mode &= ~S_ISGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) sd_iattr->ia_mode = sd->s_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static inline void set_default_inode_attr(struct inode * inode, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) inode->i_atime = inode->i_mtime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static inline void set_inode_attr(struct inode * inode, struct iattr * iattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) inode->i_mode = iattr->ia_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) inode->i_uid = iattr->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) inode->i_gid = iattr->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) inode->i_atime = iattr->ia_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) inode->i_mtime = iattr->ia_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) inode->i_ctime = iattr->ia_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct inode *configfs_new_inode(umode_t mode, struct configfs_dirent *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct inode * inode = new_inode(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) inode->i_ino = get_next_ino();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) inode->i_mapping->a_ops = &configfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) inode->i_op = &configfs_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (sd->s_iattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* sysfs_dirent has non-default attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * get them for the new inode from persistent copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * in sysfs_dirent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) set_inode_attr(inode, sd->s_iattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) set_default_inode_attr(inode, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void configfs_set_inode_lock_class(struct configfs_dirent *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int depth = sd->s_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (depth > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (depth <= ARRAY_SIZE(default_group_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) lockdep_set_class(&inode->i_rwsem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) &default_group_class[depth - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * In practice the maximum level of locking depth is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * already reached. Just inform about possible reasons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) pr_info("Too many levels of inodes for the locking correctness validator.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) pr_info("Spurious warnings may appear.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #else /* CONFIG_LOCKDEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static void configfs_set_inode_lock_class(struct configfs_dirent *sd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #endif /* CONFIG_LOCKDEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct inode *configfs_create(struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct configfs_dirent *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct inode *p_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (d_really_is_positive(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return ERR_PTR(-EEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) sd = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) inode = configfs_new_inode(mode, sd, dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) p_inode = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) p_inode->i_mtime = p_inode->i_ctime = current_time(p_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) configfs_set_inode_lock_class(sd, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Get the name for corresponding element represented by the given configfs_dirent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) const unsigned char * configfs_get_name(struct configfs_dirent *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct configfs_attribute *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) BUG_ON(!sd || !sd->s_element);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* These always have a dentry, so use that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (sd->s_type & (CONFIGFS_DIR | CONFIGFS_ITEM_LINK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return sd->s_dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (sd->s_type & (CONFIGFS_ITEM_ATTR | CONFIGFS_ITEM_BIN_ATTR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) attr = sd->s_element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return attr->ca_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Unhashes the dentry corresponding to given configfs_dirent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * Called with parent inode's i_mutex held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void configfs_drop_dentry(struct configfs_dirent * sd, struct dentry * parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct dentry * dentry = sd->s_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) spin_lock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (simple_positive(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dget_dlock(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) __d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) spin_unlock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) simple_unlink(d_inode(parent), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) spin_unlock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) void configfs_hash_and_remove(struct dentry * dir, const char * name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct configfs_dirent * sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct configfs_dirent * parent_sd = dir->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (d_really_is_negative(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* no inode means this hasn't been made visible yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) inode_lock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (!sd->s_element)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (!strcmp(configfs_get_name(sd), name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) spin_lock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) list_del_init(&sd->s_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) spin_unlock(&configfs_dirent_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) configfs_drop_dentry(sd, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) configfs_put(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }