From 92204ead683ef1b4a8bf7576ade161b460301a07 Mon Sep 17 00:00:00 2001 From: Takahiro Hirofuchi Date: Thu, 7 Feb 2013 15:46:19 +0100 Subject: [PATCH] do cleanup around msg_vm_state_abc In the near future, some code related to VM state should be moved to the surf layer. --- include/msg/datatypes.h | 22 +++++++---- src/msg/msg_vm.c | 86 ++++++++++++++++++++++++++++++++--------- 2 files changed, 81 insertions(+), 27 deletions(-) diff --git a/include/msg/datatypes.h b/include/msg/datatypes.h index e5b3ea12ec..2738847c6f 100644 --- a/include/msg/datatypes.h +++ b/include/msg/datatypes.h @@ -106,14 +106,20 @@ typedef msg_host_t msg_vm_t; typedef msg_host_priv_t msg_vm_priv_t; typedef enum { -msg_vm_state_created, -msg_vm_state_running, -msg_vm_state_sleeping, -msg_vm_state_migrating, -msg_vm_state_resuming, -msg_vm_state_suspended, -msg_vm_state_saved, -msg_vm_state_restoring, + /* created, but not yet started */ + msg_vm_state_created, + + msg_vm_state_running, + msg_vm_state_migrating, + + /* Suspend/resume does not involve disk I/O, so we assume there is no transition states. */ + msg_vm_state_suspended, + + /* Save/restore involves disk I/O, so there should be transition states. */ + msg_vm_state_saving, + msg_vm_state_saved, + msg_vm_state_restoring, + } e_msg_vm_state_t; static inline msg_vm_priv_t MSG_vm_priv(msg_vm_t vm){ diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index 1bab452afb..6891726b66 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -92,6 +92,73 @@ const char *MSG_vm_get_name(msg_vm_t vm) { return MSG_host_get_name(vm); } + +/* **** Check state of a VM **** */ +static inline int __MSG_vm_is_state(msg_vm_t vm, e_msg_vm_state_t state) { + return simcall_vm_get_state(vm) == state; +} + +/** @brief Returns whether the given VM has just reated, not running. + * @ingroup msg_VMs + */ +int MSG_vm_is_created(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_created); +} + +/** @brief Returns whether the given VM is currently running + * @ingroup msg_VMs + */ +int MSG_vm_is_running(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_running); +} + +/** @brief Returns whether the given VM is currently migrating + * @ingroup msg_VMs + */ +int MSG_vm_is_migrating(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_migrating); +} + +/** @brief Returns whether the given VM is currently suspended, not running. + * @ingroup msg_VMs + */ +int MSG_vm_is_suspended(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_suspended); +} + +/** @brief Returns whether the given VM is being saved (FIXME: live saving or not?). + * @ingroup msg_VMs + */ +int MSG_vm_is_saving(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_saving); +} + +/** @brief Returns whether the given VM has been saved, not running. + * @ingroup msg_VMs + */ +int MSG_vm_is_saved(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_saved); +} + +/** @brief Returns whether the given VM is being restored, not running. + * @ingroup msg_VMs + */ +int MSG_vm_is_restoring(msg_vm_t vm) +{ + return __MSG_vm_is_state(vm, msg_vm_state_restoring); +} + + + +/* ------------------------------------------------------------------------- */ +/* ------------------------------------------------------------------------- */ + /* **** ******** MSG vm actions ********* **** */ /** @brief Create a new VM (the VM is just attached to the location but it is not started yet). @@ -140,25 +207,6 @@ void MSG_vm_start(msg_vm_t vm) { #endif } -/* **** Check state of a VM **** */ -int __MSG_vm_is_state(msg_vm_t vm, e_msg_vm_state_t state) { - return simcall_vm_get_state(vm) == state ; -} - -/** @brief Returns whether the given VM is currently suspended - * @ingroup msg_VMs - */ -int MSG_vm_is_suspended(msg_vm_t vm) { - return __MSG_vm_is_state(vm, msg_vm_state_suspended); -} -/** @brief Returns whether the given VM is currently running - * @ingroup msg_VMs - */ -int MSG_vm_is_running(msg_vm_t vm) { - return __MSG_vm_is_state(vm, msg_vm_state_running); -} - -// TODO Implement the functions for the different state /** @brief Immediately kills all processes within the given VM. Any memory that they allocated will be leaked. -- 2.20.1