From patchwork Mon Jun 29 18:02:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Salvaterra X-Patchwork-Id: 1318963 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=SzSn1D76; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Wqk3LfE4; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49wb5y6BCZz9s6w for ; Tue, 30 Jun 2020 04:06:30 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=RuwqYw7e6pVn2FyUXoyYkeXeUaIxbmpKeLX+mnJ6Qxk=; b=SzSn1D76nBxWXjofMursXuofiI iENq3OMT4v9RkHoU41GSuy18KXvMDBvWuoVJQHDeAW6cZygg+NDNsCX5sbO1N8HMEKMkw6oFU1MbP 7RF+EbNJDLXWBuV3SPPRnK9YfgU+MvyBeRG0jN/qB942MwGkSBdA9iMLQq1xbvur4pcX1YusaGT5t J5ZJRHpP9fCVvttMzWrXh0Xh64HMMlS+KwdsXibAGWQLohJXJ0mDmTk3h8ZCzWOuSNYV426Va8kUF aYb9j0rf+bClPFGemlnRj9m3YupkpmIMeXlvkvVdd4swKqCKhiBdRLpss6D7itifFI/myoUiOUWbV EISyCktg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpy93-0006XM-FL; Mon, 29 Jun 2020 18:04:41 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpy90-0006Wg-Kp for openwrt-devel@lists.openwrt.org; Mon, 29 Jun 2020 18:04:39 +0000 Received: by mail-pf1-x441.google.com with SMTP id x3so2697947pfo.9 for ; Mon, 29 Jun 2020 11:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R8Su3nNnQ9fRiLMMbHEnwycgG+x1ExuA3m71iwdyQ6g=; b=Wqk3LfE48+qYa4q4cn8QvCuZgZ5Sk1qzUOP++npDOk0G19HUouV3VIWI21Bed0n7ps nntqxoThbN5ZTma7+lekJZxilNqqBx2AGwMxgYAaDEQjoGiaIYr9UIJaLOsOKqU/F+5d YhOF+Rq8be4qfSfd+HBa0RcaxWSjJeXtqFmYlfh2vi9hImZLWcx6S+4d/9J3Tzhb4NlU MMIMm/BO/vg8o5BGOftOjY1bqQs4Jfr+7cO0CArSbH1n1SQ4S3qQUewRnnkvdjAPVIQ1 9Ri3uZego/U6HMNRNHFPBcR/kyQWGrf4egP2Gsi/j3dBaXqep2W9QYIVsU3w+srShJTE pCsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R8Su3nNnQ9fRiLMMbHEnwycgG+x1ExuA3m71iwdyQ6g=; b=Kmohzj85tRbOOg6d/iHkDmP1lkYxnOzWj3xQizqQvtHGxvotBxqoWx1JthTfMMTeMv LFK2AMI4h2V7tPRXtGJUJIJ0rNNddb3OfmcInmXQeWEgpGJXxzliwacA9tAdgxT++J/W a2Oh9VuHlEfqQTIYnwxamjV1QSrkUFe0WBfcybcDN1jCiggyMI/FFVaQKlLDejtO7HRR YYIYCwDuGGdGecx/YsTcyVIEFZKe33I1dhEZfg2QHriOXLMXRrnSTlITxe0HTwCKgo28 x3jqSmJ3SYIn3H04ca0PY9Ff/+SLYq2z2ZfIcUZ5ydw+bVuZ+oyi9brE2bLhj75Uw6zz nCyw== X-Gm-Message-State: AOAM5335cq06FXZnyQ7eKcvHFEWOqu0YmS1P9JKUwAT07PVrLY/OCJ6w d8v6UYh+KFCJ6WpzY6nPKMeu2K0= X-Google-Smtp-Source: ABdhPJwfr7R5VY2Ty4iNdTMTonlKq1IoYtaE9rAq3CjtTcqxkIr9+QfyxqM/2L+t7322/eTAwBBj6w== X-Received: by 2002:a63:7d4e:: with SMTP id m14mr11782853pgn.391.1593453875288; Mon, 29 Jun 2020 11:04:35 -0700 (PDT) Received: from presler.lan (a95-93-116-221.cpe.netcabo.pt. [95.93.116.221]) by smtp.gmail.com with ESMTPSA id h3sm221447pje.28.2020.06.29.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 11:04:34 -0700 (PDT) From: Rui Salvaterra To: openwrt-devel@lists.openwrt.org Subject: [RFC PATCH] procd: completely remove tmp-on-zram support Date: Mon, 29 Jun 2020 19:02:06 +0100 Message-Id: <20200629180204.1424-1-rsalvaterra@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:441 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [rsalvaterra[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rui Salvaterra Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This is the follow-up patch to "procd: don't let the user choose to mount /tmp on zram". As explained there, this feature is both redundant and more limited than using a zram swap device, as already provided by the zram-swap package. 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 3eb79f9..5f23fb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,11 +41,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() - add_subdirectory(upgraded) ADD_EXECUTABLE(procd ${SOURCES}) @@ -61,7 +56,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_LINK_LIBRARIES(init ${LIBS}) INSTALL(TARGETS init RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} diff --git a/initd/early.c b/initd/early.c index 7b281b2..6ba553f 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; -}