Esempio n. 1
0
const char *tst_acquire_device(void (cleanup_fn)(void))
{
	char *dev;
	struct stat st;

	if (device_acquired)
		tst_brkm(TBROK, cleanup_fn, "Device allready acquired");

	if (!tst_tmpdir_created()) {
		tst_brkm(TBROK, cleanup_fn,
		         "Cannot acquire device without tmpdir() created");
	}

	dev = getenv("LTP_DEV");

	if (dev) {
		tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);

		SAFE_STAT(cleanup_fn, dev, &st);

		if (!S_ISBLK(st.st_mode)) {
			tst_brkm(TBROK, cleanup_fn,
			         "%s is not a block device", dev);
		}

		if (tst_fill_file(dev, 0, 1024, 512)) {
			tst_brkm(TBROK | TERRNO, cleanup_fn,
				 "Failed to clear the first 512k of %s", dev);
		}

		return dev;
	}

	if (tst_fill_file(DEV_FILE, 0, 1024, 102400)) {
		tst_brkm(TBROK | TERRNO, cleanup_fn,
		         "Failed to create " DEV_FILE);

	}

	if (find_free_loopdev())
		return NULL;

	attach_device(cleanup_fn, dev_path, DEV_FILE);

	device_acquired = 1;

	return dev_path;
}
Esempio n. 2
0
const char *tst_acquire_device_(void (cleanup_fn)(void), unsigned int size)
{
	int fd;
	char *dev;
	struct stat st;
	unsigned int acq_dev_size;
	uint64_t ltp_dev_size;

	acq_dev_size = size > 150 ? size : 150;

	if (device_acquired)
		tst_brkm(TBROK, cleanup_fn, "Device allready acquired");

	if (!tst_tmpdir_created()) {
		tst_brkm(TBROK, cleanup_fn,
		         "Cannot acquire device without tmpdir() created");
	}

	dev = getenv("LTP_DEV");

	if (dev) {
		tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);

		SAFE_STAT(cleanup_fn, dev, &st);

		if (!S_ISBLK(st.st_mode)) {
			tst_brkm(TBROK, cleanup_fn,
			         "%s is not a block device", dev);
		}

		fd = SAFE_OPEN(cleanup_fn, dev, O_RDONLY);
		SAFE_IOCTL(cleanup_fn, fd, BLKGETSIZE64, &ltp_dev_size);
		SAFE_CLOSE(cleanup_fn, fd);
		ltp_dev_size = ltp_dev_size/1024/1024;

		if (acq_dev_size <= ltp_dev_size) {
			if (tst_fill_file(dev, 0, 1024, 512)) {
				tst_brkm(TBROK | TERRNO, cleanup_fn,
					"Failed to clear the first 512k of %s", dev);
			}

			return dev;
		}

		tst_resm(TINFO, "Skipping $LTP_DEV size %"PRIu64"MB, requested size %uMB",
				ltp_dev_size, acq_dev_size);
	}

	if (tst_fill_file(DEV_FILE, 0, 1024, 1024 * acq_dev_size)) {
		tst_brkm(TBROK | TERRNO, cleanup_fn,
		         "Failed to create " DEV_FILE);

	}

	if (find_free_loopdev())
		return NULL;

	attach_device(cleanup_fn, dev_path, DEV_FILE);

	device_acquired = 1;

	return dev_path;
}