|
|
b524e3 |
From 47c1f956e7f212aec0eec174c3fb5801eae5d5bc Mon Sep 17 00:00:00 2001
|
|
|
b524e3 |
From: Chris Leech <cleech@redhat.com>
|
|
|
b524e3 |
Date: Thu, 24 Jan 2019 18:16:47 -0800
|
|
|
b524e3 |
Subject: [PATCH 1/1] fcoemon: link buffer resize fix
|
|
|
b524e3 |
|
|
|
b524e3 |
---
|
|
|
b524e3 |
fcoemon.c | 54 ++++++++++++++++++------------------------------------
|
|
|
b524e3 |
1 file changed, 18 insertions(+), 36 deletions(-)
|
|
|
b524e3 |
|
|
|
b524e3 |
diff --git a/fcoemon.c b/fcoemon.c
|
|
|
b524e3 |
index bf73a0d4c89e..ff8a8b869ba4 100644
|
|
|
b524e3 |
--- a/fcoemon.c
|
|
|
b524e3 |
+++ b/fcoemon.c
|
|
|
b524e3 |
@@ -328,7 +328,6 @@ static int fcm_link_socket;
|
|
|
b524e3 |
static int fcm_link_seq;
|
|
|
b524e3 |
static void fcm_link_recv(void *);
|
|
|
b524e3 |
static void fcm_link_getlink(void);
|
|
|
b524e3 |
-static int fcm_link_buf_check(size_t);
|
|
|
b524e3 |
static void clear_dcbd_info(struct fcm_netif *ff);
|
|
|
b524e3 |
static int fcoe_vid_from_ifname(const char *ifname);
|
|
|
b524e3 |
|
|
|
b524e3 |
@@ -354,8 +353,7 @@ char progname[20];
|
|
|
b524e3 |
* large enough to fit and expand it if we ever do a read that almost fills it.
|
|
|
b524e3 |
*/
|
|
|
b524e3 |
static char *fcm_link_buf;
|
|
|
b524e3 |
-static size_t fcm_link_buf_size = 4096; /* initial size */
|
|
|
b524e3 |
-static const size_t fcm_link_buf_fuzz = 300; /* "almost full" remainder */
|
|
|
b524e3 |
+static size_t fcm_link_buf_size = 8192; /* initial size */
|
|
|
b524e3 |
|
|
|
b524e3 |
/*
|
|
|
b524e3 |
* A value must be surrounded by quates, e.g. "x".
|
|
|
b524e3 |
@@ -1856,8 +1854,22 @@ static void fcm_link_recv(UNUSED void *arg)
|
|
|
b524e3 |
size_t plen;
|
|
|
b524e3 |
size_t rlen;
|
|
|
b524e3 |
|
|
|
b524e3 |
+ /* check to make sure our receive buffer is large enough,
|
|
|
b524e3 |
+ * or scale it up as needed */
|
|
|
b524e3 |
+ rc = recv(fcm_link_socket, NULL, 0, MSG_PEEK | MSG_TRUNC);
|
|
|
b524e3 |
+ if (rc > fcm_link_buf_size) {
|
|
|
b524e3 |
+ FCM_LOG_DBG("resizing link buf to %d bytes\n", rc);
|
|
|
b524e3 |
+ void *resize = realloc(fcm_link_buf, rc);
|
|
|
b524e3 |
+ if (resize) {
|
|
|
b524e3 |
+ fcm_link_buf = resize;
|
|
|
b524e3 |
+ fcm_link_buf_size = rc;
|
|
|
b524e3 |
+ } else {
|
|
|
b524e3 |
+ FCM_LOG_ERR(errno, "Failed to allocate link buffer");
|
|
|
b524e3 |
+ }
|
|
|
b524e3 |
+ }
|
|
|
b524e3 |
+
|
|
|
b524e3 |
buf = fcm_link_buf;
|
|
|
b524e3 |
- rc = read(fcm_link_socket, buf, fcm_link_buf_size);
|
|
|
b524e3 |
+ rc = recv(fcm_link_socket, buf, fcm_link_buf_size, 0);
|
|
|
b524e3 |
if (rc <= 0) {
|
|
|
b524e3 |
if (rc < 0)
|
|
|
b524e3 |
FCM_LOG_ERR(errno, "Error reading from "
|
|
|
b524e3 |
@@ -1866,11 +1878,6 @@ static void fcm_link_recv(UNUSED void *arg)
|
|
|
b524e3 |
return;
|
|
|
b524e3 |
}
|
|
|
b524e3 |
|
|
|
b524e3 |
- if (fcm_link_buf_check(rc)) {
|
|
|
b524e3 |
- fcm_link_getlink();
|
|
|
b524e3 |
- return;
|
|
|
b524e3 |
- }
|
|
|
b524e3 |
-
|
|
|
b524e3 |
hp = (struct nlmsghdr *)buf;
|
|
|
b524e3 |
rlen = rc;
|
|
|
b524e3 |
for (hp = (struct nlmsghdr *)buf; NLMSG_OK(hp, rlen);
|
|
|
b524e3 |
@@ -1935,34 +1942,9 @@ static void fcm_link_getlink(void)
|
|
|
b524e3 |
msg.nl.nlmsg_pid = getpid();
|
|
|
b524e3 |
msg.ifi.ifi_family = AF_UNSPEC;
|
|
|
b524e3 |
msg.ifi.ifi_type = ARPHRD_ETHER;
|
|
|
b524e3 |
- rc = write(fcm_link_socket, &msg, sizeof(msg));
|
|
|
b524e3 |
+ rc = send(fcm_link_socket, &msg, sizeof(msg), 0);
|
|
|
b524e3 |
if (rc < 0)
|
|
|
b524e3 |
- FCM_LOG_ERR(errno, "write error");
|
|
|
b524e3 |
-}
|
|
|
b524e3 |
-
|
|
|
b524e3 |
-/*
|
|
|
b524e3 |
- * Check for whether buffer needs to grow based on amount read.
|
|
|
b524e3 |
- * Free's the old buffer so don't use that after this returns non-zero.
|
|
|
b524e3 |
- */
|
|
|
b524e3 |
-static int fcm_link_buf_check(size_t read_len)
|
|
|
b524e3 |
-{
|
|
|
b524e3 |
- char *buf;
|
|
|
b524e3 |
- size_t len = read_len;
|
|
|
b524e3 |
-
|
|
|
b524e3 |
- if (len > fcm_link_buf_size - fcm_link_buf_fuzz) {
|
|
|
b524e3 |
- len = fcm_link_buf_size;
|
|
|
b524e3 |
- len = len + len / 2; /* grow by 50% */
|
|
|
b524e3 |
- buf = malloc(len);
|
|
|
b524e3 |
- if (buf != NULL) {
|
|
|
b524e3 |
- free(fcm_link_buf);
|
|
|
b524e3 |
- fcm_link_buf = buf;
|
|
|
b524e3 |
- fcm_link_buf_size = len;
|
|
|
b524e3 |
- return 1;
|
|
|
b524e3 |
- } else {
|
|
|
b524e3 |
- FCM_LOG_ERR(errno, "failed to allocate link buffer");
|
|
|
b524e3 |
- }
|
|
|
b524e3 |
- }
|
|
|
b524e3 |
- return 0;
|
|
|
b524e3 |
+ FCM_LOG_ERR(errno, "send error");
|
|
|
b524e3 |
}
|
|
|
b524e3 |
|
|
|
b524e3 |
static void fcm_fcoe_init(void)
|
|
|
b524e3 |
--
|
|
|
b524e3 |
2.17.2
|
|
|
b524e3 |
|