1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2014 Red Hat, Inc. 4 * All Rights Reserved. 5 */ 6 7 #ifndef __XFS_SYSFS_H__ 8 #define __XFS_SYSFS_H__ 9 10 extern const struct kobj_type xfs_dbg_ktype; /* debug */ 11 extern const struct kobj_type xfs_log_ktype; /* xlog */ 12 extern const struct kobj_type xfs_stats_ktype; /* stats */ 13 14 static inline struct xfs_kobj * 15 to_kobj(struct kobject *kobject) 16 { 17 return container_of(kobject, struct xfs_kobj, kobject); 18 } 19 20 static inline void 21 xfs_sysfs_release(struct kobject *kobject) 22 { 23 struct xfs_kobj *kobj = to_kobj(kobject); 24 complete(&kobj->complete); 25 } 26 27 static inline int 28 xfs_sysfs_init( 29 struct xfs_kobj *kobj, 30 const struct kobj_type *ktype, 31 struct xfs_kobj *parent_kobj, 32 const char *name) 33 { 34 struct kobject *parent; 35 int err; 36 37 parent = parent_kobj ? &parent_kobj->kobject : NULL; 38 init_completion(&kobj->complete); 39 err = kobject_init_and_add(&kobj->kobject, ktype, parent, "%s", name); 40 if (err) 41 kobject_put(&kobj->kobject); 42 43 return err; 44 } 45 46 static inline void 47 xfs_sysfs_del( 48 struct xfs_kobj *kobj) 49 { 50 kobject_del(&kobj->kobject); 51 kobject_put(&kobj->kobject); 52 wait_for_completion(&kobj->complete); 53 } 54 55 int xfs_mount_sysfs_init(struct xfs_mount *mp); 56 void xfs_mount_sysfs_del(struct xfs_mount *mp); 57 58 #endif /* __XFS_SYSFS_H__ */ 59