summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2022-09-14 09:13:58 -0500
committerDavid Teigland <teigland@redhat.com>2022-09-14 14:19:29 -0500
commit0887896847807e159a70edc5ac92a4030c13923a (patch)
tree9d84b79ae450559d83b51d2ce9fdfeadd3ee58a9 /lib
parenta2d33cdfc516d946d390645cc694e745008b6fc0 (diff)
downloadlvm2-0887896847807e159a70edc5ac92a4030c13923a.tar.gz
vgremove: remove online files in run dir
These files are automatically cleared on reboot given that /run is tmpfs, and that remains the primary way of clearing online files. But, if there's extreme use of vgcreate+pvscan+vgremove between reboots, then removing online files in vgremove will limit the number of unused online files using space in /run.
Diffstat (limited to 'lib')
-rw-r--r--lib/device/online.c56
-rw-r--r--lib/device/online.h2
2 files changed, 58 insertions, 0 deletions
diff --git a/lib/device/online.c b/lib/device/online.c
index 79652d990..7ffe14b18 100644
--- a/lib/device/online.c
+++ b/lib/device/online.c
@@ -17,6 +17,7 @@
#include "lib/commands/toolcontext.h"
#include "lib/device/device.h"
#include "lib/device/online.h"
+#include "lib/metadata/metadata.h"
#include <dirent.h>
@@ -504,3 +505,58 @@ do_lookup:
if ((rv < 0) && stat(PVS_LOOKUP_DIR, &st))
log_error_pvscan(cmd, "Failed to create %s %d", PVS_LOOKUP_DIR, errno);
}
+
+void online_lookup_file_remove(const char *vgname)
+{
+ char path[PATH_MAX];
+
+ if (dm_snprintf(path, sizeof(path), "%s/%s", PVS_LOOKUP_DIR, vgname) < 0) {
+ log_error("Path %s/%s is too long.", PVS_LOOKUP_DIR, vgname);
+ return;
+ }
+
+ log_debug("Unlink pvs_lookup: %s", path);
+
+ if (unlink(path) && (errno != ENOENT))
+ log_sys_debug("unlink", path);
+}
+
+static int _online_pvid_file_remove(char *pvid)
+{
+ char path[PATH_MAX];
+
+ if (dm_snprintf(path, sizeof(path), "%s/%s", PVS_ONLINE_DIR, pvid) < 0)
+ return_0;
+ if (!unlink(path))
+ return 1;
+ return 0;
+}
+
+/*
+ * Reboot automatically clearing tmpfs on /run is the main method of removing
+ * online files. It's important to note that removing the online files for a
+ * VG is not a technical requirement for anything and could easily be skipped
+ * if it had any downside. It's only done to clean up the space used in /run
+ * by the online files, e.g. if there happens to be an extreme amount of
+ * vgcreate/pvscan/vgremove between reboots that are leaving a large number of
+ * useless online files consuming tmpfs space.
+ */
+void online_vgremove(struct volume_group *vg)
+{
+ char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };
+ struct pv_list *pvl;
+
+ /*
+ * online files may not exist for the vg if there has been no
+ * pvscans or autoactivation.
+ */
+
+ online_vg_file_remove(vg->name);
+ online_lookup_file_remove(vg->name);
+
+ dm_list_iterate_items(pvl, &vg->pvs) {
+ memcpy(pvid, &pvl->pv->id.uuid, ID_LEN);
+ _online_pvid_file_remove(pvid);
+ }
+}
+
diff --git a/lib/device/online.h b/lib/device/online.h
index 850b03db8..488129e3f 100644
--- a/lib/device/online.h
+++ b/lib/device/online.h
@@ -54,5 +54,7 @@ void online_dir_setup(struct cmd_context *cmd);
int get_pvs_online(struct dm_list *pvs_online, const char *vgname);
int get_pvs_lookup(struct dm_list *pvs_online, const char *vgname);
void free_po_list(struct dm_list *list);
+void online_lookup_file_remove(const char *vgname);
+void online_vgremove(struct volume_group *vg);
#endif