xfs_sysfs.h 1.3 KB

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