From 48beda6efcfe2241a6a1671cd9dc6413cc0ada10 Mon Sep 17 00:00:00 2001 From: Sonia Sharma Date: Thu, 21 Sep 2017 10:21:50 -0700 Subject: [PATCH] LU-9667 lnet: Generic helper functions for sysfs Adding generic helper functions for the sysfs callback functions to use when implemented. Add the base directory "lnet" to create the path /sys/fs/lnet/ sysfs show and store callback functions for lnet and lnd to use the helper functions. Test-Parameters: trivial Change-Id: I250eb0e3f3398f0882c2ab66dd4bf7f56871711b Signed-off-by: Sonia Sharma Reviewed-on: https://review.whamcloud.com/29163 Reviewed-by: James Simmons Reviewed-by: Amir Shehata Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Sonia Sharma --- lnet/include/lnet/Makefile.am | 1 + lnet/include/lnet/lnet-sysfs.h | 77 ++++++++++++++++++++++++++++++++++++++++++ lnet/lnet/Makefile.in | 2 +- lnet/lnet/lnet-sysfs.c | 64 +++++++++++++++++++++++++++++++++++ lnet/lnet/module.c | 12 +++++++ 5 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 lnet/include/lnet/lnet-sysfs.h create mode 100644 lnet/lnet/lnet-sysfs.c diff --git a/lnet/include/lnet/Makefile.am b/lnet/include/lnet/Makefile.am index 923074e..e9f5fd0 100644 --- a/lnet/include/lnet/Makefile.am +++ b/lnet/include/lnet/Makefile.am @@ -2,4 +2,5 @@ EXTRA_DIST = \ api.h \ lib-lnet.h \ lib-types.h \ + lnet-sysfs.h \ socklnd.h diff --git a/lnet/include/lnet/lnet-sysfs.h b/lnet/include/lnet/lnet-sysfs.h new file mode 100644 index 0000000..a47c09b --- /dev/null +++ b/lnet/include/lnet/lnet-sysfs.h @@ -0,0 +1,77 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.gnu.org/licenses/gpl-2.0.html + * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + * + * Copyright (c) 2011, 2017, Intel Corporation. + * + * Author: + * Sonia Sharma + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lnet/include/lnet/lnet-sysfs.h + * + */ + +#ifndef __LNET_LNET_SYSFS_H__ +#define __LNET_LNET_SYSFS_H__ + +#ifndef __KERNEL__ +# error This include is only for kernel use. +#endif + +#include +#include +#include +#include +#include + + +extern struct kobject *lnet_kobj; /* Sysfs lnet kobject */ + +struct lnet_attr { + struct attribute attr; + ssize_t (*show)(struct kobject *kobj, struct attribute *attr, + char *buf); + ssize_t (*store)(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len); +}; + +#define LNET_ATTR(name, mode, show, store) \ +static struct lnet_attr lnet_attr_##name = __ATTR(name, mode, show, store) + +#define LNET_RO_ATTR(name) LNET_ATTR(name, 0444, name##_show, NULL) +#define LNET_RW_ATTR(name) LNET_ATTR(name, 0644, name##_show, name##_store) + +ssize_t lnet_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf); + +ssize_t lnet_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len); + +extern const struct sysfs_ops lnet_sysfs_ops; + +#endif diff --git a/lnet/lnet/Makefile.in b/lnet/lnet/Makefile.in index ee119ad..5c62479 100644 --- a/lnet/lnet/Makefile.in +++ b/lnet/lnet/Makefile.in @@ -1,6 +1,6 @@ MODULES := lnet -lnet-objs := api-ni.o config.o nidstrings.o +lnet-objs := api-ni.o config.o nidstrings.o lnet-sysfs.o lnet-objs += lib-me.o lib-msg.o lib-eq.o lib-md.o lib-ptl.o lnet-objs += lib-socket.o lib-move.o module.o lo.o lnet-objs += router.o router_proc.o acceptor.o peer.o net_fault.o diff --git a/lnet/lnet/lnet-sysfs.c b/lnet/lnet/lnet-sysfs.c new file mode 100644 index 0000000..0f2bab9d --- /dev/null +++ b/lnet/lnet/lnet-sysfs.c @@ -0,0 +1,64 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.gnu.org/licenses/gpl-2.0.html + * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + * + * Copyright (c) 2011, 2017, Intel Corporation. + * + * Author: + * Sonia Sharma + */ + + +#include +#include + +struct kobject *lnet_kobj; +EXPORT_SYMBOL_GPL(lnet_kobj); + +/* + * Helper functions for sysfs callbacks implementation + */ +ssize_t lnet_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct lnet_attr *a = container_of(attr, struct lnet_attr, attr); + + return a->show ? a->show(kobj, attr, buf) : 0; +} +EXPORT_SYMBOL_GPL(lnet_attr_show); + +ssize_t lnet_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len) +{ + struct lnet_attr *a = container_of(attr, struct lnet_attr, attr); + + return a->store ? a->store(kobj, attr, buf, len) : len; +} +EXPORT_SYMBOL_GPL(lnet_attr_store); + +const struct sysfs_ops lnet_sysfs_ops = { + .show = lnet_attr_show, + .store = lnet_attr_store, +}; +EXPORT_SYMBOL_GPL(lnet_sysfs_ops); diff --git a/lnet/lnet/module.c b/lnet/lnet/module.c index 676f734..bfa6e12 100644 --- a/lnet/lnet/module.c +++ b/lnet/lnet/module.c @@ -33,6 +33,7 @@ #define DEBUG_SUBSYSTEM S_LNET #include +#include #include static int config_on_load = 0; @@ -237,9 +238,17 @@ static int __init lnet_init(void) mutex_init(&lnet_config_mutex); + /* Create sysfs base directories for LNet statistics */ + lnet_kobj = kobject_create_and_add("lnet", fs_kobj); + if (!lnet_kobj) { + CERROR("Sysfs kobject for lnet could not be created\n"); + RETURN(-ENOMEM); + } + rc = lnet_lib_init(); if (rc != 0) { CERROR("lnet_lib_init: error %d\n", rc); + kobject_put(lnet_kobj); RETURN(rc); } @@ -265,6 +274,9 @@ static void __exit lnet_exit(void) LASSERT(rc == 0); lnet_lib_exit(); + + /* cleanup the base sysfs directories */ + kobject_put(lnet_kobj); } MODULE_AUTHOR("OpenSFS, Inc. "); -- 1.8.3.1