ANDROID: sdcardfs: Refactor configfs interface
This refactors the configfs code to be more easily extended. It will allow additional files to be added easily. Signed-off-by: Daniel Rosenberg <drosen@google.com> Bug: 34542611 Bug: 34262585 Change-Id: I73c9b0ae5ca7eb27f4ebef3e6807f088b512d539
This commit is contained in:
parent
080b3fcf03
commit
4c43f87830
1 changed files with 53 additions and 80 deletions
|
@ -220,26 +220,24 @@ static void packagelist_destroy(void)
|
||||||
printk(KERN_INFO "sdcardfs: destroyed packagelist pkgld\n");
|
printk(KERN_INFO "sdcardfs: destroyed packagelist pkgld\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct package_appid {
|
struct package_details {
|
||||||
struct config_item item;
|
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 ssize_t package_appid_attr_show(struct config_item *item,
|
static ssize_t package_details_appid_show(struct config_item *item, char *page)
|
||||||
char *page)
|
|
||||||
{
|
{
|
||||||
return scnprintf(page, PAGE_SIZE, "%u\n", get_appid(item->ci_name));
|
return scnprintf(page, PAGE_SIZE, "%u\n", get_appid(to_package_details(item)->name));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t package_appid_attr_store(struct config_item *item,
|
static ssize_t package_details_appid_store(struct config_item *item,
|
||||||
const char *page, size_t count)
|
const char *page, size_t count)
|
||||||
{
|
{
|
||||||
struct package_appid *package_appid = to_package_appid(item);
|
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -247,73 +245,60 @@ static ssize_t package_appid_attr_store(struct config_item *item,
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = insert_packagelist_entry(item->ci_name, tmp);
|
ret = insert_packagelist_entry(to_package_details(item)->name, tmp);
|
||||||
package_appid->add_pid = tmp;
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct configfs_attribute package_appid_attr_add_pid = {
|
static void package_details_release(struct config_item *item)
|
||||||
.ca_owner = THIS_MODULE,
|
{
|
||||||
.ca_name = "appid",
|
struct package_details *package_details = to_package_details(item);
|
||||||
.ca_mode = S_IRUGO | S_IWUGO,
|
printk(KERN_INFO "sdcardfs: removing %s\n", package_details->name);
|
||||||
.show = package_appid_attr_show,
|
remove_packagelist_entry(package_details->name);
|
||||||
.store = package_appid_attr_store,
|
kfree(package_details->name);
|
||||||
};
|
kfree(package_details);
|
||||||
|
}
|
||||||
|
|
||||||
static struct configfs_attribute *package_appid_attrs[] = {
|
CONFIGFS_ATTR(package_details_, appid);
|
||||||
&package_appid_attr_add_pid,
|
|
||||||
|
static struct configfs_attribute *package_details_attrs[] = {
|
||||||
|
&package_details_attr_appid,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void package_appid_release(struct config_item *item)
|
static struct configfs_item_operations package_details_item_ops = {
|
||||||
{
|
.release = package_details_release,
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct configfs_item_operations package_appid_item_ops = {
|
|
||||||
.release = package_appid_release,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct config_item_type package_appid_type = {
|
static struct config_item_type package_appid_type = {
|
||||||
.ct_item_ops = &package_appid_item_ops,
|
.ct_item_ops = &package_details_item_ops,
|
||||||
.ct_attrs = package_appid_attrs,
|
.ct_attrs = package_details_attrs,
|
||||||
.ct_owner = THIS_MODULE,
|
.ct_owner = THIS_MODULE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct config_item *packages_make_item(struct config_group *group, const char *name)
|
||||||
struct sdcardfs_packages {
|
|
||||||
struct config_group group;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline struct sdcardfs_packages *to_sdcardfs_packages(struct config_item *item)
|
|
||||||
{
|
{
|
||||||
return item ? container_of(to_config_group(item), struct sdcardfs_packages, group) : NULL;
|
struct package_details *package_details;
|
||||||
}
|
|
||||||
|
|
||||||
static struct config_item *sdcardfs_packages_make_item(struct config_group *group, const char *name)
|
package_details = kzalloc(sizeof(struct package_details), GFP_KERNEL);
|
||||||
{
|
if (!package_details)
|
||||||
struct package_appid *package_appid;
|
|
||||||
|
|
||||||
package_appid = kzalloc(sizeof(struct package_appid), GFP_KERNEL);
|
|
||||||
if (!package_appid)
|
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
package_details->name = kstrdup(name, GFP_KERNEL);
|
||||||
|
if (!package_details->name) {
|
||||||
|
kfree(package_details);
|
||||||
|
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_type);
|
||||||
|
|
||||||
package_appid->add_pid = 0;
|
return &package_details->item;
|
||||||
|
|
||||||
return &package_appid->item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t packages_attr_show(struct config_item *item,
|
static ssize_t packages_list_show(struct config_item *item, char *page)
|
||||||
char *page)
|
|
||||||
{
|
{
|
||||||
struct hashtable_entry *hash_cur;
|
struct hashtable_entry *hash_cur;
|
||||||
int i;
|
int i;
|
||||||
|
@ -335,49 +320,37 @@ static ssize_t packages_attr_show(struct config_item *item,
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct configfs_attribute sdcardfs_packages_attr_description = {
|
static struct configfs_attribute packages_attr_packages_gid_list = {
|
||||||
.ca_owner = THIS_MODULE,
|
.ca_name = "packages_gid.list",
|
||||||
.ca_name = "packages_gid.list",
|
.ca_mode = S_IRUGO,
|
||||||
.ca_mode = S_IRUGO,
|
.ca_owner = THIS_MODULE,
|
||||||
.show = packages_attr_show,
|
.show = packages_list_show,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct configfs_attribute *sdcardfs_packages_attrs[] = {
|
static struct configfs_attribute *packages_attrs[] = {
|
||||||
&sdcardfs_packages_attr_description,
|
&packages_attr_packages_gid_list,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void sdcardfs_packages_release(struct config_item *item)
|
|
||||||
{
|
|
||||||
|
|
||||||
printk(KERN_INFO "sdcardfs: destroyed something?\n");
|
|
||||||
kfree(to_sdcardfs_packages(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct configfs_item_operations sdcardfs_packages_item_ops = {
|
|
||||||
.release = sdcardfs_packages_release,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that, since no extra work is required on ->drop_item(),
|
* Note that, since no extra work is required on ->drop_item(),
|
||||||
* no ->drop_item() is provided.
|
* no ->drop_item() is provided.
|
||||||
*/
|
*/
|
||||||
static struct configfs_group_operations sdcardfs_packages_group_ops = {
|
static struct configfs_group_operations packages_group_ops = {
|
||||||
.make_item = sdcardfs_packages_make_item,
|
.make_item = packages_make_item,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct config_item_type sdcardfs_packages_type = {
|
static struct config_item_type packages_type = {
|
||||||
.ct_item_ops = &sdcardfs_packages_item_ops,
|
.ct_group_ops = &packages_group_ops,
|
||||||
.ct_group_ops = &sdcardfs_packages_group_ops,
|
.ct_attrs = packages_attrs,
|
||||||
.ct_attrs = sdcardfs_packages_attrs,
|
|
||||||
.ct_owner = THIS_MODULE,
|
.ct_owner = THIS_MODULE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct configfs_subsystem sdcardfs_packages_subsys = {
|
static struct configfs_subsystem sdcardfs_packages = {
|
||||||
.su_group = {
|
.su_group = {
|
||||||
.cg_item = {
|
.cg_item = {
|
||||||
.ci_namebuf = "sdcardfs",
|
.ci_namebuf = "sdcardfs",
|
||||||
.ci_type = &sdcardfs_packages_type,
|
.ci_type = &packages_type,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -385,7 +358,7 @@ static struct configfs_subsystem sdcardfs_packages_subsys = {
|
||||||
static int configfs_sdcardfs_init(void)
|
static int configfs_sdcardfs_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct configfs_subsystem *subsys = &sdcardfs_packages_subsys;
|
struct configfs_subsystem *subsys = &sdcardfs_packages;
|
||||||
|
|
||||||
config_group_init(&subsys->su_group);
|
config_group_init(&subsys->su_group);
|
||||||
mutex_init(&subsys->su_mutex);
|
mutex_init(&subsys->su_mutex);
|
||||||
|
@ -400,7 +373,7 @@ static int configfs_sdcardfs_init(void)
|
||||||
|
|
||||||
static void configfs_sdcardfs_exit(void)
|
static void configfs_sdcardfs_exit(void)
|
||||||
{
|
{
|
||||||
configfs_unregister_subsystem(&sdcardfs_packages_subsys);
|
configfs_unregister_subsystem(&sdcardfs_packages);
|
||||||
}
|
}
|
||||||
|
|
||||||
int packagelist_init(void)
|
int packagelist_init(void)
|
||||||
|
|
Loading…
Reference in a new issue