From patchwork Thu Apr 2 12:12:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1265566 X-Patchwork-Delegate: zajec5@gmail.com 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20170209 header.b=KFsIDpyf; 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=Q6IrgT0Q; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 48tMQK14dbz9sSW for ; Thu, 2 Apr 2020 23:12:41 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4kOXpgiW5SV73aJ/anJk6t4tROvhpcEA165O6fRtmgY=; b=KFsIDpyf1AK2jY DnWZkY3p2MWrHrgKWi1m5EpFN2o3Mtcvp71I2X515tBQUF0qJDk5bExEScWyUQQmZ8uVPgrJb4IwN Fv226H245Vq/6nxHKUp2i4g4SfRnB2pxdOSXDOFBQ8E3Ealcon29fX0ILprsztqWrCunnhguyrUGM Y2UQRJoOfJ5uRWoBgdYBmVLAc22BeUUGFUVLefmXSpwNLYq2t6lRP45wYq7VYjquJ4O7hLu/6Pec1 WpSMxoJazTX+cTreMUAIYe4l/6yBLqAm8qD4JN1Zg5oodL9nmRJEA33UyjrcQ6Zme0Fg4acIdG63m MZvDWEQj8buwlrg86EIQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jJyi7-0005J6-AZ; Thu, 02 Apr 2020 12:12:39 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jJyhy-00057y-9D for openwrt-devel@lists.openwrt.org; Thu, 02 Apr 2020 12:12:32 +0000 Received: by mail-lj1-x244.google.com with SMTP id v16so2971981ljg.5 for ; Thu, 02 Apr 2020 05:12:30 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=I0F3gHJJRPtNrbiFucaABIAx9izDGvFqSCAH7wLdrAk=; b=Q6IrgT0QnHL0fu2+DmxdbFuKpQkydKJwYlJKbUdDPDjZttwbWBZDd5KPsugqupnc09 +1rjAk84Kpja0S7Lfi0kqEyuUfKVkIOxvVBNcv6pp98/Wlg52QxUJaOYUC6c20uLji/5 Z16pxPN1YpayDFkJh0EF38oWgMVdUOJi01dpvXN+qh87kaiB4ZabQ9sI9M3ndOEBa83S doxun5VKWKyCjiotD+3mVdziwkNxaVAVPNQSYXknJo4hWt3uhe5VvMP1j1xeEkJolTHu 22vK7gBUFtkSL911IREEvacb1pjVgLYgAZ/MIU3qeDupRN6la8BA0kK/Uj7bcsQ0VtWI KeHg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=I0F3gHJJRPtNrbiFucaABIAx9izDGvFqSCAH7wLdrAk=; b=GsqYXuKLlLeIjkWuoury8H5SOK4+Kt+JzDvYv8TenZ880R7BAo0+e/QLBAiC+eswhO 1Gjksvr2SiZF7U/f4CibYDVfDnxiYRvATdUYLh0dklVw6XzUipXrRuCJonBzQmTDniDN hdrYRP3KCXMTHb9jBMGDZIwUc2+jDskZvX3SMW31AsYutBq2bHr+nT4I9BidPRUpWx8q Am7qPCmOUZmbLgQv4K2sEh0ay2PgpyEFpHGCMnUSwOxecRscRMLbrRp3biwjHwpWpuH/ N0WIj9tFYUV3eyhXkh0sTo+591Vg86qR7Kf+BEn7uIE22Dxq7QEy2/MMQElRJrR0vIfn H5Fw== X-Gm-Message-State: AGi0PubEclnOAz0cqjiZOxLc5UjCZeC9Rs6BlFxI0Fhk24BeBZ/Lp3UK itJaOKwbrFjLXjBxU0Ut/rvJG2pZ X-Google-Smtp-Source: APiQypIeedOg65+E42l4e+9/1KNKeFRpilT9QsvqJtgkyEMlQZUTCwSwe2CHJQPE98WhBGEfdAoBNw== X-Received: by 2002:a2e:9395:: with SMTP id g21mr1979222ljh.8.1585829548383; Thu, 02 Apr 2020 05:12:28 -0700 (PDT) Received: from localhost.localdomain (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id s6sm3141311ljm.58.2020.04.02.05.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 05:12:27 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Date: Thu, 2 Apr 2020 14:12:13 +0200 Message-Id: <20200402121213.16777-2-zajec5@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200402121213.16777-1-zajec5@gmail.com> References: <20200402121213.16777-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200402_051230_492292_A7D527FD X-CRM114-Status: GOOD ( 16.60 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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 [zajec5[at]gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 Subject: [OpenWrt-Devel] [PATCH fstools V3 2/2] Revert "block: support hierarchical mount/umount" X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Yousong Zhou , John Crispin Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki This reverts commit fb0700f0fdfc4bec220203d31df87be2b4ccc467. Switching to AVL tree allows sorting devices by selected parameter (mount path) but does not implement a real hierarchical layout. That would require a tree with parent nodes being parent devices / mount paths. Cc: Yousong Zhou Signed-off-by: Rafał Miłecki --- V3: Revert this commit as well --- block.c | 152 +++++++++++++++++++------------------------------------- 1 file changed, 51 insertions(+), 101 deletions(-) diff --git a/block.c b/block.c index f743e75..dfee7fb 100644 --- a/block.c +++ b/block.c @@ -82,20 +82,9 @@ struct mount { unsigned int prio; }; -struct device { - struct vlist_node node; - - struct probe_info *pr; - struct mount *m; -}; - -static void vlist_nop_update(struct vlist_tree *tree, struct vlist_node *node_new, - struct vlist_node *node_old); -static int devices_cmp(const void *k1, const void *k2, void *ptr); - +static struct vlist_tree mounts; static struct blob_buf b; -static VLIST_TREE(mounts, avl_strcmp, vlist_nop_update, false, false); -static VLIST_TREE(devices, devices_cmp, vlist_nop_update, false, false); +static LIST_HEAD(devices); static int anon_mount, anon_swap, auto_mount, auto_swap, check_fs; static unsigned int delay_root; @@ -420,10 +409,9 @@ static struct mount* find_block(const char *uuid, const char *label, const char return NULL; } -static void vlist_nop_update(struct vlist_tree *tree, struct vlist_node *node_new, +static void mounts_update(struct vlist_tree *tree, struct vlist_node *node_new, struct vlist_node *node_old) { - // NOTE: free on delete skipped } static struct uci_package * config_try_load(struct uci_context *ctx, char *path) @@ -454,6 +442,8 @@ static int config_load(char *cfg) struct uci_element *e; char path[64]; + vlist_init(&mounts, avl_strcmp, mounts_update); + if (cfg) { snprintf(path, sizeof(path), "%s/upper/etc/config/fstab", cfg); pkg = config_try_load(ctx, path); @@ -492,15 +482,15 @@ static int config_load(char *cfg) static struct probe_info* _probe_path(char *path) { - struct device *dev; + struct probe_info *pr; char tmppath[64]; /* skip ubi device if ubiblock device is present */ if (path[5] == 'u' && path[6] == 'b' && path[7] == 'i' && path[8] >= '0' && path[8] <= '9' ) { snprintf(tmppath, sizeof(tmppath), "/dev/ubiblock%s", path + 8); - vlist_for_each_element(&devices, dev, node) - if (!strcasecmp(dev->pr->dev, tmppath)) + list_for_each_entry(pr, &devices, list) + if (!strcasecmp(pr->dev, tmppath)) return NULL; } @@ -512,20 +502,14 @@ static int _cache_load(const char *path) int gl_flags = GLOB_NOESCAPE | GLOB_MARK; int j; glob_t gl; - struct device *dev; if (glob(path, gl_flags, NULL, &gl) < 0) return -1; for (j = 0; j < gl.gl_pathc; j++) { struct probe_info *pr = _probe_path(gl.gl_pathv[j]); - if (pr) { - dev = malloc(sizeof(struct device)); - dev->pr = pr; - dev->m = find_block(pr->uuid, pr->label, - basename(pr->dev), NULL); - vlist_add(&devices, &dev->node, dev); - } + if (pr) + list_add_tail(&pr->list, &devices); } globfree(&gl); @@ -533,30 +517,8 @@ static int _cache_load(const char *path) return 0; } -static int devices_cmp(const void *k1, const void *k2, void *ptr) -{ - struct device *dev1 = (struct device *)k1; - struct device *dev2 = (struct device *)k2; - - if (dev1->m) { - if (!dev2->m) - return -1; - if (dev1->m->type == TYPE_MOUNT && dev2->m->type == TYPE_MOUNT && - dev1->m->target && dev2->m->target) { - int len1 = strlen(dev1->m->target); - int len2 = strlen(dev2->m->target); - if (len1 != len2) - return len1 - len2; - } - } else if (dev2->m) { - return 1; - } - return strcmp(dev1->pr->dev, dev2->pr->dev); -} - static void cache_load(int mtd) { - vlist_update(&devices); if (mtd) { _cache_load("/dev/mtdblock*"); _cache_load("/dev/ubiblock*"); @@ -571,28 +533,27 @@ static void cache_load(int mtd) _cache_load("/dev/vd*"); _cache_load("/dev/xvd*"); _cache_load("/dev/mapper/*"); - vlist_flush(&devices); } -static struct device* find_block_device(char *uuid, char *label, char *path) +static struct probe_info* find_block_info(char *uuid, char *label, char *path) { - struct device *dev; + struct probe_info *pr = NULL; if (uuid) - vlist_for_each_element(&devices, dev, node) - if (dev->pr->uuid && !strcasecmp(dev->pr->uuid, uuid)) - return dev; + list_for_each_entry(pr, &devices, list) + if (pr->uuid && !strcasecmp(pr->uuid, uuid)) + return pr; if (label) - vlist_for_each_element(&devices, dev, node) - if (dev->pr->label && !strcmp(dev->pr->label, label)) - return dev; + list_for_each_entry(pr, &devices, list) + if (pr->label && !strcmp(pr->label, label)) + return pr; if (path) - vlist_for_each_element(&devices, dev, node) - if (dev->pr->dev && !strcmp(basename(dev->pr->dev), basename(path))) - return dev; + list_for_each_entry(pr, &devices, list) + if (pr->dev && !strcmp(basename(pr->dev), basename(path))) + return pr; return NULL; } @@ -1068,10 +1029,9 @@ static int blockd_notify(char *device, struct mount *m, struct probe_info *pr) return err; } -static int mount_device(struct device *dev, int type) +static int mount_device(struct probe_info *pr, int type) { struct mount *m; - struct probe_info *pr; struct stat st; char _target[32]; char *target; @@ -1079,10 +1039,9 @@ static int mount_device(struct device *dev, int type) char *mp; int err; - if (!dev) + if (!pr) return -1; - pr = dev->pr; device = basename(pr->dev); if (!strcmp(pr->type, "swap")) { @@ -1095,7 +1054,7 @@ static int mount_device(struct device *dev, int type) return 0; } - m = dev->m; + m = find_block(pr->uuid, pr->label, device, NULL); if (m && m->extroot) return -1; @@ -1225,7 +1184,7 @@ static int mount_action(char *action, char *device, int type) return -1; cache_load(0); - return mount_device(find_block_device(NULL, NULL, path), type); + return mount_device(find_block_info(NULL, NULL, path), type); } static int main_hotplug(int argc, char **argv) @@ -1241,21 +1200,19 @@ static int main_autofs(int argc, char **argv) return -1; if (!strcmp(argv[2], "start")) { - struct device *dev; struct probe_info *pr; if (config_load(NULL)) return -1; cache_load(0); - vlist_for_each_element(&devices, dev, node) { + list_for_each_entry(pr, &devices, list) { struct mount *m; - pr = dev->pr; if (!strcmp(pr->type, "swap")) continue; - m = dev->m; + m = find_block(pr->uuid, pr->label, NULL, NULL); if (m && m->extroot) continue; @@ -1419,8 +1376,7 @@ static int test_fs_support(const char *name) static int check_extroot(char *path) { - struct device *dev; - struct probe_info *pr; + struct probe_info *pr = NULL; char devpath[32]; #ifdef UBIFS_EXTROOT @@ -1443,8 +1399,7 @@ static int check_extroot(char *path) } #endif - vlist_for_each_element(&devices, dev, node) { - pr = dev->pr; + list_for_each_entry(pr, &devices, list) { if (!strcmp(pr->dev, devpath)) { struct stat s; FILE *fp = NULL; @@ -1502,7 +1457,6 @@ static int mount_extroot(char *cfg) char overlay[] = "/tmp/extroot/overlay"; char mnt[] = "/tmp/extroot/mnt"; char *path = mnt; - struct device *dev; struct probe_info *pr; struct mount *m; int err = -1; @@ -1523,17 +1477,16 @@ static int mount_extroot(char *cfg) } /* Find block device pointed by the mount config */ - dev = find_block_device(m->uuid, m->label, m->device); + pr = find_block_info(m->uuid, m->label, m->device); - if (!dev && delay_root){ + if (!pr && delay_root){ ULOG_INFO("extroot: device not present, retrying in %u seconds\n", delay_root); sleep(delay_root); make_devs(); cache_load(1); - dev = find_block_device(m->uuid, m->label, m->device); + pr = find_block_info(m->uuid, m->label, m->device); } - if (dev) { - pr = dev->pr; + if (pr) { if (strncmp(pr->type, "ext", 3) && strncmp(pr->type, "f2fs", 4) && strncmp(pr->type, "btrfs", 5) && @@ -1577,6 +1530,7 @@ static int mount_extroot(char *cfg) static int main_extroot(int argc, char **argv) { + struct probe_info *pr; char blkdev_path[32] = { 0 }; int err = -1; #ifdef UBIFS_EXTROOT @@ -1605,8 +1559,8 @@ static int main_extroot(int argc, char **argv) /* Start with looking for MTD partition */ find_block_mtd("\"rootfs_data\"", blkdev_path, sizeof(blkdev_path)); if (blkdev_path[0]) { - struct device *dev = find_block_device(NULL, NULL, blkdev_path); - if (dev && !strcmp(dev->pr->type, "jffs2")) { + pr = find_block_info(NULL, NULL, blkdev_path); + if (pr && !strcmp(pr->type, "jffs2")) { char cfg[] = "/tmp/jffs_cfg"; /* @@ -1652,14 +1606,14 @@ static int main_extroot(int argc, char **argv) static int main_mount(int argc, char **argv) { - struct device *dev; + struct probe_info *pr; if (config_load(NULL)) return -1; cache_load(1); - vlist_for_each_element(&devices, dev, node) - mount_device(dev, TYPE_DEV); + list_for_each_entry(pr, &devices, list) + mount_device(pr, TYPE_DEV); handle_swapfiles(true); @@ -1668,7 +1622,6 @@ static int main_mount(int argc, char **argv) static int main_umount(int argc, char **argv) { - struct device *dev; struct probe_info *pr; bool all = false; @@ -1682,14 +1635,13 @@ static int main_umount(int argc, char **argv) if (argc == 3) all = !strcmp(argv[2], "-a"); - vlist_for_each_element_reverse(&devices, dev, node) { + list_for_each_entry(pr, &devices, list) { struct mount *m; - pr = dev->pr; if (!strcmp(pr->type, "swap")) continue; - m = dev->m; + m = find_block(pr->uuid, pr->label, basename(pr->dev), NULL); if (m && m->extroot) continue; @@ -1701,7 +1653,7 @@ static int main_umount(int argc, char **argv) static int main_detect(int argc, char **argv) { - struct device *dev; + struct probe_info *pr; cache_load(0); printf("config 'global'\n"); @@ -1711,8 +1663,8 @@ static int main_detect(int argc, char **argv) printf("\toption\tauto_mount\t'1'\n"); printf("\toption\tdelay_root\t'5'\n"); printf("\toption\tcheck_fs\t'0'\n\n"); - vlist_for_each_element(&devices, dev, node) - print_block_uci(dev->pr); + list_for_each_entry(pr, &devices, list) + print_block_uci(pr); return 0; } @@ -1720,12 +1672,12 @@ static int main_detect(int argc, char **argv) static int main_info(int argc, char **argv) { int i; - struct device *dev; + struct probe_info *pr; cache_load(1); if (argc == 2) { - vlist_for_each_element(&devices, dev, node) - print_block_info(dev->pr); + list_for_each_entry(pr, &devices, list) + print_block_info(pr); return 0; }; @@ -1741,9 +1693,9 @@ static int main_info(int argc, char **argv) ULOG_ERR("%s is not a block device\n", argv[i]); continue; } - dev = find_block_device(NULL, NULL, argv[i]); - if (dev) - print_block_info(dev->pr); + pr = find_block_info(NULL, NULL, argv[i]); + if (pr) + print_block_info(pr); } return 0; @@ -1765,7 +1717,6 @@ static int main_swapon(int argc, char **argv) FILE *fp; char *lineptr; size_t s; - struct device *dev; struct probe_info *pr; int flags = 0; int pri; @@ -1790,8 +1741,7 @@ static int main_swapon(int argc, char **argv) return 0; case 'a': cache_load(0); - vlist_for_each_element(&devices, dev, node) { - pr = dev->pr; + list_for_each_entry(pr, &devices, list) { if (strcmp(pr->type, "swap")) continue; if (swapon(pr->dev, 0))