Commit 269ce62b authored by Olaf Hering's avatar Olaf Hering Committed by Greg Kroah-Hartman

Tools: hv: use single send+recv buffer

send_buffer is used only once during registration. To reduce runtime
memory usage reuse the recv_buffer for registration. Also use
NLMSG_LENGTH instead of NLMSG_HDRLEN to take alignment into account.
Signed-off-by: default avatarOlaf Hering <olaf@aepfle.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 58125210
...@@ -1434,7 +1434,6 @@ int main(void) ...@@ -1434,7 +1434,6 @@ int main(void)
int pool; int pool;
char *if_name; char *if_name;
struct hv_kvp_ipaddr_value *kvp_ip_val; struct hv_kvp_ipaddr_value *kvp_ip_val;
char *kvp_send_buffer;
char *kvp_recv_buffer; char *kvp_recv_buffer;
size_t kvp_recv_buffer_len; size_t kvp_recv_buffer_len;
...@@ -1443,11 +1442,10 @@ int main(void) ...@@ -1443,11 +1442,10 @@ int main(void)
openlog("KVP", 0, LOG_USER); openlog("KVP", 0, LOG_USER);
syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); syslog(LOG_INFO, "KVP starting; pid is:%d", getpid());
kvp_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg); kvp_recv_buffer_len = NLMSG_LENGTH(0) + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg);
kvp_send_buffer = calloc(1, kvp_recv_buffer_len);
kvp_recv_buffer = calloc(1, kvp_recv_buffer_len); kvp_recv_buffer = calloc(1, kvp_recv_buffer_len);
if (!(kvp_send_buffer && kvp_recv_buffer)) { if (!kvp_recv_buffer) {
syslog(LOG_ERR, "Failed to allocate netlink buffers"); syslog(LOG_ERR, "Failed to allocate netlink buffer");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* /*
...@@ -1494,7 +1492,7 @@ int main(void) ...@@ -1494,7 +1492,7 @@ int main(void)
/* /*
* Register ourselves with the kernel. * Register ourselves with the kernel.
*/ */
message = (struct cn_msg *)kvp_send_buffer; message = (struct cn_msg *)kvp_recv_buffer;
message->id.idx = CN_KVP_IDX; message->id.idx = CN_KVP_IDX;
message->id.val = CN_KVP_VAL; message->id.val = CN_KVP_VAL;
......
...@@ -140,7 +140,6 @@ int main(void) ...@@ -140,7 +140,6 @@ int main(void)
struct cn_msg *incoming_cn_msg; struct cn_msg *incoming_cn_msg;
int op; int op;
struct hv_vss_msg *vss_msg; struct hv_vss_msg *vss_msg;
char *vss_send_buffer;
char *vss_recv_buffer; char *vss_recv_buffer;
size_t vss_recv_buffer_len; size_t vss_recv_buffer_len;
...@@ -150,10 +149,9 @@ int main(void) ...@@ -150,10 +149,9 @@ int main(void)
openlog("Hyper-V VSS", 0, LOG_USER); openlog("Hyper-V VSS", 0, LOG_USER);
syslog(LOG_INFO, "VSS starting; pid is:%d", getpid()); syslog(LOG_INFO, "VSS starting; pid is:%d", getpid());
vss_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg); vss_recv_buffer_len = NLMSG_LENGTH(0) + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg);
vss_send_buffer = calloc(1, vss_recv_buffer_len);
vss_recv_buffer = calloc(1, vss_recv_buffer_len); vss_recv_buffer = calloc(1, vss_recv_buffer_len);
if (!(vss_send_buffer && vss_recv_buffer)) { if (!vss_recv_buffer) {
syslog(LOG_ERR, "Failed to allocate netlink buffers"); syslog(LOG_ERR, "Failed to allocate netlink buffers");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -185,7 +183,7 @@ int main(void) ...@@ -185,7 +183,7 @@ int main(void)
/* /*
* Register ourselves with the kernel. * Register ourselves with the kernel.
*/ */
message = (struct cn_msg *)vss_send_buffer; message = (struct cn_msg *)vss_recv_buffer;
message->id.idx = CN_VSS_IDX; message->id.idx = CN_VSS_IDX;
message->id.val = CN_VSS_VAL; message->id.val = CN_VSS_VAL;
message->ack = 0; message->ack = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment