"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "stress-fanotify.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-fanotify.c  (stress-ng-0.12.09.tar.xz):stress-fanotify.c  (stress-ng-0.12.10.tar.xz)
skipping to change at line 316 skipping to change at line 316
(void)close(ret_fd); (void)close(ret_fd);
return 0; return 0;
} }
/* /*
* fanotify_event_init() * fanotify_event_init()
* initialize fanotify * initialize fanotify
*/ */
static int fanotify_event_init(const char *name, char *mounts[]) static int fanotify_event_init(const char *name, char *mounts[], const int flags )
{ {
int fan_fd, count = 0, i; int fan_fd, count = 0, i;
fan_fd = fanotify_init(0, 0); fan_fd = fanotify_init(flags, 0);
if (fan_fd < 0) { if (fan_fd < 0) {
pr_err("%s: cannot initialize fanotify, errno=%d (%s)\n", pr_err("%s: cannot initialize fanotify, errno=%d (%s)\n",
name, errno, strerror(errno)); name, errno, strerror(errno));
return -1; return -1;
} }
/* /*
* Gather all mounted file systems and monitor them * Gather all mounted file systems and monitor them
*/ */
for (i = 0; i < n_mnts; i++) { for (i = 0; i < n_mnts; i++) {
skipping to change at line 423 skipping to change at line 423
*/ */
static void stress_fanotify_init_exercise(const unsigned int flags) static void stress_fanotify_init_exercise(const unsigned int flags)
{ {
int ret_fd; int ret_fd;
ret_fd = fanotify_init(flags, 0); ret_fd = fanotify_init(flags, 0);
if (ret_fd != -1) if (ret_fd != -1)
(void)close(ret_fd); (void)close(ret_fd);
} }
static void stress_fanotify_read_events(
const stress_args_t *args,
const int fan_fd,
void *buffer,
const size_t buffer_size,
stress_fanotify_account_t *account)
{
ssize_t len;
struct fanotify_event_metadata *metadata;
len = read(fan_fd, (void *)buffer, buffer_size);
if (len <= 0)
return;
metadata = (struct fanotify_event_metadata *)buffer;
while (FAN_EVENT_OK(metadata, len)) {
if (!keep_stressing_flag())
break;
if ((metadata->fd != FAN_NOFD) && (metadata->fd >= 0)) {
#if defined(FAN_OPEN)
if (metadata->mask & FAN_OPEN)
account->open++;
#endif
#if defined(FAN_CLOSE_WRITE)
if (metadata->mask & FAN_CLOSE_WRITE)
account->close_write++;
#endif
#if defined(FAN_CLOSE_NOWRITE)
if (metadata->mask & FAN_CLOSE_NOWRITE)
account->close_nowrite++;
#endif
#if defined(FAN_ACCESS)
if (metadata->mask & FAN_ACCESS)
account->access++;
#endif
#if defined(FAN_MODIFY)
if (metadata->mask & FAN_MODIFY)
account->modify++;
#endif
inc_counter(args);
(void)close(metadata->fd);
}
metadata = FAN_EVENT_NEXT(metadata, len);
}
}
/* /*
* stress_fanotify() * stress_fanotify()
* stress fanotify * stress fanotify
*/ */
static int stress_fanotify(const stress_args_t *args) static int stress_fanotify(const stress_args_t *args)
{ {
char pathname[PATH_MAX - 16], filename[PATH_MAX]; char pathname[PATH_MAX - 16], filename[PATH_MAX];
int ret, fan_fd, pid, rc = EXIT_SUCCESS; int ret, pid, rc = EXIT_SUCCESS;
stress_fanotify_account_t account; stress_fanotify_account_t account;
(void)memset(&account, 0, sizeof(account)); (void)memset(&account, 0, sizeof(account));
stress_temp_dir_args(args, pathname, sizeof(pathname)); stress_temp_dir_args(args, pathname, sizeof(pathname));
(void)stress_mk_filename(filename, sizeof(filename), pathname, "fanotify_ file"); (void)stress_mk_filename(filename, sizeof(filename), pathname, "fanotify_ file");
ret = stress_temp_dir_mk_args(args); ret = stress_temp_dir_mk_args(args);
if (ret < 0) if (ret < 0)
return exit_status(-ret); return exit_status(-ret);
skipping to change at line 511 skipping to change at line 558
(void)n; (void)n;
(void)close(fd); (void)close(fd);
/* Force remove */ /* Force remove */
(void)unlink(filename); (void)unlink(filename);
} while (keep_stressing(args)); } while (keep_stressing(args));
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} else { } else {
void *buffer; void *buffer;
int fan_fd1, max_fd;
#if defined(FAN_CLASS_NOTIF) && \
defined(FAN_REPORT_DFID_NAME)
int fan_fd2;
#endif
fanotify_event_init_invalid(); fanotify_event_init_invalid();
ret = posix_memalign(&buffer, BUFFER_SIZE, BUFFER_SIZE); ret = posix_memalign(&buffer, BUFFER_SIZE, BUFFER_SIZE);
if ((ret != 0) || (buffer == NULL)) { if ((ret != 0) || (buffer == NULL)) {
pr_err("%s: posix_memalign: cannot allocate 4K " pr_err("%s: posix_memalign: cannot allocate 4K "
"aligned buffer\n", args->name); "aligned buffer\n", args->name);
rc = EXIT_NO_RESOURCE; rc = EXIT_NO_RESOURCE;
goto tidy; goto tidy;
} }
fan_fd = fanotify_event_init(args->name, mnts); fan_fd1 = fanotify_event_init(args->name, mnts, 0);
if (fan_fd < 0) { if (fan_fd1 < 0) {
free(buffer); free(buffer);
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
goto tidy; goto tidy;
} }
#if defined(FAN_CLASS_NOTIF) && \
defined(FAN_REPORT_DFID_NAME)
fan_fd2 = fanotify_event_init(args->name, mnts, FAN_CLASS_NOTIF |
FAN_REPORT_DFID_NAME);
if (fan_fd2 < 0) {
fan_fd2 = -1;
}
max_fd = STRESS_MAXIMUM(fan_fd1, fan_fd2);
#else
max_fd = fan_fd1;
#endif
ret = test_fanotify_mark(args->name, mnts); ret = test_fanotify_mark(args->name, mnts);
if (ret < 0) { if (ret < 0) {
free(buffer); free(buffer);
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
goto tidy; goto tidy;
} }
do { do {
fd_set rfds; fd_set rfds;
ssize_t len;
size_t i; size_t i;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(fan_fd, &rfds); FD_SET(fan_fd1, &rfds);
ret = select(fan_fd + 1, &rfds, NULL, NULL, NULL); #if defined(FAN_CLASS_NOTIF) && \
defined(FAN_REPORT_DFID_NAME)
if (fan_fd2 >= 0)
FD_SET(fan_fd2, &rfds);
#endif
ret = select(max_fd + 1, &rfds, NULL, NULL, NULL);
if (ret == -1) { if (ret == -1) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
pr_fail("%s: select failed, errno=%d (%s)\n", pr_fail("%s: select failed, errno=%d (%s)\n",
args->name, errno, strerror(errno)); args->name, errno, strerror(errno));
continue; continue;
} }
if (ret == 0) if (ret == 0)
continue; continue;
#if defined(FIONREAD) #if defined(FIONREAD)
{ {
int isz; int isz;
/* /*
* Force kernel to determine number * Force kernel to determine number
* of bytes that are ready to be read * of bytes that are ready to be read
* for some extra stress * for some extra stress
*/ */
ret = ioctl(fan_fd, FIONREAD, &isz); ret = ioctl(fan_fd1, FIONREAD, &isz);
(void)ret; (void)ret;
} }
#endif #endif
if ((len = read(fan_fd, (void *)buffer, BUFFER_SIZE)) > 0 if (FD_ISSET(fan_fd1, &rfds))
) { stress_fanotify_read_events(args, fan_fd1, buffer
struct fanotify_event_metadata *metadata; , BUFFER_SIZE, &account);
metadata = (struct fanotify_event_metadata *)buff #if defined(FAN_CLASS_NOTIF) && \
er; defined(FAN_REPORT_DFID_NAME)
if ((fan_fd2 >= 0) && FD_ISSET(fan_fd2, &rfds))
while (FAN_EVENT_OK(metadata, len)) { stress_fanotify_read_events(args, fan_fd2, buffer
if (!keep_stressing_flag()) , BUFFER_SIZE, &account);
break;
if ((metadata->fd != FAN_NOFD) && (metada
ta->fd >= 0)) {
#if defined(FAN_OPEN)
if (metadata->mask & FAN_OPEN)
account.open++;
#endif
#if defined(FAN_CLOSE_WRITE)
if (metadata->mask & FAN_CLOSE_WR
ITE)
account.close_write++;
#endif
#if defined(FAN_CLOSE_NOWRITE)
if (metadata->mask & FAN_CLOSE_NO
WRITE)
account.close_nowrite++;
#endif #endif
#if defined(FAN_ACCESS)
if (metadata->mask & FAN_ACCESS)
account.access++;
#endif
#if defined(FAN_MODIFY)
if (metadata->mask & FAN_MODIFY)
account.modify++;
#endif
inc_counter(args);
(void)close(metadata->fd);
}
metadata = FAN_EVENT_NEXT(metadata, len);
}
}
/* /*
* Exercise fanotify_init with all possible values * Exercise fanotify_init with all possible values
* of flag argument to increase kernel coverage * of flag argument to increase kernel coverage
*/ */
for (i = 0; i < SIZEOF_ARRAY(init_flags); i++) { for (i = 0; i < SIZEOF_ARRAY(init_flags); i++) {
stress_fanotify_init_exercise(init_flags[i]); stress_fanotify_init_exercise(init_flags[i]);
} }
} while (keep_stressing(args)); } while (keep_stressing(args));
free(buffer); free(buffer);
fanotify_event_clear(fan_fd); fanotify_event_clear(fan_fd1);
(void)close(fan_fd); (void)close(fan_fd1);
#if defined(FAN_CLASS_NOTIF) && \
defined(FAN_REPORT_DFID_NAME)
if (fan_fd2 >= 0) {
fanotify_event_clear(fan_fd2);
(void)close(fan_fd2);
}
#endif
pr_inf("%s: " pr_inf("%s: "
"%" PRIu64 " open, " "%" PRIu64 " open, "
"%" PRIu64 " close write, " "%" PRIu64 " close write, "
"%" PRIu64 " close nowrite, " "%" PRIu64 " close nowrite, "
"%" PRIu64 " access, " "%" PRIu64 " access, "
"%" PRIu64 " modify\n", "%" PRIu64 " modify\n",
args->name, args->name,
account.open, account.open,
account.close_write, account.close_write,
account.close_nowrite, account.close_nowrite,
 End of changes. 13 change blocks. 
49 lines changed or deleted 94 lines changed or added

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