diff options
| author | Daniel Rosenberg <drosen@google.com> | 2017-01-21 00:35:26 -0800 |
|---|---|---|
| committer | Arvin Quilao <arquilao@gmail.com> | 2017-03-07 04:06:46 +0000 |
| commit | 382404eaa451c24b41bf79343c454afa297df7ee (patch) | |
| tree | 969cc1798224d0edccfe5d88e4ffbd7b5931577f | |
| parent | 07094e2a84ff1733f158d57cbe9532a679ed58c7 (diff) | |
ANDROID: sdcardfs: Refactor configfs interface
This refactors the configfs code to be more easily extended.
It will allow additional files to be added easily.
Bug: 34542611
Bug: 34262585
Change-Id: I73c9b0ae5ca7eb27f4ebef3e6807f088b512d539
Signed-off-by: Daniel Rosenberg <drosen@google.com>
| -rwxr-xr-x | fs/sdcardfs/packagelist.c | 156 |
1 files changed, 76 insertions, 80 deletions
diff --git a/fs/sdcardfs/packagelist.c b/fs/sdcardfs/packagelist.c index dac5d0f7d2d..7321aa609dc 100755 --- a/fs/sdcardfs/packagelist.c +++ b/fs/sdcardfs/packagelist.c @@ -220,39 +220,29 @@ static void packagelist_destroy(void) printk(KERN_INFO "sdcardfs: destroyed packagelist pkgld\n"); } -struct package_appid { +struct package_details { struct config_item item; - int add_pid; + const char* name; }; -static inline struct package_appid *to_package_appid(struct config_item *item) +static inline struct package_details *to_package_details(struct config_item *item) { - return item ? container_of(item, struct package_appid, item) : NULL; + return item ? container_of(item, struct package_details, item) : NULL; } -static struct configfs_attribute package_appid_attr_add_pid = { - .ca_owner = THIS_MODULE, - .ca_name = "appid", - .ca_mode = S_IRUGO | S_IWUGO, -}; - -static struct configfs_attribute *package_appid_attrs[] = { - &package_appid_attr_add_pid, - NULL, -}; +CONFIGFS_ATTR_STRUCT(package_details); +#define PACKAGE_DETAILS_ATTR(_name, _mode, _show, _store) \ +struct package_details_attribute package_details_attr_##_name = __CONFIGFS_ATTR(_name, _mode, _show, _store) -static ssize_t package_appid_attr_show(struct config_item *item, - struct configfs_attribute *attr, +static ssize_t package_details_appid_show(struct package_details *package_details, char *page) { - return scnprintf(page, PAGE_SIZE, "%u\n", get_appid(item->ci_name)); + return scnprintf(page, PAGE_SIZE, "%u\n", get_appid(package_details->name)); } -static ssize_t package_appid_attr_store(struct config_item *item, - struct configfs_attribute *attr, +static ssize_t package_details_appid_store(struct package_details *package_details, const char *page, size_t count) { - struct package_appid *package_appid = to_package_appid(item); unsigned int tmp; int ret; @@ -260,73 +250,76 @@ static ssize_t package_appid_attr_store(struct config_item *item, if (ret) return ret; - ret = insert_packagelist_entry(item->ci_name, tmp); - package_appid->add_pid = tmp; + ret = insert_packagelist_entry(package_details->name, tmp); + if (ret) return ret; return count; } -static void package_appid_release(struct config_item *item) +static void package_details_release(struct config_item *item) { - printk(KERN_INFO "sdcardfs: removing %s\n", item->ci_dentry->d_name.name); - /* item->ci_name is freed already, so we rely on the dentry */ - remove_packagelist_entry(item->ci_dentry->d_name.name); - kfree(to_package_appid(item)); + struct package_details *package_details = to_package_details(item); + printk(KERN_INFO "sdcardfs: removing %s\n", package_details->name); + remove_packagelist_entry(package_details->name); + kfree(package_details->name); + kfree(package_details); } -static struct configfs_item_operations package_appid_item_ops = { - .release = package_appid_release, - .show_attribute = package_appid_attr_show, - .store_attribute = package_appid_attr_store, +PACKAGE_DETAILS_ATTR(appid, S_IRUGO | S_IWUGO, package_details_appid_show, package_details_appid_store); + +static struct configfs_attribute *package_details_attrs[] = { + &package_details_attr_appid.attr, + NULL, +}; + +CONFIGFS_ATTR_OPS(package_details); +static struct configfs_item_operations package_details_item_ops = { + .release = package_details_release, + .show_attribute = package_details_attr_show, + .store_attribute = package_details_attr_store, }; static struct config_item_type package_appid_type = { - .ct_item_ops = &package_appid_item_ops, - .ct_attrs = package_appid_attrs, + .ct_item_ops = &package_details_item_ops, + .ct_attrs = package_details_attrs, .ct_owner = THIS_MODULE, }; - -struct sdcardfs_packages { - struct config_group group; +struct packages { + struct configfs_subsystem subsystem; }; -static inline struct sdcardfs_packages *to_sdcardfs_packages(struct config_item *item) +static inline struct packages *to_packages(struct config_item *item) { - return item ? container_of(to_config_group(item), struct sdcardfs_packages, group) : NULL; + return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct packages, subsystem) : NULL; } -static struct config_item *sdcardfs_packages_make_item(struct config_group *group, const char *name) +CONFIGFS_ATTR_STRUCT(packages); +#define PACKAGES_ATTR(_name, _mode, _show, _store) \ +struct packages_attribute packages_attr_##_name = __CONFIGFS_ATTR(_name, _mode, _show, _store) +#define PACKAGES_ATTR_RO(_name, _show) \ +struct packages_attribute packages_attr_##_name = __CONFIGFS_ATTR_RO(_name, _show); + +static struct config_item *packages_make_item(struct config_group *group, const char *name) { - struct package_appid *package_appid; + struct package_details *package_details; - package_appid = kzalloc(sizeof(struct package_appid), GFP_KERNEL); - if (!package_appid) + package_details = kzalloc(sizeof(struct package_details), GFP_KERNEL); + if (!package_details) + return ERR_PTR(-ENOMEM); + package_details->name = kstrdup(name, GFP_KERNEL); + if (!package_details->name) return ERR_PTR(-ENOMEM); - config_item_init_type_name(&package_appid->item, name, + config_item_init_type_name(&package_details->item, name, &package_appid_type); - package_appid->add_pid = 0; - - return &package_appid->item; + return &package_details->item; } -static struct configfs_attribute sdcardfs_packages_attr_description = { - .ca_owner = THIS_MODULE, - .ca_name = "packages_gid.list", - .ca_mode = S_IRUGO, -}; - -static struct configfs_attribute *sdcardfs_packages_attrs[] = { - &sdcardfs_packages_attr_description, - NULL, -}; - -static ssize_t packages_attr_show(struct config_item *item, - struct configfs_attribute *attr, +static ssize_t packages_list_show(struct packages *packages, char *page) { struct hashtable_entry *hash_cur; @@ -349,38 +342,41 @@ static ssize_t packages_attr_show(struct config_item *item, return count; } -static void sdcardfs_packages_release(struct config_item *item) -{ +struct packages_attribute packages_attr_packages_gid_list = __CONFIGFS_ATTR_RO(packages_gid.list, packages_list_show); - printk(KERN_INFO "sdcardfs: destroyed something?\n"); - kfree(to_sdcardfs_packages(item)); -} +static struct configfs_attribute *packages_attrs[] = { + &packages_attr_packages_gid_list.attr, + NULL, +}; -static struct configfs_item_operations sdcardfs_packages_item_ops = { - .release = sdcardfs_packages_release, - .show_attribute = packages_attr_show, +CONFIGFS_ATTR_OPS(packages) +static struct configfs_item_operations packages_item_ops = { + .show_attribute = packages_attr_show, + .store_attribute = packages_attr_store, }; /* * Note that, since no extra work is required on ->drop_item(), * no ->drop_item() is provided. */ -static struct configfs_group_operations sdcardfs_packages_group_ops = { - .make_item = sdcardfs_packages_make_item, +static struct configfs_group_operations packages_group_ops = { + .make_item = packages_make_item, }; -static struct config_item_type sdcardfs_packages_type = { - .ct_item_ops = &sdcardfs_packages_item_ops, - .ct_group_ops = &sdcardfs_packages_group_ops, - .ct_attrs = sdcardfs_packages_attrs, +static struct config_item_type packages_type = { + .ct_item_ops = &packages_item_ops, + .ct_group_ops = &packages_group_ops, + .ct_attrs = packages_attrs, .ct_owner = THIS_MODULE, }; -static struct configfs_subsystem sdcardfs_packages_subsys = { - .su_group = { - .cg_item = { - .ci_namebuf = "sdcardfs", - .ci_type = &sdcardfs_packages_type, +static struct packages sdcardfs_packages = { + .subsystem = { + .su_group = { + .cg_item = { + .ci_namebuf = "sdcardfs", + .ci_type = &packages_type, + }, }, }, }; @@ -388,7 +384,7 @@ static struct configfs_subsystem sdcardfs_packages_subsys = { static int configfs_sdcardfs_init(void) { int ret; - struct configfs_subsystem *subsys = &sdcardfs_packages_subsys; + struct configfs_subsystem *subsys = &sdcardfs_packages.subsystem; config_group_init(&subsys->su_group); mutex_init(&subsys->su_mutex); @@ -403,7 +399,7 @@ static int configfs_sdcardfs_init(void) static void configfs_sdcardfs_exit(void) { - configfs_unregister_subsystem(&sdcardfs_packages_subsys); + configfs_unregister_subsystem(&sdcardfs_packages.subsystem); } int packagelist_init(void) |
