/* * stress_str() * stress CPU by doing various string operations */ int stress_str( uint64_t *const counter, const uint32_t instance, const uint64_t max_ops, const char *name) { stress_str_func func = opt_str_stressor->func; (void)instance; do { char str1[256], str2[128]; stress_strnrnd(str1, sizeof(str1)); stress_strnrnd(str2, sizeof(str2)); (void)func(name, str1, sizeof(str1), str2, sizeof(str2)); (*counter)++; } while (opt_do_run && (!max_ops || *counter < max_ops)); return EXIT_SUCCESS; }
/* * stress_fiemap_writer() * write data in random places and punch holes * in data in random places to try and maximize * extents in the file */ int stress_fiemap_writer( const char *name, const int fd, uint64_t *counters, const uint64_t max_ops) { uint8_t buf[1]; uint64_t len = (off_t)opt_fiemap_size - sizeof(buf); uint64_t counter; int rc = EXIT_FAILURE; #if defined(FALLOC_FL_PUNCH_HOLE) && \ defined(FALLOC_FL_KEEP_SIZE) bool punch_hole = true; #endif stress_strnrnd((char *)buf, sizeof(buf)); do { uint64_t offset; size_t i; counter = 0; offset = (mwc64() % len) & ~0x1fff; if (lseek(fd, (off_t)offset, SEEK_SET) < 0) break; if (write(fd, buf, sizeof(buf)) < 0) { if ((errno != EAGAIN) && (errno != EINTR)) { pr_fail_err(name, "write"); goto tidy; } } #if defined(FALLOC_FL_PUNCH_HOLE) && \ defined(FALLOC_FL_KEEP_SIZE) if (!punch_hole) continue; offset = mwc64() % len; if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, 8192) < 0) { if (errno == EOPNOTSUPP) punch_hole = false; } #endif for (i = 0; i < MAX_FIEMAP_PROCS; i++) counter += counters[i]; } while (opt_do_run && (!max_ops || counter < max_ops)); rc = EXIT_SUCCESS; tidy: (void)close(fd); return rc; }