lkml.org 
[lkml]   [2024]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH v3 12/14] fs/configfs: Add a callback to determine attribute visibility
    On 4/16/24 00:46, Dan Williams wrote:
    > Tom Lendacky wrote:
    >> In order to support dynamic decisions as to whether an attribute should be
    >> created, add a callback that returns a bool to indicate whether the
    >> attribute should be display. If no callback is registered, the attribute
    >
    > s/display/displayed/

    Will fix.

    >
    >> is displayed by default.
    >>
    >> Cc: Joel Becker <jlbec@evilplan.org>
    >> Cc: Christoph Hellwig <hch@lst.de>
    >> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
    >> ---
    >> fs/configfs/file.c | 7 +++
    >> include/linux/configfs.h | 111 +++++++++++++++++++++++++++------------
    >> 2 files changed, 84 insertions(+), 34 deletions(-)
    >>
    >> diff --git a/fs/configfs/file.c b/fs/configfs/file.c
    >> index 0ad32150611e..a976c183756c 100644
    >> --- a/fs/configfs/file.c
    >> +++ b/fs/configfs/file.c
    >> @@ -451,6 +451,9 @@ int configfs_create_file(struct config_item * item, const struct configfs_attrib
    >> umode_t mode = (attr->ca_mode & S_IALLUGO) | S_IFREG;
    >> int error = 0;
    >>
    >> + if (attr->is_visible && !attr->is_visible(item, attr))
    >> + return 0;
    >> +
    >> inode_lock_nested(d_inode(dir), I_MUTEX_NORMAL);
    >> error = configfs_make_dirent(parent_sd, NULL, (void *) attr, mode,
    >> CONFIGFS_ITEM_ATTR, parent_sd->s_frag);
    >> @@ -470,9 +473,13 @@ int configfs_create_bin_file(struct config_item *item,
    >> {
    >> struct dentry *dir = item->ci_dentry;
    >> struct configfs_dirent *parent_sd = dir->d_fsdata;
    >> + const struct configfs_attribute *attr = &bin_attr->cb_attr;
    >> umode_t mode = (bin_attr->cb_attr.ca_mode & S_IALLUGO) | S_IFREG;
    >> int error = 0;
    >>
    >> + if (attr->is_visible && !attr->is_visible(item, attr))
    >> + return 0;
    >> +
    >> inode_lock_nested(dir->d_inode, I_MUTEX_NORMAL);
    >> error = configfs_make_dirent(parent_sd, NULL, (void *) bin_attr, mode,
    >> CONFIGFS_ITEM_BIN_ATTR, parent_sd->s_frag);
    >> diff --git a/include/linux/configfs.h b/include/linux/configfs.h
    >> index 2606711adb18..c836d7bc7c9e 100644
    >> --- a/include/linux/configfs.h
    >> +++ b/include/linux/configfs.h
    >> @@ -116,35 +116,57 @@ struct configfs_attribute {
    >> const char *ca_name;
    >> struct module *ca_owner;
    >> umode_t ca_mode;
    >> + bool (*is_visible)(const struct config_item *, const struct configfs_attribute *);
    >> ssize_t (*show)(struct config_item *, char *);
    >> ssize_t (*store)(struct config_item *, const char *, size_t);
    >> };
    >>
    >> -#define CONFIGFS_ATTR(_pfx, _name) \
    >> +#define __CONFIGFS_ATTR(_pfx, _name, _vis) \
    >> static struct configfs_attribute _pfx##attr_##_name = { \
    >> .ca_name = __stringify(_name), \
    >> .ca_mode = S_IRUGO | S_IWUSR, \
    >> .ca_owner = THIS_MODULE, \
    >> + .is_visible = _vis, \
    >> .show = _pfx##_name##_show, \
    >> .store = _pfx##_name##_store, \
    >
    > Shouldn't this operation live in configfs_group_operations? That would
    > mirror the sysfs organization, and likely saves some memory.

    I suppose it can, but then you lose the grouping of attributes within
    the same directory, right? A configfs group will result in moving the
    entries into a subdirectory, right? If we go with the group level, then
    we will be moving the existing TSM extra attributes and the new TSM SVSM
    attributes into new, separate sub-directories.

    Thanks,
    Tom



    \
     
     \ /
      Last update: 2024-04-16 18:03    [W:3.315 / U:0.120 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site