From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH cluster] pmxcfs: status: create subdirs in /var/lib/rrdcached/db when needed
Date: Fri, 1 Aug 2025 10:34:15 +0200 [thread overview]
Message-ID: <20250801083415.64421-1-l.wagner@proxmox.com> (raw)
Storage metrics and node metrics use a nested directory structure, e.g.:
pve-storage-9.0
somenode
local
local-lvm
The second level ('somenode') was not created correctly, leading to
errors when trying to update the RRD database.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
src/pmxcfs/status.c | 39 +++++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/pmxcfs/status.c b/src/pmxcfs/status.c
index b086896..a00e793 100644
--- a/src/pmxcfs/status.c
+++ b/src/pmxcfs/status.c
@@ -1301,6 +1301,12 @@ static inline const char *rrd_skip_data(const char *data, int count, char separa
return data;
}
+static inline void checked_mkdir(char* path, int mode) {
+ if (!mkdir(path, mode) && errno != EEXIST) {
+ cfs_message("could not create directory %s: %s", path, strerror(errno));
+ };
+}
+
// The key and subdirectory format used up until PVE8 is 'pve{version}-{type}/{id}' with version
// being 2 or 2.3 for VMs. Starting with PVE9 'pve-{type}-{version}/{id}'. Newer versions are only
// allowed to append new columns to the data! Otherwise this would be a breaking change.
@@ -1379,15 +1385,19 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
g_free(filename);
filename = g_strdup_printf("%s", filename_pve2);
+ char *dir = g_path_get_dirname(filename);
+ checked_mkdir(dir, 0755);
+ g_free(dir);
+
int argcount = sizeof(rrd_def_node) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_node);
} else {
// no dir exists yet, use new pve-node-9.0
- const char *path = RRDDIR "/pve-node-9.0";
+ checked_mkdir(RRDDIR "/pve-node-9.0", 0755);
- if (!mkdir(path, 0755)) {
- cfs_message("could not create directory %s: %s", path, strerror(errno));
- }
+ char *dir = g_path_get_dirname(filename);
+ checked_mkdir(dir, 0755);
+ g_free(dir);
int argcount = sizeof(rrd_def_node_pve9_0) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_node_pve9_0);
@@ -1455,10 +1465,7 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
create_rrd_file(filename, argcount, rrd_def_vm);
} else {
// no dir exists yet, use new pve-vm-9.0
- const char *path = RRDDIR "/pve-vm-9.0";
- if (!mkdir(path, 0755)) {
- cfs_message("could not create directory %s: %s", path, strerror(errno));
- };
+ checked_mkdir(RRDDIR "/pve-vm-9.0", 0755);
int argcount = sizeof(rrd_def_vm_pve9_0) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_vm_pve9_0);
@@ -1515,6 +1522,9 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
char *dir_pve90 = g_strdup_printf(RRDDIR "/pve-storage-9.0");
if (g_file_test(dir_pve90, G_FILE_TEST_IS_DIR)) {
+ char *dir = g_path_get_dirname(filename);
+ checked_mkdir(dir, 0755);
+ g_free(dir);
int argcount = sizeof(rrd_def_storage_pve9_0) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_storage_pve9_0);
@@ -1522,14 +1532,19 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
g_free(filename);
filename = g_strdup_printf("%s", filename_pve2);
+ char *dir = g_path_get_dirname(filename);
+ checked_mkdir(dir, 0755);
+ g_free(dir);
+
int argcount = sizeof(rrd_def_storage) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_storage);
} else {
// no dir exists yet, use new pve-storage-9.0
- const char *path = RRDDIR "/pve-storage-9.0";
- if (!mkdir(path, 0755)) {
- cfs_message("could not create directory %s: %s", path, strerror(errno));
- }
+ checked_mkdir(RRDDIR "/pve-storage-9.0", 0755);
+
+ char *dir = g_path_get_dirname(filename);
+ checked_mkdir(dir, 0755);
+ g_free(dir);
int argcount = sizeof(rrd_def_storage_pve9_0) / sizeof(void *) - 1;
create_rrd_file(filename, argcount, rrd_def_storage_pve9_0);
--
2.47.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next reply other threads:[~2025-08-01 8:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 8:34 Lukas Wagner [this message]
2025-08-01 8:50 ` [pve-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250801083415.64421-1-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.