Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Brian Foster and committed by
Dave Chinner
a31b1d3d 3d871226

+133 -1
+1
fs/xfs/Makefile
··· 86 86 xfs_mru_cache.o \ 87 87 xfs_super.o \ 88 88 xfs_symlink.o \ 89 + xfs_sysfs.o \ 89 90 xfs_trans.o \ 90 91 xfs_xattr.o \ 91 92 kmem.o \
+11
fs/xfs/xfs_linux.h
··· 191 191 #define MAX(a,b) (max(a,b)) 192 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 + */ 200 + struct xfs_kobj { 201 + struct kobject kobject; 202 + struct completion complete; 203 + }; 204 + 194 205 /* Kernel uid/gid conversion. These are used to convert to/from the on disk 195 206 * uid_t/gid_t types to the kuid_t/kgid_t types that the kernel uses internally. 196 207 * The conversion here is type only, the value will remain the same since we
+13 -1
fs/xfs/xfs_mount.c
··· 42 42 #include "xfs_trace.h" 43 43 #include "xfs_icache.h" 44 44 #include "xfs_dinode.h" 45 + #include "xfs_sysfs.h" 45 46 46 47 47 48 #ifdef HAVE_PERCPU_SB ··· 60 59 static DEFINE_MUTEX(xfs_uuid_table_mutex); 61 60 static int xfs_uuid_table_size; 62 61 static uuid_t *xfs_uuid_table; 62 + 63 + extern struct kset *xfs_kset; 63 64 64 65 /* 65 66 * See if the UUID is unique among mounted XFS filesystems. ··· 734 731 735 732 xfs_set_maxicount(mp); 736 733 737 - error = xfs_uuid_mount(mp); 734 + mp->m_kobj.kobject.kset = xfs_kset; 735 + error = xfs_sysfs_init(&mp->m_kobj, &xfs_mp_ktype, NULL, mp->m_fsname); 738 736 if (error) 739 737 goto out; 738 + 739 + error = xfs_uuid_mount(mp); 740 + if (error) 741 + goto out_remove_sysfs; 740 742 741 743 /* 742 744 * Set the minimum read and write sizes ··· 997 989 xfs_da_unmount(mp); 998 990 out_remove_uuid: 999 991 xfs_uuid_unmount(mp); 992 + out_remove_sysfs: 993 + xfs_sysfs_del(&mp->m_kobj); 1000 994 out: 1001 995 return error; 1002 996 } ··· 1081 1071 xfs_errortag_clearall(mp, 0); 1082 1072 #endif 1083 1073 xfs_free_perag(mp); 1074 + 1075 + xfs_sysfs_del(&mp->m_kobj); 1084 1076 } 1085 1077 1086 1078 int
+1
fs/xfs/xfs_mount.h
··· 166 166 on the next remount,rw */ 167 167 int64_t m_low_space[XFS_LOWSP_MAX]; 168 168 /* low free space thresholds */ 169 + struct xfs_kobj m_kobj; 169 170 170 171 struct workqueue_struct *m_data_workqueue; 171 172 struct workqueue_struct *m_unwritten_workqueue;
+49
fs/xfs/xfs_sysfs.c
··· 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 + 22 + struct 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 + 28 + static inline struct xfs_sysfs_attr * 29 + to_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 + 47 + struct kobj_type xfs_mp_ktype = { 48 + .release = xfs_sysfs_release, 49 + };
+58
fs/xfs/xfs_sysfs.h
··· 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 + 22 + extern struct kobj_type xfs_mp_ktype; /* xfs_mount */ 23 + 24 + static inline struct xfs_kobj * 25 + to_kobj(struct kobject *kobject) 26 + { 27 + return container_of(kobject, struct xfs_kobj, kobject); 28 + } 29 + 30 + static inline void 31 + xfs_sysfs_release(struct kobject *kobject) 32 + { 33 + struct xfs_kobj *kobj = to_kobj(kobject); 34 + complete(&kobj->complete); 35 + } 36 + 37 + static inline int 38 + xfs_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 + 49 + static inline void 50 + xfs_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__ */