Skip to content

Commit

Permalink
Merge tag 'configfs-6.13-2024-11-19' of git://git.infradead.org/users…
Browse files Browse the repository at this point in the history
…/hch/configfs

Pull configfs updates from Christoph Hellwig:

 - remove unused code (Dr. David Alan Gilbert)

 - improve item creation performance (Seamus Connor)

* tag 'configfs-6.13-2024-11-19' of git://git.infradead.org/users/hch/configfs:
  configfs: improve item creation performance
  configfs: remove unused configfs_hash_and_remove
  • Loading branch information
torvalds committed Nov 21, 2024
2 parents fc39fb5 + 84147f4 commit 40f48f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
4 changes: 2 additions & 2 deletions fs/configfs/configfs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct configfs_dirent {
#define CONFIGFS_USET_IN_MKDIR 0x0200
#define CONFIGFS_USET_CREATING 0x0400
#define CONFIGFS_NOT_PINNED (CONFIGFS_ITEM_ATTR | CONFIGFS_ITEM_BIN_ATTR)
#define CONFIGFS_PINNED \
(CONFIGFS_ROOT | CONFIGFS_DIR | CONFIGFS_ITEM_LINK)

extern struct mutex configfs_symlink_mutex;
extern spinlock_t configfs_dirent_lock;
Expand All @@ -73,8 +75,6 @@ extern int configfs_make_dirent(struct configfs_dirent *, struct dentry *,
void *, umode_t, int, struct configfs_fragment *);
extern int configfs_dirent_is_ready(struct configfs_dirent *);

extern void configfs_hash_and_remove(struct dentry * dir, const char * name);

extern const unsigned char * configfs_get_name(struct configfs_dirent *sd);
extern void configfs_drop_dentry(struct configfs_dirent *sd, struct dentry *parent);
extern int configfs_setattr(struct mnt_idmap *idmap,
Expand Down
42 changes: 32 additions & 10 deletions fs/configfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,17 @@ static struct configfs_dirent *configfs_new_dirent(struct configfs_dirent *paren
return ERR_PTR(-ENOENT);
}
sd->s_frag = get_fragment(frag);
list_add(&sd->s_sibling, &parent_sd->s_children);

/*
* configfs_lookup scans only for unpinned items. s_children is
* partitioned so that configfs_lookup can bail out early.
* CONFIGFS_PINNED and CONFIGFS_NOT_PINNED are not symmetrical. readdir
* cursors still need to be inserted at the front of the list.
*/
if (sd->s_type & CONFIGFS_PINNED)
list_add_tail(&sd->s_sibling, &parent_sd->s_children);
else
list_add(&sd->s_sibling, &parent_sd->s_children);
spin_unlock(&configfs_dirent_lock);

return sd;
Expand All @@ -220,10 +230,11 @@ static struct configfs_dirent *configfs_new_dirent(struct configfs_dirent *paren
*
* called with parent inode's i_mutex held
*/
static int configfs_dirent_exists(struct configfs_dirent *parent_sd,
const unsigned char *new)
static int configfs_dirent_exists(struct dentry *dentry)
{
struct configfs_dirent * sd;
struct configfs_dirent *parent_sd = dentry->d_parent->d_fsdata;
const unsigned char *new = dentry->d_name.name;
struct configfs_dirent *sd;

list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
if (sd->s_element) {
Expand Down Expand Up @@ -289,10 +300,6 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry,

BUG_ON(!item);

error = configfs_dirent_exists(p->d_fsdata, dentry->d_name.name);
if (unlikely(error))
return error;

error = configfs_make_dirent(p->d_fsdata, dentry, item, mode,
CONFIGFS_DIR | CONFIGFS_USET_CREATING,
frag);
Expand Down Expand Up @@ -451,6 +458,18 @@ static struct dentry * configfs_lookup(struct inode *dir,

spin_lock(&configfs_dirent_lock);
list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {

/*
* s_children is partitioned, see configfs_new_dirent. The first
* pinned item indicates we can stop scanning.
*/
if (sd->s_type & CONFIGFS_PINNED)
break;

/*
* Note: CONFIGFS_PINNED and CONFIGFS_NOT_PINNED are asymmetric.
* there may be a readdir cursor in this list
*/
if ((sd->s_type & CONFIGFS_NOT_PINNED) &&
!strcmp(configfs_get_name(sd), dentry->d_name.name)) {
struct configfs_attribute *attr = sd->s_element;
Expand Down Expand Up @@ -1885,8 +1904,11 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)
if (dentry) {
d_add(dentry, NULL);

err = configfs_attach_group(sd->s_element, &group->cg_item,
dentry, frag);
err = configfs_dirent_exists(dentry);
if (!err)
err = configfs_attach_group(sd->s_element,
&group->cg_item,
dentry, frag);
if (err) {
BUG_ON(d_inode(dentry));
d_drop(dentry);
Expand Down
25 changes: 0 additions & 25 deletions fs/configfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,3 @@ void configfs_drop_dentry(struct configfs_dirent * sd, struct dentry * parent)
spin_unlock(&dentry->d_lock);
}
}

void configfs_hash_and_remove(struct dentry * dir, const char * name)
{
struct configfs_dirent * sd;
struct configfs_dirent * parent_sd = dir->d_fsdata;

if (d_really_is_negative(dir))
/* no inode means this hasn't been made visible yet */
return;

inode_lock(d_inode(dir));
list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
if (!sd->s_element)
continue;
if (!strcmp(configfs_get_name(sd), name)) {
spin_lock(&configfs_dirent_lock);
list_del_init(&sd->s_sibling);
spin_unlock(&configfs_dirent_lock);
configfs_drop_dentry(sd, dir);
configfs_put(sd);
break;
}
}
inode_unlock(d_inode(dir));
}

0 comments on commit 40f48f8

Please sign in to comment.