From f8f2580fcd49ffed129579c814dcf05eb15d39bf Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 15 Aug 2013 05:34:33 +0000 Subject: [PATCH] From: Benjamin Black There is not a way to specify an attribute that applies to only one target or target driver. This patch provides such an interface. Copyright (C) 2013 Emulex. All rights reserved. This software is provided as-is, without any express or implied warranty. In no event will Emulex be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely. If you use this software in a product, an acknowledgment in the product documentation would be appreciated, but is not required. This notice may be removed from any source code distribution that includes all or any part of the original software. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4970 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 3 +++ scst/src/scst_sysfs.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/scst/include/scst.h b/scst/include/scst.h index e3b0bbdb9..0f3095638 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -4467,6 +4467,9 @@ int scst_alloc_sysfs_work(int (*sysfs_work_fn)(struct scst_sysfs_work_item *), int scst_sysfs_queue_wait_work(struct scst_sysfs_work_item *work); void scst_sysfs_work_get(struct scst_sysfs_work_item *work); void scst_sysfs_work_put(struct scst_sysfs_work_item *work); +int scst_create_tgt_attr(struct scst_tgt *tgt, struct kobj_attribute *attribute); +int scst_create_tgt_driver_attr(struct scst_tgt_template *tgtt, + struct kobj_attribute *attribute); #endif /* CONFIG_SCST_PROC */ diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index 30933f95a..3e474120c 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -2285,6 +2285,44 @@ static struct kobj_attribute scst_tgt_comment = __ATTR(comment, S_IRUGO | S_IWUSR, scst_tgt_comment_show, scst_tgt_comment_store); +/* + * Creates an attribute entry for one target. Allows for target driver to + * specify an attribute that is not for every target. + */ +int scst_create_tgt_attr(struct scst_tgt *tgt, struct kobj_attribute *attribute) +{ + int res; + + res = sysfs_create_file(&tgt->tgt_kobj, &attribute->attr); + if (res != 0) { + PRINT_ERROR("Can't add attribute %s for tgt %s", + attribute->attr.name, tgt->tgt_name); + res = -ENOMEM; + } + + return res; +} +EXPORT_SYMBOL(scst_create_tgt_attr); + +/* + * Creates an attribute entry for target driver. + */ +int scst_create_tgt_driver_attr(struct scst_tgt_template *tgtt, + struct kobj_attribute *attribute) +{ + int res; + + res = sysfs_create_file(&tgtt->tgtt_kobj, &attribute->attr); + if (res != 0) { + PRINT_ERROR("Can't add attribute %s for target driver %s", + attribute->attr.name, tgtt->name); + res = -ENOMEM; + } + + return res; +} +EXPORT_SYMBOL(scst_create_tgt_driver_attr); + /* * Supposed to be called under scst_mutex. In case of error will drop, * then reacquire it.