Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/configfs: Add a callback to determine attribute visibility

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 displayed. If no callback is registered, the attribute
is displayed by default.

Co-developed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/e555c8740a263fab9f83b2cbb44da1af49a2813c.1717600736.git.thomas.lendacky@amd.com

authored by

Tom Lendacky and committed by
Borislav Petkov (AMD)
0e6a35b9 614dc0fb

+13
+10
fs/configfs/dir.c
··· 580 580 static int populate_attrs(struct config_item *item) 581 581 { 582 582 const struct config_item_type *t = item->ci_type; 583 + struct configfs_group_operations *ops; 583 584 struct configfs_attribute *attr; 584 585 struct configfs_bin_attribute *bin_attr; 585 586 int error = 0; ··· 588 587 589 588 if (!t) 590 589 return -EINVAL; 590 + 591 + ops = t->ct_group_ops; 592 + 591 593 if (t->ct_attrs) { 592 594 for (i = 0; (attr = t->ct_attrs[i]) != NULL; i++) { 595 + if (ops && ops->is_visible && !ops->is_visible(item, attr, i)) 596 + continue; 597 + 593 598 if ((error = configfs_create_file(item, attr))) 594 599 break; 595 600 } 596 601 } 597 602 if (t->ct_bin_attrs) { 598 603 for (i = 0; (bin_attr = t->ct_bin_attrs[i]) != NULL; i++) { 604 + if (ops && ops->is_bin_visible && !ops->is_bin_visible(item, bin_attr, i)) 605 + continue; 606 + 599 607 error = configfs_create_bin_file(item, bin_attr); 600 608 if (error) 601 609 break;
+3
include/linux/configfs.h
··· 216 216 struct config_group *(*make_group)(struct config_group *group, const char *name); 217 217 void (*disconnect_notify)(struct config_group *group, struct config_item *item); 218 218 void (*drop_item)(struct config_group *group, struct config_item *item); 219 + bool (*is_visible)(struct config_item *item, struct configfs_attribute *attr, int n); 220 + bool (*is_bin_visible)(struct config_item *item, struct configfs_bin_attribute *attr, 221 + int n); 219 222 }; 220 223 221 224 struct configfs_subsystem {