lkml.org 
[lkml]   [2022]   [Mar]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 1/3] ipmi: msghandler: Get the number of user through sysfs
Date
The administrator reads the user_count file corresponding the ipmi device, ipmi
traverse all intf, and count the number of user.

Signed-off-by: Chen Guanqiao <chen.chenchacha@foxmail.com>
---
drivers/char/ipmi/ipmi_msghandler.c | 33 +++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index c59265146e9c..e14beb51cae4 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2706,6 +2706,29 @@ static int bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
return __bmc_get_device_id(intf, bmc, id, guid_set, guid, -1);
}

+static unsigned int get_user_count(void)
+{
+ struct ipmi_smi *intf;
+ int index;
+ unsigned int total_count = 0;
+
+ index = srcu_read_lock(&ipmi_interfaces_srcu);
+ list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
+ struct ipmi_user *user;
+ int intf_index, count = 0;
+
+ intf_index = srcu_read_lock(&intf->users_srcu);
+ list_for_each_entry_rcu(user, &intf->users, link)
+ count++;
+ srcu_read_unlock(&intf->users_srcu, intf_index);
+
+ total_count += count;
+ }
+ srcu_read_unlock(&ipmi_interfaces_srcu, index);
+
+ return total_count;
+}
+
static ssize_t device_id_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -2875,6 +2898,15 @@ static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(guid);

+static ssize_t user_count_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ unsigned int user_count = get_user_count();
+
+ return snprintf(buf, 20, "%u\n", user_count);
+}
+static DEVICE_ATTR_ADMIN_RO(user_count);
+
static struct attribute *bmc_dev_attrs[] = {
&dev_attr_device_id.attr,
&dev_attr_provides_device_sdrs.attr,
@@ -2886,6 +2918,7 @@ static struct attribute *bmc_dev_attrs[] = {
&dev_attr_product_id.attr,
&dev_attr_aux_firmware_revision.attr,
&dev_attr_guid.attr,
+ &dev_attr_user_count.attr,
NULL
};

--
2.25.1
\
 
 \ /
  Last update: 2022-03-27 18:52    [W:0.034 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site