* [PATCH 1/3] ipmi: msghandler: Get the number of user through sysfs
[not found] <cover.1648397283.git.chen.chenchacha@foxmail.com>
@ 2022-03-27 16:47 ` Chen Guanqiao
2022-03-27 16:47 ` [PATCH 2/3] ipmi: msghandler: Get the number of message " Chen Guanqiao
2022-03-27 16:47 ` [PATCH 3/3] ipmi: msghandler: add a interface to clean message queue in sysfs Chen Guanqiao
2 siblings, 0 replies; 3+ messages in thread
From: Chen Guanqiao @ 2022-03-27 16:47 UTC (permalink / raw)
To: minyard, openipmi-developer, linux-kernel; +Cc: Chen Guanqiao
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/3] ipmi: msghandler: Get the number of message through sysfs
[not found] <cover.1648397283.git.chen.chenchacha@foxmail.com>
2022-03-27 16:47 ` [PATCH 1/3] ipmi: msghandler: Get the number of user through sysfs Chen Guanqiao
@ 2022-03-27 16:47 ` Chen Guanqiao
2022-03-27 16:47 ` [PATCH 3/3] ipmi: msghandler: add a interface to clean message queue in sysfs Chen Guanqiao
2 siblings, 0 replies; 3+ messages in thread
From: Chen Guanqiao @ 2022-03-27 16:47 UTC (permalink / raw)
To: minyard, openipmi-developer, linux-kernel; +Cc: Chen Guanqiao
Reads the message_count file corresponding the ipmi device, ipmi traverse all
intf, and count the number of message and high priority message.
Signed-off-by: Chen Guanqiao <chen.chenchacha@foxmail.com>
---
drivers/char/ipmi/ipmi_msghandler.c | 44 +++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e14beb51cae4..0238be81c435 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2729,6 +2729,38 @@ static unsigned int get_user_count(void)
return total_count;
}
+static void get_msg_count(unsigned int *hp_count, unsigned int *count)
+{
+ struct ipmi_smi *intf;
+ int index;
+ int hp_msg_count = 0, msg_count = 0;
+
+ index = srcu_read_lock(&ipmi_interfaces_srcu);
+ list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
+ struct ipmi_smi_msg *msg;
+ unsigned long flags;
+ int run_to_completion = intf->run_to_completion;
+
+ rcu_read_lock();
+ if (!run_to_completion)
+ spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
+ if (!intf->in_shutdown) {
+ list_for_each_entry(msg, &intf->hp_xmit_msgs, link)
+ hp_msg_count++;
+
+ list_for_each_entry(msg, &intf->xmit_msgs, link)
+ msg_count++;
+ }
+ if (!run_to_completion)
+ spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
+ rcu_read_unlock();
+ }
+ srcu_read_unlock(&ipmi_interfaces_srcu, index);
+
+ *hp_count = msg_count;
+ *count = hp_msg_count;
+}
+
static ssize_t device_id_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -2907,6 +2939,17 @@ static ssize_t user_count_show(struct device *dev,
}
static DEVICE_ATTR_ADMIN_RO(user_count);
+static ssize_t msg_count_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ unsigned int hp_count, count;
+
+ get_msg_count(&hp_count, &count);
+
+ return snprintf(buf, 40, "hp msg:%u, msg:%u\n", hp_count, count);
+}
+static DEVICE_ATTR_ADMIN_RO(msg_count);
+
static struct attribute *bmc_dev_attrs[] = {
&dev_attr_device_id.attr,
&dev_attr_provides_device_sdrs.attr,
@@ -2919,6 +2962,7 @@ static struct attribute *bmc_dev_attrs[] = {
&dev_attr_aux_firmware_revision.attr,
&dev_attr_guid.attr,
&dev_attr_user_count.attr,
+ &dev_attr_msg_count.attr,
NULL
};
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 3/3] ipmi: msghandler: add a interface to clean message queue in sysfs
[not found] <cover.1648397283.git.chen.chenchacha@foxmail.com>
2022-03-27 16:47 ` [PATCH 1/3] ipmi: msghandler: Get the number of user through sysfs Chen Guanqiao
2022-03-27 16:47 ` [PATCH 2/3] ipmi: msghandler: Get the number of message " Chen Guanqiao
@ 2022-03-27 16:47 ` Chen Guanqiao
2 siblings, 0 replies; 3+ messages in thread
From: Chen Guanqiao @ 2022-03-27 16:47 UTC (permalink / raw)
To: minyard, openipmi-developer, linux-kernel; +Cc: Chen Guanqiao
The further approach, add a cleanup interface in sysfs. The administrator write
'1' to clean_msg, and ipmi clear the entire message queue.
Signed-off-by: Chen Guanqiao <chen.chenchacha@foxmail.com>
---
drivers/char/ipmi/ipmi_msghandler.c | 82 +++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 0238be81c435..29d6779a569f 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -46,6 +46,9 @@ static void handle_new_recv_msgs(struct ipmi_smi *intf);
static void need_waiter(struct ipmi_smi *intf);
static int handle_one_recv_msg(struct ipmi_smi *intf,
struct ipmi_smi_msg *msg);
+static void deliver_smi_err_response(struct ipmi_smi *intf,
+ struct ipmi_smi_msg *msg,
+ unsigned char err);
static bool initialized;
static bool drvregistered;
@@ -2761,6 +2764,71 @@ static void get_msg_count(unsigned int *hp_count, unsigned int *count)
*count = hp_msg_count;
}
+static void __cleanup_msgs_queue(struct ipmi_smi *intf)
+{
+ int i;
+ unsigned long flags;
+ int run_to_completion = intf->run_to_completion;
+
+ rcu_read_lock();
+ if (!run_to_completion)
+ spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
+ if (!intf->in_shutdown) {
+ struct ipmi_smi_msg *msg;
+ struct list_head *entry = NULL;
+
+ while (!list_empty(&intf->xmit_msgs)) {
+ if (!list_empty(&intf->hp_xmit_msgs))
+ entry = intf->hp_xmit_msgs.next;
+ else if (!list_empty(&intf->xmit_msgs))
+ entry = intf->xmit_msgs.next;
+
+ if (!entry)
+ continue;
+
+ list_del(entry);
+ msg = list_entry(entry, struct ipmi_smi_msg, link);
+ deliver_smi_err_response(intf, msg,
+ IPMI_ERR_UNSPECIFIED);
+ }
+ }
+ if (!run_to_completion)
+ spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
+ rcu_read_unlock();
+
+ spin_lock_irqsave(&intf->seq_lock, flags);
+ for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) {
+ struct seq_table *ent = &intf->seq_table[i];
+
+ if (!ent->inuse)
+ continue;
+ deliver_err_response(intf, ent->recv_msg, IPMI_ERR_UNSPECIFIED);
+ }
+ spin_unlock_irqrestore(&intf->seq_lock, flags);
+}
+
+static void cleanup_msgs_queue(void)
+{
+ struct ipmi_smi *intf;
+ int index;
+
+ index = srcu_read_lock(&ipmi_interfaces_srcu);
+ list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
+ struct bmc_device *bmc = intf->bmc;
+
+ kref_get(&intf->refcount);
+ mutex_lock(&intf->bmc_reg_mutex);
+ mutex_lock(&bmc->dyn_mutex);
+
+ __cleanup_msgs_queue(intf);
+
+ mutex_unlock(&bmc->dyn_mutex);
+ mutex_unlock(&intf->bmc_reg_mutex);
+ kref_put(&intf->refcount, intf_free);
+ }
+ srcu_read_unlock(&ipmi_interfaces_srcu, index);
+}
+
static ssize_t device_id_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -2950,6 +3018,19 @@ static ssize_t msg_count_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_ADMIN_RO(msg_count);
+static ssize_t clean_msgs_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t count)
+{
+ if (!sysfs_streq(buf, "1"))
+ return -EINVAL;
+
+ cleanup_msgs_queue();
+
+ return count;
+}
+static DEVICE_ATTR_WO(clean_msgs);
+
static struct attribute *bmc_dev_attrs[] = {
&dev_attr_device_id.attr,
&dev_attr_provides_device_sdrs.attr,
@@ -2963,6 +3044,7 @@ static struct attribute *bmc_dev_attrs[] = {
&dev_attr_guid.attr,
&dev_attr_user_count.attr,
&dev_attr_msg_count.attr,
+ &dev_attr_clean_msgs.attr,
NULL
};
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-27 16:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <cover.1648397283.git.chen.chenchacha@foxmail.com>
2022-03-27 16:47 ` [PATCH 1/3] ipmi: msghandler: Get the number of user through sysfs Chen Guanqiao
2022-03-27 16:47 ` [PATCH 2/3] ipmi: msghandler: Get the number of message " Chen Guanqiao
2022-03-27 16:47 ` [PATCH 3/3] ipmi: msghandler: add a interface to clean message queue in sysfs Chen Guanqiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®