Example #1
0
/*
 *  stress on sync()
 *	stress system by IO sync calls
 */
static int stress_io(const args_t *args)
{
#if defined(HAVE_SYNCFS)
	int i, fd, n_mnts;
	char *mnts[MAX_MNTS];
	int  fds[MAX_MNTS];

	n_mnts = mount_get(mnts, MAX_MNTS);
	for (i = 0; i < n_mnts; i++)
		fds[i] = openat(AT_FDCWD, mnts[i], O_RDONLY | O_NONBLOCK | O_DIRECTORY);

	fd = openat(AT_FDCWD, ".", O_RDONLY | O_NONBLOCK | O_DIRECTORY);
#endif

	do {
		(void)sync();
#if defined(HAVE_SYNCFS)
		if ((fd != -1) && (syncfs(fd) < 0))
			pr_fail_err("syncfs");

		/* try to sync on all the mount points */
		for (i = 0; i < n_mnts; i++)
			if (fds[i] != -1)
				(void)syncfs(fds[i]);
#endif
		inc_counter(args);
	} while (keep_stressing());

#if defined(HAVE_SYNCFS)
	if (fd != -1)
		(void)close(fd);

	for (i = 0; i < n_mnts; i++)
		if (fds[i] != -1)
			(void)close(fds[i]);

	mount_free(mnts, n_mnts);
#endif

	return EXIT_SUCCESS;
}
Example #2
0
/*
 *  stress_quota
 *	stress various quota options
 */
int stress_quota(
	uint64_t *const counter,
	const uint32_t instance,
	const uint64_t max_ops,
	const char *name)
{
	int i, n_mounts, n_devs = 0;
	int rc = EXIT_FAILURE;
	char *mnts[MAX_DEVS];
	dev_info_t devs[MAX_DEVS];
	DIR *dir;
	struct dirent *d;
	struct stat buf;

	(void)instance;

	memset(mnts, 0, sizeof(mnts));
	memset(devs, 0, sizeof(devs));

	n_mounts = mount_get(mnts, SIZEOF_ARRAY(mnts));

	dir = opendir("/dev/");
	if (!dir) {
		pr_err(stderr, "%s: opendir on /dev failed: errno=%d: (%s)\n",
			name, errno, strerror(errno));
		return rc;
	}

	for (i = 0; i < n_mounts; i++) {
		if (lstat(mnts[i], &buf) == 0) {
			devs[i].st_dev = buf.st_dev;
			devs[i].valid = true;
		}
	}

	while ((d = readdir(dir)) != NULL) {
		char path[PATH_MAX];

		snprintf(path, sizeof(path), "/dev/%s", d->d_name);
		if (lstat(path, &buf) < 0)
			continue;
		if ((buf.st_mode & S_IFBLK) == 0)
			continue;
		for (i = 0; i < n_mounts; i++) {
			if (devs[i].valid &&
			    !devs[i].name &&
			    (buf.st_rdev == devs[i].st_dev)) {
				devs[i].name = strdup(path);
				devs[i].mount = mnts[i];
				if (!devs[i].name) {
					pr_err(stderr, "%s: out of memory\n", name);
					closedir(dir);
					goto tidy;
				}
			}
		}
	}
	closedir(dir);

	/* Compact up, remove duplicates too */
	for (i = 0; i < n_mounts; i++) {
		int j;
		bool unique = true;

		for (j = 0; j < n_devs; j++) {
			if (devs[i].st_dev == devs[j].st_dev) {
				unique = false;
				break;
			}
		}
		if (unique && devs[i].name)
			devs[n_devs++] = devs[i];
		else
			free(devs[i].name);
	}
	for (i = n_devs; i < n_mounts; i++)
		memset(&devs[i], 0, sizeof(devs[i]));

	if (!n_devs) {
		pr_err(stderr, "%s: cannot find any canditate block devices\n", name);
	} else {
		do {
			for (i = 0; opt_do_run && (i < n_devs); i++)
				if (do_quotas(&devs[i], name) < 0) {
					goto tidy;
				}
			(*counter)++;
		} while (opt_do_run && (!max_ops || *counter < max_ops));
	}
	rc = EXIT_SUCCESS;

tidy:
	for (i = 0; i < n_devs; i++)
		free(devs[i].name);

	mount_free(mnts, n_mounts);
	return rc;
}
Example #3
0
/*
 *  stress on system information
 *	stress system by rapid fetches of system information
 */
int stress_sysinfo(
	uint64_t *const counter,
	const uint32_t instance,
	const uint64_t max_ops,
	const char *name)
{
	int n_mounts;
	char *mnts[128];

	(void)instance;

	n_mounts = mount_get(mnts, SIZEOF_ARRAY(mnts));
	if (n_mounts < 0) {
		pr_err(stderr, "%s: failed to get mount points\n", name);
		return EXIT_FAILURE;
	}
	pr_dbg(stderr, "%s: found %d mount points\n",
		name, n_mounts);

	do {
		struct tms tms_buf;
		clock_t clk;
		struct statvfs statvfs_buf;
		int i, ret;
#if defined(__linux__)
		struct sysinfo sysinfo_buf;
		struct statfs statfs_buf;
#endif

#if defined(__linux__)
		ret = sysinfo(&sysinfo_buf);
		if ((ret < 0) && (opt_flags & OPT_FLAGS_VERIFY)) {
			 pr_fail(stderr, "%s: sysinfo failed: errno=%d (%s)\n",
				name, errno, strerror(errno));
		}
		check_do_run();

		/* Linux statfs variant */
		for (i = 0; i < n_mounts; i++) {
			check_do_run();

			if (!mnts[i])
				continue;

			ret = statfs(mnts[i], &statfs_buf);
			/* Mount may have been removed, so purge it */
			if ((ret < 0) && (errno == ENOENT)) {
				free(mnts[i]);
				mnts[i] = NULL;
				continue;
			}
			if ((ret < 0) && (opt_flags & OPT_FLAGS_VERIFY)) {
				if (errno != ENOSYS &&
				    errno != EOVERFLOW &&
				    errno != EACCES) {
					pr_fail(stderr, "%s: statfs on %s "
						"failed: errno=%d (%s)\n",
						name, mnts[i], errno,
						strerror(errno));
				}
			}
		}
#endif
		check_do_run();

		/* POSIX.1-2001 statfs variant */
		for (i = 0; i < n_mounts; i++) {
			check_do_run();

			if (!mnts[i])
				continue;

			ret = statvfs(mnts[i], &statvfs_buf);
			if ((ret < 0) && (opt_flags & OPT_FLAGS_VERIFY)) {
				if (errno != ENOSYS &&
				    errno != EOVERFLOW &&
				    errno != EACCES) {
					pr_fail(stderr, "%s: statvfs on %s "
						"failed: errno=%d (%s)\n",
						name, mnts[i], errno,
						strerror(errno));
				}
			}
		}

		check_do_run();
		clk = times(&tms_buf);
		if ((clk == (clock_t)-1) && (opt_flags & OPT_FLAGS_VERIFY)) {
			 pr_fail(stderr, "%s: times failed: errno=%d (%s)\n",
				name, errno, strerror(errno));
		}
		(*counter)++;
	} while (opt_do_run && (!max_ops || *counter < max_ops));

	mount_free(mnts, n_mounts);

	return EXIT_SUCCESS;
}