configfs updates for Linux 6.13

- remove unused code (Dr. David Alan Gilbert)
  - improve item creation performance (Seamus Connor)
 -----BEGIN PGP SIGNATURE-----
 
 iQI/BAABCgApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAmc8w7wLHGhjaEBsc3Qu
 ZGUACgkQD55TZVIEUYNInBAAw8SDXF/rsJPic44XqRr4+nSgFif0Bhd0l8Xu1EZl
 ujE6EDGpbpk35CPK2cqhCk6tboFDayNeACWur52/NHxm+fO/gQq22LZU618HFtxJ
 QgS40naf6PczCY3SgEe4pOp/KlpGiO7y/FbgGYF2mVsTXpLzFq6ZC/RkAc3iir5E
 VUrnXRfsw0B7uZ/ndS+kBh6q0wTHkGqppi8rf4IpK051b/b5boFG+Kn0UpwK0iLX
 47W7mwMgamAOWXHTHRxb/1dL7w5Q7YHvEqD39yHgs1iS+B9ooLZxSkdrkaigjWTM
 q6VQfemq9UQuDfbuAH8RKTbsopTxAUbPok/ioFe8SCiqbc/3CiU6ejQoIIWEh7Gy
 WUvD1ObMQKyP1T+rzblIzg1IU8XxddDjE/qpwZxhAKSmiihh6roRfjtTXmIGJdD4
 TbwaqIOROSFCHFSbjLraXZ2YqE0OznIT01ZaV9SYEfi4AdbbVyy7bt8YOGX6zd36
 Z73Z6G/t+ksL252KHQqtbUOTz2S3bVI3RePTqD6tl+J4sXLIR8CVC5zYn2z+gY8I
 0fDBGt1Ur6XHOf/RGAuLo5PFo9xRntgKKPIMjTah4BFYAhIGhPGlxiX0l/XeokuX
 3z/3zPJNX82o7QeI8bGo4qYz3oAs7PDsK4xmW2m6Ho8xXKVzLoohRQe8Aiex8o4o
 zQg=
 =nC4V
 -----END PGP SIGNATURE-----

Merge tag 'configfs-6.13-2024-11-19' of git://git.infradead.org/users/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
This commit is contained in:
Linus Torvalds 2024-11-21 11:26:38 -08:00
commit 40f48f82a1
3 changed files with 34 additions and 37 deletions

View File

@ -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;
@ -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,

View File

@ -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;
@ -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) {
@ -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);
@ -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;
@ -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);

View File

@ -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));
}