]> git.proxmox.com Git - pve-cluster.git/blobdiff - data/src/status.c
add nodes/hardware-map.conf
[pve-cluster.git] / data / src / status.c
index 656cf71db8cb86a9769f3b3c494f612ac0c9589f..f46f71d13b6ead08a25ef25f0ac330837e197df3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2010 Proxmox Server Solutions GmbH
+  Copyright (C) 2010 - 2020 Proxmox Server Solutions GmbH
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
@@ -83,9 +83,13 @@ static memdb_change_t memdb_change_array[] = {
        { .path = "user.cfg" },
        { .path = "domains.cfg" },
        { .path = "priv/shadow.cfg" },
+       { .path = "priv/acme/plugins.cfg" },
        { .path = "priv/tfa.cfg" },
+       { .path = "priv/token.cfg" },
+       { .path = "priv/ipam.db" },
        { .path = "datacenter.cfg" },
        { .path = "vzdump.cron" },
+       { .path = "jobs.cfg" },
        { .path = "ha/crm_commands" },
        { .path = "ha/manager_status" },
        { .path = "ha/resources.cfg" },
@@ -94,8 +98,15 @@ static memdb_change_t memdb_change_array[] = {
        { .path = "status.cfg" },
        { .path = "replication.cfg" },
        { .path = "ceph.conf" },
-       { .path = "sdn.cfg" },
-       { .path = "sdn.cfg.new" },
+       { .path = "sdn/vnets.cfg" },
+       { .path = "sdn/zones.cfg" },
+       { .path = "sdn/controllers.cfg" },
+       { .path = "sdn/subnets.cfg" },
+       { .path = "sdn/ipams.cfg" },
+       { .path = "sdn/dns.cfg" },
+       { .path = "sdn/.running-config" },
+       { .path = "virtual-guest/cpu-models.conf" },
+       { .path = "nodes/hardware-map.conf" },
 };
 
 static GMutex mutex;
@@ -168,6 +179,7 @@ static const char *vminfo_type_to_string(vminfo_t *vminfo)
        if (vminfo->vmtype == VMTYPE_QEMU) {
                return "qemu";
        } else if (vminfo->vmtype == VMTYPE_OPENVZ) {
+               // FIXME: remove openvz stuff for 7.x
                return "openvz";
        } else if (vminfo->vmtype == VMTYPE_LXC) {
                return "lxc";
@@ -627,6 +639,7 @@ vmlist_hash_insert_vm(
        g_return_val_if_fail(vmlist != NULL, FALSE);
        g_return_val_if_fail(nodename != NULL, FALSE);
        g_return_val_if_fail(vmid != 0, FALSE);
+       // FIXME: remove openvz stuff for 7.x
        g_return_val_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ ||
                             vmtype == VMTYPE_LXC, FALSE);
 
@@ -657,6 +670,7 @@ vmlist_register_vm(
        g_return_if_fail(cfs_status.vmlist != NULL);
        g_return_if_fail(nodename != NULL);
        g_return_if_fail(vmid != 0);
+       // FIXME: remove openvz stuff for 7.x
        g_return_if_fail(vmtype == VMTYPE_QEMU || vmtype == VMTYPE_OPENVZ ||
                         vmtype == VMTYPE_LXC);
 
@@ -801,15 +815,22 @@ cfs_create_vmlist_msg(GString *str)
 // currently we only look at the current configuration in place, i.e., *no*
 // snapshort and *no* pending changes
 static char *
-_get_property_value(char *conf, const char *prop, int prop_len)
+_get_property_value(char *conf, int conf_size, const char *prop, int prop_len)
 {
-       char *line = NULL, *temp = NULL;
+       const char *const conf_end = conf + conf_size;
+       char *line = conf;
+       size_t remaining_size;
+
+       char *next_newline = memchr(conf, '\n', conf_size);
+       if (next_newline == NULL) {
+               return NULL; // valid property lines end with \n, but none in the config
+       }
+       *next_newline = '\0';
 
-       line = strtok_r(conf, "\n", &temp);
        while (line != NULL) {
                if (!line[0]) goto next;
 
-               // snapshot or pending section start and nothing found yet
+               // snapshot or pending section start, but nothing found yet -> not found
                if (line[0] == '[') return NULL;
                // properties start with /^[a-z]/, so continue early if not
                if (line[0] < 'a' || line[0] > 'z') goto next;
@@ -832,7 +853,16 @@ _get_property_value(char *conf, const char *prop, int prop_len)
                        return v_start;
                }
 next:
-               line = strtok_r(NULL, "\n", &temp);
+               line = next_newline + 1;
+               remaining_size = conf_end - line;
+               if (remaining_size <= prop_len) {
+                       return NULL;
+               }
+               next_newline = memchr(line, '\n', remaining_size);
+               if (next_newline == NULL) {
+                       return NULL; // valid property lines end with \n, but none in the config
+               }
+               *next_newline = '\0';
        }
 
        return NULL; // not found
@@ -863,6 +893,9 @@ cfs_create_guest_conf_property_msg(GString *str, memdb_t *memdb, const char *pro
        int res = 0;
        GString *path = NULL;
 
+       // Prelock &memdb->mutex in order to enable the usage of memdb_read_nolock
+       // to prevent Deadlocks as in #2553
+       g_mutex_lock (&memdb->mutex);
        g_mutex_lock (&mutex);
 
        g_string_printf(str,"{\n");
@@ -873,18 +906,23 @@ cfs_create_guest_conf_property_msg(GString *str, memdb_t *memdb, const char *pro
                goto ret;
        }
 
-       path = g_string_sized_new(256);
+       if ((path = g_string_sized_new(256)) == NULL) {
+               res = -ENOMEM;
+               goto ret;
+       }
+
        if (vmid >= 100) {
                vminfo_t *vminfo = (vminfo_t *) g_hash_table_lookup(cfs_status.vmlist, &vmid);
                if (vminfo == NULL) goto enoent;
 
                if (!vminfo_to_path(vminfo, path)) goto err;
 
-               int size = memdb_read(memdb, path->str, &tmp);
+               // use memdb_read_nolock because lock is handled here
+               int size = memdb_read_nolock(memdb, path->str, &tmp);
                if (tmp == NULL) goto err;
                if (size <= prop_len) goto ret;
 
-               char *val = _get_property_value(tmp, prop, prop_len);
+               char *val = _get_property_value(tmp, size, prop, prop_len);
                if (val == NULL) goto ret;
 
                g_string_append_printf(str, "\"%u\":{", vmid);
@@ -904,10 +942,11 @@ cfs_create_guest_conf_property_msg(GString *str, memdb_t *memdb, const char *pro
 
                        g_free(tmp); // no-op if already null
                        tmp = NULL;
-                       int size = memdb_read(memdb, path->str, &tmp);
+                       // use memdb_read_nolock because lock is handled here
+                       int size = memdb_read_nolock(memdb, path->str, &tmp);
                        if (tmp == NULL || size <= prop_len) continue;
 
-                       char *val = _get_property_value(tmp, prop, prop_len);
+                       char *val = _get_property_value(tmp, size, prop, prop_len);
                        if (val == NULL) continue;
 
                        if (!first) g_string_append_printf(str, ",\n");
@@ -925,7 +964,7 @@ ret:
        }
        g_string_append_printf(str,"\n}\n");
        g_mutex_unlock (&mutex);
-
+       g_mutex_unlock (&memdb->mutex);
        return res;
 err:
        res = -EIO;