Similar to the sysaufs_sbinfo, sysaufs_br doesn't need to exist.
Rather than having a wrapper, it's trivial to attach a generic attribute
structure and a name to struct aufs_branch and have them managed
automatically. The "added" variable is unnecessary since sysfs doesn't
care if the file is there or not, and is silent about it.
Signed-off-by: Jeff Mahoney <[EMAIL PROTECTED]>
---
fs/aufs/branch.c | 13 ++------
fs/aufs/branch.h | 5 +--
fs/aufs/sysaufs.c | 86 +++++++++++++++---------------------------------------
fs/aufs/sysaufs.h | 14 +-------
4 files changed, 33 insertions(+), 85 deletions(-)
--- a/fs/aufs/branch.c
+++ b/fs/aufs/branch.c
@@ -44,7 +44,6 @@ static void free_branch(struct aufs_bran
lockdep_on();
}
AuDebugOn(br_count(br) || atomic_read(&br->br_wh_running));
- sysaufs_br_put(br);
kfree(br);
}
@@ -235,9 +234,6 @@ static struct aufs_branch *alloc_addbr(s
//if (LktrCond) {kfree(add_branch); add_branch = NULL;}
if (unlikely(!add_branch))
goto out;
- add_branch->br_sabr = sysaufs_br_alloc();
- if (unlikely(!add_branch->br_sabr))
- goto out;
sz = sizeof(*branchp) * (new_nbranch - 1);
if (unlikely(!sz))
@@ -247,7 +243,7 @@ static struct aufs_branch *alloc_addbr(s
GFP_KERNEL);
//if (LktrCond) branchp = NULL;
if (unlikely(!branchp))
- goto out_sabr;
+ goto out;
stosi(sb)->si_branch = branchp;
sz = sizeof(*hdentryp) * (new_nbranch - 1);
@@ -258,7 +254,7 @@ static struct aufs_branch *alloc_addbr(s
GFP_KERNEL);
//if (LktrCond) hdentryp = NULL;
if (unlikely(!hdentryp))
- goto out_sabr;
+ goto out;
dtodi(root)->di_hdentry = hdentryp;
sz = sizeof(*hinodep) * (new_nbranch - 1);
@@ -269,12 +265,10 @@ static struct aufs_branch *alloc_addbr(s
GFP_KERNEL);
//if (LktrCond) hinodep = NULL; // unavailable test
if (unlikely(!hinodep))
- goto out_sabr;
+ goto out;
itoii(inode)->ii_hinode = hinodep;
return add_branch; /* success */
- out_sabr:
- sysaufs_br_put(add_branch);
out:
kfree(add_branch);
AuTraceErr(-ENOMEM);
@@ -515,6 +509,7 @@ int br_add(struct super_block *sb, struc
}
}
+ sysaufs_name_branch(add_branch, add_bindex);
if (remount)
sysaufs_brs_add(sb);
--- a/fs/aufs/branch.h
+++ b/fs/aufs/branch.h
@@ -30,6 +30,7 @@
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/aufs_type.h>
+#include <linux/sysfs.h>
#include "misc.h"
#include "super.h"
@@ -60,7 +61,6 @@ struct xino_file {
};
/* protected by superblock rwsem */
-struct sysaufs_br;
struct aufs_branch {
struct file *br_xino;
//struct xino_file *br_xino;
@@ -91,7 +91,8 @@ struct aufs_branch {
au_gen_t br_generation;
/* an entry under sysfs per mount-point */
- struct sysaufs_br *br_sabr;
+ char br_name[8];
+ struct attribute br_attr;
};
/* ---------------------------------------------------------------------- */
--- a/fs/aufs/sysaufs.c
+++ b/fs/aufs/sysaufs.c
@@ -348,6 +348,15 @@ static int sysaufs_sbi_br(struct seq_fil
return err;
}
+void sysaufs_name_branch(struct aufs_branch *br, aufs_bindex_t bindex)
+{
+ snprintf(br->br_name, sizeof(br->br_name),
+ SysaufsBr_PREFIX "%d", bindex);
+ br->br_attr.name = br->br_name;
+ br->br_attr.mode = 0444;
+ br->br_attr.owner = THIS_MODULE;
+}
+
/* ---------------------------------------------------------------------- */
struct sbi_attribute {
@@ -443,44 +452,11 @@ static ssize_t sysaufs_sbi_show(struct k
/* ---------------------------------------------------------------------- */
-static void sysaufs_br_free(struct kref *ref)
-{
- AuTraceEnter();
- //AuDbg("here\n");
- kfree(container_of(ref, struct sysaufs_br, ref));
-}
-
-struct sysaufs_br *sysaufs_br_alloc(void)
-{
- struct sysaufs_br *sabr;
-
- AuTraceEnter();
- //AuDbg("here\n");
-
- sabr = kcalloc(sizeof(*sabr), 1, GFP_KERNEL);
- if (sabr)
- kref_init(&sabr->ref);
-
- AuTraceErrPtr(sabr);
- return sabr;
-}
-
-void sysaufs_br_get(struct aufs_branch *br)
-{
- kref_get(&br->br_sabr->ref);
-}
-
-void sysaufs_br_put(struct aufs_branch *br)
-{
- kref_put(&br->br_sabr->ref, sysaufs_br_free);
-}
-
//todo: they may take a long time
void sysaufs_brs_del(struct super_block *sb)
{
aufs_bindex_t bindex, bend;
struct aufs_sbinfo *sa;
- struct sysaufs_br *sabr;
struct aufs_branch *br;
AuTraceEnter();
@@ -492,51 +468,37 @@ void sysaufs_brs_del(struct super_block
bend = sbend(sb);
for (bindex = 0; bindex <= bend; bindex++) {
br = stobr(sb, bindex);
- sabr = br->br_sabr;
- if (unlikely(!sabr->added))
- continue;
-
- sabr->added = 0;
- sysfs_remove_file(&sa->si_kobj, &sabr->attr);
- sysaufs_br_put(br);
- /* for older sysfs */
- module_put(THIS_MODULE);
+ sysfs_remove_file(&sa->si_kobj, &br->br_attr);
+ kfree(br->br_attr.name);
}
}
-void sysaufs_brs_add(struct super_block *sb)
+int sysaufs_brs_add(struct super_block *sb)
{
int err;
aufs_bindex_t bindex, bend;
- struct sysaufs_br *sabr;
struct aufs_sbinfo *sa;
- struct aufs_branch *br;
AuTraceEnter();
sa = stosi(sb);
if (!sysaufs_brs)
- return;
+ return 0;
bend = sbend(sb);
for (bindex = 0; bindex <= bend; bindex++) {
- br = stobr(sb, bindex);
- sysaufs_br_get(br);
- sabr = br->br_sabr;
- AuDebugOn(sabr->added);
- snprintf(sabr->name, sizeof(sabr->name),
- SysaufsBr_PREFIX "%d", bindex);
- sabr->attr.name = sabr->name;
- sabr->attr.mode = 0444;
- sabr->attr.owner = THIS_MODULE;
- /* for older sysfs */
- BUG_ON(!try_module_get(THIS_MODULE));
- err = sysfs_create_file(&sa->si_kobj, &sabr->attr);
- if (!err)
- sabr->added = 1;
- else
- AuWarn("failed %s under sysfs(%d)\n", sabr->name, err);
+ struct aufs_branch *br = stobr(sb, bindex);
+ err |= sysfs_create_file(&sa->si_kobj, &br->br_attr);
+ if (err) {
+ AuWarn("failed %s under sysfs(%d)\n", br->br_name, err);
+ break;
+ }
}
+
+ if (err)
+ sysaufs_brs_del(sb);
+ return err;
+
}
/* ---------------------------------------------------------------------- */
--- a/fs/aufs/sysaufs.h
+++ b/fs/aufs/sysaufs.h
@@ -44,14 +44,6 @@ enum {
SysaufsSb_Last
};
-/* 'brN' entry under sysfs per super block */
-struct sysaufs_br {
- char name[8];
- struct attribute attr;
- struct kref ref;
- int added;
-};
-
/* ---------------------------------------------------------------------- */
struct aufs_branch;
@@ -82,10 +74,8 @@ static inline void au_sbilist_add(struct
int sysaufs_register(struct super_block *sb);
void sysaufs_unregister(struct super_block *sb);
-struct sysaufs_br *sysaufs_br_alloc(void);
-void sysaufs_br_get(struct aufs_branch *br);
-void sysaufs_br_put(struct aufs_branch *br);
-void sysaufs_brs_add(struct super_block *sb);
+void sysaufs_name_branch(struct aufs_branch *branch, aufs_bindex_t bindex);
+int sysaufs_brs_add(struct super_block *sb);
void sysaufs_brs_del(struct super_block *sb);
int __init sysaufs_init(void);
void sysaufs_fin(void);
--
Jeff Mahoney
SUSE Labs
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone