Index: /branches/rel_avx_2_7_5/src/avxd/avx_daemon.c
===================================================================
--- /branches/rel_avx_2_7_5/src/avxd/avx_daemon.c	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/avxd/avx_daemon.c	(working copy)
@@ -39,6 +39,7 @@
 #include "avx_dpdk.h"
 #include "property.h"
 #include "avxnet.h"
+#include "ca_util.h"
 
 #define COREDUMP_STR "Avxd coredump has happened.\n"
 
@@ -60,6 +61,7 @@
 main(int argc, char *argv[]) {
     int ch, debug=0;
     int ret = -1;
+    char buf_init[128] = {0};
 
     while ((ch = getopt(argc, argv, "d")) != -1) {
         switch (ch) {
@@ -71,6 +73,8 @@
         }
     }
 
+    snprintf(buf_init, sizeof(buf_init), "touch %s", AVXD_INIT_FINISHED);
+    system(buf_init);
     signal(SIGUSR1, SIG_IGN);
     signal(SIGUSR2, SIG_IGN);
     signal(SIGSEGV, sig_handler_coredump);
Index: /branches/rel_avx_2_7_5/src/avxd/avx_rpcserver.c
===================================================================
--- /branches/rel_avx_2_7_5/src/avxd/avx_rpcserver.c	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/avxd/avx_rpcserver.c	(working copy)
@@ -1377,6 +1377,7 @@
 
     va_log_info("running xml-rpc server...");
 
+    unlink(AVXD_INIT_FINISHED);
     xmlrpc_server_abyss_run_server(&env, server_p);
     int cnt = 1;
     do{
Index: /branches/rel_avx_2_7_5/src/backend/sys_mgm.c
===================================================================
--- /branches/rel_avx_2_7_5/src/backend/sys_mgm.c	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/backend/sys_mgm.c	(working copy)
@@ -38,7 +38,12 @@
 void
 system_reboot(char *optional)
 {
+     
     if(strcmp(optional, "noninteractive") != 0) {
+        if(access(AVXD_INIT_FINISHED, F_OK) == 0) {
+               printf("System is still coming up. It is not safe to reboot now. Please retry later");
+               return;
+        }
 
         printf("All running VAs will be stopped and unsaved configurations"
                " on running VAs will be lost after this operation.\n"
Index: /branches/rel_avx_2_7_5/src/library/avxvainst/libvirt_connection.c
===================================================================
--- /branches/rel_avx_2_7_5/src/library/avxvainst/libvirt_connection.c	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/library/avxvainst/libvirt_connection.c	(working copy)
@@ -23,11 +23,10 @@
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <stdio.h>
-
+#include <time.h>
 //#include "vtch/vtch.h"
 #include "vtch/vtch-host.h"
 #include "feactl/apv_feactl.h"
-
 #include "libvirt_connection.h"
 #include "va_constants.h"
 #include "va_log.h"
@@ -35,6 +34,9 @@
 #include "avxnet.h"
 #include "avx_host.h"
 
+#define MIN_REBOOT_INTERVAL 180
+#define MAX_REBOOTS_IN_MIN_REBOOT_INTERVAL 3
+
 static int is_continue;
 static pthread_t event_fd;
 static virConnectPtr conn = NULL;
@@ -378,7 +380,29 @@
                                     void *opaque)
 {
     int ret = 0;
+    int num_reboots = 0;
+    uint64_t last_reboot_time = 0;
+    uint64_t current_reboot_time = (uint64_t)time(NULL);
     const char * dom_name = virDomainGetName(dom);
+    va_instance_info_get_last_reboot_time(dom_name, &last_reboot_time);
+
+    if(current_reboot_time - last_reboot_time <= MIN_REBOOT_INTERVAL)
+    {
+        va_instance_info_get_num_reboots(dom_name, &num_reboots);
+        if (num_reboots >= MAX_REBOOTS_IN_MIN_REBOOT_INTERVAL){
+            va_log_debug("VA rebooted %d times in %ld seconds. Shutting down %s", num_reboots, last_reboot_time, dom_name);
+            ret = virDomainDestroy(dom);
+            return ret;
+        } else {
+            num_reboots++;
+            va_instance_info_set_num_reboots(dom_name, num_reboots);
+        }
+    }
+    else {
+        va_instance_info_set_last_reboot_time(dom_name, current_reboot_time);
+	va_instance_info_set_num_reboots(dom_name, 1);
+    }
+    
     va_log_debug("EVENT: Domain(%s) rebooted", dom_name);
     va_log_debug("will destroy domain(%s).", dom_name);
     ret = virDomainDestroy(dom);
Index: /branches/rel_avx_2_7_5/src/library/avxvainst/va_info.h
===================================================================
--- /branches/rel_avx_2_7_5/src/library/avxvainst/va_info.h	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/library/avxvainst/va_info.h	(working copy)
@@ -112,6 +112,8 @@
     int va_memory;
     int va_usb_cnt;
     va_usb_t va_usb_info[VA_USB_MAX];
+    uint64_t last_reboot_time;
+    int num_reboots;
 };
 
 struct va_info_resource {
@@ -231,8 +233,12 @@
 int va_instance_info_del_exdisk(const char *name, const char *disk_name);
 int va_instance_info_get_disk(const char *name, va_disk_info_t* disks);
 int va_instance_info_set_mgmttype(const char* name, const char* type);
+int va_instance_info_set_num_reboots(const char* name, int num_reboots);
+int va_instance_info_set_last_reboot_time(const char* name, uint64_t last_reboot_time);
 int va_instance_info_get_mgmttype(const char* name, char* type);
 int va_instance_info_get_mgmtmac(const char* name, mac_addr_t mac);
+int va_instance_info_get_num_reboots(const char* name, int* num_reboots);
+int va_instance_info_get_last_reboot_time(const char* name, uint64_t* last_reboot_time);
 int init_ssl_vf_info(ssl_detail_t* ssl_vfs, int ssl_cnt);
 int va_instance_info_get_sp(const char *info_file, struct va_instance_info *info);
 int va_instance_info_disk_md5_gen(const char* name);
Index: /branches/rel_avx_2_7_5/src/library/avxvainst/va_info.c
===================================================================
--- /branches/rel_avx_2_7_5/src/library/avxvainst/va_info.c	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/library/avxvainst/va_info.c	(working copy)
@@ -18,7 +18,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
-
+#include <stdint.h>
 #include <libxml/tree.h>
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
@@ -494,7 +494,14 @@
     snprintf(buff, sizeof(buff), "%d", info->va_vapv_private_license);
     xmlNewChild(root_node, NULL, BAD_CAST "privatelicense",
                     BAD_CAST buff);
+    // add last reboot time and number of reboots 
+    bzero(buff, sizeof(buff));
+    snprintf(buff, sizeof(buff), "%ld", info->last_reboot_time);
+    xmlNewChild(root_node, NULL, BAD_CAST "lastreboottime",BAD_CAST buff);
 
+    bzero(buff, sizeof(buff));
+    snprintf(buff, sizeof(buff), "%d", info->num_reboots);
+    xmlNewChild(root_node, NULL, BAD_CAST "numreboots",BAD_CAST buff);
     // dumping doc to file and release resource
     xmlSaveFormatFileEnc(info_file, doc, "UTF-8", 1);
     xmlFreeDoc(doc);
@@ -817,7 +824,21 @@
                 xmlNodeSetContent(current_node, (const xmlChar *)buff);
             }
             have_private_license_key = 1;
+        } else if (!xmlStrcmp(current_node->name, BAD_CAST "lastreboottime")) {
+            if(info->last_reboot_time > 0){
+                bzero(buff, sizeof(buff));
+                snprintf(buff, sizeof(buff), "%ld", info->last_reboot_time);
+                xmlNodeSetContent(current_node, (const xmlChar *)buff);
+            }
+        } else if (!xmlStrcmp(current_node->name, BAD_CAST "numreboots")) {
+            if(info->num_reboots >= 0){
+                bzero(buff, sizeof(buff));
+                snprintf(buff, sizeof(buff), "%d", info->num_reboots);
+                xmlNodeSetContent(current_node, (const xmlChar *)buff);
+            }
         }
+        
+ 
 
         current_node = current_node->next;
     }
@@ -850,6 +871,7 @@
 _va_instance_info_get(const char *name, struct va_instance_info *info, const char * dir)
 {
     int cnt, gcnt, tmp;
+    uint64_t long_tmp;
     char info_file[AVX_MAX_PATH_LEN + 1];
     xmlChar *v1 = NULL;
     xmlChar *v2 = NULL;
@@ -1158,8 +1180,16 @@
             v1 = xmlNodeGetContent(current_node);
             sscanf((char *)v1, "%d", &tmp);
             info->va_vapv_private_license = tmp;
-        }
+        } else if (!xmlStrcmp(current_node->name, BAD_CAST "lastreboottime")){
+            v1 = xmlNodeGetContent(current_node);
+            sscanf((char *)v1, "%ld", &long_tmp);
+            info->last_reboot_time = long_tmp;
 
+        } else if (!xmlStrcmp(current_node->name, BAD_CAST "numreboots")){
+            v1 = xmlNodeGetContent(current_node);
+            sscanf((char *)v1, "%d", &tmp);
+            info->num_reboots = tmp;
+	}
         if(v1 != NULL) {
             xmlFree(v1);
             v1 = NULL;
@@ -1213,6 +1243,43 @@
 }
 
 int
+va_instance_info_get_num_reboots(const char *name, int *num_reboots)
+{
+    struct va_instance_info *info = (struct va_instance_info *)
+                                    malloc(sizeof(struct va_instance_info));
+    if(!info) {
+        return -1;
+    }
+
+    va_instance_info_init_struct(info);
+    va_instance_info_get(name, info);
+    *num_reboots = info->num_reboots;
+
+    free(info);
+    info = NULL;
+    return 0;
+}
+
+int
+va_instance_info_get_last_reboot_time(const char *name, uint64_t *last_reboot_time)
+{
+    struct va_instance_info *info = (struct va_instance_info *)
+                                    malloc(sizeof(struct va_instance_info));
+    if(!info) {
+        return -1;
+    }
+
+    va_instance_info_init_struct(info);
+    va_instance_info_get(name, info);
+    *last_reboot_time = info->last_reboot_time;
+
+    free(info);
+    info = NULL;
+    return 0;
+}
+
+
+int
 va_instance_info_set_vsites(const char *name, int vs)
 {
     struct va_instance_info *info = (struct va_instance_info *)
@@ -1478,6 +1545,46 @@
 }
 
 int
+va_instance_info_set_num_reboots(const char *name, int num_reboots)
+{
+    struct va_instance_info *info = (struct va_instance_info *)
+                                    malloc(sizeof(struct va_instance_info));
+    if(!info) {
+        return -1;
+    }
+
+    va_instance_info_init_struct(info);
+
+    strcpy(info->va_inst_name, name);
+    info->num_reboots = num_reboots;
+    va_instance_info_update(info);
+
+    free(info);
+    info = NULL;
+    return 0;
+}
+
+int
+va_instance_info_set_last_reboot_time(const char *name, uint64_t last_reboot_time)
+{
+    struct va_instance_info *info = (struct va_instance_info *)
+                                    malloc(sizeof(struct va_instance_info));
+    if(!info) {
+        return -1;
+    }
+
+    va_instance_info_init_struct(info);
+
+    strcpy(info->va_inst_name, name);
+    info->last_reboot_time = last_reboot_time;
+    va_instance_info_update(info);
+
+    free(info);
+    info = NULL;
+    return 0;
+}
+
+int
 va_instance_info_get_vatype(const char *name, int *type)
 {
     struct va_instance_info *tinfo = (struct va_instance_info *) 
@@ -1568,7 +1675,6 @@
     va_instance_info_init_struct(tinfo);
     strcpy(tinfo->va_inst_name, name);
     tinfo->va_inst_status = status;
-
     va_instance_info_update(tinfo);
 
     free(tinfo);
@@ -1601,6 +1707,8 @@
     info->va_inst_vncport = -1;
     info->va_inst_redefine = 0;
     info->va_memory = -1;
+    info->last_reboot_time = 0;
+    info->num_reboots = -1;
     for(i = 0; i < VA_MAX_NICS_VFS; i++) {
         ((info->va_inst_io_vf_arr[i]).pfname)[0] = '\0';
         (info->va_inst_io_vf_arr[i]).vfidx = -1;
Index: /branches/rel_avx_2_7_5/src/library/ca_util/ca_util.h
===================================================================
--- /branches/rel_avx_2_7_5/src/library/ca_util/ca_util.h	(revision 9183)
+++ /branches/rel_avx_2_7_5/src/library/ca_util/ca_util.h	(working copy)
@@ -100,6 +100,7 @@
 #define min(a,b) ((a) > (b) ? (b) : (a))
 
 #define TIMESTAMP_LEN 15
+#define AVXD_INIT_FINISHED "/var/crash/avxd_init"
 
 /*define some print debug macros*/
 #define PLINE \
