11573Srgrimes// SPDX-License-Identifier: GPL-2.0
21573Srgrimes/*
31573Srgrimes * Copyright (c) 2014 Red Hat, Inc.
41573Srgrimes * All Rights Reserved.
51573Srgrimes */
61573Srgrimes
71573Srgrimes#ifndef __XFS_SYSFS_H__
81573Srgrimes#define __XFS_SYSFS_H__
91573Srgrimes
101573Srgrimesextern const struct kobj_type xfs_mp_ktype;	/* xfs_mount */
111573Srgrimesextern const struct kobj_type xfs_dbg_ktype;	/* debug */
121573Srgrimesextern const struct kobj_type xfs_log_ktype;	/* xlog */
131573Srgrimesextern const struct kobj_type xfs_stats_ktype;	/* stats */
141573Srgrimes
151573Srgrimesstatic inline struct xfs_kobj *
16251069Semasteto_kobj(struct kobject *kobject)
171573Srgrimes{
181573Srgrimes	return container_of(kobject, struct xfs_kobj, kobject);
191573Srgrimes}
201573Srgrimes
211573Srgrimesstatic inline void
221573Srgrimesxfs_sysfs_release(struct kobject *kobject)
231573Srgrimes{
241573Srgrimes	struct xfs_kobj *kobj = to_kobj(kobject);
251573Srgrimes	complete(&kobj->complete);
261573Srgrimes}
271573Srgrimes
281573Srgrimesstatic inline int
291573Srgrimesxfs_sysfs_init(
301573Srgrimes	struct xfs_kobj		*kobj,
311573Srgrimes	const struct kobj_type	*ktype,
321573Srgrimes	struct xfs_kobj		*parent_kobj,
3350476Speter	const char		*name)
341573Srgrimes{
3584810Smike	struct kobject		*parent;
361573Srgrimes	int err;
371573Srgrimes
381573Srgrimes	parent = parent_kobj ? &parent_kobj->kobject : NULL;
3932818Sdanny	init_completion(&kobj->complete);
4047881Smpp	err = kobject_init_and_add(&kobj->kobject, ktype, parent, "%s", name);
411573Srgrimes	if (err)
4259460Sphantom		kobject_put(&kobj->kobject);
4359460Sphantom
441573Srgrimes	return err;
4584306Sru}
461573Srgrimes
471573Srgrimesstatic inline void
481573Srgrimesxfs_sysfs_del(
491573Srgrimes	struct xfs_kobj	*kobj)
501573Srgrimes{
511573Srgrimes	kobject_del(&kobj->kobject);
521573Srgrimes	kobject_put(&kobj->kobject);
531573Srgrimes	wait_for_completion(&kobj->complete);
541573Srgrimes}
551573Srgrimes
561573Srgrimesint	xfs_error_sysfs_init(struct xfs_mount *mp);
571573Srgrimesvoid	xfs_error_sysfs_del(struct xfs_mount *mp);
581573Srgrimes
591573Srgrimes#endif	/* __XFS_SYSFS_H__ */
6047879Smpp