Skip to content

Commit d07f132

Browse files
author
Christoph Hellwig
committed
configfs: fold configfs_attach_attr into configfs_lookup
This makes it more clear what gets added to the dcache and prepares for an additional locking fix. Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 899587c commit d07f132

1 file changed

Lines changed: 24 additions & 49 deletions

File tree

fs/configfs/dir.c

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void configfs_d_iput(struct dentry * dentry,
4545
/*
4646
* Set sd->s_dentry to null only when this dentry is the one
4747
* that is going to be killed. Otherwise configfs_d_iput may
48-
* run just after configfs_attach_attr and set sd->s_dentry to
48+
* run just after configfs_lookup and set sd->s_dentry to
4949
* NULL even it's still in use.
5050
*/
5151
if (sd->s_dentry == dentry)
@@ -417,44 +417,13 @@ static void configfs_remove_dir(struct config_item * item)
417417
dput(dentry);
418418
}
419419

420-
421-
/* attaches attribute's configfs_dirent to the dentry corresponding to the
422-
* attribute file
423-
*/
424-
static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * dentry)
425-
{
426-
struct configfs_attribute * attr = sd->s_element;
427-
struct inode *inode;
428-
429-
spin_lock(&configfs_dirent_lock);
430-
dentry->d_fsdata = configfs_get(sd);
431-
sd->s_dentry = dentry;
432-
spin_unlock(&configfs_dirent_lock);
433-
434-
inode = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG);
435-
if (IS_ERR(inode)) {
436-
configfs_put(sd);
437-
return PTR_ERR(inode);
438-
}
439-
if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) {
440-
inode->i_size = 0;
441-
inode->i_fop = &configfs_bin_file_operations;
442-
} else {
443-
inode->i_size = PAGE_SIZE;
444-
inode->i_fop = &configfs_file_operations;
445-
}
446-
d_add(dentry, inode);
447-
return 0;
448-
}
449-
450420
static struct dentry * configfs_lookup(struct inode *dir,
451421
struct dentry *dentry,
452422
unsigned int flags)
453423
{
454424
struct configfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
455425
struct configfs_dirent * sd;
456-
int found = 0;
457-
int err;
426+
struct inode *inode = NULL;
458427

459428
if (dentry->d_name.len > NAME_MAX)
460429
return ERR_PTR(-ENAMETOOLONG);
@@ -471,28 +440,34 @@ static struct dentry * configfs_lookup(struct inode *dir,
471440
return ERR_PTR(-ENOENT);
472441

473442
list_for_each_entry(sd, &parent_sd->s_children, s_sibling) {
474-
if (sd->s_type & CONFIGFS_NOT_PINNED) {
475-
const unsigned char * name = configfs_get_name(sd);
443+
if ((sd->s_type & CONFIGFS_NOT_PINNED) &&
444+
!strcmp(configfs_get_name(sd), dentry->d_name.name)) {
445+
struct configfs_attribute *attr = sd->s_element;
446+
umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG;
476447

477-
if (strcmp(name, dentry->d_name.name))
478-
continue;
448+
spin_lock(&configfs_dirent_lock);
449+
dentry->d_fsdata = configfs_get(sd);
450+
sd->s_dentry = dentry;
451+
spin_unlock(&configfs_dirent_lock);
479452

480-
found = 1;
481-
err = configfs_attach_attr(sd, dentry);
453+
inode = configfs_create(dentry, mode);
454+
if (IS_ERR(inode)) {
455+
configfs_put(sd);
456+
return ERR_CAST(inode);
457+
}
458+
if (sd->s_type & CONFIGFS_ITEM_BIN_ATTR) {
459+
inode->i_size = 0;
460+
inode->i_fop = &configfs_bin_file_operations;
461+
} else {
462+
inode->i_size = PAGE_SIZE;
463+
inode->i_fop = &configfs_file_operations;
464+
}
482465
break;
483466
}
484467
}
485468

486-
if (!found) {
487-
/*
488-
* If it doesn't exist and it isn't a NOT_PINNED item,
489-
* it must be negative.
490-
*/
491-
d_add(dentry, NULL);
492-
return NULL;
493-
}
494-
495-
return ERR_PTR(err);
469+
d_add(dentry, inode);
470+
return NULL;
496471
}
497472

498473
/*

0 commit comments

Comments
 (0)