From 7a2aa8aaa249877ba7caf43aa5170659805be2eb Mon Sep 17 00:00:00 2001 From: Jack Ding Date: Fri, 25 May 2018 12:52:51 -0400 Subject: [PATCH] vm_voting on migration action are sometimes not getting rejected Due to race conditions, multiple messages might be received from a single read by guestServer. guestServer in this case would only handle the first message and discard the remaining ones. In this particular issue, guestServer received a heartbeat challenge response message and a vote notification response (reject) message from a single read, and the latter message was discarded. This fix re-writes message handler for virtio serial channel to handle segmented and multiple messages, and removed any newline characters in client log message. It contains fix for both host and client, so both host load and guest image need to be updated to test the fix. Change-Id: I50ed2236ad24b61a79dce7773ace5b4b6ee33f28 Signed-off-by: Al Bailey --- .../guest_client/src/guest_utils.c | 18 +++++++++++++++++- .../guest_client/src/guest_utils.h | 7 ++++++- .../src/heartbeat/guest_heartbeat_msg.c | 13 ++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.c b/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.c index 41633482..9a31c0fb 100755 --- a/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.c +++ b/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016, Wind River Systems, Inc. + * Copyright (c) 2013-2018, Wind River Systems, Inc. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -119,3 +119,19 @@ int guest_utils_json_get_value( struct json_object* jobj, return 0; } // **************************************************************************** + +// **************************************************************************** +// Guest Utilities - replace newline with space +// ====================== +char* guest_utils_remove_newline( char* str) +{ + char match = '\n'; + char replace = ' '; + char *match_found = strchr(str, match); + while (match_found){ + *match_found = replace; + match_found = strchr(match_found+1, match); + } + return str; +} +// **************************************************************************** \ No newline at end of file diff --git a/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.h b/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.h index 25b75b67..313ae2eb 100755 --- a/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.h +++ b/guest-client/guest-client-3.0.1/guest_client/src/guest_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016, Wind River Systems, Inc. + * Copyright (c) 2013-2018, Wind River Systems, Inc. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -56,6 +56,11 @@ extern char* guest_utils_basename( char* str ); // ========================================= extern int guest_utils_json_get_value( struct json_object* jobj, const char* key, void * value ); + +// **************************************************************************** +// Guest Utilities - replace newline with space +// ====================== +char* guest_utils_remove_newline( char* str); // **************************************************************************** #ifdef __cplusplus diff --git a/guest-client/guest-client-3.0.1/guest_client/src/heartbeat/guest_heartbeat_msg.c b/guest-client/guest-client-3.0.1/guest_client/src/heartbeat/guest_heartbeat_msg.c index 11df2feb..87aa977d 100755 --- a/guest-client/guest-client-3.0.1/guest_client/src/heartbeat/guest_heartbeat_msg.c +++ b/guest-client/guest-client-3.0.1/guest_client/src/heartbeat/guest_heartbeat_msg.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016, Wind River Systems, Inc. + * Copyright (c) 2013-2018, Wind River Systems, Inc. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -382,7 +382,8 @@ GuestErrorT guest_heartbeat_msg_send_exit( char log_msg[] ) GuestErrorT error; char log_msg_buf[GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE]; - snprintf(log_msg_buf, GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE, "%s", log_msg); + snprintf(log_msg_buf, GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE, "%s", + guest_utils_remove_newline(log_msg)); char msg[GUEST_HEARTBEAT_MSG_MAX_MSG_SIZE]; snprintf(msg, sizeof(msg), "\n{\"%s\":%d,\"%s\":%d,\"%s\":\"%s\",\"%s\":%d," @@ -456,7 +457,8 @@ GuestErrorT guest_heartbeat_msg_send_challenge_response( GuestErrorT error; char log_msg_buf[GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE]; - snprintf(log_msg_buf, GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE, "%s", log_msg); + snprintf(log_msg_buf, GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE, "%s", + guest_utils_remove_newline(log_msg)); char msg[GUEST_HEARTBEAT_MSG_MAX_MSG_SIZE]; snprintf(msg, sizeof(msg), "\n{\"%s\":%d,\"%s\":%d,\"%s\":\"%s\",\"%s\":%d," @@ -543,7 +545,8 @@ GuestErrorT guest_heartbeat_msg_send_action_response( GuestErrorT error; char log_msg_buf[GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE]; - snprintf(log_msg_buf, GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE, "%s", log_msg); + snprintf(log_msg_buf, GUEST_HEARTBEAT_MSG_MAX_LOG_SIZE, "%s", + guest_utils_remove_newline(log_msg)); char msg[GUEST_HEARTBEAT_MSG_MAX_MSG_SIZE]; @@ -852,7 +855,7 @@ void guest_heartbeat_msg_dispatch(json_object *jobj_msg) if (guest_utils_json_get_value(jobj_msg, GUEST_HEARTBEAT_MSG_VERSION, &version)) return; - if (GUEST_HEARTBEAT_MSG_VERSION_CURRENT != version) + if (GUEST_HEARTBEAT_MSG_VERSION_CURRENT > version) { DPRINTFI("message received version %d, expected %d, dropping\n", version, GUEST_HEARTBEAT_MSG_VERSION_CURRENT);