Exemple #1
0
static void setup(void)
{
	long type;
	struct passwd *nobody;

	tst_sig(FORK, DEF_HANDLER, cleanup);

	TEST_EXP_ENOS(exp_enos);

	tst_require_root(NULL);

	nobody = SAFE_GETPWNAM(NULL, "nobody");
	nobody_uid = nobody->pw_uid;

	TEST_PAUSE;

	tst_tmpdir();

	switch ((type = tst_fs_type(cleanup, "."))) {
	case TST_NFS_MAGIC:
	case TST_TMPFS_MAGIC:
		tst_brkm(TCONF, cleanup,
			 "Cannot do swapoff on a file on %s filesystem",
			 tst_fs_type_name(type));
	break;
	}

	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
		tst_brkm(TBROK, cleanup,
			 "Insufficient disk space to create swap file");
	}

	if (tst_fill_file("./swapfile01", 0x00, 1024, 1))
		tst_brkm(TBROK, cleanup, "Failed to create swapfile");
}
Exemple #2
0
int apicmd_fs_has_free(int argc, char *argv[])
{
	if (argc != 3) {
		fprintf(stderr, "Usage: tst_fs_has_free path required_bytes\n"
			"path: the pathname of the mounted filesystem\n"
			"required_bytes: the required free space"
			" (supports kB, MB and GB suffixes)\n");
		exit(2);
	}

	char *endptr;
	unsigned int required_kib = strtoull(argv[1], &endptr, 0);
	unsigned int mul = TST_BYTES;

	if (*argv[1] == '\0')
		goto fs_has_free_err;

	if (*endptr != '\0') {
		if (!strcasecmp(endptr, "kB")) {
			mul = TST_KB;
		} else if (!strcasecmp(endptr, "MB")) {
			mul = TST_MB;
		} else if (!strcasecmp(endptr, "GB")) {
			mul = TST_GB;
		} else {
			goto fs_has_free_err;
		}
	}

	exit(!tst_fs_has_free(NULL, argv[0], required_kib, mul));

fs_has_free_err:
	fprintf(stderr, "%s is not a valid size\n", argv[1]);
	exit(2);
}
Exemple #3
0
/*
 * Make a swap file
 */
void make_swapfile(void (cleanup)(void), const char *swapfile)
{
	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
	    TST_BYTES)) {
		tst_brkm(TBROK, cleanup,
			"Insufficient disk space to create swap file");
	}

	/* create file */
	if (tst_fill_file(swapfile, 0,
			sysconf(_SC_PAGESIZE), 10) != 0) {
		tst_brkm(TBROK, cleanup, "Failed to create swapfile");
	}

	/* make the file swapfile */
	const char *argv[2 + 1];
	argv[0] = "mkswap";
	argv[1] = swapfile;
	argv[2] = NULL;

	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
}
Exemple #4
0
static void setup(void)
{
	char filename[PATH_MAX];
	int n, j, fd, directflag = 1;
	long type;

	if (align_str) {
		align = atoi(align_str);
		if (align < 0 || align > PAGE_SIZE)
			tst_brkm(TCONF, NULL, "Bad alignment %d.", align);
	}
	tst_resm(TINFO, "using alignment %d", align);

	if (workers_str) {
		workers = atoi(workers_str);
		if (workers < MIN_WORKERS || workers > MAX_WORKERS) {
			tst_brkm(TCONF, NULL, "Worker count %d not between "
				 "%d and %d, inclusive",
				 workers, MIN_WORKERS, MAX_WORKERS);
		}
	}
	tst_resm(TINFO, "using %d workers.", workers);

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

	TEST_PAUSE;

	tst_tmpdir();

	/*
	 * Some file systems may not implement the O_DIRECT flag and open() will
	 * fail with EINVAL if it is used. So add this check for current
	 * filesystem current directory is in, if not supported, we choose to
	 * have this test in LTP_BIG_DEV and mkfs it as ext3.
	 */
	fd = open("testfile", O_CREAT | O_DIRECT, 0644);
	if (fd < 0 && errno == EINVAL) {
		type = tst_fs_type(NULL, ".");
		tst_resm(TINFO, "O_DIRECT flag is not supported on %s "
			 "filesystem", tst_fs_type_name(type));
		directflag = 0;
	} else if (fd > 0) {
		SAFE_CLOSE(NULL, fd);
	}

	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);

	/*
	 * verify whether the current directory has enough free space,
	 * if it is not satisfied, we will use the LTP_BIG_DEV, which
	 * will be exported by runltp with "-z" option.
	 */
	if (!directflag || !tst_fs_has_free(NULL, ".", 1300, TST_MB)) {
		device = getenv("LTP_BIG_DEV");
		if (device == NULL) {
			tst_brkm(TCONF, NULL,
				 "you must specify a big blockdevice(>1.3G)");
		} else {
			tst_mkfs(NULL, device, "ext3", NULL);
		}

		if (mount(device, MNT_POINT, "ext3", 0, NULL) < 0) {
			tst_brkm(TBROK | TERRNO, NULL,
				 "mount device:%s failed", device);
		}
		mount_flag = 1;
	}

	worker = SAFE_MALLOC(cleanup, workers * sizeof(worker_t));

	for (j = 0; j < workers; j++)
		worker[j].worker_number = j;

	for (n = 1; n <= FILECOUNT; n++) {
		snprintf(filename, sizeof(filename), FILE_BASEPATH, n);

		if (tst_fill_file(filename, n, FILESIZE, 1)) {
			tst_brkm(TBROK, cleanup, "failed to create file: %s",
				 filename);
		}
	}

	if (posix_memalign((void **)&buffer, PAGE_SIZE, READSIZE + align) != 0)
		tst_brkm(TBROK, cleanup, "call posix_memalign failed");
}