aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2014-07-14 18:07:01 -0400
committerDave Chinner <david@fromorbit.com>2014-07-14 18:07:01 -0400
commita31b1d3d89e40f585a1c6745b066774ee3263eb2 (patch)
tree89f547e925078ab1fb8c24136508b62deaa45915
parent3d8712265c26546823b38eb97487262500ff13db (diff)
xfs: add xfs_mount sysfs kobject
Embed a base kobject into xfs_mount. This creates a kobject associated with each XFS mount and a subdirectory in sysfs with the name of the filesystem. The subdirectory lifecycle matches that of the mount. Also add the new xfs_sysfs.[c,h] source files with some XFS sysfs infrastructure to facilitate attribute creation. Note that there are currently no attributes exported as part of the xfs_mount kobject. It exists solely to serve as a per-mount container for child objects. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
-rw-r--r--fs/xfs/Makefile1
-rw-r--r--fs/xfs/xfs_linux.h11
-rw-r--r--fs/xfs/xfs_mount.c14
-rw-r--r--fs/xfs/xfs_mount.h1
-rw-r--r--fs/xfs/xfs_sysfs.c49
-rw-r--r--fs/xfs/xfs_sysfs.h58
6 files changed, 133 insertions, 1 deletions
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 0dfa26d626f5..d61799949580 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -86,6 +86,7 @@ xfs-y += xfs_aops.o \
86 xfs_mru_cache.o \ 86 xfs_mru_cache.o \
87 xfs_super.o \ 87 xfs_super.o \
88 xfs_symlink.o \ 88 xfs_symlink.o \
89 xfs_sysfs.o \
89 xfs_trans.o \ 90 xfs_trans.o \
90 xfs_xattr.o \ 91 xfs_xattr.o \
91 kmem.o \ 92 kmem.o \
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index f59b966bf903..8312771c2b5b 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -191,6 +191,17 @@ typedef __uint64_t __psunsigned_t;
191#define MAX(a,b) (max(a,b)) 191#define MAX(a,b) (max(a,b))
192#define howmany(x, y) (((x)+((y)-1))/(y)) 192#define howmany(x, y) (((x)+((y)-1))/(y))
193 193
194/*
195 * XFS wrapper structure for sysfs support. It depends on external data
196 * structures and is embedded in various internal data structures to implement
197 * the XFS sysfs object heirarchy. Define it here for broad access throughout
198 * the codebase.
199 */
200struct xfs_kobj {
201 struct kobject kobject;
202 struct completion complete;
203};
204
194/* Kernel uid/gid conversion. These are used to convert to/from the on disk 205/* Kernel uid/gid conversion. These are used to convert to/from the on disk
195 * uid_t/gid_t types to the kuid_t/kgid_t types that the kernel uses internally. 206 * uid_t/gid_t types to the kuid_t/kgid_t types that the kernel uses internally.
196 * The conversion here is type only, the value will remain the same since we 207 * The conversion here is type only, the value will remain the same since we
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 4e9dd4a9c69a..c8a328ee2c2a 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -42,6 +42,7 @@
42#include "xfs_trace.h" 42#include "xfs_trace.h"
43#include "xfs_icache.h" 43#include "xfs_icache.h"
44#include "xfs_dinode.h" 44#include "xfs_dinode.h"
45#include "xfs_sysfs.h"
45 46
46 47
47#ifdef HAVE_PERCPU_SB 48#ifdef HAVE_PERCPU_SB
@@ -60,6 +61,8 @@ static DEFINE_MUTEX(xfs_uuid_table_mutex);
60static int xfs_uuid_table_size; 61static int xfs_uuid_table_size;
61static uuid_t *xfs_uuid_table; 62static uuid_t *xfs_uuid_table;
62 63
64extern struct kset *xfs_kset;
65
63/* 66/*
64 * See if the UUID is unique among mounted XFS filesystems. 67 * See if the UUID is unique among mounted XFS filesystems.
65 * Mount fails if UUID is nil or a FS with the same UUID is already mounted. 68 * Mount fails if UUID is nil or a FS with the same UUID is already mounted.
@@ -731,10 +734,15 @@ xfs_mountfs(
731 734
732 xfs_set_maxicount(mp); 735 xfs_set_maxicount(mp);
733 736
734 error = xfs_uuid_mount(mp); 737 mp->m_kobj.kobject.kset = xfs_kset;
738 error = xfs_sysfs_init(&mp->m_kobj, &xfs_mp_ktype, NULL, mp->m_fsname);
735 if (error) 739 if (error)
736 goto out; 740 goto out;
737 741
742 error = xfs_uuid_mount(mp);
743 if (error)
744 goto out_remove_sysfs;
745
738 /* 746 /*
739 * Set the minimum read and write sizes 747 * Set the minimum read and write sizes
740 */ 748 */
@@ -989,6 +997,8 @@ xfs_mountfs(
989 xfs_da_unmount(mp); 997 xfs_da_unmount(mp);
990 out_remove_uuid: 998 out_remove_uuid:
991 xfs_uuid_unmount(mp); 999 xfs_uuid_unmount(mp);
1000 out_remove_sysfs:
1001 xfs_sysfs_del(&mp->m_kobj);
992 out: 1002 out:
993 return error; 1003 return error;
994} 1004}
@@ -1071,6 +1081,8 @@ xfs_unmountfs(
1071 xfs_errortag_clearall(mp, 0); 1081 xfs_errortag_clearall(mp, 0);
1072#endif 1082#endif
1073 xfs_free_perag(mp); 1083 xfs_free_perag(mp);
1084
1085 xfs_sysfs_del(&mp->m_kobj);
1074} 1086}
1075 1087
1076int 1088int
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 7295a0b7c343..b0447c86e7e2 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -166,6 +166,7 @@ typedef struct xfs_mount {
166 on the next remount,rw */ 166 on the next remount,rw */
167 int64_t m_low_space[XFS_LOWSP_MAX]; 167 int64_t m_low_space[XFS_LOWSP_MAX];
168 /* low free space thresholds */ 168 /* low free space thresholds */
169 struct xfs_kobj m_kobj;
169 170
170 struct workqueue_struct *m_data_workqueue; 171 struct workqueue_struct *m_data_workqueue;
171 struct workqueue_struct *m_unwritten_workqueue; 172 struct workqueue_struct *m_unwritten_workqueue;
diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
new file mode 100644
index 000000000000..ae9aa7a1a06a
--- /dev/null
+++ b/fs/xfs/xfs_sysfs.c
@@ -0,0 +1,49 @@
1/*
2 * Copyright (c) 2014 Red Hat, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "xfs.h"
20#include "xfs_sysfs.h"
21
22struct xfs_sysfs_attr {
23 struct attribute attr;
24 ssize_t (*show)(char *buf, void *data);
25 ssize_t (*store)(const char *buf, size_t count, void *data);
26};
27
28static inline struct xfs_sysfs_attr *
29to_attr(struct attribute *attr)
30{
31 return container_of(attr, struct xfs_sysfs_attr, attr);
32}
33
34#define XFS_SYSFS_ATTR_RW(name) \
35 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
36#define XFS_SYSFS_ATTR_RO(name) \
37 static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
38
39#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
40
41/*
42 * xfs_mount kobject. This currently has no attributes and thus no need for show
43 * and store helpers. The mp kobject serves as the per-mount parent object that
44 * is identified by the fsname under sysfs.
45 */
46
47struct kobj_type xfs_mp_ktype = {
48 .release = xfs_sysfs_release,
49};
diff --git a/fs/xfs/xfs_sysfs.h b/fs/xfs/xfs_sysfs.h
new file mode 100644
index 000000000000..4bd5fff75d0f
--- /dev/null
+++ b/fs/xfs/xfs_sysfs.h
@@ -0,0 +1,58 @@
1/*
2 * Copyright (c) 2014 Red Hat, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef __XFS_SYSFS_H__
20#define __XFS_SYSFS_H__
21
22extern struct kobj_type xfs_mp_ktype; /* xfs_mount */
23
24static inline struct xfs_kobj *
25to_kobj(struct kobject *kobject)
26{
27 return container_of(kobject, struct xfs_kobj, kobject);
28}
29
30static inline void
31xfs_sysfs_release(struct kobject *kobject)
32{
33 struct xfs_kobj *kobj = to_kobj(kobject);
34 complete(&kobj->complete);
35}
36
37static inline int
38xfs_sysfs_init(
39 struct xfs_kobj *kobj,
40 struct kobj_type *ktype,
41 struct xfs_kobj *parent_kobj,
42 const char *name)
43{
44 init_completion(&kobj->complete);
45 return kobject_init_and_add(&kobj->kobject, ktype,
46 &parent_kobj->kobject, "%s", name);
47}
48
49static inline void
50xfs_sysfs_del(
51 struct xfs_kobj *kobj)
52{
53 kobject_del(&kobj->kobject);
54 kobject_put(&kobj->kobject);
55 wait_for_completion(&kobj->complete);
56}
57
58#endif /* __XFS_SYSFS_H__ */