4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
22 * Copyright 2020, DataDirect Networks Storage.
24 * This file is part of Lustre, http://www.lustre.org/
26 * Author: John L. Hammond <jhammond@whamcloud.com>
28 * lustre/utils/ofd_access_log_reader.c
30 * Sample utility to discover and read Lustre (ofd) access logs.
32 * This demonstrates the discovery and reading of Lustre access logs
33 * (see linux/lustre/lustre_access_log.h and
34 * lustre/ofd/ofd_access_log.c.). By default it opens the control
35 * device, discovers and opens all access log devices, and consumes
36 * all access log entries. If invoked with the --list option then it
37 * prints information about all available devices to stdout and exits.
39 * Structured trace points (when --trace is used) are added to permit
40 * testing of the access log functionality (see test_165* in
41 * lustre/tests/sanity.sh).
58 #include <sys/epoll.h>
59 #include <sys/ioctl.h>
60 #include <sys/signalfd.h>
62 #include <sys/sysmacros.h>
63 #include <sys/timerfd.h>
64 #include <sys/types.h>
65 #include <linux/types.h>
66 #include <linux/lustre/lustre_user.h>
67 #include <linux/lustre/lustre_access_log.h>
68 #include "ofd_access_batch.h"
71 /* TODO fsname filter */
73 static FILE *debug_file;
74 static FILE *trace_file;
76 #define DEBUG(fmt, args...) \
78 if (debug_file != NULL) \
79 fprintf(debug_file, "DEBUG %s:%d: "fmt, __func__, __LINE__, ##args); \
82 #define TRACE(fmt, args...) \
84 if (trace_file != NULL) \
85 fprintf(trace_file, "TRACE "fmt, ##args); \
88 #define DEBUG_D(x) DEBUG("%s = %"PRIdMAX"\n", #x, (intmax_t)x)
89 #define DEBUG_P(x) DEBUG("%s = %p\n", #x, x)
90 #define DEBUG_S(x) DEBUG("%s = '%s'\n", #x, x)
91 #define DEBUG_U(x) DEBUG("%s = %"PRIuMAX"\n", #x, (uintmax_t)x)
93 #define ERROR(fmt, args...) \
94 fprintf(stderr, "%s: "fmt, program_invocation_short_name, ##args)
96 #define FATAL(fmt, args...) \
98 ERROR("FATAL: "fmt, ##args); \
103 ALR_EXIT_SUCCESS = INT_MIN + EXIT_SUCCESS,
104 ALR_EXIT_FAILURE = INT_MIN + EXIT_FAILURE,
112 int (*alr_io)(int /* epoll_fd */, struct alr_dev * /* this */, unsigned int /* mask */);
113 void (*alr_destroy)(struct alr_dev *);
118 struct alr_dev alr_dev;
121 size_t alr_entry_size;
122 size_t alr_read_count;
126 static unsigned int alr_log_count;
127 static struct alr_log *alr_log[1 << 20]; /* 20 == MINORBITS */
128 static int oal_version; /* FIXME ... major version, minor version */
129 static __u32 alr_filter = 0xffffffff; /* no filter by default */
130 static unsigned int oal_log_major;
131 static unsigned int oal_log_minor_max;
132 static struct alr_batch *alr_batch;
133 static FILE *alr_batch_file;
134 static pthread_mutex_t alr_batch_file_mutex = PTHREAD_MUTEX_INITIALIZER;
135 static const char *alr_batch_file_path;
136 static const char *alr_stats_file_path;
137 static int alr_print_fraction = 100;
139 #define D_ALR_DEV "%s %d"
140 #define P_ALR_DEV(ad) \
141 (ad)->alr_name, (ad)->alr_fd
143 #define D_ALR_LOG D_ALR_DEV" %u:%u"
144 #define P_ALR_LOG(al) \
145 P_ALR_DEV(&(al)->alr_dev), major((al)->alr_rdev), minor((al)->alr_rdev)
147 static void alr_dev_free(int epoll_fd, struct alr_dev *ad)
149 TRACE("alr_dev_free %s\n", ad->alr_name);
151 if (!(ad->alr_fd < 0))
152 epoll_ctl(epoll_fd, EPOLL_CTL_DEL, ad->alr_fd, NULL);
154 if (ad->alr_destroy != NULL)
155 (*ad->alr_destroy)(ad);
157 if (!(ad->alr_fd < 0))
164 static struct alr_log **alr_log_lookup(dev_t rdev)
166 assert(major(rdev) == oal_log_major);
168 if (!(minor(rdev) < ARRAY_SIZE(alr_log)))
171 return &alr_log[minor(rdev)];
174 static const char *alr_flags_to_str(unsigned int flags)
176 switch (flags & (OFD_ACCESS_READ | OFD_ACCESS_WRITE)) {
179 case OFD_ACCESS_READ:
181 case OFD_ACCESS_WRITE:
183 case OFD_ACCESS_READ | OFD_ACCESS_WRITE:
188 /* /dev/lustre-access-log/scratch-OST0000 device poll callback: read entries
189 * from log and print. */
190 static int alr_log_io(int epoll_fd, struct alr_dev *ad, unsigned int mask)
192 struct alr_log *al = container_of(ad, struct alr_log, alr_dev);
195 TRACE("alr_log_io %s\n", ad->alr_name);
198 assert(al->alr_entry_size != 0);
199 assert(al->alr_buf_size != 0);
200 assert(al->alr_buf != NULL);
202 count = read(ad->alr_fd, al->alr_buf, al->alr_buf_size);
204 ERROR("cannot read events from '%s': %s\n", ad->alr_name, strerror(errno));
209 TRACE("alr_log_eof %s\n", ad->alr_name);
213 if (count % al->alr_entry_size != 0) {
214 ERROR("invalid read from "D_ALR_LOG": entry_size = %zu, count = %zd\n",
215 P_ALR_LOG(al), al->alr_entry_size, count);
219 DEBUG("read "D_ALR_LOG", count = %zd\n", P_ALR_LOG(al), count);
221 al->alr_read_count += count / al->alr_entry_size;
223 for (i = 0; i < count; i += al->alr_entry_size) {
224 struct ofd_access_entry_v1 *oae =
225 (struct ofd_access_entry_v1 *)&al->alr_buf[i];
227 TRACE("alr_log_entry %s "DFID" %lu %lu %lu %u %u %s\n",
229 PFID(&oae->oae_parent_fid),
230 (unsigned long)oae->oae_begin,
231 (unsigned long)oae->oae_end,
232 (unsigned long)oae->oae_time,
233 (unsigned int)oae->oae_size,
234 (unsigned int)oae->oae_segment_count,
235 alr_flags_to_str(oae->oae_flags));
237 alr_batch_add(alr_batch, ad->alr_name, &oae->oae_parent_fid,
238 oae->oae_time, oae->oae_begin, oae->oae_end,
239 oae->oae_size, oae->oae_segment_count, oae->oae_flags);
245 static void alr_log_destroy(struct alr_dev *ad)
247 struct alr_log *al = container_of(ad, struct alr_log, alr_dev);
248 struct alr_log **pal;
250 TRACE("alr_log_free %s\n", ad->alr_name);
251 assert(major(al->alr_rdev) == oal_log_major);
253 pal = alr_log_lookup(al->alr_rdev);
254 if (pal != NULL && *pal == al)
259 al->alr_buf_size = 0;
263 /* Add an access log (identified by path) to the epoll set. */
264 static int alr_log_add(int epoll_fd, const char *path)
266 struct alr_log **pal, *al = NULL;
273 fd = open(path, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
275 ERROR("cannot open device '%s': %s\n", path, strerror(errno));
276 rc = (errno == ENOENT ? 0 : -1); /* Possible race. */
280 /* Revalidate rdev in case of race. */
283 ERROR("cannot stat '%s': %s\n", path, strerror(errno));
287 if (major(st.st_rdev) != oal_log_major)
290 pal = alr_log_lookup(st.st_rdev);
292 ERROR("no device slot available for '%s' with minor %u\n",
293 path, minor(st.st_rdev));
298 goto out; /* We already have this device. */
300 struct lustre_access_log_info_v1 lali;
302 memset(&lali, 0, sizeof(lali));
304 rc = ioctl(fd, LUSTRE_ACCESS_LOG_IOCTL_INFO, &lali);
306 ERROR("cannot get info for device '%s': %s\n",
307 path, strerror(errno));
311 if (lali.lali_type != LUSTRE_ACCESS_LOG_TYPE_OFD) {
315 rc = ioctl(fd, LUSTRE_ACCESS_LOG_IOCTL_FILTER, alr_filter);
317 ERROR("cannot set filter '%s': %s\n",
318 path, strerror(errno));
322 al = calloc(1, sizeof(*al));
324 FATAL("cannot allocate struct alr_dev of size %zu: %s\n",
325 sizeof(*al), strerror(errno));
328 al->alr_dev.alr_io = &alr_log_io;
329 al->alr_dev.alr_destroy = &alr_log_destroy;
330 al->alr_dev.alr_fd = fd;
333 al->alr_rdev = st.st_rdev;
335 al->alr_dev.alr_name = strdup(lali.lali_name);
336 if (al->alr_dev.alr_name == NULL)
337 FATAL("cannot copy name of size %zu: %s\n",
338 strlen(lali.lali_name), strerror(errno));
340 al->alr_buf_size = lali.lali_log_size;
341 al->alr_entry_size = lali.lali_entry_size;
343 if (al->alr_entry_size == 0) {
344 ERROR("device '%s' has zero entry size\n", path);
349 if (al->alr_buf_size == 0)
350 al->alr_buf_size = 1048576;
352 al->alr_buf_size = roundup(al->alr_buf_size, al->alr_entry_size);
354 al->alr_buf = malloc(al->alr_buf_size);
355 if (al->alr_buf == NULL)
356 FATAL("cannot allocate log buffer for '%s' of size %zu: %s\n",
357 path, al->alr_buf_size, strerror(errno));
359 struct epoll_event ev = {
360 .events = EPOLLIN | EPOLLHUP,
361 .data.ptr = &al->alr_dev,
364 rc = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, al->alr_dev.alr_fd, &ev);
366 ERROR("cannot add device '%s' to epoll set: %s\n",
367 path, strerror(errno));
371 TRACE("alr_log_add %s\n", al->alr_dev.alr_name);
373 if (oal_log_minor_max < minor(al->alr_rdev))
374 oal_log_minor_max = minor(al->alr_rdev);
376 assert(*pal == NULL);
382 alr_dev_free(epoll_fd, &al->alr_dev);
390 /* Call LUSTRE_ACCESS_LOG_IOCTL_INFO to get access log info and print
391 * YAML formatted info to stdout. */
392 static int alr_log_info(struct alr_log *al)
394 struct lustre_access_log_info_v1 lali;
397 rc = ioctl(al->alr_dev.alr_fd, LUSTRE_ACCESS_LOG_IOCTL_INFO, &lali);
399 ERROR("cannot get info for device '%s': %s\n",
400 al->alr_dev.alr_name, strerror(errno));
404 printf("- name: %s\n"
413 lali.lali_entry_size);
418 static int alr_log_stats(FILE *file, struct alr_log *al)
420 struct lustre_access_log_info_v1 lali;
423 rc = ioctl(al->alr_dev.alr_fd, LUSTRE_ACCESS_LOG_IOCTL_INFO, &lali);
425 ERROR("cannot get info for device '%s': %s\n",
426 al->alr_dev.alr_name, strerror(errno));
431 fprintf(file, "STATS %s %s %u\n", lali.lali_name, #m, lali.m)
435 X(_lali_entry_space);
436 X(_lali_entry_count);
441 fprintf(file, "STATS %s %s %zu\n",
442 lali.lali_name, "alr_read_count", al->alr_read_count);
447 static void alr_log_stats_all(void)
452 if (alr_stats_file_path == NULL) {
454 } else if (strcmp(alr_stats_file_path, "-") == 0) {
457 stats_file = fopen(alr_stats_file_path, "a");
458 if (stats_file == NULL) {
459 ERROR("cannot open '%s': %s\n",
460 alr_stats_file_path, strerror(errno));
465 for (m = 0; m <= oal_log_minor_max; m++) {
466 if (alr_log[m] == NULL)
469 alr_log_stats(stats_file, alr_log[m]);
472 if (stats_file == stdout || stats_file == stderr)
478 /* Scan /dev/lustre-access-log/ for new access log devices and add to
480 static int alr_scan(int epoll_fd)
482 const char dir_path[] = "/dev/"LUSTRE_ACCESS_LOG_DIR_NAME;
488 dir = opendir(dir_path);
490 ERROR("cannot open '%s' for scanning: %s\n", dir_path, strerror(errno));
491 return ALR_EXIT_FAILURE;
496 /* Scan /dev for devices with major equal to oal_log_major and add
497 * any new devices. */
498 while ((d = readdir(dir)) != NULL) {
499 char path[6 + PATH_MAX];
500 struct alr_log **pal;
503 if (d->d_type != DT_CHR)
506 rc = fstatat(dir_fd, d->d_name, &st, 0);
508 ERROR("cannot stat '%s/%s' while scanning: %s\n",
509 dir_path, d->d_name, strerror(errno));
513 if (!S_ISCHR(st.st_mode))
516 if (major(st.st_rdev) != oal_log_major)
519 pal = alr_log_lookup(st.st_rdev);
521 ERROR("no device slot available for '%s/%s' with minor %u\n",
522 dir_path, d->d_name, minor(st.st_rdev));
527 continue; /* We already have this device. */
529 snprintf(path, sizeof(path), "%s/%s", dir_path, d->d_name);
531 alr_log_add(epoll_fd, path);
539 /* /dev/lustre-access-log/control device poll callback: call prescan
540 * ioctl and scan /dev/lustre-access-log/ for new access log
542 static int alr_ctl_io(int epoll_fd, struct alr_dev *cd, unsigned int mask)
546 TRACE("%s\n", __func__);
550 return ALR_EXIT_FAILURE;
553 return ALR_EXIT_SUCCESS;
555 rc = ioctl(cd->alr_fd, LUSTRE_ACCESS_LOG_IOCTL_PRESCAN);
557 ERROR("cannot start scanning: %s\n", strerror(errno));
558 return ALR_EXIT_FAILURE;
561 return alr_scan(epoll_fd);
564 /* signalfd epoll callback. Handle SIGINT and SIGTERM by breaking from
565 * the epoll loop and exiting normally.*/
566 static int alr_signal_io(int epoll_fd, struct alr_dev *sd, unsigned int mask)
568 struct signalfd_siginfo ssi;
571 TRACE("%s\n", __func__);
574 rc = read(sd->alr_fd, &ssi, sizeof(ssi));
578 DEBUG_U(ssi.ssi_signo);
579 switch (ssi.ssi_signo) {
582 return ALR_EXIT_SUCCESS;
588 if (debug_file == NULL)
591 if (trace_file == NULL)
600 /* batching timerfd epoll callback. Print batched access entries to
602 static int alr_batch_timer_io(int epoll_fd, struct alr_dev *td, unsigned int mask)
604 time_t now = time(NULL);
605 uint64_t expire_count;
608 TRACE("%s\n", __func__);
612 rc = read(td->alr_fd, &expire_count, sizeof(expire_count));
616 DEBUG_U(expire_count);
618 rc = alr_batch_print(alr_batch, alr_batch_file, &alr_batch_file_mutex,
621 ERROR("cannot write to '%s': %s\n",
622 alr_batch_file_path, strerror(errno));
626 /* Failed writes will leave alr_batch_file (pipe) in a
627 * weird state so make that fatal. */
628 return (rc < 0) ? ALR_EXIT_FAILURE : ALR_OK;
631 /* batch file (stdout) poll callback: detect remote pipe close and exit. */
632 static int alr_batch_file_io(int epoll_fd, struct alr_dev *ad, unsigned int mask)
634 TRACE("%s\n", __func__);
638 return ALR_EXIT_SUCCESS;
641 return ALR_EXIT_FAILURE;
646 static struct alr_dev *alr_dev_create(int epoll_fd, int fd, const char *name,
648 int (*io)(int, struct alr_dev *, unsigned int),
649 void (*destroy)(struct alr_dev *))
654 alr = calloc(1, sizeof(*alr));
658 alr->alr_name = strdup(name);
659 if (alr->alr_name == NULL) {
664 alr->alr_destroy = destroy;
667 struct epoll_event event = {
672 rc = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, alr->alr_fd, &event);
683 printf("Usage: %s: [OPTION]...\n"
684 "Discover, read, batch, and write Lustre access logs\n"
686 "Mandatory arguments to long options are mandatory for short options too.\n"
687 " -f, --batch-file=FILE print batch to file (default stdout)\n"
688 " -F, --batch-fraction=P set batch printing fraction to P/100\n"
689 " -i, --batch-interval=INTERVAL print batch every INTERVAL seconds\n"
690 " -o, --batch-offset=OFFSET print batch at OFFSET seconds\n"
691 " -e, --exit-on-close exit on close of all log devices\n"
692 " -I, --mdt-index-filter=INDEX set log MDT index filter to INDEX\n"
693 " -h, --help display this help and exit\n"
694 " -l, --list print YAML list of available access logs\n"
695 " -d, --debug[=FILE] print debug messages to FILE (stderr)\n"
696 " -s, --stats=FILE print stats messages to FILE (stderr)\n"
697 " -t, --trace[=FILE] print trace messages to FILE (stderr)\n",
698 program_invocation_short_name);
701 int main(int argc, char *argv[])
703 const char ctl_path[] = "/dev/"LUSTRE_ACCESS_LOG_DIR_NAME"/control";
704 struct alr_dev *alr_signal = NULL;
705 struct alr_dev *alr_batch_timer = NULL;
706 struct alr_dev *alr_batch_file_hup = NULL;
707 struct alr_dev *alr_ctl = NULL;
708 int exit_on_close = 0;
709 time_t batch_interval = 0;
710 time_t batch_offset = 0;
718 static struct option options[] = {
719 { .name = "batch-file", .has_arg = required_argument, .val = 'f', },
720 { .name = "batch-fraction", .has_arg = required_argument, .val = 'F', },
721 { .name = "batch-interval", .has_arg = required_argument, .val = 'i', },
722 { .name = "batch-offset", .has_arg = required_argument, .val = 'o', },
723 { .name = "exit-on-close", .has_arg = no_argument, .val = 'e', },
724 { .name = "mdt-index-filter", .has_arg = required_argument, .val = 'I' },
725 { .name = "debug", .has_arg = optional_argument, .val = 'd', },
726 { .name = "help", .has_arg = no_argument, .val = 'h', },
727 { .name = "list", .has_arg = no_argument, .val = 'l', },
728 { .name = "stats", .has_arg = required_argument, .val = 's', },
729 { .name = "trace", .has_arg = optional_argument, .val = 't', },
733 while ((c = getopt_long(argc, argv, "d::ef:F:hi:I:ls:t::", options, NULL)) != -1) {
739 alr_batch_file_path = optarg;
743 batch_interval = strtoll(optarg, NULL, 0);
744 if (batch_interval < 0 || batch_interval >= 1048576 ||
746 FATAL("invalid batch interval '%s'\n", optarg);
750 batch_offset = strtoll(optarg, NULL, 0);
751 if (batch_offset < 0 || batch_offset >= 1048576 ||
753 FATAL("invalid batch offset '%s'\n", optarg);
756 if (optarg == NULL) {
758 } else if (strcmp(optarg, "-") == 0) {
761 debug_file = fopen(optarg, "a");
762 if (debug_file == NULL)
763 FATAL("cannot open debug file '%s': %s\n",
764 optarg, strerror(errno));
772 alr_print_fraction = strtoll(optarg, NULL, 0);
773 if (alr_print_fraction < 1 || alr_print_fraction > 100)
774 FATAL("invalid batch offset '%s'\n", optarg);
777 alr_filter = strtoll(optarg, NULL, 0);
783 alr_stats_file_path = optarg;
786 if (optarg == NULL) {
788 } else if (strcmp(optarg, "-") == 0) {
791 trace_file = fopen(optarg, "a");
792 if (debug_file == NULL)
793 FATAL("cannot open debug file '%s': %s\n",
794 optarg, strerror(errno));
799 fprintf(stderr, "Try '%s --help' for more information.\n",
800 program_invocation_short_name);
805 if (batch_interval > 0) {
806 alr_batch = alr_batch_create(-1);
807 if (alr_batch == NULL)
808 FATAL("cannot create batch struct: %s\n",
812 if (alr_batch_file_path != NULL) {
813 alr_batch_file = fopen(alr_batch_file_path, "w");
814 if (alr_batch_file == NULL)
815 FATAL("cannot open batch file '%s': %s\n",
816 alr_batch_file_path, strerror(errno));
818 alr_batch_file_path = "stdout";
819 alr_batch_file = stdout;
822 epoll_fd = epoll_create1(EPOLL_CLOEXEC);
824 FATAL("cannot create epoll set: %s\n", strerror(errno));
826 /* Setup signal FD and add to epoll set. */
827 sigset_t signal_mask;
828 sigemptyset(&signal_mask);
829 sigaddset(&signal_mask, SIGINT);
830 sigaddset(&signal_mask, SIGTERM);
831 sigaddset(&signal_mask, SIGUSR1);
832 sigaddset(&signal_mask, SIGUSR2);
833 rc = sigprocmask(SIG_BLOCK, &signal_mask, NULL);
835 FATAL("cannot set process signal mask: %s\n", strerror(errno));
837 int signal_fd = signalfd(-1, &signal_mask, SFD_NONBLOCK|SFD_CLOEXEC);
839 FATAL("cannot create signalfd: %s\n", strerror(errno));
841 alr_signal = alr_dev_create(epoll_fd, signal_fd, "signal", EPOLLIN,
842 &alr_signal_io, NULL);
843 if (alr_signal == NULL)
844 FATAL("cannot register signalfd: %s\n", strerror(errno));
848 /* Setup batch timer FD and add to epoll set. */
850 rc = clock_gettime(CLOCK_REALTIME, &now);
852 FATAL("cannot read realtime clock: %s\n", strerror(errno));
854 int timer_fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC);
856 FATAL("cannot create batch timerfd: %s\n", strerror(errno));
858 struct itimerspec it = {
859 .it_value.tv_sec = (batch_interval > 0) ?
860 roundup(now.tv_sec, batch_interval) +
861 (batch_offset % batch_interval) :
863 .it_interval.tv_sec = batch_interval,
866 DEBUG_D(it.it_value.tv_sec);
868 rc = timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &it, NULL);
870 FATAL("cannot arm timerfd: %s\n", strerror(errno));
872 alr_batch_timer = alr_dev_create(epoll_fd, timer_fd, "batch_timer",
873 EPOLLIN, &alr_batch_timer_io, NULL);
874 if (alr_batch_timer == NULL)
875 FATAL("cannot register batch timerfd: %s\n", strerror(errno));
879 int batch_fd = dup(fileno(alr_batch_file));
881 FATAL("cannot duplicate batch file descriptor: %s\n",
884 /* We pass events = 0 since we only care about EPOLLHUP. */
885 alr_batch_file_hup = alr_dev_create(epoll_fd, batch_fd, "batch_file", 0,
886 &alr_batch_file_io, NULL);
887 if (alr_batch_file_hup == NULL)
888 FATAL("cannot register batch file HUP: %s\n", strerror(errno));
892 /* Open control device. */
893 int ctl_fd = open(ctl_path, O_RDONLY|O_NONBLOCK|O_CLOEXEC);
895 FATAL("cannot open '%s': %s\n", ctl_path, strerror(errno));
897 /* Get and print interface version. */
898 oal_version = ioctl(ctl_fd, LUSTRE_ACCESS_LOG_IOCTL_VERSION);
900 FATAL("cannot get ofd access log interface version: %s\n", strerror(errno));
902 DEBUG_D(oal_version);
904 /* Get and print device major used for access log devices. */
905 oal_log_major = ioctl(ctl_fd, LUSTRE_ACCESS_LOG_IOCTL_MAJOR);
906 if (oal_log_major < 0)
907 FATAL("cannot get ofd access log major: %s\n", strerror(errno));
909 DEBUG_D(oal_log_major);
911 /* Add control device to epoll set. */
912 alr_ctl = alr_dev_create(epoll_fd, ctl_fd, "control", EPOLLIN,
915 FATAL("cannot register control device: %s\n", strerror(errno));
920 struct epoll_event ev[32];
921 int timeout = (list_info ? 0 : -1);
924 ev_count = epoll_wait(epoll_fd, ev, ARRAY_SIZE(ev), timeout);
926 if (errno == EINTR) /* Signal or timeout. */
929 ERROR("cannot wait on epoll set: %s\n", strerror(errno));
930 exit_status = EXIT_FAILURE;
936 for (i = 0; i < ev_count; i++) {
937 struct alr_dev *ad = ev[i].data.ptr;
938 unsigned int mask = ev[i].events;
940 rc = (*ad->alr_io)(epoll_fd, ad, mask);
942 case ALR_EXIT_FAILURE:
943 exit_status = EXIT_FAILURE;
945 case ALR_EXIT_SUCCESS:
946 exit_status = EXIT_SUCCESS;
950 alr_dev_free(epoll_fd, ad);
958 if (exit_on_close && alr_log_count == 0) {
959 DEBUG("no open logs devices, exiting\n");
960 exit_status = EXIT_SUCCESS;
963 } while (!list_info);
965 exit_status = EXIT_SUCCESS;
967 assert(oal_log_minor_max < ARRAY_SIZE(alr_log));
969 for (m = 0; m <= oal_log_minor_max; m++) {
970 if (alr_log[m] == NULL)
974 rc = alr_log_info(alr_log[m]);
976 exit_status = EXIT_FAILURE;
979 alr_dev_free(epoll_fd, &alr_log[m]->alr_dev);
982 alr_dev_free(epoll_fd, alr_ctl);
983 alr_dev_free(epoll_fd, alr_signal);
984 alr_dev_free(epoll_fd, alr_batch_timer);
985 alr_dev_free(epoll_fd, alr_batch_file_hup);
988 alr_batch_destroy(alr_batch);
990 DEBUG_D(exit_status);