Merge pull request #3150 from rpv-tomsk/libvirt-3
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Mon, 13 May 2019 11:41:33 +0000 (13:41 +0200)
committerGitHub <noreply@github.com>
Mon, 13 May 2019 11:41:33 +0000 (13:41 +0200)
virt plugin: Added new code of virDomainShutoffReason enum and domain events

1  2 
src/virt.c

diff --combined src/virt.c
  #define HAVE_DOM_REASON_POSTCOPY 1
  #endif
  
+ #if LIBVIR_CHECK_VERSION(4, 10, 0)
+ #define HAVE_DOM_REASON_SHUTOFF_DAEMON 1
+ #endif
  #endif /* LIBVIR_CHECK_VERSION */
  
  /* structure used for aggregating notification-thread data*/
@@@ -300,6 -303,16 +303,16 @@@ static int map_domain_event_detail_to_r
      switch (detail) {
      case VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED: /* Guest finished shutdown
                                                  sequence */
+ #ifdef LIBVIR_CHECK_VERSION
+ #if LIBVIR_CHECK_VERSION(3, 4, 0)
+     case VIR_DOMAIN_EVENT_SHUTDOWN_GUEST: /* Domain finished shutting down after
+                                              request from the guest itself (e.g.
+                                              hardware-specific action) */
+     case VIR_DOMAIN_EVENT_SHUTDOWN_HOST:  /* Domain finished shutting down after
+                                              request from the host (e.g. killed
+                                              by a signal) */
+ #endif
+ #endif
        ret = VIR_DOMAIN_SHUTDOWN_USER;
        break;
      default:
@@@ -425,6 -438,10 +438,10 @@@ const char *domain_reasons[][DOMAIN_STA
              "domain failed to start",
          [VIR_DOMAIN_SHUTOFF][VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT] =
              "restored from a snapshot which was taken while domain was shutoff",
+ #ifdef HAVE_DOM_REASON_SHUTOFF_DAEMON
+         [VIR_DOMAIN_SHUTOFF][VIR_DOMAIN_SHUTOFF_DAEMON] =
+             "daemon decides to kill domain during reconnection processing",
+ #endif
  
          [VIR_DOMAIN_CRASHED][VIR_DOMAIN_CRASHED_UNKNOWN] =
              "the reason is unknown",
@@@ -635,8 -652,6 +652,8 @@@ static enum if_field interface_format 
  static time_t last_refresh = (time_t)0;
  
  static int refresh_lists(struct lv_read_instance *inst);
 +static int register_event_impl(void);
 +static int start_event_loop(virt_notif_thread_t *thread_data);
  
  struct lv_block_stats {
    virDomainBlockStatsStruct bi;
@@@ -918,10 -933,10 +935,10 @@@ static void memory_submit(virDomainPtr 
  
  static void memory_stats_submit(gauge_t value, virDomainPtr dom,
                                  int tag_index) {
 -  static const char *tags[] = {"swap_in",        "swap_out", "major_fault",
 -                               "minor_fault",    "unused",   "available",
 -                               "actual_balloon", "rss",      "usable",
 -                               "last_update"};
 +  static const char *tags[] = {"swap_in",        "swap_out",   "major_fault",
 +                               "minor_fault",    "unused",     "available",
 +                               "actual_balloon", "rss",        "usable",
 +                               "last_update",    "disk_caches"};
  
    if ((tag_index < 0) || (tag_index >= (int)STATIC_ARRAY_SIZE(tags))) {
      ERROR("virt plugin: Array index out of bounds: tag_index = %d", tag_index);
@@@ -1443,11 -1458,6 +1460,11 @@@ static int lv_config(oconfig_item_t *ci
  
  static int lv_connect(void) {
    if (conn == NULL) {
 +    /* event implementation must be registered before connection is opened */
 +    if (!persistent_notification)
 +      if (register_event_impl() != 0)
 +        return -1;
 +
  /* `conn_string == NULL' is acceptable */
  #ifdef HAVE_FS_INFO
      /* virDomainGetFSInfo requires full read-write access connection */
      int status = virNodeGetInfo(conn, &nodeinfo);
      if (status != 0) {
        ERROR(PLUGIN_NAME " plugin: virNodeGetInfo failed");
 +      virConnectClose(conn);
 +      conn = NULL;
        return -1;
      }
 +
 +    if (!persistent_notification)
 +      if (start_event_loop(&notif_thread) != 0) {
 +        virConnectClose(conn);
 +        conn = NULL;
 +        return -1;
 +      }
    }
    c_release(LOG_NOTICE, &conn_complain,
              PLUGIN_NAME " plugin: Connection established.");
@@@ -2107,9 -2108,10 +2124,9 @@@ static void *event_loop_worker(void *ar
  }
  
  static int virt_notif_thread_init(virt_notif_thread_t *thread_data) {
 -  int ret;
 -
    assert(thread_data != NULL);
 -  ret = pthread_mutex_init(&thread_data->active_mutex, NULL);
 +
 +  int ret = pthread_mutex_init(&thread_data->active_mutex, NULL);
    if (ret != 0) {
      ERROR(PLUGIN_NAME " plugin: Failed to initialize mutex, err %u", ret);
      return ret;
@@@ -2245,26 -2247,33 +2262,26 @@@ static int persistent_domains_state_not
  }
  
  static int lv_read(user_data_t *ud) {
 -  time_t t;
 -  struct lv_read_instance *inst = NULL;
 -  struct lv_read_state *state = NULL;
 -
    if (ud->data == NULL) {
      ERROR(PLUGIN_NAME " plugin: NULL userdata");
      return -1;
    }
  
 -  inst = ud->data;
 -  state = &inst->read_state;
 -
 -  bool reconnect = conn == NULL ? true : false;
 -  /* event implementation must be registered before connection is opened */
 -  if (inst->id == 0) {
 -    if (!persistent_notification && reconnect)
 -      if (register_event_impl() != 0)
 -        return -1;
 +  struct lv_read_instance *inst = ud->data;
 +  struct lv_read_state *state = &inst->read_state;
  
 +  if (inst->id == 0)
      if (lv_connect() < 0)
        return -1;
  
 -    if (!persistent_notification && reconnect && conn != NULL)
 -      if (start_event_loop(&notif_thread) != 0)
 -        return -1;
 +  /* Wait until inst#0 establish connection */
 +  if (conn == NULL) {
 +    DEBUG(PLUGIN_NAME " plugin#%s: Wait until inst#0 establish connection",
 +          inst->tag);
 +    return 0;
    }
  
 +  time_t t;
    time(&t);
  
    /* Need to refresh domain or device lists? */
@@@ -2385,11 -2394,19 +2402,11 @@@ static int lv_init(void) 
    if (lv_init_ignorelists() != 0)
      return -1;
  
 -  /* event implementation must be registered before connection is opened */
    if (!persistent_notification)
 -    if (register_event_impl() != 0)
 +    if (virt_notif_thread_init(&notif_thread) != 0)
        return -1;
  
 -  if (lv_connect() != 0)
 -    return -1;
 -
 -  if (!persistent_notification) {
 -    virt_notif_thread_init(&notif_thread);
 -    if (start_event_loop(&notif_thread) != 0)
 -      return -1;
 -  }
 +  lv_connect();
  
    DEBUG(PLUGIN_NAME " plugin: starting %i instances", nr_instances);