From: Michael Tremer Date: Tue, 12 Sep 2023 17:42:30 +0000 (+0000) Subject: pakfire: Create a ramdisk if no path has been given X-Git-Tag: 0.9.29~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=06d741c659f365cce87c2023d436ec87b6eac30f;p=pakfire.git pakfire: Create a ramdisk if no path has been given 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 --- diff --git a/src/libpakfire/include/pakfire/mount.h b/src/libpakfire/include/pakfire/mount.h index 893053911..b3b14fbb8 100644 --- a/src/libpakfire/include/pakfire/mount.h +++ b/src/libpakfire/include/pakfire/mount.h @@ -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); diff --git a/src/libpakfire/mount.c b/src/libpakfire/mount.c index fc7781f6f..21238e1be 100644 --- a/src/libpakfire/mount.c +++ b/src/libpakfire/mount.c @@ -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]; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 90683b62f..e1c837b8b 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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;