From patchwork Tue May 16 05:42:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Vagin X-Patchwork-Id: 9728367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4D237602B4 for ; Tue, 16 May 2017 05:42:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 426692890B for ; Tue, 16 May 2017 05:42:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36F0B289DC; Tue, 16 May 2017 05:42:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0F9D2890B for ; Tue, 16 May 2017 05:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751291AbdEPFme (ORCPT ); Tue, 16 May 2017 01:42:34 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35002 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751157AbdEPFmc (ORCPT ); Tue, 16 May 2017 01:42:32 -0400 Received: by mail-pg0-f67.google.com with SMTP id i63so20039228pgd.2; Mon, 15 May 2017 22:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PfxX6GIAZqZqb/RoplKXHBy2pACa6oY01jloczrYmbo=; b=q1gIJCNr0tgZVN3sG/ZeJ11BLLvQdi4Fjp9imoczwJ468X31HIeHy0G86LdoGYwhEU 5y4mjt1Y0woQffKJcf+wV8XP/L3flQVCZnAbNWX96RWIyqz9KTV/Ge4byzvgvsjfqOJb rx1DQNWNHoMxhFTLSiBhxDMAjavSzWHRcPnwR4rNoXqFnG+indDMlRMjo+Kybm51A78k X4sWuJa7YZRLhXx6iAqLA+qRcsro5iILsOC23EEifB9ibudkNzZ8y/sXtDDENefVY3WN rgdKkMgMGUDR4qnKUfFFzwUuMpS4RKCQWCSRDuPQREH+nwaWtNuj8bNPAGTQpEbSZf0s EoIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PfxX6GIAZqZqb/RoplKXHBy2pACa6oY01jloczrYmbo=; b=rVRMd5tMnn5oVwdds9GRu4L0Y18CpMAV/70uqSojAXC9RJp3dPB9JS40FsRju8WQaB 7vDQS8eSSNBMv7EkK6fkRlIMbOjafi6IAnPab3yMVg3LBkHSi9ax9svVH4NjCIVJSo7u zcTb+opIcY1LQw3uP/lQxrT/e+Qjb0PePrgJRRPlbSNoFYtoIa1UkF9OwBCz8u20CAwa Ol8mshvgSnzyfmHqUygNnBdVj/zuPNnmAXBmsV21PHoimZm2Ix9KvgKn8vH5SN1vMxdG LaMTSUYcojezFc++h9NRr/320tqJjuXAHr1DWHA0JI18siK3Xe/v6q3/jb8HmOwyAEUM O8AQ== X-Gm-Message-State: AODbwcCJ0J9WLbxzro+fWbddD4GgBFH+ZgVU+78hxj4GcinZbmZAunEA 32S4ZQXO1ZgJ7/ytEdo= X-Received: by 10.84.128.66 with SMTP id 60mr13470768pla.167.1494913351957; Mon, 15 May 2017 22:42:31 -0700 (PDT) Received: from localhost.localdomain (c-73-140-212-29.hsd1.wa.comcast.net. [73.140.212.29]) by smtp.gmail.com with ESMTPSA id q27sm22329816pfk.4.2017.05.15.22.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 May 2017 22:42:30 -0700 (PDT) From: Andrei Vagin To: "Eric W . Biederman" Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Andrei Vagin , Shuah Khan Subject: [PATCH] test: check a case when a mount is propagated between exiting mounts Date: Mon, 15 May 2017 22:42:17 -0700 Message-Id: <20170516054217.29119-1-avagin@openvz.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <871srpj2yp.fsf_-_@xmission.com> References: <871srpj2yp.fsf_-_@xmission.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This test checks two behaviour cases: When a mount is propagated to a place which is already busy, the new mount is inserted between parent and old mount. When a mount that is being unmounted due to propagation has another mount on top of it, it is replaced by the top mount. Cc: Shuah Khan Signed-off-by: Andrei Vagin --- tools/testing/selftests/mount/Makefile | 19 +++-- tools/testing/selftests/mount/test-reparent-mounts | 92 ++++++++++++++++++++++ 2 files changed, 105 insertions(+), 6 deletions(-) create mode 100755 tools/testing/selftests/mount/test-reparent-mounts diff --git a/tools/testing/selftests/mount/Makefile b/tools/testing/selftests/mount/Makefile index 9093d7f..5927230 100644 --- a/tools/testing/selftests/mount/Makefile +++ b/tools/testing/selftests/mount/Makefile @@ -6,11 +6,18 @@ TEST_GEN_PROGS := unprivileged-remount-test include ../lib.mk -override RUN_TESTS := if [ -f /proc/self/uid_map ] ; \ - then \ - ./unprivileged-remount-test ; \ - else \ - echo "WARN: No /proc/self/uid_map exist, test skipped." ; \ - fi +override define RUN_TESTS + if [ -f /proc/self/uid_map ] ; \ + then \ + ./unprivileged-remount-test ; \ + else \ + echo "WARN: No /proc/self/uid_map exist, test skipped." ; \ + fi + unshare -Urm ./test-reparent-mounts + unshare -Urm ./test-reparent-mounts -c + unshare -Urm ./test-reparent-mounts -s + unshare -Urm ./test-reparent-mounts -s -S +endef + override EMIT_TESTS := echo "$(RUN_TESTS)" diff --git a/tools/testing/selftests/mount/test-reparent-mounts b/tools/testing/selftests/mount/test-reparent-mounts new file mode 100755 index 0000000..57ae300 --- /dev/null +++ b/tools/testing/selftests/mount/test-reparent-mounts @@ -0,0 +1,92 @@ +#!/bin/sh + +# This test checks two following behaviour cases: +# +# When a mount is propagated to a place which is already busy, the new mount is +# inserted between parent and old mount. +# +# When a mount that is being unmounted due to propagation has another mount on +# top of it, it is replaced by the top mount. + +ITER=3 + +set -e + +usage() +{ + echo " ./$0 [OPTIONS] +This test checks a case when a mount has to be propagated under another mount. + -c - create a mount which is visible only from the second tree + -s - make a second tree as a slave to the first one + -S - create a sub-mount when the send tree is a slave to the first one + -i - how many times to call mount +" +} + +while getopts "csi:hS" opt; do + case $opt in + c ) with_child=1;; + s ) make_slave=1;; + S ) slave_child=1;; + i ) ITER=$OPTARG;; + h ) usage; exit 0 ;; + esac +done + +shift $(($OPTIND - 1)) + +if [ -n "$1" ]; then + usage + exit 1 +fi + +mount -t tmpfs test /mnt +mkdir /mnt/main +mkdir /mnt/second +mount --bind /mnt/main /mnt/main +mount --make-shared /mnt/main +mount --bind /mnt/main /mnt/second +mkdir -p /mnt/main/sub + +if [ -n "$make_slave" ]; then + mount --make-slave /mnt/second + if [ -n "slave_child" ]; then + mount -t tmpfs slave_child /mnt/second/sub/ + touch /mnt/second/sub/slave_child + fi +fi + +if [ -n "$make_slave" ]; then + mount --make-slave /mnt/second + if [ -n "$slave_child" ]; then + mount -t tmpfs test_slave /mnt/second/sub/ + touch /mnt/second/sub/slave_child + fi +fi + +for i in `seq $ITER`; do + mount --bind /mnt/main/sub /mnt/main/sub +done + +if [ -n "$with_child" ]; then + mkdir /mnt/second/sub/child + mount --make-private /mnt/second/sub + mount --bind /mnt/second/sub/child /mnt/second/sub/child +fi +if [ -n "$slave_child" ]; then + test -f /mnt/second/sub/slave_child +fi + +umount /mnt/main/sub + +if [ -n "$with_child" ]; then + umount /mnt/second/sub/child + umount /mnt/second/sub +fi +if [ -n "$slave_child" ]; then + test -f /mnt/second/sub/slave_child + umount /mnt/second/sub +fi + +umount /mnt/second +umount /mnt/main