From: "J. R. Okajima" <hooanon05@yahoo.co.jp>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, "J. R. Okajima" <hooanon05@yahoo.co.jp>
Subject: [RFC Aufs2 #2 07/28] aufs object lifetime management via sysfs
Date: Mon, 16 Mar 2009 16:20:19 +0900 [thread overview]
Message-ID: <1237188040-11404-8-git-send-email-hooanon05@yahoo.co.jp> (raw)
In-Reply-To: <1237188040-11404-1-git-send-email-hooanon05@yahoo.co.jp>
initial commit
some aufs objects have a corresponding entry under sysfs, so the
lifetime will be managed by struct kref even if CONFIG_SYSFS is
disabled.
This file is compiled unconditionally.
Signed-off-by: J. R. Okajima <hooanon05@yahoo.co.jp>
---
fs/aufs/sysaufs.c | 79 +++++++++++++++++++++++++++++++++++++++++
fs/aufs/sysaufs.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 181 insertions(+), 0 deletions(-)
create mode 100644 fs/aufs/sysaufs.c
create mode 100644 fs/aufs/sysaufs.h
diff --git a/fs/aufs/sysaufs.c b/fs/aufs/sysaufs.c
new file mode 100644
index 0000000..47ffbfd
--- /dev/null
+++ b/fs/aufs/sysaufs.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2005-2009 Junjiro R. Okajima
+ *
+ * This program, aufs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+/*
+ * sysfs interface and lifetime management
+ * they are necessary regardless sysfs is disabled.
+ */
+
+#include <linux/fs.h>
+#include <linux/random.h>
+#include <linux/sysfs.h>
+#include "aufs.h"
+
+unsigned long sysaufs_si_mask;
+struct kset *sysaufs_ket;
+
+#define AuSiAttr(_name) { \
+ .attr = { .name = __stringify(_name), .mode = 0444 }, \
+ .show = sysaufs_si_##_name, \
+}
+
+static struct sysaufs_si_attr sysaufs_si_attr_xino = AuSiAttr(xino);
+struct attribute *sysaufs_si_attrs[] = {
+ &sysaufs_si_attr_xino.attr,
+ NULL,
+};
+
+static struct sysfs_ops au_sbi_ops = {
+ .show = sysaufs_si_show
+};
+
+static struct kobj_type au_sbi_ktype = {
+ .release = au_si_free,
+ .sysfs_ops = &au_sbi_ops,
+ .default_attrs = sysaufs_si_attrs
+};
+
+/* ---------------------------------------------------------------------- */
+
+int sysaufs_si_init(struct au_sbinfo *sbinfo)
+{
+ int err;
+
+ sbinfo->si_kobj.kset = sysaufs_ket;
+ err = kobject_init_and_add(&sbinfo->si_kobj, &au_sbi_ktype,
+ /*&sysaufs_ket->kobj*/NULL,
+ "si_%lx", sysaufs_si_id(sbinfo));
+ return err;
+}
+
+void sysaufs_fin(void)
+{
+ sysfs_remove_group(&sysaufs_ket->kobj, sysaufs_attr_group);
+ kset_unregister(sysaufs_ket);
+}
+
+int __init sysaufs_init(void)
+{
+ int err;
+
+ get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
+
+ sysaufs_ket = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
+ err = PTR_ERR(sysaufs_ket);
+ if (IS_ERR(sysaufs_ket))
+ goto out;
+ err = sysfs_create_group(&sysaufs_ket->kobj, sysaufs_attr_group);
+ if (unlikely(err))
+ kset_unregister(sysaufs_ket);
+
+ out:
+ return err;
+}
diff --git a/fs/aufs/sysaufs.h b/fs/aufs/sysaufs.h
new file mode 100644
index 0000000..04ffab2
--- /dev/null
+++ b/fs/aufs/sysaufs.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2005-2009 Junjiro R. Okajima
+ *
+ * This program, aufs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+/*
+ * sysfs interface and mount lifetime management
+ */
+
+#ifndef __SYSAUFS_H__
+#define __SYSAUFS_H__
+
+#ifdef __KERNEL__
+
+#include <linux/fs.h>
+#include <linux/sysfs.h>
+#include <linux/aufs_type.h>
+
+struct sysaufs_si_attr {
+ struct attribute attr;
+ int (*show)(struct seq_file *seq, struct super_block *sb);
+};
+
+/* ---------------------------------------------------------------------- */
+
+/* sysaufs.c */
+extern unsigned long sysaufs_si_mask;
+extern struct kset *sysaufs_ket;
+extern struct attribute *sysaufs_si_attrs[];
+int sysaufs_si_init(struct au_sbinfo *sbinfo);
+int __init sysaufs_init(void);
+void sysaufs_fin(void);
+
+/* ---------------------------------------------------------------------- */
+
+/* some people doesn't like to show a pointer in kernel */
+static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
+{
+ return sysaufs_si_mask ^ (unsigned long)sbinfo;
+}
+
+struct au_branch;
+#ifdef CONFIG_SYSFS
+/* sysfs.c */
+extern struct attribute_group *sysaufs_attr_group;
+extern struct kobj_type *sysaufs_ktype;
+
+int sysaufs_si_xino(struct seq_file *seq, struct super_block *sb);
+ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
+ char *buf);
+
+void sysaufs_br_init(struct au_branch *br);
+void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
+void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
+
+#define sysaufs_brs_init() do {} while (0)
+
+#else
+#define sysaufs_attr_group NULL
+#define sysaufs_ktype NULL
+
+static inline
+int sysaufs_si_xino(struct seq_file *seq, struct super_block *sb)
+{
+ return 0;
+}
+
+static inline
+ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ return 0;
+}
+
+static inline void sysaufs_br_init(struct au_branch *br)
+{
+ /* empty */
+}
+
+static inline void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
+{
+ /* nothing */
+}
+
+static inline void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
+{
+ /* nothing */
+}
+
+static inline void sysaufs_brs_init(void)
+{
+ sysaufs_brs = 0;
+}
+
+#endif /* CONFIG_SYSFS */
+
+#endif /* __KERNEL__ */
+#endif /* __SYSAUFS_H__ */
--
1.6.1.284.g5dc13
next prev parent reply other threads:[~2009-03-16 7:30 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-16 7:20 [RFC Aufs2 #2 00/28] source files J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 01/28] aufs documents J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 02/28] aufs public header file J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 03/28] aufs module global J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 04/28] aufs super_block J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 05/28] aufs branch directory/filesystem J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 06/28] aufs xino J. R. Okajima
2009-03-16 7:20 ` J. R. Okajima [this message]
2009-03-16 7:20 ` [RFC Aufs2 #2 08/28] aufs mount options/flags J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 09/28] aufs workqueue J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 10/28] aufs sub-VFS J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 11/28] aufs sub-dcache J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 12/28] aufs copy-up J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 13/28] aufs whiteout J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 14/28] aufs pseudo-link J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 15/28] aufs policies to select one among multiple writable branches J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 16/28] aufs dentry and lookup J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 17/28] aufs file J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 18/28] aufs direcotry J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 19/28] aufs inode J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 20/28] aufs ioctl J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 21/28] aufs sysfs entries J. R. Okajima
2009-03-16 18:05 ` Greg KH
2009-03-17 3:26 ` hooanon05
2009-03-17 3:37 ` Greg KH
2009-03-17 4:05 ` hooanon05
2009-03-17 4:22 ` Greg KH
2009-03-17 4:50 ` hooanon05
2009-03-17 10:39 ` Evgeniy Polyakov
2009-03-17 12:56 ` hooanon05
2009-03-19 8:04 ` hooanon05
2009-03-16 7:20 ` [RFC Aufs2 #2 22/28] aufs branch for loopback block device J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 23/28] aufs internal inotify J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 24/28] aufs test for fstype J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 25/28] aufs debug J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 26/28] export splice functions J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 27/28] export lookup functions J. R. Okajima
2009-03-16 7:20 ` [RFC Aufs2 #2 28/28] kbuild aufs J. R. Okajima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1237188040-11404-8-git-send-email-hooanon05@yahoo.co.jp \
--to=hooanon05@yahoo.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®