]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
pakfire: Create a ramdisk if no path has been given
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Sep 2023 17:42:30 +0000 (17:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Sep 2023 17:42:30 +0000 (17:42 +0000)
This might be more useful when we struggle to cleanup the build
environment due to large IO. The build environment should generally be
small enough to easily fit into memory.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/mount.h
src/libpakfire/mount.c
src/libpakfire/pakfire.c

index 893053911d14aae9d4e2f5b99a629a155c143663..b3b14fbb832eebc9230c2f4b10a04489d9b288ed 100644 (file)
@@ -29,6 +29,8 @@ int pakfire_mount_change_propagation(struct pakfire* pakfire, int propagation, c
 
 int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path);
 
+int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args);
+
 int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags);
 
 int pakfire_mount_list(struct pakfire* pakfire);
index fc7781f6fbe784673dd3ad9263cbc45597bcf48f..21238e1be2206dd85384d0fcd2a816fda16030b4 100644 (file)
@@ -436,6 +436,26 @@ int pakfire_mount_all(struct pakfire* pakfire, int flags) {
        return 0;
 }
 
+int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args) {
+       int r;
+
+       // Create a new temporary directory
+       char* p = pakfire_mkdtemp(path);
+       if (!p)
+               return -errno;
+
+       // Mount the ramdisk
+       r = pakfire_mount(pakfire, "pakfire_ramdisk", p, "tmpfs", 0, args);
+       if (r) {
+               ERROR_ERRNO(pakfire, r, "Could not mount ramdisk at %s (%s): %m\n", p, args);
+               return r;
+       }
+
+       DEBUG(pakfire, "Ramdisk mounted at %s (%s)\n", p, args);
+
+       return 0;
+}
+
 int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
        struct stat st;
        char mountpoint[PATH_MAX];
index 90683b62f792c09483993e55733c8ae29f3da9ff..e1c837b8b9066980f92dd9d89ce5b22a4bc33f37 100644 (file)
@@ -413,6 +413,11 @@ static void pakfire_free(struct pakfire* pakfire) {
        if (pakfire->destroy_on_free && *pakfire->path) {
                DEBUG(pakfire, "Destroying %s\n", pakfire->path);
 
+               // Umount the ramdisk
+               r = umount2(pakfire->path, MNT_DETACH);
+               if (r)
+                       ERROR(pakfire, "Could not umount ramdisk at %s: %m\n", pakfire->path);
+
                // Destroy the temporary directory
                pakfire_rmtree(pakfire->path, 0);
        }
@@ -908,13 +913,14 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, const char* path,
                goto ERROR;
        }
 
-       // Generate a random path if none is set
+       // Create a ramdisk if no path was given
        if (!path) {
-               path = pakfire_mkdtemp(tempdir);
-               if (!path) {
-                       r = -errno;
+               r = pakfire_make_ramdisk(p, tempdir, NULL);
+               if (r)
                        goto ERROR;
-               }
+
+               // Use the ramdisk as path
+               path = tempdir;
 
                // Destroy everything when done
                p->destroy_on_free = 1;