Whamcloud - gitweb
LU-1399 config: check lustre_cfg_new() return
[fs/lustre-release.git] / lustre / utils / obd.c
index dcc263f..20ec5f4 100644 (file)
@@ -52,6 +52,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <getopt.h>
 #include <glob.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -64,7 +65,7 @@
 
 #include "obdctl.h"
 #include <libcfs/libcfs.h>
-#include <lnet/lnet.h>
+#include <lnet/nidstr.h>
 #include <lustre/lustre_idl.h>
 #include <lustre_cfg.h>
 #include <lustre_ioctl.h>
@@ -932,17 +933,12 @@ int jt_get_version(int argc, char **argv)
         if (rc)
                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
                         strerror(-rc));
-        else
-                printf("Lustre version: %s\n", version);
+       else
+               printf("Lustre version: %s\n", version);
 
-        printf("lctl   version: %s\n", BUILD_VERSION);
-        return rc;
+       return rc;
 }
 
-/*
- * Print an obd device line with the ost_conn_uuid inserted, if the obd
- * is an osc.
- */
 static void print_obd_line(char *s)
 {
         char buf[MAX_STRING_SIZE];
@@ -950,7 +946,9 @@ static void print_obd_line(char *s)
         FILE *fp = NULL;
         char *ptr;
 
-        if (sscanf(s, " %*d %*s osc %s %*s %*d ", obd_name) == 0)
+       snprintf(buf, sizeof(buf), " %%*d %%*s osc %%%zus %%*s %%*d ",
+                sizeof(obd_name) - 1);
+       if (sscanf(s, buf, obd_name) == 0)
                 goto try_mdc;
         snprintf(buf, sizeof(buf),
                  "/proc/fs/lustre/osc/%s/ost_conn_uuid", obd_name);
@@ -959,7 +957,9 @@ static void print_obd_line(char *s)
         goto got_one;
 
 try_mdc:
-        if (sscanf(s, " %*d %*s mdc %s %*s %*d ", obd_name) == 0)
+       snprintf(buf, sizeof(buf), " %%*d %%*s mdc %%%zus %%*s %%*d ",
+                sizeof(obd_name) - 1);
+       if (sscanf(s, buf, obd_name) == 0)
                 goto fail;
         snprintf(buf, sizeof(buf),
                  "/proc/fs/lustre/mdc/%s/mds_conn_uuid", obd_name);
@@ -3209,9 +3209,9 @@ static int pool_cmd(enum lcfg_command_type cmd,
         if (ostname != NULL)
                 lustre_cfg_bufs_set_string(&bufs, 2, ostname);
 
-        lcfg = lustre_cfg_new(cmd, &bufs);
+       lcfg = lustre_cfg_new(cmd, &bufs);
        if (lcfg == NULL)
-               return rc;
+               return -ENOMEM;
 
         memset(&data, 0, sizeof(data));
         rc = data.ioc_dev = get_mgs_device();
@@ -3228,6 +3228,7 @@ static int pool_cmd(enum lcfg_command_type cmd,
         if (rc) {
                 fprintf(stderr, "error: %s: invalid ioctl\n",
                         jt_cmdname(cmdname));
+               lustre_cfg_free(lcfg);
                 return rc;
         }
         rc = l_ioctl(OBD_DEV_ID, OBD_IOC_POOL, buf);
@@ -3741,8 +3742,10 @@ int jt_nodemap_modify(int argc, char **argv)
        }
 
        if (nodemap_name == NULL || param == NULL || value == NULL) {
-               fprintf(stderr, "usage: nodemap_modify --name <name> "
-                               "--property <range> --value <value>\n");
+               fprintf(stderr, "usage: nodemap_modify --name <nodemap_name> "
+                               "--property <property_name> --value <value>\n");
+               fprintf(stderr, "valid properties: admin trusted "
+                               "squash_uid squash_gid\n");
                return -1;
        }
 
@@ -3909,7 +3912,7 @@ int jt_nodemap_del_idmap(int argc, char **argv)
        rc = nodemap_cmd(cmd, NULL, 0, argv[0], nodemap_name, idmap, NULL);
        if (rc != 0) {
                errno = -rc;
-               fprintf(stderr, "cannot add %smap '%s' to nodemap '%s'"
+               fprintf(stderr, "cannot delete %smap '%s' from nodemap '%s'"
                        ": rc = %d\n", idtype, idmap, nodemap_name, rc);
        }