Commit a03323e1 authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm: Basic test for mount points in mount namespace

Test with sysfs and proc as no other fs-s are currently supported.
Will be fixed later.

Note, that the original /proc mount is kept as the dumping code requires
it for reading pagemap file with RSS info. Worth fixing it some day?
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a201f598
...@@ -53,6 +53,10 @@ transition/fork ...@@ -53,6 +53,10 @@ transition/fork
static/file_fown static/file_fown
" "
MNT_TEST_LIST="
static/mountpoints
"
# These ones are in pidns # These ones are in pidns
TEST_LIST="$TEST_LIST TEST_LIST="$TEST_LIST
pidns/static/session00 pidns/static/session00
...@@ -230,11 +234,14 @@ if [ $# -eq 0 ]; then ...@@ -230,11 +234,14 @@ if [ $# -eq 0 ]; then
for t in $UTS_TEST_LIST; do for t in $UTS_TEST_LIST; do
run_test $t -n uts || case_error $t run_test $t -n uts || case_error $t
done done
for t in $MNT_TEST_LIST; do
run_test $t -n mnt || case_error $t
done
for t in $IPC_TEST_LIST; do for t in $IPC_TEST_LIST; do
run_test $t -n ipc || case_error $t run_test $t -n ipc || case_error $t
done done
elif [ "$1" == "-l" ]; then elif [ "$1" == "-l" ]; then
echo $TEST_LIST $UTS_TEST_LIST $IPC_TEST_LIST | tr ' ' '\n' echo $TEST_LIST $UTS_TEST_LIST $MNT_TEST_LIST $IPC_TEST_LIST | tr ' ' '\n'
elif [ "$1" == "-h" ]; then elif [ "$1" == "-h" ]; then
cat >&2 <<EOF cat >&2 <<EOF
This script is used for executing unit tests. This script is used for executing unit tests.
...@@ -248,6 +255,8 @@ EOF ...@@ -248,6 +255,8 @@ EOF
else else
if echo $UTS_TEST_LIST | fgrep -qw $1; then if echo $UTS_TEST_LIST | fgrep -qw $1; then
run_test $1 -n uts || case_error $1 run_test $1 -n uts || case_error $1
elif echo $MNT_TEST_LIST | fgrep -qw $1; then
run_test $1 -n mnt || case_error $1
elif echo $IPC_TEST_LIST | fgrep -qw $1; then elif echo $IPC_TEST_LIST | fgrep -qw $1; then
run_test $1 -n ipc || case_error $1 run_test $1 -n ipc || case_error $1
else else
......
...@@ -50,6 +50,7 @@ TST_NOFILE = \ ...@@ -50,6 +50,7 @@ TST_NOFILE = \
session00 \ session00 \
pty00 \ pty00 \
tty00 \ tty00 \
mountpoints \
# jobctl00 \ # jobctl00 \
TST_FILE = \ TST_FILE = \
......
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include "zdtmtst.h"
const char *test_doc = "Check that mountpoints (in mount namespace) are supported";
const char *test_author = "Pavel Emelianov <xemul@parallels.com>";
#define MPTS_ROOT "/zdtm_mpts/"
static char buf[1024];
static int test_fn(int argc, char **argv)
{
FILE *f;
unsigned fs_cnt, fs_cnt_last = 0;
again:
fs_cnt = 0;
f = fopen("/proc/self/mountinfo", "r");
if (!f) {
fail("Can't open mountinfo");
return -1;
}
while (fgets(buf, sizeof(buf), f) != NULL) {
char *mp = buf, *end;
mp = strchr(mp, ' ') + 1;
mp = strchr(mp, ' ') + 1;
mp = strchr(mp, ' ') + 1;
mp = strchr(mp, ' ') + 1;
end = strchr(mp, ' ');
*end = '\0';
if (!strcmp(mp, "/"))
continue;
if (!strcmp(mp, "/proc"))
continue;
umount(mp);
fs_cnt++;
}
fclose(f);
if (fs_cnt == 0)
goto done;
if (fs_cnt != fs_cnt_last) {
fs_cnt_last = fs_cnt;
goto again;
}
fail("Can't umount all the filesystems");
return -1;
done:
close(0);
close(1);
close(2);
rmdir(MPTS_ROOT);
if (mkdir(MPTS_ROOT, 0600) < 0) {
fail("Can't make zdtm_sys");
return 1;
}
if (mount("none", MPTS_ROOT, "sysfs", 0, "") < 0) {
fail("Can't mount sysfs");
return 1;
}
if (mount("none", MPTS_ROOT"/kernel/debug", "proc", 0, "") < 0) {
fail("Can't mount proc");
return 1;
}
test_daemon();
test_waitsig();
/* this checks both -- sys and proc presence */
if (access(MPTS_ROOT"/kernel/debug/slabinfo", F_OK)) {
fail("No proc after restore");
return 1;
}
pass();
return 0;
}
#define CLONE_NEWNS 0x00020000
int main(int argc, char **argv)
{
test_init_ns(argc, argv, CLONE_NEWNS, test_fn);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment