public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: Matus Marhefka <mmarhefk@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH 2/2 v2] containers: added mountns/mountns04.c
Date: Thu, 4 Sep 2014 10:21:38 -0400 (EDT)	[thread overview]
Message-ID: <2033057817.18477225.1409840498036.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <1409320025-12778-1-git-send-email-mmarhefk@redhat.com>




----- Original Message -----
> From: "Matus Marhefka" <mmarhefk@redhat.com>
> To: ltp-list@lists.sourceforge.net
> Sent: Friday, 29 August, 2014 3:47:05 PM
> Subject: [LTP] [PATCH 2/2 v2] containers: added mountns/mountns04.c
> 
> * Tests an unbindable mount: unbindable mount is an unbindable
>   private mount
> 
> Signed-off-by: Matus Marhefka <mmarhefk@redhat.com>
> ---
>  runtest/containers                              |   1 +
>  testcases/kernel/containers/.gitignore          |   1 +
>  testcases/kernel/containers/mountns/mountns04.c | 124
>  ++++++++++++++++++++++++
>  3 files changed, 126 insertions(+)
>  create mode 100644 testcases/kernel/containers/mountns/mountns04.c
> 
> diff --git a/runtest/containers b/runtest/containers
> index 3653c9c..8e8e067 100644
> --- a/runtest/containers
> +++ b/runtest/containers
> @@ -59,3 +59,4 @@ utstest_clone_5 utstest clone 5
>  mountns01 mountns01
>  mountns02 mountns02
>  mountns03 mountns03
> +mountns04 mountns04
> diff --git a/testcases/kernel/containers/.gitignore
> b/testcases/kernel/containers/.gitignore
> index 5b96cb9..4a98373 100644
> --- a/testcases/kernel/containers/.gitignore
> +++ b/testcases/kernel/containers/.gitignore
> @@ -2,3 +2,4 @@
>  mountns/mountns01
>  mountns/mountns02
>  mountns/mountns03
> +mountns/mountns04
> diff --git a/testcases/kernel/containers/mountns/mountns04.c
> b/testcases/kernel/containers/mountns/mountns04.c
> new file mode 100644
> index 0000000..32ba8c9
> --- /dev/null
> +++ b/testcases/kernel/containers/mountns/mountns04.c
> @@ -0,0 +1,124 @@
> +/* Copyright (c) 2014 Red Hat, Inc.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of version 2 the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + ***********************************************************************
> + * File: mountns04.c
> + *
> + * Tests an unbindable mount: unbindable mount is an unbindable
> + * private mount.
> + * Description:
> + * 1. Creates directories "A", "B" and files "A/A", "B/B"
> + * 2. Unshares mount namespace and makes it private (so mounts/umounts
> + *    have no effect on a real system)
> + * 3. Bind mounts directory "A" to "A" and "B" to "B"
> + * 4. Makes directory "B" shared and directory "A" unbindable

Hi,

Same question as for mountns03, is it necessary for B to be bind mounted
to itself and shared?

Regards,
Jan

> + * 5. Tries to bind mount unbindable "A" to "B":
> + *    - if it fails, test passes
> + *    - if it passes, test fails
> + ***********************************************************************/
> +
> +#define _GNU_SOURCE
> +#include <sys/wait.h>
> +#include <sys/mount.h>
> +#include <stdio.h>
> +#include <errno.h>
> +#include "test.h"
> +#include "usctest.h"
> +#include "libclone.h"
> +#include "safe_macros.h"
> +#include "safe_file_ops.h"
> +#include "mountns_helper.h"
> +
> +
> +#define DIRA "A"
> +#define DIRB "B"
> +char *TCID	= "mountns04";
> +int TST_TOTAL	= 1;
> +
> +
> +/* checks if following mountflags are defined */
> +#if defined(MS_SHARED) && defined(MS_PRIVATE) \
> +    && defined(MS_REC) && defined(MS_UNBINDABLE)
> +
> +static void cleanup(void)
> +{
> +	umount(DIRA);
> +	umount(DIRB);
> +	tst_rmdir();
> +}
> +
> +static void setup(void)
> +{
> +	tst_require_root(NULL);
> +	check_newns();	/* from mountns_helper.h */
> +	tst_tmpdir();
> +	SAFE_MKDIR(cleanup, DIRA, 0777);
> +	SAFE_MKDIR(cleanup, DIRB, 0777);
> +	SAFE_TOUCH(cleanup, DIRA"/A", 0, NULL);
> +	SAFE_TOUCH(cleanup, DIRB"/B", 0, NULL);
> +}
> +
> +static void test(void)
> +{
> +	/* unshares the mount ns */
> +	if (unshare(CLONE_NEWNS) == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
> +	/* makes sure mounts/umounts have no effect on a real system */
> +	SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
> +
> +	/* bind mounts DIRA to itself */
> +	SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
> +	/* bind mounts DIRB to itself */
> +	SAFE_MOUNT(cleanup, DIRB, DIRB, "none", MS_BIND, NULL);
> +
> +	/* makes mount DIRA unbindable */
> +	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_UNBINDABLE, NULL);
> +	/* makes mount DIRB shared */
> +	SAFE_MOUNT(cleanup, "none", DIRB, "none", MS_SHARED, NULL);
> +
> +	/* tries to bind mount unbindable DIRA to DIRB which should fail */
> +	if (mount(DIRA, DIRB, "none", MS_BIND, NULL) == -1)
> +		tst_resm(TPASS, "unbindable mount passed");
> +	else {
> +		SAFE_UMOUNT(cleanup, DIRB);
> +		tst_resm(TFAIL, "unbindable mount faled");
> +	}
> +
> +	SAFE_UMOUNT(cleanup, DIRA);
> +	SAFE_UMOUNT(cleanup, DIRB);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +	const char *msg;
> +	int lc;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++)
> +		test();
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +#else /* MS_SHARED && MS_PRIVATE && MS_REC && MS_UNBINDABLE */
> +int main(void)
> +{
> +	tst_brkm(TCONF, NULL, "needed mountflags are not defined");
> +}
> +#endif
> --
> 1.8.3.1
> 
> 
> ------------------------------------------------------------------------------
> Slashdot TV.
> Video for Nerds.  Stuff that matters.
> http://tv.slashdot.org/
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
> 

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2014-09-04 14:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26  9:59 [LTP] [PATCH 1/2] containers: added mountns/mountns03.c Matus Marhefka
2014-08-26  9:59 ` [LTP] [PATCH 2/2] containers: added mountns/mountns04.c Matus Marhefka
2014-08-29 13:47   ` [LTP] [PATCH 2/2 v2] " Matus Marhefka
2014-09-04 14:21     ` Jan Stancek [this message]
2014-10-02 13:47       ` Cyril Hrubis
     [not found]         ` <1080778288.46330076.1412258911538.JavaMail.zimbra@redhat.com>
2014-10-15 12:39           ` Cyril Hrubis
2014-09-24  8:14     ` chrubis
2014-10-02 12:29   ` [LTP] [PATCH 2/2 v3] " Matus Marhefka
2014-08-29 13:46 ` [LTP] [PATCH 1/2 v2] containers: added mountns/mountns03.c Matus Marhefka
2014-09-04 14:13   ` Jan Stancek
2014-09-11 15:09     ` Jiri Jaburek
2014-09-12 12:59       ` Jan Stancek
2014-09-12 13:41         ` Jiri Jaburek
2014-09-12 14:19           ` Jan Stancek
2014-09-24  7:56   ` chrubis
     [not found]     ` <273164774.30346037.1411649870605.JavaMail.zimbra@redhat.com>
     [not found]       ` <461070711.43439951.1411650253035.JavaMail.zimbra@redhat.com>
2014-09-29  8:14         ` chrubis
2014-10-02 12:28 ` [LTP] [PATCH 1/2 v3] " Matus Marhefka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2033057817.18477225.1409840498036.JavaMail.zimbra@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=mmarhefk@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox