From 6343c3a8b967abd23c9f858341a5d46afab0f36a Mon Sep 17 00:00:00 2001 From: Rui Salvaterra Date: Mon, 29 Jun 2020 11:24:35 +0100 Subject: [PATCH] procd: completely remove tmp-on-zram support The configuration settings were removed from the package, this is now dead code. Signed-off-by: Rui Salvaterra --- CMakeLists.txt | 7 +-- initd/early.c | 12 ++--- initd/init.h | 7 --- initd/zram.c | 137 ------------------------------------------------- 4 files changed, 5 insertions(+), 158 deletions(-) delete mode 100644 initd/zram.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 36599f0..488c555 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,11 +42,6 @@ IF(EARLY_PATH) ADD_DEFINITIONS(-DEARLY_PATH="${EARLY_PATH}") ENDIF() -IF(ZRAM_TMPFS) - ADD_DEFINITIONS(-DZRAM_TMPFS) - SET(SOURCES_ZRAM initd/zram.c) -ENDIF() - IF(SELINUX) include(FindPkgConfig) pkg_search_module(SELINUX REQUIRED libselinux) @@ -68,7 +63,7 @@ IF(DISABLE_INIT) ADD_DEFINITIONS(-DDISABLE_INIT) ELSE() ADD_EXECUTABLE(init initd/init.c initd/early.c initd/preinit.c initd/mkdev.c sysupgrade.c watchdog.c - utils/utils.c ${SOURCES_ZRAM}) + utils/utils.c) TARGET_INCLUDE_DIRECTORIES(init PUBLIC ${SELINUX_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(init ${LIBS} ${SELINUX_LIBRARIES}) INSTALL(TARGETS init diff --git a/initd/early.c b/initd/early.c index 4b7e61c..4857525 100644 --- a/initd/early.c +++ b/initd/early.c @@ -70,14 +70,10 @@ early_mounts(void) } early_console("/dev/console"); - if (mount_zram_on_tmp()) { - mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, "mode=01777"); - mkdir("/tmp/shm", 01777); - } else { - mkdir("/tmp/shm", 01777); - mount("tmpfs", "/tmp/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, - "mode=01777"); - } + + mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOATIME, "mode=01777"); + mkdir("/tmp/shm", 01777); + mkdir("/tmp/run", 0755); mkdir("/tmp/lock", 0755); mkdir("/tmp/state", 0755); diff --git a/initd/init.h b/initd/init.h index 123e114..dcf9d30 100644 --- a/initd/init.h +++ b/initd/init.h @@ -26,11 +26,4 @@ void preinit(void); void early(void); int mkdev(const char *progname, int progmode); -#ifdef ZRAM_TMPFS -int mount_zram_on_tmp(void); -#else -static inline int mount_zram_on_tmp(void) { - return -ENOSYS; -} -#endif #endif diff --git a/initd/zram.c b/initd/zram.c deleted file mode 100644 index 380fe0e..0000000 --- a/initd/zram.c +++ /dev/null @@ -1,137 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "../log.h" -#include "../container.h" - -#include "init.h" - -#define KB(x) (x * 1024) - -#define ZRAM_MOD_PATH "/lib/modules/%s/zram.ko" -#define EXT4_MOD_PATH "/lib/modules/%s/ext4.ko" - -static long -proc_meminfo(void) -{ - FILE *fp; - char line[256]; - char *key; - long val = KB(16); - - fp = fopen("/proc/meminfo", "r"); - if (fp == NULL) { - ERROR("Can't open /proc/meminfo: %m\n"); - return errno; - } - - while (fgets(line, sizeof(line), fp)) { - key = strtok(line, ":"); - if (strcasecmp(key, "MemTotal")) - continue; - val = atol(strtok(NULL, " kB\n")); - break; - } - fclose(fp); - - if (val > KB(32)) - val = KB(32); - - return val; -} - -static int -early_insmod(char *module) -{ - pid_t pid = fork(); - char *modprobe[] = { "/sbin/modprobe", NULL, NULL }; - - if (!pid) { - char *path; - struct utsname ver; - - uname(&ver); - path = alloca(strlen(module) + strlen(ver.release) + 1); - sprintf(path, module, ver.release); - modprobe[1] = path; - execvp(modprobe[0], modprobe); - ERROR("Can't exec %s: %m\n", modprobe[0]); - exit(EXIT_FAILURE); - } - - if (pid <= 0) { - ERROR("Can't exec %s: %m\n", modprobe[0]); - return -1; - } else { - waitpid(pid, NULL, 0); - } - - return 0; -} - - -int -mount_zram_on_tmp(void) -{ - char *mkfs[] = { "/usr/sbin/mkfs.ext4", "-b", "4096", "-F", "-L", "TEMP", "-m", "0", "/dev/zram0", NULL }; - FILE *fp; - long zramsize; - pid_t pid; - int ret; - - if (early_insmod(ZRAM_MOD_PATH) || early_insmod(EXT4_MOD_PATH)) { - ERROR("failed to insmod zram support\n"); - return -1; - } - - mkdev("*", 0600); - - zramsize = proc_meminfo() / 2; - fp = fopen("/sys/block/zram0/disksize", "r+"); - if (fp == NULL) { - ERROR("Can't open /sys/block/zram0/disksize: %m\n"); - return errno; - } - fprintf(fp, "%ld", KB(zramsize)); - fclose(fp); - - pid = fork(); - if (!pid) { - execvp(mkfs[0], mkfs); - ERROR("Can't exec %s: %m\n", mkfs[0]); - exit(EXIT_FAILURE); - } else if (pid <= 0) { - ERROR("Can't exec %s: %m\n", mkfs[0]); - return -1; - } else { - waitpid(pid, NULL, 0); - } - - if (!is_container()) { - ret = mount("/dev/zram0", "/tmp", "ext4", MS_NOSUID | MS_NODEV | MS_NOATIME, "errors=continue,noquota"); - if (ret < 0) { - ERROR("Can't mount /dev/zram0 on /tmp: %m\n"); - return errno; - } - } - - LOG("Using up to %ld kB of RAM as ZRAM storage on /mnt\n", zramsize); - - ret = chmod("/tmp", 01777); - if (ret < 0) { - ERROR("Can't set /tmp mode to 1777: %m\n"); - return errno; - } - - return 0; -} -- 2.30.2