xref: /openbmc/linux/fs/ocfs2/cluster/sys.c (revision c4c3c32d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * sys.c
4  *
5  * OCFS2 cluster sysfs interface
6  *
7  * Copyright (C) 2005 Oracle.  All rights reserved.
8  */
9 
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/kobject.h>
13 #include <linux/sysfs.h>
14 #include <linux/fs.h>
15 
16 #include "ocfs2_nodemanager.h"
17 #include "masklog.h"
18 #include "sys.h"
19 
20 
21 static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
22 			    char *buf)
23 {
24 	return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
25 }
26 static struct kobj_attribute attr_version =
27 	__ATTR(interface_revision, S_IRUGO, version_show, NULL);
28 
29 static struct attribute *o2cb_attrs[] = {
30 	&attr_version.attr,
31 	NULL,
32 };
33 
34 static struct attribute_group o2cb_attr_group = {
35 	.attrs = o2cb_attrs,
36 };
37 
38 static struct kset *o2cb_kset;
39 
40 void o2cb_sys_shutdown(void)
41 {
42 	mlog_sys_shutdown();
43 	kset_unregister(o2cb_kset);
44 }
45 
46 int o2cb_sys_init(void)
47 {
48 	int ret;
49 
50 	o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
51 	if (!o2cb_kset)
52 		return -ENOMEM;
53 
54 	ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
55 	if (ret)
56 		goto error;
57 
58 	ret = mlog_sys_init(o2cb_kset);
59 	if (ret)
60 		goto error;
61 	return 0;
62 error:
63 	kset_unregister(o2cb_kset);
64 	return ret;
65 }
66