Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * sys.c |
| 5 | * |
| 6 | * OCFS2 cluster sysfs interface |
| 7 | * |
| 8 | * Copyright (C) 2005 Oracle. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public |
| 12 | * License as published by the Free Software Foundation, |
| 13 | * version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public |
| 21 | * License along with this program; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 021110-1307, USA. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/kobject.h> |
| 30 | #include <linux/sysfs.h> |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 31 | #include <linux/fs.h> |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 32 | |
| 33 | #include "ocfs2_nodemanager.h" |
| 34 | #include "masklog.h" |
| 35 | #include "sys.h" |
| 36 | |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 37 | |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 38 | static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 39 | char *buf) |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 40 | { |
| 41 | return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION); |
| 42 | } |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 43 | static struct kobj_attribute attr_version = |
| 44 | __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 45 | |
| 46 | static struct attribute *o2cb_attrs[] = { |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 47 | &attr_version.attr, |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 48 | NULL, |
| 49 | }; |
| 50 | |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 51 | static struct attribute_group o2cb_attr_group = { |
| 52 | .attrs = o2cb_attrs, |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 53 | }; |
| 54 | |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 55 | static struct kset *o2cb_kset; |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 56 | |
| 57 | void o2cb_sys_shutdown(void) |
| 58 | { |
| 59 | mlog_sys_shutdown(); |
Mark Fasheh | 52f7c21 | 2008-01-29 17:08:26 -0800 | [diff] [blame] | 60 | sysfs_remove_link(NULL, "o2cb"); |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 61 | kset_unregister(o2cb_kset); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int o2cb_sys_init(void) |
| 65 | { |
| 66 | int ret; |
| 67 | |
Joel Becker | 9d80f75 | 2008-04-22 11:46:44 -0700 | [diff] [blame] | 68 | o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj); |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 69 | if (!o2cb_kset) |
| 70 | return -ENOMEM; |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 71 | |
Mark Fasheh | 52f7c21 | 2008-01-29 17:08:26 -0800 | [diff] [blame] | 72 | /* |
| 73 | * Create this symlink for backwards compatibility with old |
| 74 | * versions of ocfs2-tools which look for things in /sys/o2cb. |
| 75 | */ |
| 76 | ret = sysfs_create_link(NULL, &o2cb_kset->kobj, "o2cb"); |
| 77 | if (ret) |
| 78 | goto error; |
| 79 | |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 80 | ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 81 | if (ret) |
Greg Kroah-Hartman | c60b717 | 2007-11-02 16:19:59 -0700 | [diff] [blame] | 82 | goto error; |
| 83 | |
| 84 | ret = mlog_sys_init(o2cb_kset); |
| 85 | if (ret) |
| 86 | goto error; |
| 87 | return 0; |
| 88 | error: |
| 89 | kset_unregister(o2cb_kset); |
Zach Brown | 9821148 | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 90 | return ret; |
| 91 | } |