Esempio n. 1
0
static void test(void)
{
	int status;

	/* unshares the mount ns */
	if (unshare(CLONE_NEWNS) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
	/* makes sure parent 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);

	/* makes mount DIRA shared */
	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_SHARED, NULL);

	if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");

	/* waits for child to make a slave mount */
	TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1);

	/* bind mounts DIRB to DIRA making contents of DIRB visible
	 * in DIRA */
	SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL);

	TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2);
	TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1);

	SAFE_UMOUNT(cleanup, DIRA);

	TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2);
	TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1);

	/* checks that slave mount doesn't propagate to shared mount */
	if ((access(DIRA"/A", F_OK) == 0) && (access(DIRA"/B", F_OK) == -1))
		tst_resm(TPASS, "propagation from slave mount passed");
	else
		tst_resm(TFAIL, "propagation form slave mount failed");

	TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2);


	SAFE_WAIT(cleanup, &status);
	if (WIFEXITED(status)) {
		if (WEXITSTATUS(status) == 0)
			tst_resm(TPASS, "propagation to slave mount passed");
		else
			tst_resm(TFAIL, "propagation to slave mount failed");
	}
	if (WIFSIGNALED(status)) {
		tst_resm(TBROK, "child was killed with signal %s",
			 tst_strsig(WTERMSIG(status)));
		return;
	}

	SAFE_UMOUNT(cleanup, DIRA);
}
Esempio n. 2
0
static void test(void)
{
	int status;

	/* unshares the mount ns */
	if (unshare(CLONE_NEWNS) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
	/* makes sure parent 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);

	/* makes mount DIRA shared */
	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_SHARED, NULL);

	if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1)
		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");

	/* bind mounts DIRB to DIRA making contents of DIRB visible
	 * in DIRA */
	SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL);

	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);

	SAFE_UMOUNT(cleanup, DIRA);

	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);

	if (access(DIRA"/B", F_OK) == 0)
		tst_resm(TPASS, "shared mount in child passed");
	else
		tst_resm(TFAIL, "shared mount in child failed");

	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);


	SAFE_WAIT(cleanup, &status);
	if (WIFEXITED(status)) {
		if ((WEXITSTATUS(status) == 0))
			tst_resm(TPASS, "shared mount in parent passed");
		else
			tst_resm(TFAIL, "shared mount in parent failed");
	}
	if (WIFSIGNALED(status)) {
		tst_resm(TBROK, "child was killed with signal %s",
			 tst_strsig(WTERMSIG(status)));
		return;
	}

	SAFE_UMOUNT(cleanup, DIRA);
}
Esempio n. 3
0
int main(int ac, char **av)
{
	int lc;
	int tc;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
		mount_flag = 1;

		for (tc = 0; tc < TST_TOTAL; tc++)
			test_umount2(tc);

		if (mount_flag) {
			SAFE_UMOUNT(cleanup, MNTPOINT);
			mount_flag = 0;
		}
	}

	cleanup();
	tst_exit();
}
Esempio n. 4
0
static void setup(void)
{
	unsigned int i;
	int fd;

	SAFE_MKDIR(TMP_DIR, 0664);
	SAFE_MOUNT(TMP_DIR, TMP_DIR, "tmpfs", 0, NULL);

	fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0664);

	/* Writing 40 KB of random data into this file [32 * 1280 = 40960] */
	for (i = 0; i < 1280; i++)
		SAFE_WRITE(1, fd, STR, strlen(STR));

	SAFE_FSTAT(fd, &st);

	/* Map the input file into shared memory */
	sfile = SAFE_MMAP(NULL, st.st_size,
			PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

	/* Map the input file into private memory. MADV_HUGEPAGE only works
	 * with private anonymous pages */
	amem = SAFE_MMAP(NULL, st.st_size,
			PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);

	SAFE_CLOSE(fd);
}
Esempio n. 5
0
static void setup(void)
{
	int ret;

	SAFE_MKDIR(mntpoint, DIR_MODE);

	SAFE_MOUNT(tst_device->dev, mntpoint, tst_device->fs_type, 0, NULL);
	mount_flag = 1;

	sprintf(fname, "%s/tfile_%d", mntpoint, getpid());
	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);

	ret = write(fd, fname, 1);
	if (ret == -1) {
		tst_brk(TBROK | TERRNO,
			 "write(%d, %s, 1) failed", fd, fname);
	}

	/* close the file we have open */
	SAFE_CLOSE(fd);

	fd_notify = myinotify_init();
	if (fd_notify < 0) {
		if (errno == ENOSYS)
			tst_brk(TCONF,
				"inotify is not configured in this kernel.");
		else
			tst_brk(TBROK | TERRNO,
				"inotify_init failed");
	}

	tst_umount(mntpoint);
	mount_flag = 0;
}
Esempio n. 6
0
static void setup(void)
{
	const char *fs_opts[3] = {"-b", "1024", NULL};

	tst_sig(FORK, DEF_HANDLER, NULL);
	tst_require_root();

	TEST_PAUSE;
	tst_tmpdir();

	TST_CHECKPOINT_INIT(tst_rmdir);

	page_size = getpagesize();

	device = tst_acquire_device(cleanup);
	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
	tst_mkfs(cleanup, device, fs_type, fs_opts, "10240");

	SAFE_MKDIR(cleanup, MNTPOINT, 0755);
	/*
	 * Disable ext4 delalloc feature, so block will be allocated
	 * as soon as possible
	 */
	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, "nodelalloc");
	mount_flag = 1;

	SAFE_CHDIR(cleanup, MNTPOINT);
	chdir_flag = 1;

}
Esempio n. 7
0
static void setup(void)
{
	check_hugepage();
	hugepagesize = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
	init_sys_sz_paths();

	if (opt_sysfs) {
		path = path_sys_sz_huge;
		pathover = path_sys_sz_over;
	} else {
		path = PATH_PROC_HUGE;
		pathover = PATH_PROC_OVER;
	}

	if (opt_alloc) {
		size = atoi(opt_alloc);
		length = (size + size * 0.5) * 2;
	}

	if (opt_shmid) {
		SAFE_FILE_SCANF(PATH_SHMMAX, "%llu", &shmmax);
		if (shmmax < (unsigned long long)(length / 2 * hugepagesize)) {
			restore_shmmax = 1;
			SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld",
					(length / 2 * hugepagesize));
		}
	}

	SAFE_FILE_SCANF(path, "%ld", &nr_hugepages);
	tst_res(TINFO, "original nr_hugepages is %ld", nr_hugepages);

	/* Reset. */
	SAFE_FILE_PRINTF(path, "%ld", size);
	restore_nr_hgpgs = 1;

	if (access(pathover, F_OK)) {
		tst_brk(TCONF, "file %s does not exist in the system",
			pathover);
	}

	SAFE_FILE_SCANF(pathover, "%ld", &nr_overcommit_hugepages);
	tst_res(TINFO, "original nr_overcommit_hugepages is %ld",
		nr_overcommit_hugepages);

	/* Reset. */
	SAFE_FILE_PRINTF(pathover, "%ld", size);
	restore_overcomm_hgpgs = 1;

	SAFE_MKDIR(MOUNT_DIR, 0700);
	SAFE_MOUNT(NULL, MOUNT_DIR, "hugetlbfs", 0, NULL);
	mounted = 1;

	if (opt_shmid) {
		/* Use /proc/meminfo to generate an IPC key. */
		key = ftok(PATH_MEMINFO, strlen(PATH_MEMINFO));
		if (key == -1)
			tst_brk(TBROK | TERRNO, "ftok");
	}
}
Esempio n. 8
0
static void setup(void)
{
	SAFE_MKDIR(MOUNT_NAME, 0755);
	SAFE_MOUNT(MOUNT_NAME, MOUNT_NAME, "none", MS_BIND, NULL);
	mount_created = 1;
	SAFE_CHDIR(MOUNT_NAME);
	SAFE_MKDIR(DIR_NAME, 0755);

	sprintf(fname, "tfile_%d", getpid());
	SAFE_FILE_PRINTF(fname, "1");
}
Esempio n. 9
0
static void setup(void)
{
    SAFE_MKDIR(mntpoint, 0755);

    SAFE_MKFS(tst_device->dev, "xfs", NULL, NULL);

    SAFE_MOUNT(tst_device->dev, mntpoint, "xfs", 0, "usrquota");
    mount_flag = 1;

    test_id = geteuid();
}
Esempio n. 10
0
static void setup(void)
{
	struct passwd *pw;

	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
	SAFE_MKDIR(MNTPOINT, 0775);
	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
	mount_flag = 1;

	pw = SAFE_GETPWNAM("nobody");
	SAFE_SETEUID(pw->pw_uid);
}
Esempio n. 11
0
static void prepare_device(void)
{
	if (tst_test->format_device) {
		SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
			  tst_test->dev_extra_opt);
	}

	if (tst_test->mount_device) {
		SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
			   tst_test->mnt_flags, tst_test->mnt_data);
		mntpoint_mounted = 1;
	}
}
Esempio n. 12
0
File: mountns04.c Progetto: 1587/ltp
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);
	/* makes mount DIRA unbindable */
	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_UNBINDABLE, 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);
}
Esempio n. 13
0
void setup(void)
{
	save_nr_hugepages();

	if (!Hopt)
		Hopt = tst_get_tmpdir();
	SAFE_MOUNT("none", Hopt, "hugetlbfs", 0, NULL);

	if (nr_opt)
		hugepages = SAFE_STRTOL(nr_opt, 0, LONG_MAX);
	set_sys_tune("nr_hugepages", hugepages, 1);

	snprintf(TEMPFILE, sizeof(TEMPFILE), "%s/mmapfile%d", Hopt, getpid());
}
Esempio n. 14
0
File: mount03.c Progetto: kraj/ltp
static void setup(void)
{
	char path[PATH_MAX];
	struct stat file_stat;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_require_root();

	tst_tmpdir();

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to obtain block device");

	tst_mkfs(cleanup, device, fs_type, NULL, NULL);

	SAFE_MKDIR(cleanup, mntpoint, DIR_MODE);

	if (getcwd(path_name, sizeof(path_name)) == NULL)
		tst_brkm(TBROK, cleanup, "getcwd failed");

	if (chmod(path_name, DIR_MODE) != 0)
		tst_brkm(TBROK, cleanup, "chmod(%s, %#o) failed",
			 path_name, DIR_MODE);

	strncpy(path, path_name, PATH_MAX);
	snprintf(path_name, PATH_MAX, "%s/%s/", path, mntpoint);

	SAFE_MOUNT(cleanup, device, mntpoint, fs_type, 0, NULL);
	TST_RESOURCE_COPY(cleanup, "mount03_setuid_test", path_name);

	snprintf(file, PATH_MAX, "%smount03_setuid_test", path_name);
	SAFE_STAT(cleanup, file, &file_stat);

	if (file_stat.st_mode != SUID_MODE &&
	    chmod(file, SUID_MODE) < 0)
		tst_brkm(TBROK, cleanup,
			 "setuid for setuid_test failed");
	SAFE_UMOUNT(cleanup, mntpoint);

	TEST_PAUSE;
}
Esempio n. 15
0
static void test_umount2(int i)
{
	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
	mount_flag = 1;

	TEST(umount2_retry(test_cases[i].mntpoint, UMOUNT_NOFOLLOW));

	if (test_cases[i].exp_errno != 0)
		verify_failure(i);
	else
		verify_success(i);

	if (mount_flag) {
		if (tst_umount(MNTPOINT))
			tst_brkm(TBROK, cleanup, "umount() failed");
		mount_flag = 0;
	}
}
Esempio n. 16
0
static void setup(void)
{
	struct statvfs fs;

	srand(getpid());

	tst_tmpdir();

	SAFE_MKDIR(tst_rmdir, MOUNT_DIR, 0777);

	TST_CHECKPOINT_INIT(tst_rmdir);

	if (statvfs(".", &fs) == -1)
		tst_brkm(TFAIL | TERRNO, tst_rmdir, "statvfs failed");

	if ((fs.f_flag & MS_MANDLOCK))
		return;

	tst_resm(TINFO, "TMPDIR does not support mandatory locks");

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to obtain block device");

	/* the kernel returns EPERM when CONFIG_MANDATORY_FILE_LOCKING is not
	 * supported - to avoid false negatives, mount the fs first without
	 * flags and then remount it as MS_MANDLOCK */

	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
	SAFE_MOUNT(cleanup, device, MOUNT_DIR, fs_type, 0, NULL);
	mount_flag = 1;

	if (mount(NULL, MOUNT_DIR, NULL, MS_REMOUNT|MS_MANDLOCK, NULL) == -1) {
		if (errno == EPERM) {
			tst_brkm(TCONF, cleanup, "Mandatory locking (likely) "
				 "not supported by this system");
		} else {
			tst_brkm(TBROK | TERRNO, cleanup,
				 "Remount with MS_MANDLOCK failed");
		}
	}
}
Esempio n. 17
0
File: mknodat02.c Progetto: kraj/ltp
static void setup(void)
{
	int i;
	const char *fs_type;

	if (tst_kvercmp(2, 6, 16) < 0) {
		tst_brkm(TCONF, NULL, "This test can only run on kernels "
			 "that are 2.6.16 and higher");
	}

	tst_require_root();

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	fs_type = tst_dev_fs_type();
	device = tst_acquire_device(cleanup);

	if (!device)
		tst_brkm(TCONF, cleanup, "Failed to acquire device");

	tst_mkfs(cleanup, device, fs_type, NULL, NULL);

	TEST_PAUSE;

	/*
	 * mount a read-only file system for EROFS test
	 */
	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL);
	mount_flag = 1;
	dir_fd = SAFE_OPEN(cleanup, MNT_POINT, O_DIRECTORY);

	/*
	 * NOTE: the ELOOP test is written based on that the consecutive
	 * symlinks limits in kernel is hardwired to 40.
	 */
	SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
	for (i = 0; i < 43; i++)
		strcat(elooppathname, ELOPFILE);
}
Esempio n. 18
0
static void setup(void)
{
	const char *mount_flags[] = {"noatime", "relatime", NULL};

	TEST_PAUSE;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);

	if (tst_path_has_mnt_flags(cleanup, NULL, mount_flags)) {
		const char *fs_type;

		if ((tst_kvercmp(2, 6, 30)) < 0) {
			tst_resm(TCONF,
				"MS_STRICTATIME flags for mount(2) needs kernel 2.6.30 "
				"or higher");
			skip_noatime = 1;
			return;
		}

		fs_type = tst_dev_fs_type();
		device = tst_acquire_device(cleanup);

		if (!device) {
			tst_resm(TINFO, "Failed to obtain block device");
			skip_noatime = 1;
			goto end;
		}

		tst_mkfs(cleanup, device, fs_type, NULL, NULL);

		SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_STRICTATIME, NULL);
		mount_flag = 1;
	}

end:
	SAFE_FILE_PRINTF(cleanup, TEST_FILE, TEST_FILE);
}
Esempio n. 19
0
File: mount05.c Progetto: kraj/ltp
void setup(void)
{
	tst_require_root();

	tst_sig(NOFORK, DEF_HANDLER, cleanup);

	tst_tmpdir();

	SAFE_MKDIR(cleanup, mntpoint_src, DIR_MODE);
	SAFE_MKDIR(cleanup, mntpoint_des, DIR_MODE);

	if (dflag) {
		tst_mkfs(NULL, device, fstype, NULL, NULL);

		SAFE_MOUNT(cleanup, device, mntpoint_src, fstype, 0, NULL);
	}

	SAFE_FILE_PRINTF(cleanup, file_src, "TEST FILE");

	TEST_PAUSE;
}
Esempio n. 20
0
File: creat06.c Progetto: 1587/ltp
static void setup(void)
{
	ltpuser = SAFE_GETPWNAM("nobody");

	SAFE_MKDIR(TEST_FILE, MODE2);

	memset(long_name, 'a', PATH_MAX+1);

	SAFE_TOUCH("file1", MODE1, NULL);

	SAFE_MKDIR("dir6", MODE2);

	SAFE_SYMLINK(TEST7_FILE, "test_file_eloop2");
	SAFE_SYMLINK("test_file_eloop2", TEST7_FILE);

	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);

	SAFE_MKDIR("mntpoint", 0777);
	SAFE_MOUNT(tst_device->dev, "mntpoint", tst_device->fs_type,
	           MS_RDONLY, NULL);
	mount_flag = 1;
}
Esempio n. 21
0
static void verify_umount(void)
{
	if (mount_flag != 1) {
		SAFE_MOUNT(tst_device->dev, MNTPOINT,
			tst_device->fs_type, 0, NULL);
		mount_flag = 1;
	}

	TEST(umount(MNTPOINT));

	if (TEST_RETURN != 0 && TEST_ERRNO == EBUSY) {
		tst_res(TINFO, "umount() Failed with EBUSY "
			"possibly some daemon (gvfsd-trash) "
			"is probing newly mounted dirs");
	}

	if (TEST_RETURN != 0) {
		tst_res(TFAIL | TTERRNO, "umount() Failed");
		return;
	}

	tst_res(TPASS, "umount() Passed");
	mount_flag = 0;
}
Esempio n. 22
0
void verify_inotify(void)
{
	int ret;
	int len, i, test_num;

	int test_cnt = 0;

	SAFE_MOUNT(tst_device->dev, mntpoint, tst_device->fs_type, 0, NULL);
	mount_flag = 1;

	wd = myinotify_add_watch(fd_notify, fname, IN_ALL_EVENTS);
	if (wd < 0) {
		tst_brk(TBROK | TERRNO,
			"inotify_add_watch (%d, %s, IN_ALL_EVENTS) failed.",
			fd_notify, fname);
	}

	event_set[test_cnt] = IN_UNMOUNT;
	test_cnt++;
	event_set[test_cnt] = IN_IGNORED;
	test_cnt++;

	/*check exit code from inotify_rm_watch */
	test_cnt++;

	tst_res(TINFO, "umount %s", tst_device->dev);
	TEST(tst_umount(mntpoint));
	if (TEST_RETURN != 0) {
		tst_brk(TBROK, "umount(2) Failed "
			"while unmounting errno = %d : %s",
			TEST_ERRNO, strerror(TEST_ERRNO));
	}
	mount_flag = 0;

	len = read(fd_notify, event_buf, EVENT_BUF_LEN);
	if (len < 0) {
		tst_brk(TBROK | TERRNO,
			"read(%d, buf, %zu) failed", fd_notify, EVENT_BUF_LEN);
	}

	/* check events */
	test_num = 0;
	i = 0;
	while (i < len) {
		struct inotify_event *event;
		event = (struct inotify_event *)&event_buf[i];
		if (test_num >= (test_cnt - 1)) {
			tst_res(TFAIL,
				"get unnecessary event: wd=%d mask=%x "
				"cookie=%u len=%u",
				event->wd, event->mask,
				event->cookie, event->len);
		} else if (event_set[test_num] == event->mask) {
			tst_res(TPASS, "get event: wd=%d mask=%x"
				" cookie=%u len=%u",
				event->wd, event->mask,
				event->cookie, event->len);

		} else {
			tst_res(TFAIL, "get event: wd=%d mask=%x "
				"(expected %x) cookie=%u len=%u",
				event->wd, event->mask,
				event_set[test_num],
				event->cookie, event->len);
		}
		test_num++;
		i += EVENT_SIZE + event->len;
	}
	for (; test_num < test_cnt - 1; test_num++) {
		tst_res(TFAIL, "don't get event: mask=%x ",
			event_set[test_num]);

	}
	ret = myinotify_rm_watch(fd_notify, wd);
	if (ret != -1 || errno != EINVAL)
		tst_res(TFAIL | TERRNO,
			"inotify_rm_watch (%d, %d) didn't return EINVAL",
			fd_notify, wd);
	else
		tst_res(TPASS, "inotify_rm_watch (%d, %d) returned EINVAL",
			fd_notify, wd);
}
Esempio n. 23
0
static void run(unsigned int test_case)
{
	/* Work in child process - needed to undo unshare and chroot */
	if (SAFE_FORK()) {
		tst_reap_children();
		return;
	}

	/* pivot_root requires no shared mounts exist in process namespace */
	TEST(unshare(CLONE_NEWNS | CLONE_FS));
	if (TST_RET == -1)
		tst_brk(TFAIL | TERRNO, "unshare failed");

	/*
	 * Create an initial root dir. pivot_root doesn't work if the initial root
	 * dir is a initramfs, so use chroot to create a safe environment
	 */
	SAFE_MOUNT("none", "/", NULL, MS_REC|MS_PRIVATE, NULL);
	SAFE_MOUNT("none", CHROOT_DIR, "tmpfs", 0, 0);
	SAFE_CHROOT(CHROOT_DIR);

	SAFE_MKDIR(NEW_ROOT, 0777);

	/*
	 * pivot_root only works if new_root is a mount point, so mount a tmpfs
	 * unless testing for that fail mode
	 */
	if (test_cases[test_case].test_case != NEW_ROOT_ON_CURRENT_ROOT)
		SAFE_MOUNT("none", NEW_ROOT, "tmpfs", 0, 0);

	/*
	 * Create put_old under new_root, unless testing for that specific fail
	 * mode
	 */
	const char* actual_put_old = NULL;
	if (test_cases[test_case].test_case == PUT_OLD_NOT_UNDERNEATH_NEW_ROOT) {
		actual_put_old = PUT_OLD_BAD;
		SAFE_MKDIR(PUT_OLD_FS, 0777);
		SAFE_MOUNT("none", PUT_OLD_FS, "tmpfs", 0, 0);
		SAFE_MKDIR(PUT_OLD_BAD, 0777);
	} else {
		actual_put_old = PUT_OLD;

		if (test_cases[test_case].test_case == PUT_OLD_NOT_DIR)
			SAFE_CREAT(PUT_OLD, 0777);
		else
			SAFE_MKDIR(PUT_OLD, 0777);
	}

	if (test_cases[test_case].test_case == NO_CAP_SYS_ADMIN) {
#ifdef HAVE_LIBCAP
		drop_cap_sys_admin();
#else
		tst_res(TCONF,
			"System doesn't have POSIX capabilities support");
		return;
#endif
	}

	TEST(syscall(__NR_pivot_root, NEW_ROOT, actual_put_old));

	if (test_cases[test_case].test_case == NORMAL) {
		if (TST_RET)
			tst_res(TFAIL | TERRNO, "pivot_root failed");
		else
			tst_res(TPASS, "pivot_root succeeded");

		return;
	}

	if (TST_RET == 0) {
		tst_res(TFAIL, "pivot_root succeeded unexpectedly");
		return;
	}

	if (errno != test_cases[test_case].expected_error) {
		tst_res(TFAIL | TERRNO,	"pivot_root failed with wrong errno");
		return;
	}

	tst_res(TPASS | TERRNO, "pivot_root failed as expectedly");
}
Esempio n. 24
0
static void umount2_verify(void)
{
	int ret;
	char buf[256];
	const char *str = "abcdefghijklmnopqrstuvwxyz";

	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
	mount_flag = 1;

	fd = SAFE_CREAT(cleanup, MNTPOINT "/file", FILE_MODE);

	TEST(umount2(MNTPOINT, MNT_DETACH));

	if (TEST_RETURN != 0) {
		tst_resm(TFAIL | TTERRNO, "umount2(2) Failed");
		goto EXIT;
	}

	mount_flag = 0;

	/* check the unavailability for new access */
	ret = access(MNTPOINT "/file", F_OK);

	if (ret != -1) {
		tst_resm(TFAIL, "umount2(2) MNT_DETACH flag "
			"performed abnormally");
		goto EXIT;
	}

	/*
	 * check the old fd still points to the file
	 * in previous mount point and is available
	 */
	SAFE_WRITE(cleanup, 1, fd, str, strlen(str));

	SAFE_CLOSE(cleanup, fd);

	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
	mount_flag = 1;

	fd = SAFE_OPEN(cleanup, MNTPOINT "/file", O_RDONLY);

	memset(buf, 0, sizeof(buf));

	SAFE_READ(cleanup, 1, fd, buf, strlen(str));

	if (strcmp(str, buf)) {
		tst_resm(TFAIL, "umount2(2) MNT_DETACH flag "
			"performed abnormally");
		goto EXIT;
	}

	tst_resm(TPASS, "umount2(2) Passed");

EXIT:
	SAFE_CLOSE(cleanup, fd);
	fd = 0;

	if (mount_flag) {
		if (tst_umount(MNTPOINT))
			tst_brkm(TBROK, cleanup, "umount() failed");
		mount_flag = 0;
	}
}