Whamcloud - gitweb
LU-12780 lod: don't use ptlrpc_thread for recovery thread
[fs/lustre-release.git] / lustre / utils / lr_reader.c
index dff6de3..f1072a2 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -46,6 +42,9 @@
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif
+#include <errno.h>
+#include <limits.h>
+#include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 #include <getopt.h>
 
-#include <lustre_disk.h>
-#include <lustre_ver.h>
+#include <asm/byteorder.h>
+#include <linux/lustre/lustre_disk.h>
+#include <linux/lustre/lustre_ver.h>
 
 char *progname;
-static struct option const longopts[] = {
-       { "help", no_argument, 0, 'h' },
-       { "client", no_argument, 0, 'c' },
-       { "reply", no_argument, 0, 'r' },
-       { 0, 0, 0, 0}
-};
+static struct option const long_opts[] = {
+       { .val = 'c',   .name = "client",       .has_arg = no_argument },
+       { .val = 'h',   .name = "help",         .has_arg = no_argument },
+       { .val = 'r',   .name = "reply",        .has_arg = no_argument },
+       { .name = NULL } };
 
 /* Executes the command \a cmd and returns command status.
  */
@@ -87,10 +86,10 @@ int run_command(char *cmd, size_t cmdsz)
        fd = mkstemp(log);
        if (fd >= 0) {
                close(fd);
-               strncat(cmd, " >", 2);
-               strncat(cmd, log, strlen(log));
+               strncat(cmd, " >", cmdsz);
+               strncat(cmd, log, cmdsz);
        }
-       strncat(cmd, " 2>&1", 5);
+       strncat(cmd, " 2>&1", cmdsz - strlen(cmd));
 
        /* Can't use popen because we need the rv of the command */
        rc = system(cmd);
@@ -137,7 +136,7 @@ int main(int argc, char *const argv[])
        int opt_reply = 0;
 
        progname = argv[0];
-       while ((c = getopt_long(argc, argv, "chr", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "chr", long_opts, NULL)) != -1) {
                switch (c) {
                case 'c':
                        opt_client = 1;
@@ -198,26 +197,28 @@ int main(int argc, char *const argv[])
        }
 
        /* swab structure fields of interest */
-       lsd.lsd_feature_compat = le32_to_cpu(lsd.lsd_feature_compat);
-       lsd.lsd_feature_incompat = le32_to_cpu(lsd.lsd_feature_incompat);
-       lsd.lsd_feature_rocompat = le32_to_cpu(lsd.lsd_feature_rocompat);
-       lsd.lsd_last_transno = le64_to_cpu(lsd.lsd_last_transno);
-       lsd.lsd_osd_index = le32_to_cpu(lsd.lsd_osd_index);
-       lsd.lsd_mount_count = le64_to_cpu(lsd.lsd_mount_count);
+       lsd.lsd_feature_compat = __le32_to_cpu(lsd.lsd_feature_compat);
+       lsd.lsd_feature_incompat = __le32_to_cpu(lsd.lsd_feature_incompat);
+       lsd.lsd_feature_rocompat = __le32_to_cpu(lsd.lsd_feature_rocompat);
+       lsd.lsd_last_transno = __le64_to_cpu(lsd.lsd_last_transno);
+       lsd.lsd_osd_index = __le32_to_cpu(lsd.lsd_osd_index);
+       lsd.lsd_mount_count = __le64_to_cpu(lsd.lsd_mount_count);
 
        /* display */
        printf("  uuid: %.40s\n", lsd.lsd_uuid);
        printf("  feature_compat: %#x\n", lsd.lsd_feature_compat);
        printf("  feature_incompat: %#x\n", lsd.lsd_feature_incompat);
        printf("  feature_rocompat: %#x\n", lsd.lsd_feature_rocompat);
-       printf("  last_transaction: %llu\n", lsd.lsd_last_transno);
+       printf("  last_transaction: %llu\n",
+              (unsigned long long)lsd.lsd_last_transno);
        printf("  target_index: %u\n", lsd.lsd_osd_index);
-       printf("  mount_count: %llu\n", lsd.lsd_mount_count);
+       printf("  mount_count: %llu\n",
+              (unsigned long long)lsd.lsd_mount_count);
 
        /* read client information */
        if (opt_client) {
-               lsd.lsd_client_start = le32_to_cpu(lsd.lsd_client_start);
-               lsd.lsd_client_size = le16_to_cpu(lsd.lsd_client_size);
+               lsd.lsd_client_start = __le32_to_cpu(lsd.lsd_client_start);
+               lsd.lsd_client_size = __le16_to_cpu(lsd.lsd_client_size);
                printf("  client_area_start: %u\n", lsd.lsd_client_start);
                printf("  client_area_size: %hu\n", lsd.lsd_client_size);
 
@@ -250,35 +251,36 @@ int main(int argc, char *const argv[])
 
                        /* swab structure fields */
                        lcd.lcd_last_transno =
-                                       le64_to_cpu(lcd.lcd_last_transno);
-                       lcd.lcd_last_xid = le64_to_cpu(lcd.lcd_last_xid);
-                       lcd.lcd_last_result = le32_to_cpu(lcd.lcd_last_result);
-                       lcd.lcd_last_data = le32_to_cpu(lcd.lcd_last_data);
-                       lcd.lcd_generation = le32_to_cpu(lcd.lcd_generation);
+                                       __le64_to_cpu(lcd.lcd_last_transno);
+                       lcd.lcd_last_xid = __le64_to_cpu(lcd.lcd_last_xid);
+                       lcd.lcd_last_result = __le32_to_cpu(lcd.lcd_last_result);
+                       lcd.lcd_last_data = __le32_to_cpu(lcd.lcd_last_data);
+                       lcd.lcd_generation = __le32_to_cpu(lcd.lcd_generation);
 
                        /* display per-client data area */
                        printf("\n  %.40s:\n", lcd.lcd_uuid);
                        printf("    generation: %u\n", lcd.lcd_generation);
                        printf("    last_transaction: %llu\n",
-                              lcd.lcd_last_transno);
-                       printf("    last_xid: %llu\n", lcd.lcd_last_xid);
+                              (unsigned long long)lcd.lcd_last_transno);
+                       printf("    last_xid: %llu\n",
+                              (unsigned long long)lcd.lcd_last_xid);
                        printf("    last_result: %u\n", lcd.lcd_last_result);
                        printf("    last_data: %u\n", lcd.lcd_last_data);
 
                        if (lcd.lcd_last_close_transno != 0 &&
                            lcd.lcd_last_close_xid != 0) {
                                lcd.lcd_last_close_transno =
-                                       le64_to_cpu(lcd.lcd_last_close_transno);
+                                       __le64_to_cpu(lcd.lcd_last_close_transno);
                                lcd.lcd_last_close_xid =
-                                       le64_to_cpu(lcd.lcd_last_close_xid);
+                                       __le64_to_cpu(lcd.lcd_last_close_xid);
                                lcd.lcd_last_close_result =
-                                       le32_to_cpu(lcd.lcd_last_close_result);
+                                       __le32_to_cpu(lcd.lcd_last_close_result);
                                lcd.lcd_last_close_data =
-                                       le32_to_cpu(lcd.lcd_last_close_data);
+                                       __le32_to_cpu(lcd.lcd_last_close_data);
                                printf("    last_close_transation: %llu\n",
-                                      lcd.lcd_last_close_transno);
+                                      (unsigned long long)lcd.lcd_last_close_transno);
                                printf("    last_close_xid: %llu\n",
-                                      lcd.lcd_last_close_xid);
+                                      (unsigned long long)lcd.lcd_last_close_xid);
                                printf("    last_close_result: %u\n",
                                       lcd.lcd_last_close_result);
                                printf("    last_close_data: %u\n",
@@ -329,9 +331,9 @@ int main(int argc, char *const argv[])
                }
 
                /* check header */
-               lrh.lrh_magic = le32_to_cpu(lrh.lrh_magic);
-               lrh.lrh_header_size = le32_to_cpu(lrh.lrh_header_size);
-               lrh.lrh_reply_size = le32_to_cpu(lrh.lrh_reply_size);
+               lrh.lrh_magic = __le32_to_cpu(lrh.lrh_magic);
+               lrh.lrh_header_size = __le32_to_cpu(lrh.lrh_header_size);
+               lrh.lrh_reply_size = __le32_to_cpu(lrh.lrh_reply_size);
                if (lrh.lrh_magic != LRH_MAGIC) {
                        fprintf(stderr, "%s: invalid %s header: "
                                "lrh_magic=%08x expected %08x\n",
@@ -367,19 +369,22 @@ int main(int argc, char *const argv[])
                        }
 
                        /* display reply data */
-                       lrd.lrd_transno = le64_to_cpu(lrd.lrd_transno);
-                       lrd.lrd_xid = le64_to_cpu(lrd.lrd_xid);
-                       lrd.lrd_data = le64_to_cpu(lrd.lrd_data);
-                       lrd.lrd_result = le32_to_cpu(lrd.lrd_result);
-                       lrd.lrd_client_gen = le32_to_cpu(lrd.lrd_client_gen);
+                       lrd.lrd_transno = __le64_to_cpu(lrd.lrd_transno);
+                       lrd.lrd_xid = __le64_to_cpu(lrd.lrd_xid);
+                       lrd.lrd_data = __le64_to_cpu(lrd.lrd_data);
+                       lrd.lrd_result = __le32_to_cpu(lrd.lrd_result);
+                       lrd.lrd_client_gen = __le32_to_cpu(lrd.lrd_client_gen);
 
                        printf("  %lld:\n", slot);
                        printf("    client_generation: %u\n",
                               lrd.lrd_client_gen);
-                       printf("    last_transaction: %llu\n", lrd.lrd_transno);
-                       printf("    last_xid: %llu\n", lrd.lrd_xid);
+                       printf("    last_transaction: %lluu\n",
+                              (unsigned long long)lrd.lrd_transno);
+                       printf("    last_xid: %llu\n",
+                              (unsigned long long)lrd.lrd_xid);
                        printf("    last_result: %u\n", lrd.lrd_result);
-                       printf("    last_data: %llu\n\n", lrd.lrd_data);
+                       printf("    last_data: %llu\n\n",
+                              (unsigned long long)lrd.lrd_data);
                }
        }