From patchwork Tue Oct 29 12:39:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1186091 X-Patchwork-Delegate: blogic@openwrt.org 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.b="P/NIjmVl"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="q9Lwc6/U"; 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 472WQN53N6z9s7T for ; Tue, 29 Oct 2019 23:40:28 +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:Message-Id:Date: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=dMK3rtf2oFpHSUgG9W/u5uvWKk2oRYdaEGb8l04O2kY=; b=P/NIjmVl+XsN9G Flkz0N+07qIcaEstlSJXLMHpoxEpzpnniJI0ZohwiwF4rDYkD3mjFsG5dPpyH092baGGciEheMkrz plLJxllQlOfZ7BfqdseRmJjo2KkJKYPQkqrhgzDVUS7EvHET6RHfVChDvLm+8t0QhUAYHXjMXQDmW udscvAPh38/N3oXxmX8FTjsCtgmswkq+5Zt1/2R2CAixOvk6enNON18H4rRgqSWmdI2rlAxgCRd83 oSg4/kb15+IqUItKGleWNi/i6ZxU19zXjqSeM7yurIt595OD2BUBEvQ468jRKA0TdgsI4rUhXsYgN OGzTiA7JKdHKKiMAhDpw==; 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 1iPQnG-0002DK-Lc; Tue, 29 Oct 2019 12:40:14 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQnD-0002Ca-Sl for openwrt-devel@lists.openwrt.org; Tue, 29 Oct 2019 12:40:13 +0000 Received: by mail-pg1-x544.google.com with SMTP id f19so9469560pgn.13 for ; Tue, 29 Oct 2019 05:40:11 -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=UB/dw7kmZ6ujDoGYg2rdbOSTnohqNVi5MqE99aPxWJY=; b=q9Lwc6/U+jPHCMtLnfzrOUq+cj1wJ9G23Jp/8HPXrUtXNSUgyJ/DEmNQOxj6aHJeaC rnk6+dg/dksGWXeXQCBOEzZmfZmgBhLW6sz/p7y8IWPGR2VBQo4c4RDVL1ShCCpL1Rgw cvsJsmC0yDy+HBroRJReOA7jUclirHr5KV7L+pEMdKd6xC4TlVpPibTUR59UR9fcnCy4 MmrAS08cdykgnkdmaC81tBA5UytAF8MfM4EozMRVlHeibJdbvaKmxCu9BeJE7F/YZh9i H/b3myMvN9GTDFKHuUSvlfRd4xHfECtMLBHIFBXZzcXoZU9lE7H9Rygw9m/gaxKMkjYT dCrw== 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=UB/dw7kmZ6ujDoGYg2rdbOSTnohqNVi5MqE99aPxWJY=; b=kgboSaQbinvo6i4A9o9sNPoxi5LufE6NRX6OxvWCWwjydfI1s0tXogRTYLmZehvjED Fv22cGwzNiTNOrOUtAlkTcDlo9wvyYKHtqcICwP85CQiShjICFFf1mVq4S3eaFRYKrFQ eBFENj2JP+AvjEhIg+VqvL7ph7xwrltBTRCmaagTQQqDRGN3b5RvlvLMxBCXehT1lRKB HsNAq+pZDoG+LlNqCesZUVX3PJFQMLRr6fq166IJP6hBw/AF0fs8T8wHUvg6VTulRx7F uC4YwrxZ+P4FSu/+T8tT/XqcKXFvApS4/JhKS8sQBnq/t1YhFSw7/lpqg+x3XpLYrXpT nQ6g== X-Gm-Message-State: APjAAAXbxNdDTQfGG047OjxYQ5/CrZUZNDXvbPTpwfiwLl+V08c9Hieo VsyCoS/+meAtNlt/Plt+ml8= X-Google-Smtp-Source: APXvYqzC9Rat5/7ZsNpifN/w+bxn2nkuzLmhF3FwE3rJeDtvE0DfzM9pPEnq8hnNqmzzmSxrM6Hmgg== X-Received: by 2002:a65:6091:: with SMTP id t17mr683628pgu.159.1572352811342; Tue, 29 Oct 2019 05:40:11 -0700 (PDT) Received: from titan.hq.cloud.yunionyun.com ([161.117.5.46]) by smtp.gmail.com with ESMTPSA id b26sm1090782pgs.93.2019.10.29.05.40.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 05:40:10 -0700 (PDT) From: Yousong Zhou To: john@phrozen.org Date: Tue, 29 Oct 2019 12:39:46 +0000 Message-Id: <20191029123950.40794-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_054011_952414_5FF77BE6 X-CRM114-Status: UNSURE ( 8.18 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.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:544 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 (yszhou4tech[at]gmail.com) -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH fstools 1/5] block: umount: skip / unless -a is given 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: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Signed-off-by: Yousong Zhou --- block.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index a849500..99672fb 100644 --- a/block.c +++ b/block.c @@ -1118,7 +1118,7 @@ static int mount_device(struct probe_info *pr, int type) return 0; } -static int umount_device(char *path, int type) +static int umount_device(char *path, int type, bool all) { char *mp; int err; @@ -1126,6 +1126,8 @@ static int umount_device(char *path, int type) mp = find_mount_point(path); if (!mp) return -1; + if (!strcmp(mp, "/") && !all) + return 0; if (type != TYPE_AUTOFS) hotplug_call_mount("remove", basename(path)); @@ -1155,7 +1157,7 @@ static int mount_action(char *action, char *device, int type) if (type == TYPE_HOTPLUG) blockd_notify(device, NULL, NULL); - umount_device(path, type); + umount_device(path, type, true); return 0; } else if (strcmp(action, "add")) { @@ -1607,6 +1609,7 @@ static int main_mount(int argc, char **argv) static int main_umount(int argc, char **argv) { struct probe_info *pr; + bool all = false; if (config_load(NULL)) return -1; @@ -1614,6 +1617,10 @@ static int main_umount(int argc, char **argv) handle_swapfiles(false); cache_load(0); + + if (argc == 3) + all = !strcmp(argv[2], "-a"); + list_for_each_entry(pr, &devices, list) { struct mount *m; @@ -1624,7 +1631,7 @@ static int main_umount(int argc, char **argv) if (m && m->extroot) continue; - umount_device(pr->dev, TYPE_DEV); + umount_device(pr->dev, TYPE_DEV, all); } return 0; @@ -1735,7 +1742,6 @@ static int main_swapon(int argc, char **argv) default: return swapon_usage(); } - } if (optind != (argc - 1)) From patchwork Tue Oct 29 12:39:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1186092 X-Patchwork-Delegate: blogic@openwrt.org 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.b="RLG+Frcw"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LiPdNK3W"; 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 472WQf4Br6z9s7T for ; Tue, 29 Oct 2019 23:40:42 +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=VfQTt4Vqygfq1S/hUaLqwyK2IalG5FUKAKjsFRLPdY0=; b=RLG+Frcwj+ZKr4 /wF6B7YIszlqavEqvaQIJU27N/a2IyGUTVy5mILkO6qVN15z5QbZMTlb5kwwoVRV+c5FQO80XGPIn Yyn5FAiZEvmraaGt56osZIRaGO2bRpOtMl+QzRhqu9kZBAZE2mJ6DM85X3IuwtBeOjYmw3zbnEUyW onBeG9ISwrAtyDZ3zm4z4EnZ7ZNExL5LnLCIEzvQ8b2d/6tuVcgBSOxhhBjd4ZuYI7OakStsOcmqs Go6DUTlztzYxCOrzjS26AtPgdb6v3HaGYD2rTDzcF4INBGsGR6RQ7t0QfbfVHJp66pj9ByRgrqq+a uWUeaCeL07i8KfWtjnnw==; 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 1iPQnS-0002Qx-Og; Tue, 29 Oct 2019 12:40:26 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQnG-0002DV-US for openwrt-devel@lists.openwrt.org; Tue, 29 Oct 2019 12:40:16 +0000 Received: by mail-pf1-x441.google.com with SMTP id c184so9515732pfb.0 for ; Tue, 29 Oct 2019 05:40:14 -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=LuBKWYdqI83qUSwo6qPNNJD5CjVE+jF1ISzPRKycLLg=; b=LiPdNK3Ww0RixIeDgkEZENKDf6HVlLlbzfWpyTaKv6tWljw1Yn7RjytKu3So2h9ql1 9Svjeq3w+jccYg4HTTK5f98sXXWxaYicqw2mBbESJxny5re4N4fjlbZBhs3CCkcP3l+O B2L3nlzsKY9/e7ASOtn0uDJIy04FnwXaTGieZasc2qdx8RN4zi7tZOmdm7lWjp2k8xnN 0QK2BrkO9ugy4V0bPfOYbQWesYfv8eke6TUDbxxQZUzxJzmKlbj7SKLUqLiM4CAn0ytt hg2K3ueNAXcUbCtNbQhSbaVEjIChJrdQCG7H+iGyLD3pW35iqj1+3xSnq7ZhMAeryAq9 zxOg== 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=LuBKWYdqI83qUSwo6qPNNJD5CjVE+jF1ISzPRKycLLg=; b=pIcs7qumvj2W0QN/DjX+IHA+z24vxzVGje2YKpJMHia5JB7A+omyb3FgspcVnfHxKL 18PYY9jZP5Ed2gEbbDZL1zKS1gHwE86LI1DGL0SI7gMkLndfJYL1w6B8lgkee3nT2vEf cqRvh1riXz3EmXGM0j72jV3ZCt3OS+fWeVC5TcnrOKXPHatJFugm/EmQLpFUc+BJuSI2 ccMh5EycWt12iSoEIteRKGT3RkH+JsMbXflRrLw6+U4rfQkK3Y5Wpzfl9AaD0nUO4o4i eaKn6wftiyx0tf3NJPy53dF1u/z5sExf47Z0N3Tk7XrS6TMoc7fGQTBTvovUAUaqkYf0 TzVA== X-Gm-Message-State: APjAAAVJgTasoTtW0WZrXp9asczuaNh0h24GagRGlXQ75lGv7jhCOENp x7x2pAKQab4xUhT1ClNya/c= X-Google-Smtp-Source: APXvYqzUYiZskJ6e7xviVCa5guslmYJf5/F0vISd8ij9z9H2STDwZ3io9Lno4aRZyQ6ejwGnv8kXMg== X-Received: by 2002:a65:41c5:: with SMTP id b5mr10367848pgq.78.1572352814161; Tue, 29 Oct 2019 05:40:14 -0700 (PDT) Received: from titan.hq.cloud.yunionyun.com ([161.117.5.46]) by smtp.gmail.com with ESMTPSA id b26sm1090782pgs.93.2019.10.29.05.40.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 05:40:13 -0700 (PDT) From: Yousong Zhou To: john@phrozen.org Date: Tue, 29 Oct 2019 12:39:47 +0000 Message-Id: <20191029123950.40794-2-yszhou4tech@gmail.com> In-Reply-To: <20191029123950.40794-1-yszhou4tech@gmail.com> References: <20191029123950.40794-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_054014_993907_042434B9 X-CRM114-Status: GOOD ( 15.90 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.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_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 (yszhou4tech[at]gmail.com) -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH fstools 2/5] 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: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This is needed when e.g. sda1 needs to be mounted to /mnt and sda2 /mnt/srv. We need to make sure sda1 was mounted first. "devices" is now an ordered list with elements pointing to both "struct probe_info" and "struct mount". The order is firstly on presence of mount info, then strlen(mount.target), then strcmp(probe_info.dev) Resolves FS#2214 Signed-off-by: Yousong Zhou --- block.c | 152 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 51 deletions(-) diff --git a/block.c b/block.c index 99672fb..66dcf9c 100644 --- a/block.c +++ b/block.c @@ -82,9 +82,20 @@ struct mount { unsigned int prio; }; -static struct vlist_tree mounts; +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 blob_buf b; -static LIST_HEAD(devices); +static VLIST_TREE(mounts, avl_strcmp, vlist_nop_update, false, false); +static VLIST_TREE(devices, devices_cmp, vlist_nop_update, false, false); static int anon_mount, anon_swap, auto_mount, auto_swap, check_fs; static unsigned int delay_root; @@ -409,9 +420,10 @@ static struct mount* find_block(const char *uuid, const char *label, const char return NULL; } -static void mounts_update(struct vlist_tree *tree, struct vlist_node *node_new, +static void vlist_nop_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) @@ -442,8 +454,6 @@ 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); @@ -482,15 +492,15 @@ static int config_load(char *cfg) static struct probe_info* _probe_path(char *path) { - struct probe_info *pr; + struct device *dev; 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); - list_for_each_entry(pr, &devices, list) - if (!strcasecmp(pr->dev, tmppath)) + vlist_for_each_element(&devices, dev, node) + if (!strcasecmp(dev->pr->dev, tmppath)) return NULL; } @@ -502,14 +512,20 @@ 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) - list_add_tail(&pr->list, &devices); + 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); + } } globfree(&gl); @@ -517,8 +533,30 @@ 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*"); @@ -533,6 +571,7 @@ static void cache_load(int mtd) _cache_load("/dev/vd*"); _cache_load("/dev/xvd*"); _cache_load("/dev/mapper/*"); + vlist_flush(&devices); } @@ -553,24 +592,24 @@ static int print_block_uci(struct probe_info *pr) return 0; } -static struct probe_info* find_block_info(char *uuid, char *label, char *path) +static struct device* find_block_device(char *uuid, char *label, char *path) { - struct probe_info *pr = NULL; + struct device *dev; if (uuid) - list_for_each_entry(pr, &devices, list) - if (pr->uuid && !strcasecmp(pr->uuid, uuid)) - return pr; + vlist_for_each_element(&devices, dev, node) + if (dev->pr->uuid && !strcasecmp(dev->pr->uuid, uuid)) + return dev; if (label) - list_for_each_entry(pr, &devices, list) - if (pr->label && !strcmp(pr->label, label)) - return pr; + vlist_for_each_element(&devices, dev, node) + if (dev->pr->label && !strcmp(dev->pr->label, label)) + return dev; if (path) - list_for_each_entry(pr, &devices, list) - if (pr->dev && !strcmp(basename(pr->dev), basename(path))) - return pr; + vlist_for_each_element(&devices, dev, node) + if (dev->pr->dev && !strcmp(basename(dev->pr->dev), basename(path))) + return dev; return NULL; } @@ -1022,18 +1061,20 @@ static int blockd_notify(char *device, struct mount *m, struct probe_info *pr) return err; } -static int mount_device(struct probe_info *pr, int type) +static int mount_device(struct device *dev, int type) { struct mount *m; + struct probe_info *pr; char _target[32]; char *target; char *device; char *mp; int err; - if (!pr) + if (!dev) return -1; + pr = dev->pr; device = basename(pr->dev); if (!strcmp(pr->type, "swap")) { @@ -1053,7 +1094,7 @@ static int mount_device(struct probe_info *pr, int type) return -1; } - m = find_block(pr->uuid, pr->label, device, NULL); + m = dev->m; if (m && m->extroot) return -1; @@ -1170,7 +1211,7 @@ static int mount_action(char *action, char *device, int type) return -1; cache_load(0); - return mount_device(find_block_info(NULL, NULL, path), type); + return mount_device(find_block_device(NULL, NULL, path), type); } static int main_hotplug(int argc, char **argv) @@ -1186,19 +1227,21 @@ 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); - list_for_each_entry(pr, &devices, list) { + vlist_for_each_element(&devices, dev, node) { struct mount *m; + pr = dev->pr; if (!strcmp(pr->type, "swap")) continue; - m = find_block(pr->uuid, pr->label, NULL, NULL); + m = dev->m; if (m && m->extroot) continue; @@ -1362,7 +1405,8 @@ static int test_fs_support(const char *name) static int check_extroot(char *path) { - struct probe_info *pr = NULL; + struct device *dev; + struct probe_info *pr; char devpath[32]; #ifdef UBIFS_EXTROOT @@ -1385,7 +1429,8 @@ static int check_extroot(char *path) } #endif - list_for_each_entry(pr, &devices, list) { + vlist_for_each_element(&devices, dev, node) { + pr = dev->pr; if (!strcmp(pr->dev, devpath)) { struct stat s; FILE *fp = NULL; @@ -1443,6 +1488,7 @@ 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; @@ -1463,16 +1509,17 @@ static int mount_extroot(char *cfg) } /* Find block device pointed by the mount config */ - pr = find_block_info(m->uuid, m->label, m->device); + dev = find_block_device(m->uuid, m->label, m->device); - if (!pr && delay_root){ + if (!dev && delay_root){ ULOG_INFO("extroot: device not present, retrying in %u seconds\n", delay_root); sleep(delay_root); make_devs(); cache_load(0); - pr = find_block_info(m->uuid, m->label, m->device); + dev = find_block_device(m->uuid, m->label, m->device); } - if (pr) { + if (dev) { + pr = dev->pr; if (strncmp(pr->type, "ext", 3) && strncmp(pr->type, "f2fs", 4) && strncmp(pr->type, "btrfs", 5) && @@ -1516,7 +1563,6 @@ 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 @@ -1545,8 +1591,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]) { - pr = find_block_info(NULL, NULL, blkdev_path); - if (pr && !strcmp(pr->type, "jffs2")) { + struct device *dev = find_block_device(NULL, NULL, blkdev_path); + if (dev && !strcmp(dev->pr->type, "jffs2")) { char cfg[] = "/tmp/jffs_cfg"; /* @@ -1592,14 +1638,14 @@ static int main_extroot(int argc, char **argv) static int main_mount(int argc, char **argv) { - struct probe_info *pr; + struct device *dev; if (config_load(NULL)) return -1; cache_load(1); - list_for_each_entry(pr, &devices, list) - mount_device(pr, TYPE_DEV); + vlist_for_each_element(&devices, dev, node) + mount_device(dev, TYPE_DEV); handle_swapfiles(true); @@ -1608,6 +1654,7 @@ 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; @@ -1621,13 +1668,14 @@ static int main_umount(int argc, char **argv) if (argc == 3) all = !strcmp(argv[2], "-a"); - list_for_each_entry(pr, &devices, list) { + vlist_for_each_element_reverse(&devices, dev, node) { struct mount *m; + pr = dev->pr; if (!strcmp(pr->type, "swap")) continue; - m = find_block(pr->uuid, pr->label, basename(pr->dev), NULL); + m = dev->m; if (m && m->extroot) continue; @@ -1639,7 +1687,7 @@ static int main_umount(int argc, char **argv) static int main_detect(int argc, char **argv) { - struct probe_info *pr; + struct device *dev; cache_load(0); printf("config 'global'\n"); @@ -1649,8 +1697,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"); - list_for_each_entry(pr, &devices, list) - print_block_uci(pr); + vlist_for_each_element(&devices, dev, node) + print_block_uci(dev->pr); return 0; } @@ -1658,12 +1706,12 @@ static int main_detect(int argc, char **argv) static int main_info(int argc, char **argv) { int i; - struct probe_info *pr; + struct device *dev; cache_load(1); if (argc == 2) { - list_for_each_entry(pr, &devices, list) - print_block_info(pr); + vlist_for_each_element(&devices, dev, node) + print_block_info(dev->pr); return 0; }; @@ -1679,9 +1727,9 @@ static int main_info(int argc, char **argv) ULOG_ERR("%s is not a block device\n", argv[i]); continue; } - pr = find_block_info(NULL, NULL, argv[i]); - if (pr) - print_block_info(pr); + dev = find_block_device(NULL, NULL, argv[i]); + if (dev) + print_block_info(dev->pr); } return 0; @@ -1703,6 +1751,7 @@ 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; @@ -1727,7 +1776,8 @@ static int main_swapon(int argc, char **argv) return 0; case 'a': cache_load(0); - list_for_each_entry(pr, &devices, list) { + vlist_for_each_element(&devices, dev, node) { + pr = dev->pr; if (strcmp(pr->type, "swap")) continue; if (swapon(pr->dev, 0)) From patchwork Tue Oct 29 12:39:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1186093 X-Patchwork-Delegate: blogic@openwrt.org 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.b="LWCgC4VE"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TgN1hcbc"; 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 472WR4135kz9s7T for ; Tue, 29 Oct 2019 23:41:03 +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=NATged1bPJyr7zj5N6h2ivzFJA1qeSZqQP+DhMrE4w8=; b=LWCgC4VEWbLm64 cgOY68Sl6Z1v6mQR0BMEX51cD6lO9YC9GAS1OeUA9TVld9hQBiI4cBABwnFTp9uNV9lse1xERQQBR Ty8XReSLJpIbxVVNot/NwZYkhtbvkZKY6DTjobR0/0LQjVaijRuYgsQwwAs4TqkqQH+8FPVTHgwPJ nQ1eoJqOELmBMC91PKh2hGvK8ThLh/MUzVLB+n5qHLnsNAw0PrDuxxCVU+fwQgsF0DLMOA8zFJmGI W8O3ZxNfdgBtooKscoooIVGekSvk5DByMQrqYLEUcbv46aeub1SPg2nCfz0FZeEt8cv446sgPQg0i ynYOG7DKmjSL5zSAPi5g==; 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 1iPQnm-0002ko-Ao; Tue, 29 Oct 2019 12:40:46 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQnJ-0002Gy-HO for openwrt-devel@lists.openwrt.org; Tue, 29 Oct 2019 12:40:18 +0000 Received: by mail-pf1-x441.google.com with SMTP id c7so8317405pfo.12 for ; Tue, 29 Oct 2019 05:40:17 -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=2kO8KAuOqxGYbsNBg18CIwmkD55xGI+n1VWyKukq6mw=; b=TgN1hcbcxQxS5ddkxmELGiMvYH21QIUBHBzFxTder391zqogaCyhngeUcD9+N/REGw peiiATUnI9Ex8pXBuT1j48sXpRftjSRR0r1TEjY1EhZ+aSU5L1cnnM8mkSQK1BU/lvxD 5k1HuH7YpZhtlGv74KB7uAbc2/mosvz4r6cNgm2tvfB2pccUBpniee31xIXWtZp4hzus pmPTaceHr0ogx9aJmuOG3EUIpY5BkbAQBtts2VCp4ZlWw2xPTkAmwCvNUKUEVWkBfByt +Gg4I8jqOX4f0XbA+sBjzdrjbBJfNyJf7Pn8iIoYrXSzKbZar+DCqgd2Axp4a18a72KJ N9aQ== 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=2kO8KAuOqxGYbsNBg18CIwmkD55xGI+n1VWyKukq6mw=; b=tLwqP0jSVLJpHOUThydwfgxzl5xfklNrx71OpcO4FbDhtWwQmRncX8li6gspS2kJjC oR8CNf8kSzynxn2bzRFl3RSPEMtnxVcGSpEoVN1ZavKAH5LtFRHL3/tfWl5TlzMXvcoo bbEZ05LsmUjAS5bvJXlk93o4ZR/JFEqZIdGiu4K6uhxWtGUs3hLBXwqy5ldE2L/jDi8s AfVuyJ1onzxUZZTD02Hj9Ibrj9tkHBBDV4rsW/VnNpKya1fHOEH2A53xyD15bXbdxDA/ DbbQ8q2A+JTQ6tiiFAFC4TG8F5b8tErlqCa9CWCaPhpp4Ks1BjBwsmLmTvcf5O9k7L7E Objw== X-Gm-Message-State: APjAAAX65/0xkdB96QZc50nGiEsuDpriz0psuo8lCgXrA33lKKE2xsSf /HEVtz5rS/t1hdBwhTTzaIQ= X-Google-Smtp-Source: APXvYqzabhGlkMx1f9UFIw5axJVirMJm9mD/geyCwiu5Hrfiq2Tt7MvyWoBWAN0crSaUpa49Lpp11Q== X-Received: by 2002:a63:1e5f:: with SMTP id p31mr26130731pgm.291.1572352816782; Tue, 29 Oct 2019 05:40:16 -0700 (PDT) Received: from titan.hq.cloud.yunionyun.com ([161.117.5.46]) by smtp.gmail.com with ESMTPSA id b26sm1090782pgs.93.2019.10.29.05.40.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 05:40:15 -0700 (PDT) From: Yousong Zhou To: john@phrozen.org Date: Tue, 29 Oct 2019 12:39:48 +0000 Message-Id: <20191029123950.40794-3-yszhou4tech@gmail.com> In-Reply-To: <20191029123950.40794-1-yszhou4tech@gmail.com> References: <20191029123950.40794-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_054017_622151_505A80E8 X-CRM114-Status: GOOD ( 12.07 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.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_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 (yszhou4tech[at]gmail.com) -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH fstools 3/5] block: mount_action: handle mount/umount deps 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: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This is required at least in system startup when "block hotplug" will be triggered by udevtrigger. E.g. /dev/vdb needs to be mounted at /mnt/s and /dev/vdc /mnt. It does not work if /dev/vdb was triggered then mounted first Signed-off-by: Yousong Zhou --- block.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/block.c b/block.c index 66dcf9c..15caaba 100644 --- a/block.c +++ b/block.c @@ -1188,30 +1188,47 @@ static int umount_device(char *path, int type, bool all) static int mount_action(char *action, char *device, int type) { + struct device *the_dev, *dev; char path[32]; if (!action || !device) return -1; - snprintf(path, sizeof(path), "/dev/%s", device); + + if (config_load(NULL)) + return -1; + cache_load(0); + + the_dev = find_block_device(NULL, NULL, device); if (!strcmp(action, "remove")) { if (type == TYPE_HOTPLUG) blockd_notify(device, NULL, NULL); - umount_device(path, type, true); - + if (!the_dev || !the_dev->m || the_dev->m->type != TYPE_MOUNT) { + snprintf(path, sizeof(path), "/dev/%s", device); + umount_device(path, type, true); + } else + vlist_for_element_to_last_reverse(&devices, the_dev, dev, node) + if (dev->m && dev->m->type == TYPE_MOUNT) + umount_device(dev->pr->dev, type, true); return 0; - } else if (strcmp(action, "add")) { - ULOG_ERR("Unkown action %s\n", action); - - return -1; + } else if (!strcmp(action, "add")) { + if (!the_dev) + return -1; + if (the_dev->m && the_dev->m->type == TYPE_MOUNT) { + vlist_for_first_to_element(&devices, the_dev, dev, node) { + if (dev->m && dev->m->type == TYPE_MOUNT) { + int err = mount_device(dev, type); + if (err) + return err; + } + } + return 0; + } else + return mount_device(the_dev, type); } - - if (config_load(NULL)) - return -1; - cache_load(0); - - return mount_device(find_block_device(NULL, NULL, path), type); + ULOG_ERR("Unkown action %s\n", action); + return -1; } static int main_hotplug(int argc, char **argv) From patchwork Tue Oct 29 12:39:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1186094 X-Patchwork-Delegate: blogic@openwrt.org 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.b="CJ9MW4F3"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DxBtpXV6"; 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 472WRH3Kj8z9sPc for ; Tue, 29 Oct 2019 23:41:15 +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=46eYDE4pWv/SgT1SdsVBgiB4TDSKWSHwDmeefkNiynM=; b=CJ9MW4F3f7/WEu sosN3x96BQ//q7D9e0yRt/SxXDgMwmYVVGFs68/w6t/pJgvEb0xuOMt13rUnmYLlrxG9yw+r8n+9Q AC5olzg0USL6yHMQVHT3YRMV/8NpprPRBOhY1zKrhVDUYP4+1N9q0XSOLaBaS2ZAnoHIsyUrHfljI vSCLBK+qMWBpy3wOtCccyMLsCRCNJJpw/W9e5A8RsOHBty9OLAJvfJx8YL6O/u4AnkMlBoG7SoAIR NI70nr6WwOgUZ+TInvdwj0Cgw3a4vSCnybc6SGJ8Wt9dr7Oh59gJmrYKiFcVgbQ2CMGnfC23YnLHt PoSSABC+GeXdBqw5b+uw==; 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 1iPQo2-00032q-0S; Tue, 29 Oct 2019 12:41:02 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQnM-0002KB-Vs for openwrt-devel@lists.openwrt.org; Tue, 29 Oct 2019 12:40:22 +0000 Received: by mail-pl1-x643.google.com with SMTP id t12so2922675plo.6 for ; Tue, 29 Oct 2019 05:40:20 -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=1B81C1Dh5JGsiGhtf+ZHbXnfvfzPuWVlJzGcZdbY5SU=; b=DxBtpXV69IhWrLVZn2W4EToCi7y6GLDd87/M2gZAKKgmHrV5fzMPyFKEvb430GjxJw LezGKo98QOi+Q3u6tgGwmWK8xsZilseqcGi5aQH7QwMZvXaNaKrtCZ+0p9qxHNmQwzeC DDAy/OMaEQZZL2a8JTRPKS2iks+UvHlYJ7wlKQkNJnFigSPZkJ5V6ss2VYTZaUurqkwZ vFa2SZze+cGa9Rtp3HxGo+GolK0XcjUlYNcVmrXmVAjmU38xw2HzUtTT+ORfq2ieKNBd jusdbuuDtFZA8BNH5fOpBhithP5QHxSstg3EGpDBA6cVAqjxluVOuv7Aa2bhwKcMEf5X 5FqQ== 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=1B81C1Dh5JGsiGhtf+ZHbXnfvfzPuWVlJzGcZdbY5SU=; b=CKFLOAvgI+sbiga/ut1932vhZWjiKVi8LsODPWgOiWahNNnwb5UjvJFAIV7nSq2o6d wO7Ry2EBEl3IJvFzB93vzpWnG7176kgrpmtA2Bxypy2om1B/rdUeolnJzBx4APcJQVLg ZUyeEu/CBBndLP3o/5ZTqRJRGB1QsYVlYnACA3tjBouIRXnIFMGYv0eW0cHFfyaiGq3v 5+2cmnrKN4Z3xQNzPyEzY4Nsg57QQmxkWASNX0TF6npizjQTmgkViMR/QumBCTcxExi8 sMSf4a3ZAJ1HF3DOC2YynJzycQC28XFK6CVBZNV2WNeDHB4uywtPPRmljlXBxGx7/yQV fL4A== X-Gm-Message-State: APjAAAWhSbxaAImZ9ew/fs8jLWUrieXM0oaKBYvVFmIOofxPOiJg2+Mj cFK5FMYliA2H+jO9Ate94xQ= X-Google-Smtp-Source: APXvYqwIAVjzTBek+fdLrzH4VDJbX6D7TqraXVLbzCOYGeFh80ghrdxoTxr0hD6hSUd03z8cVz+aOQ== X-Received: by 2002:a17:902:aa8a:: with SMTP id d10mr4025178plr.64.1572352819522; Tue, 29 Oct 2019 05:40:19 -0700 (PDT) Received: from titan.hq.cloud.yunionyun.com ([161.117.5.46]) by smtp.gmail.com with ESMTPSA id b26sm1090782pgs.93.2019.10.29.05.40.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 05:40:18 -0700 (PDT) From: Yousong Zhou To: john@phrozen.org Date: Tue, 29 Oct 2019 12:39:49 +0000 Message-Id: <20191029123950.40794-4-yszhou4tech@gmail.com> In-Reply-To: <20191029123950.40794-1-yszhou4tech@gmail.com> References: <20191029123950.40794-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_054021_077435_C528B46D X-CRM114-Status: GOOD ( 10.12 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.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:643 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 (yszhou4tech[at]gmail.com) -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH fstools 4/5] block: mount_device: skip extroot earlier 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: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Signed-off-by: Yousong Zhou --- block.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 15caaba..084e7fc 100644 --- a/block.c +++ b/block.c @@ -1087,6 +1087,10 @@ static int mount_device(struct device *dev, int type) return 0; } + m = dev->m; + if (m && m->extroot) + return -1; + mp = find_mount_point(pr->dev); if (mp && (type != TYPE_HOTPLUG)) { ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp); @@ -1094,10 +1098,6 @@ static int mount_device(struct device *dev, int type) return -1; } - m = dev->m; - if (m && m->extroot) - return -1; - if (type == TYPE_HOTPLUG) blockd_notify(device, m, pr); From patchwork Tue Oct 29 12:39:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1186095 X-Patchwork-Delegate: blogic@openwrt.org 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.b="o4/sTmWy"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gil2daRj"; 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 472WRN62R7z9sPc for ; Tue, 29 Oct 2019 23:41:20 +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=I7lTaaNPK4CEg/9FsC0SwQjp4v6Ps66vaRsUO+SHJZ8=; b=o4/sTmWy2zOsnS OC9YOLdJGic37FK5jG9YGUgAUsF9GFSFIxFUbp1+Du1krSV29bwm4k5sWdVWL8zg66bDdebK55h8a 96FnIzr/YAqtm+eesvQI5h64Cb15qkcv3hrGH0u+0fv8x+5797YI/2wFoUD92luPOJDueU3pqeIFa ynPHsSDy1jdgefzaD5dFjWYywjqjYMYpwtjmnoqwqiW2iEMdZZR6x7o1fM31yCQnG39LG4skwOsFR MgcMBn9yEJ2zSdn0zMmHGlW3TLMRKv4Nj7mIjJwVw8fBmJ0ZKT0tW2pEvUFmtQIGiHx9zFuhFo7XM NhliaNAMIuD+OFJQ4JKw==; 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 1iPQoE-0003JE-2A; Tue, 29 Oct 2019 12:41:14 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iPQnQ-0002Og-Bj for openwrt-devel@lists.openwrt.org; Tue, 29 Oct 2019 12:40:25 +0000 Received: by mail-pl1-x642.google.com with SMTP id v5so7542410ply.10 for ; Tue, 29 Oct 2019 05:40:24 -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=7WeNwfqgMsQCrvj7+pUxr4Stsw09iaXK00TRJPTT+Vg=; b=Gil2daRjVeLmK6s8R4X1xGkcxO6bE6nzltWw49vSWChDOU3b7e3rkUNDFfhr22YSyZ SgRQLPUX2Ih4AeroVBZKHj0yeAW1yOgGvJNnPM5U1JAWcIvY1bd3MR63MLXherbNuMVX z9U4GFCtZwj5bNeYaxD7bdSRYOd5RuslEpcOUZpJRBdLPh6zYpzR4ENbpwIGLE60XBQl 71+w6hx9E9npPVXRDIwkrD3LFEO33h72jtC0da3Ev5g0tDa34RSeByQYGt7nJNQBJ2XR PrUGTdQ/ERfmtcPa92LQl4jxsqIH50TMWJaVIWaW9O8+mCrFD+sxScpJfVxSm0Va6mbz 77Fg== 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=7WeNwfqgMsQCrvj7+pUxr4Stsw09iaXK00TRJPTT+Vg=; b=iPKZbCWFKYh9zFOtFysATUHQhG6S4k7w5Rl/ddDqEC+WVudMA13cMMqb5XlRd1vBvx l2rclSz9M0D1Ls5hC9LvRngjYVVSx1K3ZdjVxKBtwcJq4GTfjiSBWvPKc1gOvM4QPuyO eCh7gcTrujnz081mOsG2whezzeolK1ftCEiaUGBvAzcbfWrSUnMe/9ymMCBGzPjofEDs 3MdKKlzaYn63mdU1KWFaVk191FAMQUkwhZ7uTA6zlVP0wZYwdY4Vud1EDSaFNflzGSqA ToE6Dd744Ioaznt+4Q5a5XTOxuqQgK/KAkN9vNLonioHyt7KV1K5AvUX/1iGP2fXnc9k /dXA== X-Gm-Message-State: APjAAAVsuGEciy8iPNdAsZ5LfYvabYxVL4HQIJXtrNCvd+Do9lQdC/nv lWB0QaNLZa3eLcR1f66JIO2h1kqr X-Google-Smtp-Source: APXvYqxk5hwrlOUesnR3crGGBgLiZCLcyv3isJEdf7Sm86+Eshv+qcuUQ3XI9iLyzURvZywY7caj6Q== X-Received: by 2002:a17:902:7289:: with SMTP id d9mr3997335pll.121.1572352822837; Tue, 29 Oct 2019 05:40:22 -0700 (PDT) Received: from titan.hq.cloud.yunionyun.com ([161.117.5.46]) by smtp.gmail.com with ESMTPSA id b26sm1090782pgs.93.2019.10.29.05.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 05:40:22 -0700 (PDT) From: Yousong Zhou To: john@phrozen.org Date: Tue, 29 Oct 2019 12:39:50 +0000 Message-Id: <20191029123950.40794-5-yszhou4tech@gmail.com> In-Reply-To: <20191029123950.40794-1-yszhou4tech@gmail.com> References: <20191029123950.40794-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191029_054024_474705_1AD00DC6 X-CRM114-Status: GOOD ( 10.61 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.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:642 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 (yszhou4tech[at]gmail.com) -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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH fstools 5/5] block: mount_device: err log only when mp deviates from spec 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: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Fixes possible memleak of mp as well Resolves FS#1523 Signed-off-by: Yousong Zhou --- block.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 084e7fc..1972c50 100644 --- a/block.c +++ b/block.c @@ -1092,10 +1092,14 @@ static int mount_device(struct device *dev, int type) return -1; mp = find_mount_point(pr->dev); - if (mp && (type != TYPE_HOTPLUG)) { - ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp); + if (mp) { + if (m && m->type == TYPE_MOUNT && strcmp(m->target, mp)) { + ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp); + err = -1; + } else + err = 0; free(mp); - return -1; + return err; } if (type == TYPE_HOTPLUG)