+/* Call LUSTRE_ACCESS_LOG_IOCTL_INFO to get access log info and print
+ * YAML formatted info to stdout. */
+static int alr_log_info(struct alr_log *al)
+{
+ struct lustre_access_log_info_v1 lali;
+ int rc;
+
+ rc = ioctl(al->alr_dev.alr_fd, LUSTRE_ACCESS_LOG_IOCTL_INFO, &lali);
+ if (rc < 0) {
+ ERROR("cannot get info for device '%s': %s\n",
+ al->alr_dev.alr_name, strerror(errno));
+ return -1;
+ }
+
+ printf("- name: %s\n"
+ " version: %#x\n"
+ " type: %#x\n"
+ " log_size: %u\n"
+ " entry_size: %u\n",
+ lali.lali_name,
+ lali.lali_version,
+ lali.lali_type,
+ lali.lali_log_size,
+ lali.lali_entry_size);
+
+ return 0;
+}
+
+static int alr_log_stats(FILE *file, struct alr_log *al)
+{
+ struct lustre_access_log_info_v1 lali;
+ int rc;
+
+ rc = ioctl(al->alr_dev.alr_fd, LUSTRE_ACCESS_LOG_IOCTL_INFO, &lali);
+ if (rc < 0) {
+ ERROR("cannot get info for device '%s': %s\n",
+ al->alr_dev.alr_name, strerror(errno));
+ return -1;
+ }
+
+#define X(m) \
+ fprintf(file, "STATS %s %s %u\n", lali.lali_name, #m, lali.m)
+
+ X(_lali_head);
+ X(_lali_tail);
+ X(_lali_entry_space);
+ X(_lali_entry_count);
+ X(_lali_drop_count);
+ X(_lali_is_closed);
+#undef X
+
+ fprintf(file, "STATS %s %s %zu\n",
+ lali.lali_name, "alr_read_count", al->alr_read_count);
+
+ return 0;
+}
+
+static void alr_log_stats_all(void)
+{
+ FILE *stats_file;
+ int m;
+
+ if (alr_stats_file_path == NULL) {
+ stats_file = stderr;
+ } else if (strcmp(alr_stats_file_path, "-") == 0) {
+ stats_file = stdout;
+ } else {
+ stats_file = fopen(alr_stats_file_path, "a");
+ if (stats_file == NULL) {
+ ERROR("cannot open '%s': %s\n",
+ alr_stats_file_path, strerror(errno));
+ return;
+ }
+ }
+
+ for (m = 0; m <= oal_log_minor_max; m++) {
+ if (alr_log[m] == NULL)
+ continue;
+
+ alr_log_stats(stats_file, alr_log[m]);
+ }
+
+ if (stats_file == stdout || stats_file == stderr)
+ fflush(stats_file);
+ else
+ fclose(stats_file);
+}
+