"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "stress-fcntl.c" between
stress-ng-0.12.09.tar.xz and stress-ng-0.12.10.tar.xz

About: stress-ng will stress test a computer system in various selectable ways. It was designed to exercise various physical subsystems of a computer as well as the various operating system kernel interfaces.

stress-fcntl.c  (stress-ng-0.12.09.tar.xz):stress-fcntl.c  (stress-ng-0.12.10.tar.xz)
skipping to change at line 76 skipping to change at line 76
args->name, cmd, errno, strerror(errno)); args->name, cmd, errno, strerror(errno));
} }
} }
} }
#endif #endif
/* /*
* do_fcntl() * do_fcntl()
*/ */
static int do_fcntl(const stress_args_t *args, const int fd, const int bad_fd) static int do_fcntl(
const stress_args_t *args,
const int fd,
const int bad_fd,
const int path_fd)
{ {
#if defined(F_DUPFD) #if defined(F_DUPFD)
{ {
int ret; int ret;
ret = fcntl(fd, F_DUPFD, 0); ret = fcntl(fd, F_DUPFD, 0);
check_return(args, ret, "F_DUPFD"); check_return(args, ret, "F_DUPFD");
if (ret > -1) if (ret > -1)
(void)close(ret); (void)close(ret);
skipping to change at line 171 skipping to change at line 175
#if defined(HAVE_GETPGRP) #if defined(HAVE_GETPGRP)
ret = fcntl(fd, F_SETOWN, -getpgrp()); ret = fcntl(fd, F_SETOWN, -getpgrp());
check_return(args, ret, "F_SETOWN"); check_return(args, ret, "F_SETOWN");
#endif #endif
ret = fcntl(fd, F_SETOWN, args->pid); ret = fcntl(fd, F_SETOWN, args->pid);
check_return(args, ret, "F_SETOWN"); check_return(args, ret, "F_SETOWN");
/* This should return -EINVAL */ /* This should return -EINVAL */
ret = fcntl(fd, F_SETOWN, INT_MIN); ret = fcntl(fd, F_SETOWN, INT_MIN);
(void)ret; (void)ret;
/* This is intended to probably fail with -ESRCH */
ret = fcntl(fd, F_SETOWN, stress_get_unused_pid_racy(false));
(void)ret;
/* And set back to current pid */
ret = fcntl(fd, F_SETOWN, args->pid);
(void)ret;
} }
#endif #endif
#if defined(F_GETOWN) && \ #if defined(F_GETOWN) && \
defined(__linux__) defined(__linux__)
{ {
int ret; int ret;
#if defined(__NR_fcntl) #if defined(__NR_fcntl)
/* /*
skipping to change at line 215 skipping to change at line 227
#if defined(F_SETOWN_EX) && \ #if defined(F_SETOWN_EX) && \
(defined(F_OWNER_PID) || \ (defined(F_OWNER_PID) || \
defined(F_OWNER_GID) || \ defined(F_OWNER_GID) || \
defined(F_OWNER_PGRP) || \ defined(F_OWNER_PGRP) || \
(defined(F_OWNER_TID) && defined(__linux__))) (defined(F_OWNER_TID) && defined(__linux__)))
{ {
int ret; int ret;
struct f_owner_ex owner; struct f_owner_ex owner;
#if defined(F_OWNER_PID) #if defined(F_OWNER_PID)
/* This is intended to probably fail with -ESRCH */
owner.type = F_OWNER_PID;
owner.pid = stress_get_unused_pid_racy(false);
ret = fcntl(fd, F_SETOWN_EX, &owner);
(void)ret;
/* set to stressor's pid */
owner.type = F_OWNER_PID; owner.type = F_OWNER_PID;
owner.pid = args->pid; owner.pid = args->pid;
ret = fcntl(fd, F_SETOWN_EX, &owner); ret = fcntl(fd, F_SETOWN_EX, &owner);
(void)ret; (void)ret;
#endif #endif
#if defined(HAVE_GETPGRP) && \ #if defined(HAVE_GETPGRP) && \
defined(F_OWNER_PGRP) defined(F_OWNER_PGRP)
owner.type = F_OWNER_PGRP; owner.type = F_OWNER_PGRP;
owner.pid = getpgrp(); owner.pid = getpgrp();
ret = fcntl(fd, F_SETOWN_EX, &owner); ret = fcntl(fd, F_SETOWN_EX, &owner);
(void)ret; (void)ret;
#endif #endif
#if defined(F_OWNER_TID) && \ #if defined(F_OWNER_TID) && \
defined(__linux__) defined(__linux__)
skipping to change at line 581 skipping to change at line 601
#if defined(RWH_WRITE_LIFE_MEDIUM) #if defined(RWH_WRITE_LIFE_MEDIUM)
RWH_WRITE_LIFE_MEDIUM, RWH_WRITE_LIFE_MEDIUM,
#endif #endif
#if defined(RWH_WRITE_LIFE_SHORT) #if defined(RWH_WRITE_LIFE_SHORT)
RWH_WRITE_LIFE_SHORT, RWH_WRITE_LIFE_SHORT,
#endif #endif
#if defined(RWH_WRITE_LIFE_NONE) #if defined(RWH_WRITE_LIFE_NONE)
RWH_WRITE_LIFE_NONE, RWH_WRITE_LIFE_NONE,
#endif #endif
#if defined(RWF_WRITE_LIFE_NOT_SET) #if defined(RWF_WRITE_LIFE_NOT_SET)
RWF_WRITE_LIFE_NOT_SET RWF_WRITE_LIFE_NOT_SET,
#endif #endif
~0U, /* Invalid */
}; };
#if defined(F_GET_FILE_RW_HINT) && \ #if defined(F_GET_FILE_RW_HINT) && \
defined(F_SET_FILE_RW_HINT) defined(F_SET_FILE_RW_HINT)
ret = fcntl(fd, F_GET_FILE_RW_HINT, &hint); ret = fcntl(fd, F_GET_FILE_RW_HINT, &hint);
if (ret == 0) { if (ret == 0) {
for (i = 0; i < SIZEOF_ARRAY(hints); i++) { for (i = 0; i < SIZEOF_ARRAY(hints); i++) {
hint = hints[i]; hint = hints[i];
ret = fcntl(fd, F_SET_FILE_RW_HINT, &hint); ret = fcntl(fd, F_SET_FILE_RW_HINT, &hint);
(void)ret; (void)ret;
skipping to change at line 628 skipping to change at line 649
/* /*
* and exercise with an invalid fd * and exercise with an invalid fd
*/ */
ret = fcntl(bad_fd, F_GETFD, F_GETFD); ret = fcntl(bad_fd, F_GETFD, F_GETFD);
(void)ret; (void)ret;
} }
#else #else
(void)bad_fd; (void)bad_fd;
#endif #endif
#if defined(O_PATH)
#if defined(F_DUPFD)
{
int ret;
/* Exercise allowed F_DUPFD on a path fd */
ret = fcntl(path_fd, F_DUPFD, 0);
if (ret > -1)
(void)close(ret);
}
#endif
#if defined(F_GETOWN)
{
int ret;
/* Exercise not allowed F_GETOWN on a path fd, EBADF */
ret = fcntl(path_fd, F_GETOWN);
(void)ret;
}
#endif
#else
(void)path_fd;
#endif
return 0; return 0;
} }
/* /*
* stress_fcntl * stress_fcntl
* stress various fcntl calls * stress various fcntl calls
*/ */
static int stress_fcntl(const stress_args_t *args) static int stress_fcntl(const stress_args_t *args)
{ {
const pid_t ppid = getppid(); const pid_t ppid = getppid();
int fd, rc = EXIT_FAILURE, retries = 0; int fd, rc = EXIT_FAILURE, retries = 0, path_fd;
const int bad_fd = stress_get_bad_fd(); const int bad_fd = stress_get_bad_fd();
char filename[PATH_MAX], pathname[PATH_MAX]; char filename[PATH_MAX], pathname[PATH_MAX];
/* /*
* Allow for multiple workers to chmod the *same* file * Allow for multiple workers to chmod the *same* file
*/ */
stress_temp_dir(pathname, sizeof(pathname), args->name, ppid, 0); stress_temp_dir(pathname, sizeof(pathname), args->name, ppid, 0);
if (mkdir(pathname, S_IRWXU) < 0) { if (mkdir(pathname, S_IRWXU) < 0) {
if (errno != EEXIST) { if (errno != EEXIST) {
pr_fail("%s: mkdir %s failed, errno=%d (%s)\n", pr_fail("%s: mkdir %s failed, errno=%d (%s)\n",
args->name, pathname, errno, strerror(errno)); args->name, pathname, errno, strerror(errno));
return exit_status(errno); return exit_status(errno);
} }
} }
(void)stress_temp_filename(filename, sizeof(filename), (void)stress_temp_filename(filename, sizeof(filename),
args->name, ppid, 0, 0); args->name, ppid, 0, 0);
stress_set_proc_state(args->name, STRESS_STATE_RUN); stress_set_proc_state(args->name, STRESS_STATE_RUN);
#if defined(O_PATH)
path_fd = open("/bin/true", O_PATH | O_RDONLY);
#else
path_fd = -1;
#endif
do { do {
errno = 0; errno = 0;
/* /*
* Try and open the file, it may be impossible * Try and open the file, it may be impossible
* momentarily because other fcntl stressors have * momentarily because other fcntl stressors have
* already created it * already created it
*/ */
fd = creat(filename, S_IRUSR | S_IWUSR); fd = creat(filename, S_IRUSR | S_IWUSR);
if (fd < 0) { if (fd < 0) {
if ((errno == EPERM) || (errno == EACCES) || if ((errno == EPERM) || (errno == EACCES) ||
skipping to change at line 688 skipping to change at line 740
} while (keep_stressing_flag() && ++retries < 100); } while (keep_stressing_flag() && ++retries < 100);
if ((fd < 0) || (retries >= 100)) { if ((fd < 0) || (retries >= 100)) {
pr_err("%s: creat: file %s took %d " pr_err("%s: creat: file %s took %d "
"retries to create (instance %" PRIu32 ")\n", "retries to create (instance %" PRIu32 ")\n",
args->name, filename, retries, args->instance); args->name, filename, retries, args->instance);
goto tidy; goto tidy;
} }
do { do {
do_fcntl(args, fd, bad_fd); do_fcntl(args, fd, bad_fd, path_fd);
inc_counter(args); inc_counter(args);
} while (keep_stressing(args)); } while (keep_stressing(args));
rc = EXIT_SUCCESS; rc = EXIT_SUCCESS;
tidy: tidy:
stress_set_proc_state(args->name, STRESS_STATE_DEINIT); stress_set_proc_state(args->name, STRESS_STATE_DEINIT);
if (path_fd >= 0)
(void)close(path_fd);
if (fd >= 0) if (fd >= 0)
(void)close(fd); (void)close(fd);
(void)unlink(filename); (void)unlink(filename);
(void)rmdir(pathname); (void)rmdir(pathname);
return rc; return rc;
} }
stressor_info_t stress_fcntl_info = { stressor_info_t stress_fcntl_info = {
.stressor = stress_fcntl, .stressor = stress_fcntl,
 End of changes. 11 change blocks. 
4 lines changed or deleted 58 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)