Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759622AbYAYHX5 (ORCPT ); Fri, 25 Jan 2008 02:23:57 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758566AbYAYHPq (ORCPT ); Fri, 25 Jan 2008 02:15:46 -0500 Received: from cantor2.suse.de ([195.135.220.15]:47499 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758551AbYAYHPp (ORCPT ); Fri, 25 Jan 2008 02:15:45 -0500 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Michael A. Halcrow" , "Michael C. Thompson" , Tyler Hicks Subject: [PATCH 029/196] ecryptfs: clean up attribute mess Date: Thu, 24 Jan 2008 23:09:27 -0800 Message-Id: <1201245134-4876-29-git-send-email-gregkh@suse.de> X-Mailer: git-send-email 1.5.3.8 In-Reply-To: <20080125071127.GA4860@kroah.com> References: <20080125071127.GA4860@kroah.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4807 Lines: 158 It isn't that hard to add simple kset attributes, so don't go through all the gyrations of creating your own object type and show and store functions. Just use the functions that are already present. This makes things much simpler. Note, the version_str string violates the "one value per file" rule for sysfs. I suggest changing this now (individual files per type supported is one suggested way.) Cc: Michael A. Halcrow Cc: Michael C. Thompson Cc: Tyler Hicks Signed-off-by: Greg Kroah-Hartman --- fs/ecryptfs/main.c | 85 +++++++++++----------------------------------------- 1 files changed, 18 insertions(+), 67 deletions(-) diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index e5580bc..f9f3247 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c @@ -734,58 +734,14 @@ static int ecryptfs_init_kmem_caches(void) return 0; } -struct ecryptfs_obj { - char *name; - struct list_head slot_list; - struct kobject kobj; -}; - -struct ecryptfs_attribute { - struct attribute attr; - ssize_t(*show) (struct ecryptfs_obj *, char *); - ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t); -}; - -static ssize_t -ecryptfs_attr_store(struct kobject *kobj, - struct attribute *attr, const char *buf, size_t len) -{ - struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, - kobj); - struct ecryptfs_attribute *attribute = - container_of(attr, struct ecryptfs_attribute, attr); - - return (attribute->store ? attribute->store(obj, buf, len) : 0); -} - -static ssize_t -ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) -{ - struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, - kobj); - struct ecryptfs_attribute *attribute = - container_of(attr, struct ecryptfs_attribute, attr); - - return (attribute->show ? attribute->show(obj, buf) : 0); -} - -static struct sysfs_ops ecryptfs_sysfs_ops = { - .show = ecryptfs_attr_show, - .store = ecryptfs_attr_store -}; +static decl_subsys(ecryptfs, NULL, NULL); -static struct kobj_type ecryptfs_ktype = { - .sysfs_ops = &ecryptfs_sysfs_ops -}; - -static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL); - -static ssize_t version_show(struct ecryptfs_obj *obj, char *buff) +static ssize_t version_show(struct kset *kset, char *buff) { return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK); } -static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version); +static struct subsys_attribute version_attr = __ATTR_RO(version); static struct ecryptfs_version_str_map_elem { u32 flag; @@ -799,7 +755,7 @@ static struct ecryptfs_version_str_map_elem { {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"} }; -static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff) +static ssize_t version_str_show(struct kset *kset, char *buff) { int i; int remaining = PAGE_SIZE; @@ -826,7 +782,17 @@ out: return total_written; } -static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str); +static struct subsys_attribute version_attr_str = __ATTR_RO(version_str); + +static struct attribute *attributes[] = { + &version_attr.attr, + &version_attr_str.attr, + NULL, +}; + +static struct attribute_group attr_group = { + .attrs = attributes, +}; static int do_sysfs_registration(void) { @@ -838,23 +804,11 @@ static int do_sysfs_registration(void) "Unable to register ecryptfs sysfs subsystem\n"); goto out; } - rc = sysfs_create_file(&ecryptfs_subsys.kobj, - &sysfs_attr_version.attr); + rc = sysfs_create_group(&ecryptfs_subsys.kobj, &attr_group); if (rc) { printk(KERN_ERR - "Unable to create ecryptfs version attribute\n"); + "Unable to create ecryptfs version attributes\n"); subsystem_unregister(&ecryptfs_subsys); - goto out; - } - rc = sysfs_create_file(&ecryptfs_subsys.kobj, - &sysfs_attr_version_str.attr); - if (rc) { - printk(KERN_ERR - "Unable to create ecryptfs version_str attribute\n"); - sysfs_remove_file(&ecryptfs_subsys.kobj, - &sysfs_attr_version.attr); - subsystem_unregister(&ecryptfs_subsys); - goto out; } out: return rc; @@ -862,10 +816,7 @@ out: static void do_sysfs_unregistration(void) { - sysfs_remove_file(&ecryptfs_subsys.kobj, - &sysfs_attr_version.attr); - sysfs_remove_file(&ecryptfs_subsys.kobj, - &sysfs_attr_version_str.attr); + sysfs_remove_group(&ecryptfs_subsys.kobj, &attr_group); subsystem_unregister(&ecryptfs_subsys); } -- 1.5.3.8 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/