From 6e73d5c2d69592d27bf391334dc851dcec5fd519 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 3 Aug 2015 06:27:01 +0200 Subject: [PATCH] use simple files for LXC configuration --- data/PVE/Cluster.pm | 8 +---- data/src/memdb.c | 82 ++++++--------------------------------------- data/src/status.c | 12 ------- 3 files changed, 12 insertions(+), 90 deletions(-) diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm index 27b2dd9..043b4f1 100644 --- a/data/PVE/Cluster.pm +++ b/data/PVE/Cluster.pm @@ -792,18 +792,12 @@ sub cfs_file_version { my $version; my $infotag; - if ($filename =~ m!^nodes/[^/]+/(openvz|qemu-server)/(\d+)\.conf$!) { + if ($filename =~ m!^nodes/[^/]+/(openvz|lxc|qemu-server)/(\d+)\.conf$!) { my ($type, $vmid) = ($1, $2); if ($vmlist && $vmlist->{ids} && $vmlist->{ids}->{$vmid}) { $version = $vmlist->{ids}->{$vmid}->{version}; } $infotag = "/$type/"; - } elsif ($filename =~ m!^nodes/[^/]+/lxc/(\d+)/config$!) { - my $vmid = $1; - if ($vmlist && $vmlist->{ids} && $vmlist->{ids}->{$vmid}) { - $version = $vmlist->{ids}->{$vmid}->{version}; - } - $infotag = "/lxc/"; } else { $infotag = $filename; $version = $versions->{$filename}; diff --git a/data/src/memdb.c b/data/src/memdb.c index 0a65db3..af20e05 100644 --- a/data/src/memdb.c +++ b/data/src/memdb.c @@ -222,26 +222,6 @@ name_is_vm_config( return TRUE; } -static gboolean -name_is_vm_config_dir( - const char *name, - guint32 *vmid_ret) -{ - if (!name || name[0] < '1' || name[0] > '9') - return FALSE; - - char *end = NULL; - guint32 vmid = strtoul(name, &end, 10); - - if (!end || end[0] != 0) - return FALSE; - - if (vmid_ret) - *vmid_ret = vmid; - - return TRUE; -} - static gboolean valid_nodename( const char *nodename) @@ -318,19 +298,8 @@ path_contain_vm_config( split_path(path, &dirname, &base); - if ((nodename = dir_contain_vm_config(dirname, vmtype_ret))) { - if (*vmtype_ret == VMTYPE_LXC) { - if (!name_is_vm_config_dir(base, vmid_ret)) { - g_free(nodename); - nodename = NULL; - } - } else { - if (!name_is_vm_config(base, vmid_ret)) { - g_free(nodename); - nodename = NULL; - } - } - } + if (name_is_vm_config(base, vmid_ret)) + nodename = dir_contain_vm_config(dirname, vmtype_ret); if (dirname) g_free (dirname); if (base) g_free (base); @@ -364,28 +333,15 @@ vmlist_add_dir( memdb_tree_entry_t *node_te = (memdb_tree_entry_t *)value; - if (vmtype == VMTYPE_LXC) { - if (node_te->type != DT_DIR) - continue; - - guint32 vmid = 0; - if (!name_is_vm_config_dir(node_te->name, &vmid)) - continue; - - if (!vmlist_hash_insert_vm(vmlist, vmtype, vmid, nodename, FALSE)) - ret = FALSE; - - } else { - if (node_te->type != DT_REG) - continue; + if (node_te->type != DT_REG) + continue; - guint32 vmid = 0; - if (!name_is_vm_config(node_te->name, &vmid)) - continue; + guint32 vmid = 0; + if (!name_is_vm_config(node_te->name, &vmid)) + continue; - if (!vmlist_hash_insert_vm(vmlist, vmtype, vmid, nodename, FALSE)) - ret = FALSE; - } + if (!vmlist_hash_insert_vm(vmlist, vmtype, vmid, nodename, FALSE)) + ret = FALSE; } return ret; @@ -619,7 +575,6 @@ int memdb_mkdir( char *dirname = NULL; char *base = NULL; - char *nodename = NULL; g_mutex_lock (&memdb->mutex); @@ -650,17 +605,6 @@ int memdb_mkdir( goto ret; } - guint32 vmid = 0; - int vmtype = 0; - - if ((nodename = path_contain_vm_config(path, &vmtype, &vmid))) { - if (vmlist_different_vm_exists(vmtype, vmid, nodename)) { - ret = -EEXIST; - goto ret; - } - } - - memdb_tree_entry_t *te; if ((te = memdb_lookup_dir_entry(memdb, base, parent))) { ret = -EEXIST; @@ -699,15 +643,11 @@ int memdb_mkdir( } } - if (nodename) - vmlist_register_vm(vmtype, vmid, nodename); - ret = 0; ret: g_mutex_unlock (&memdb->mutex); - if (nodename) g_free (nodename); if (dirname) g_free (dirname); if (base) g_free (base); @@ -1199,12 +1139,12 @@ memdb_rename( from_node = path_contain_vm_config(from, &from_vmtype, &from_vmid); - if ((nodename = path_contain_vm_config(to, &vmtype, &vmid))) { + if (from_te->type == DT_REG && (nodename = path_contain_vm_config(to, &vmtype, &vmid))) { if (vmlist_different_vm_exists(vmtype, vmid, nodename)) { if (!(from_node && vmid == from_vmid)) { ret = -EEXIST; goto ret; - } + } } } diff --git a/data/src/status.c b/data/src/status.c index 97c97d7..a7a495c 100644 --- a/data/src/status.c +++ b/data/src/status.c @@ -762,18 +762,6 @@ record_memdb_change(const char *path) memdb_change_t *ce; - unsigned int vmid = 0; - char nodename[256]; - char rest[4096]; - if (cfs_status.vmlist && - sscanf(path, "nodes/%255[^/]/lxc/%u/%4095s", nodename, &vmid, rest) == 3) { - vminfo_t *vminfo = (vminfo_t *)g_hash_table_lookup(cfs_status.vmlist, &vmid); - if (vminfo && (vminfo->vmtype == VMTYPE_LXC && strcmp(vminfo->nodename, nodename) == 0)) { - cfs_status.vmlist_version++; - vminfo->version = ++vminfo_version_counter; - } - } - if ((ce = (memdb_change_t *)g_hash_table_lookup(cfs_status.memdb_changes, path))) { ce->version++; } -- 2.39.5