88 lines
2.5 KiB
Diff
88 lines
2.5 KiB
Diff
|
From 014e8ba4580c7917e258df084776c16079dc07ce Mon Sep 17 00:00:00 2001
|
||
|
From: Laurent Dufour <ldufour@linux.ibm.com>
|
||
|
Date: Tue, 24 Nov 2020 19:28:48 +0100
|
||
|
Subject: [PATCH 1/3] drmgr: don't open sysfs file for each command
|
||
|
|
||
|
The new __do_kernel_dlpar() API will be used in later commit to remove by
|
||
|
DRC Index LMB per LMB. This will avoiding opennig and closing the fd each
|
||
|
time.
|
||
|
|
||
|
The fd closing will now be done at the process exit time.
|
||
|
|
||
|
In addition add an optinal parameter to silently ignore some error.
|
||
|
|
||
|
Also, change the log level of the "success" message to debug to match
|
||
|
the previous one saying "Trying.."
|
||
|
|
||
|
Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
|
||
|
---
|
||
|
src/drmgr/common.c | 22 +++++++++++++---------
|
||
|
src/drmgr/dr.h | 3 ++-
|
||
|
2 files changed, 15 insertions(+), 10 deletions(-)
|
||
|
|
||
|
diff --git a/src/drmgr/common.c b/src/drmgr/common.c
|
||
|
index 5e8135bcf77e..25d244cb2f57 100644
|
||
|
--- a/src/drmgr/common.c
|
||
|
+++ b/src/drmgr/common.c
|
||
|
@@ -1469,32 +1469,36 @@ int kernel_dlpar_exists(void)
|
||
|
* @param cmd command string to write to sysfs
|
||
|
* @returns 0 on success, !0 otherwise
|
||
|
*/
|
||
|
-int do_kernel_dlpar(const char *cmd, int cmdlen)
|
||
|
+int __do_kernel_dlpar(const char *cmd, int cmdlen, int silent_error)
|
||
|
{
|
||
|
- int fd, rc;
|
||
|
+ static int fd = -1;
|
||
|
+ int rc;
|
||
|
int my_errno;
|
||
|
|
||
|
say(DEBUG, "Initiating kernel DLPAR \"%s\"\n", cmd);
|
||
|
|
||
|
/* write to file */
|
||
|
- fd = open(SYSFS_DLPAR_FILE, O_WRONLY);
|
||
|
- if (fd <= 0) {
|
||
|
- say(ERROR, "Could not open %s to initiate DLPAR request\n",
|
||
|
- SYSFS_DLPAR_FILE);
|
||
|
- return -1;
|
||
|
+ if (fd == -1) {
|
||
|
+ fd = open(SYSFS_DLPAR_FILE, O_WRONLY);
|
||
|
+ if (fd <= 0) {
|
||
|
+ say(ERROR, "Could not open %s to initiate DLPAR request\n",
|
||
|
+ SYSFS_DLPAR_FILE);
|
||
|
+ return -1;
|
||
|
+ }
|
||
|
}
|
||
|
|
||
|
rc = write(fd, cmd, cmdlen);
|
||
|
my_errno = errno;
|
||
|
- close(fd);
|
||
|
if (rc <= 0) {
|
||
|
+ if (silent_error)
|
||
|
+ return (my_errno == 0) ? -1 : -my_errno;
|
||
|
/* write does not set errno for rc == 0 */
|
||
|
say(ERROR, "Failed to write to %s: %s\n", SYSFS_DLPAR_FILE,
|
||
|
(rc == 0) ? "wrote 0 bytes" : strerror(my_errno));
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
- say(INFO, "Success\n");
|
||
|
+ say(DEBUG, "Success\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
diff --git a/src/drmgr/dr.h b/src/drmgr/dr.h
|
||
|
index f171bfea73c3..00d2fffc9919 100644
|
||
|
--- a/src/drmgr/dr.h
|
||
|
+++ b/src/drmgr/dr.h
|
||
|
@@ -172,5 +172,6 @@ enum drc_type to_drc_type(const char *);
|
||
|
int handle_prrn(void);
|
||
|
|
||
|
int kernel_dlpar_exists(void);
|
||
|
-int do_kernel_dlpar(const char *, int);
|
||
|
+int __do_kernel_dlpar(const char *, int, int);
|
||
|
+#define do_kernel_dlpar(c, l) __do_kernel_dlpar(c, l, 0)
|
||
|
#endif
|
||
|
--
|
||
|
2.29.2
|
||
|
|