From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 6F23E1FF180 for ; Fri, 1 Aug 2025 10:33:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3463313035; Fri, 1 Aug 2025 10:34:54 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Fri, 1 Aug 2025 10:34:15 +0200 Message-ID: <20250801083415.64421-1-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754037246241 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.981 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_MAILER 2 Automated Mailer Tag Left in Email RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH cluster] pmxcfs: status: create subdirs in /var/lib/rrdcached/db when needed X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- 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