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 <Al.Bailey@windriver.com>
This commit is contained in:
Jack Ding 2018-05-25 12:52:51 -04:00 committed by Al Bailey
parent 49ddf1710d
commit 7a2aa8aaa2
3 changed files with 31 additions and 7 deletions

View File

@ -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;
}
// ****************************************************************************

View File

@ -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

View File

@ -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);