Skip to content

Commit

Permalink
zdtm: add a test for non-uniform shares
Browse files Browse the repository at this point in the history
Create a tree of shared mounts where shared mounts have different sets
of children (while having the same root):

First share1 is mounted shared tmpfs and second share1/child1 is mounted
inside, third share1 is bind-mounted to share2 (now share1 and share2
have the same shared id, but share2 has no child), fourth share1/child2
is bind-mounted from share1, and also propagated to share2/child2 (now
all except share1/child1 have the same shared id), fifth share1/child3
is mounted and propagates inside the share.

Finally we have four mounts shared between each other with different
sets of children mounts, and even more two of them are children of
another two:

495 494 0:62 / /zdtm/static/non_uniform_share_propagation.test/share1 rw,relatime shared:235 - tmpfs share rw
496 495 0:63 / /zdtm/static/non_uniform_share_propagation.test/share1/child1 rw,relatime shared:236 - tmpfs child1 rw
497 494 0:62 / /zdtm/static/non_uniform_share_propagation.test/share2 rw,relatime shared:235 - tmpfs share rw
498 495 0:62 / /zdtm/static/non_uniform_share_propagation.test/share1/child2 rw,relatime shared:235 - tmpfs share rw
499 497 0:62 / /zdtm/static/non_uniform_share_propagation.test/share2/child2 rw,relatime shared:235 - tmpfs share rw
500 495 0:64 / /zdtm/static/non_uniform_share_propagation.test/share1/child3 rw,relatime shared:237 - tmpfs child3 rw
503 497 0:64 / /zdtm/static/non_uniform_share_propagation.test/share2/child3 rw,relatime shared:237 - tmpfs child3 rw
502 499 0:64 / /zdtm/static/non_uniform_share_propagation.test/share2/child2/child3 rw,relatime shared:237 - tmpfs child3 rw
501 498 0:64 / /zdtm/static/non_uniform_share_propagation.test/share1/child2/child3 rw,relatime shared:237 - tmpfs child3 rw

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
  • Loading branch information
Snorch authored and avagin committed Jul 11, 2018
1 parent a717fee commit 594c3a4
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/zdtm/static/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ TST_DIR = \
sk-unix01 \
unsupported_children_collision \
shared_slave_mount_children \
non_uniform_share_propagation \

TST_DIR_FILE = \
chroot \
Expand Down
131 changes: 131 additions & 0 deletions test/zdtm/static/non_uniform_share_propagation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <sys/mount.h>
#include <sys/stat.h>
#include <limits.h>

#include "zdtmtst.h"

const char *test_doc = "Check non-uniform shares restore fine";
const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";

char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);

int main(int argc, char **argv)
{
char share1[PATH_MAX], share2[PATH_MAX];
char child1[PATH_MAX], child2[PATH_MAX], child3[PATH_MAX];

test_init(argc, argv);

if (mkdir(dirname, 0700)) {
pr_perror("mkdir");
return 1;
}

if (mount("zdtm_fs", dirname, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}

if (mount(NULL, dirname, NULL, MS_PRIVATE, NULL)) {
pr_perror("mount");
return 1;
}

snprintf(share1, sizeof(share1), "%s/share1", dirname);
if (mkdir(share1, 0700)) {
pr_perror("mkdir");
return 1;
}

if (mount("share", share1, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}

if (mount(NULL, share1, NULL, MS_SHARED, NULL)) {
pr_perror("mount");
return 1;
}

snprintf(child1, sizeof(child1), "%s/share1/child1", dirname);
if (mkdir(child1, 0700)) {
pr_perror("mkdir");
return 1;
}

if (mount("child1", child1, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}

snprintf(share2, sizeof(share2), "%s/share2", dirname);
if (mkdir(share2, 0700)) {
pr_perror("mkdir");
return 1;
}

if (mount(share1, share2, NULL, MS_BIND, NULL)) {
pr_perror("mount");
return 1;
}

snprintf(child2, sizeof(child2), "%s/share1/child2", dirname);
if (mkdir(child2, 0700)) {
pr_perror("mkdir");
return 1;
}

if (mount(share1, child2, NULL, MS_BIND, NULL)) {
pr_perror("mount");
return 1;
}

snprintf(child3, sizeof(child3), "%s/share1/child3", dirname);
if (mkdir(child3, 0700)) {
pr_perror("mkdir");
return 1;
}

if (mount("child3", child3, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}

test_daemon();
test_waitsig();

if (umount(child3)) {
pr_perror("Unable to umount %s", child1);
return 1;
}

if (umount(child2)) {
pr_perror("Unable to umount %s", share1);
return 1;
}

if (umount(share2)) {
pr_perror("Unable to umount %s", share2);
return 1;
}

if (umount(child1)) {
pr_perror("Unable to umount %s", child1);
return 1;
}

if (umount(share1)) {
pr_perror("Unable to umount %s", share1);
return 1;
}

if (umount(dirname)) {
pr_perror("Unable to umount %s", dirname);
return 1;
}

pass();

return 0;
}
1 change: 1 addition & 0 deletions test/zdtm/static/non_uniform_share_propagation.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'flavor': 'ns uns', 'flags': 'suid'}

0 comments on commit 594c3a4

Please sign in to comment.