Whamcloud - gitweb
LU-5969 lustreapi: replace llapi_get_version() 21/16721/11
authorAndreas Dilger <andreas.dilger@intel.com>
Tue, 17 May 2016 20:15:30 +0000 (16:15 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 14 Jun 2016 03:46:23 +0000 (03:46 +0000)
The existing llapi_get_version() helper has an awkward calling
style, requiring a temporary input buffer, as well as an output
pointer.

Replace this with llapi_get_version_string() which returns the
the simple version string.  Mark llapi_get_version() deprecated.
Update "lctl lustre_build_version" to use llapi_version_string().

These versions are extracted from {/proc,/sys}/fs/lustre/version
instead of an ioctl, to avoid the messiness that is Lustre ioctls.

Update the "version" file to only print the "lustre:" version,
since the "build:" version is now identical, and the "kernel:"
version has been "patchless_client" for many years already.

Print out the build version at the start of each test so it is
logged in the test results for convenience.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Change-Id: I681a353e6f65fd1ec2d1434fe38dfa55ed3ebbe5
Reviewed-on: http://review.whamcloud.com/16721
Tested-by: Jenkins
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre/lustreapi.h
lustre/obdclass/linux/linux-module.c
lustre/tests/test-framework.sh
lustre/utils/LCOPYING
lustre/utils/lctl.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi_param.c
lustre/utils/liblustreapi_util.c
lustre/utils/lustreapi_internal.h
lustre/utils/obd.c

index e680b4e..3f0cf97 100644 (file)
@@ -303,7 +303,10 @@ extern int llapi_chomp_string(char *buf);
 extern int llapi_open_by_fid(const char *dir, const lustre_fid *fid,
                             int open_flags);
 
 extern int llapi_open_by_fid(const char *dir, const lustre_fid *fid,
                             int open_flags);
 
-extern int llapi_get_version(char *buffer, int buffer_size, char **version);
+extern int llapi_get_version_string(char *version, unsigned int version_size);
+/* llapi_get_version() is deprecated, use llapi_get_version_string() instead */
+extern int llapi_get_version(char *buffer, int buffer_size, char **version)
+       __attribute__((deprecated));
 extern int llapi_get_data_version(int fd, __u64 *data_version, __u64 flags);
 extern int llapi_hsm_state_get_fd(int fd, struct hsm_user_state *hus);
 extern int llapi_hsm_state_get(const char *path, struct hsm_user_state *hus);
 extern int llapi_get_data_version(int fd, __u64 *data_version, __u64 flags);
 extern int llapi_hsm_state_get_fd(int fd, struct hsm_user_state *hus);
 extern int llapi_hsm_state_get(const char *path, struct hsm_user_state *hus);
index e0a54c5..fbe459f 100644 (file)
@@ -214,9 +214,7 @@ struct miscdevice obd_psdev = {
 #ifdef CONFIG_PROC_FS
 static int obd_proc_version_seq_show(struct seq_file *m, void *v)
 {
 #ifdef CONFIG_PROC_FS
 static int obd_proc_version_seq_show(struct seq_file *m, void *v)
 {
-       seq_printf(m, "lustre: %s\nkernel: %s\nbuild:  %s\n",
-                  LUSTRE_VERSION_STRING, "patchless_client",
-                  LUSTRE_VERSION_STRING);
+       seq_printf(m, "lustre: %s", LUSTRE_VERSION_STRING);
        return 0;
 }
 LPROC_SEQ_FOPS_RO(obd_proc_version);
        return 0;
 }
 LPROC_SEQ_FOPS_RO(obd_proc_version);
index b143748..cc573be 100755 (executable)
@@ -401,9 +401,7 @@ export LINUX_VERSION_CODE=$(version_code ${LINUX_VERSION//\./ })
 lustre_build_version() {
        local facet=${1:-client}
 
 lustre_build_version() {
        local facet=${1:-client}
 
-       # lustre: 2.6.52
-       # kernel: patchless_client
-       # build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.x86_64
+       # lustre: 2.8.52
        local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
                    awk '/lustre: / { print $2 }')
        # lctl 2.6.50
        local VER=$(do_facet $facet $LCTL get_param -n version 2> /dev/null |
                    awk '/lustre: / { print $2 }')
        # lctl 2.6.50
@@ -6666,29 +6664,36 @@ check_write_access() {
 }
 
 init_logging() {
 }
 
 init_logging() {
-    if [[ -n $YAML_LOG ]]; then
-        return
-    fi
-    local SAVE_UMASK=`umask`
-    umask 0000
-
-    export YAML_LOG=${LOGDIR}/results.yml
-    mkdir -p $LOGDIR
-    init_clients_lists
-
-    if [ ! -f $YAML_LOG ]; then       # If the yaml log already exists then we will just append to it
-      if check_shared_dir $LOGDIR; then
-          touch $LOGDIR/shared
-          echo "Logging to shared log directory: $LOGDIR"
-      else
-          echo "Logging to local directory: $LOGDIR"
-      fi
+       [[ -n $YAML_LOG ]] && return
+       local save_umask=$(umask)
+       umask 0000
 
 
-      yml_nodes_file $LOGDIR >> $YAML_LOG
-      yml_results_file >> $YAML_LOG
-    fi
+       export YAML_LOG=${LOGDIR}/results.yml
+       mkdir -p $LOGDIR
+       init_clients_lists
+
+       # If the yaml log already exists then we will just append to it
+       if [ ! -f $YAML_LOG ]; then
+               if check_shared_dir $LOGDIR; then
+                       touch $LOGDIR/shared
+                       echo "Logging to shared log directory: $LOGDIR"
+               else
+                       echo "Logging to local directory: $LOGDIR"
+               fi
+
+               yml_nodes_file $LOGDIR >> $YAML_LOG
+               yml_results_file >> $YAML_LOG
+       fi
+
+       umask $save_umask
 
 
-    umask $SAVE_UMASK
+       # If modules are not yet loaded then older "lctl lustre_build_version"
+       # will fail.  Use lctl build version instead.
+       log "Client: $($LCTL lustre_build_version)"
+       log "MDS: $(do_facet $SINGLEMDS $LCTL lustre_build_version 2>/dev/null||
+                   do_facet $SINGLEMDS $LCTL --version)"
+       log "OSS: $(do_facet ost1 $LCTL lustre_build_version 2> /dev/null ||
+                   do_facet ost1 $LCTL --version)"
 }
 
 log_test() {
 }
 
 log_test() {
index f63120d..569c8c7 100644 (file)
@@ -1,6 +1,10 @@
 This licence file applies to new library files:
 lustre/utils/liblustreapi_hsm.c
 This licence file applies to new library files:
 lustre/utils/liblustreapi_hsm.c
+lustre/utils/liblustreapi_json.c
 lustre/utils/liblustreapi_layout.c
 lustre/utils/liblustreapi_layout.c
+lustre/utils/liblustreapi_lease.c
+lustre/utils/liblustreapi_nodemap.c
+lustre/utils/liblustreapi_util.c
 lustre/utils/lustreapi_internal.h
 -------------------------------------------------------------------------------
                  GNU LESSER GENERAL PUBLIC LICENSE
 lustre/utils/lustreapi_internal.h
 -------------------------------------------------------------------------------
                  GNU LESSER GENERAL PUBLIC LICENSE
index 3d5eef2..e988206 100644 (file)
@@ -60,28 +60,28 @@ static int jt_opt_ignore_errors(int argc, char **argv) {
 }
 
 command_t cmdlist[] = {
 }
 
 command_t cmdlist[] = {
-        /* Metacommands */
-        {"===== metacommands =======", jt_noop, 0, "metacommands"},
-        {"--device", jt_opt_device, 0,
-         "run <command> after connecting to device <devno>\n"
-         "--device <devno> <command [args ...]>"},
-        {"--ignore_errors", jt_opt_ignore_errors, 0,
-         "ignore errors that occur during script processing\n"
-         "--ignore_errors"},
-        {"ignore_errors", jt_opt_ignore_errors, 0,
-         "ignore errors that occur during script processing\n"
-         "ignore_errors"},
+       /* Metacommands */
+       {"===== metacommands =======", jt_noop, 0, "metacommands"},
+       {"--device", jt_opt_device, 0,
+        "run <command> after connecting to device <devno>\n"
+        "--device <devno> <command [args ...]>"},
+       {"--ignore_errors", jt_opt_ignore_errors, 0,
+        "ignore errors that occur during script processing\n"
+        "--ignore_errors"},
+       {"ignore_errors", jt_opt_ignore_errors, 0,
+        "ignore errors that occur during script processing\n"
+        "ignore_errors"},
 
 
-        /* User interface commands */
-        {"======== control =========", jt_noop, 0, "control commands"},
-        {"help", Parser_help, 0, "help"},
-        {"lustre_build_version", jt_get_version, 0,
-         "print the build version of lustre\n"
-         "usage: lustre_build_version"},
+       /* User interface commands */
+       {"======== control =========", jt_noop, 0, "control commands"},
+       {"help", Parser_help, 0, "help"},
+       {"lustre_build_version", jt_get_version, 0,
+        "print version of Lustre modules\n"
+        "usage: lustre_build_version"},
        {"exit", Parser_quit, 0, "quit"},
        {"quit", Parser_quit, 0, "quit"},
        {"--version", Parser_version, 0,
        {"exit", Parser_quit, 0, "quit"},
        {"quit", Parser_quit, 0, "quit"},
        {"--version", Parser_version, 0,
-        "output build version of the utility and exit"},
+        "print build version of this utility and exit"},
 
        /* Network configuration commands */
        {"===== network config =====", jt_noop, 0, "network config"},
 
        /* Network configuration commands */
        {"===== network config =====", jt_noop, 0, "network config"},
index eebb848..9880bd3 100644 (file)
@@ -4288,34 +4288,6 @@ int llapi_get_connect_flags(const char *mnt, __u64 *flags)
         return rc;
 }
 
         return rc;
 }
 
-int llapi_get_version(char *buffer, int buffer_size,
-                      char **version)
-{
-        int rc;
-        int fd;
-        struct obd_ioctl_data *data = (struct obd_ioctl_data *)buffer;
-
-        fd = open(OBD_DEV_PATH, O_RDONLY);
-        if (fd == -1)
-                return -errno;
-
-        memset(buffer, 0, buffer_size);
-        data->ioc_version = OBD_IOCTL_VERSION;
-        data->ioc_inllen1 = buffer_size - cfs_size_round(sizeof(*data));
-        data->ioc_inlbuf1 = buffer + cfs_size_round(sizeof(*data));
-        data->ioc_len = obd_ioctl_packlen(data);
-
-        rc = ioctl(fd, OBD_GET_VERSION, buffer);
-        if (rc == -1) {
-                rc = -errno;
-                close(fd);
-                return rc;
-        }
-        close(fd);
-        *version = data->ioc_bulk;
-        return 0;
-}
-
 /**
  * Get a 64-bit value representing the version of file data pointed by fd.
  *
 /**
  * Get a 64-bit value representing the version of file data pointed by fd.
  *
index 65cad29..465b7f8 100644 (file)
@@ -67,7 +67,7 @@ get_lustre_param_path(const char *obd_type, const char *filter,
        char pattern[PATH_MAX];
        int rc = 0;
 
        char pattern[PATH_MAX];
        int rc = 0;
 
-       if (filter == NULL || obd_type == NULL)
+       if (filter == NULL && type != FILTER_BY_NONE)
                return -EINVAL;
 
        switch (type) {
                return -EINVAL;
 
        switch (type) {
@@ -91,14 +91,20 @@ get_lustre_param_path(const char *obd_type, const char *filter,
                        return -EINVAL;
                rc = 0;
                break;
                        return -EINVAL;
                rc = 0;
                break;
-       default:
+       case FILTER_BY_EXACT:
                if (strlen(filter) + 1 > sizeof(pattern))
                        return -E2BIG;
                strncpy(pattern, filter, sizeof(pattern));
                break;
                if (strlen(filter) + 1 > sizeof(pattern))
                        return -E2BIG;
                strncpy(pattern, filter, sizeof(pattern));
                break;
+       case FILTER_BY_NONE:
+       default:
+               break;
        }
 
        }
 
-       if (param_name != NULL) {
+       if (type == FILTER_BY_NONE) {
+               if (cfs_get_param_paths(param, "%s", param_name) != 0)
+                       rc = -errno;
+       } else if (param_name != NULL) {
                if (cfs_get_param_paths(param, "%s/%s/%s",
                                       obd_type, pattern, param_name) != 0)
                        rc = -errno;
                if (cfs_get_param_paths(param, "%s/%s/%s",
                                       obd_type, pattern, param_name) != 0)
                        rc = -errno;
index efd9d3c..db84f98 100644 (file)
@@ -5,6 +5,8 @@
  *
  * (C) Copyright (c) 2015, Cray Inc, all rights reserved.
  *
  *
  * (C) Copyright (c) 2015, Cray Inc, all rights reserved.
  *
+ * Copyright (c) 2016 Intel Corporation.
+ *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the GNU Lesser General Public License
  * LGPL version 2.1 or (at your discretion) any later version.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the GNU Lesser General Public License
  * LGPL version 2.1 or (at your discretion) any later version.
  * Author: Frank Zago <fzago@cray.com>
  */
 
  * Author: Frank Zago <fzago@cray.com>
  */
 
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <unistd.h>
-#include <stdbool.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <sys/syscall.h>
 #include <sys/syscall.h>
+#include <lustre/lustreapi.h>
+#include <libcfs/util/string.h>        /* only needed for compat strlcpy() */
+#include <lustre_ver.h>                /* only until LUSTRE_VERSION_CODE is gone */
+#include "lustreapi_internal.h"
 
 /*
  * Indicate whether the liblustreapi_init() constructor below has run or not.
  *
 
 /*
  * Indicate whether the liblustreapi_init() constructor below has run or not.
  *
- * This can be used by external programs to ensure if the initialization
+ * This can be used by external programs to ensure that the initialization
  * mechanism has actually worked.
  */
 bool liblustreapi_initialized;
 
 
  * mechanism has actually worked.
  */
 bool liblustreapi_initialized;
 
 
-/*
- * Initializes the library
+/**
+ * Initialize the library once at startup.
+ *
+ * Initializes the random number generator (random()). Get
+ * data from different places in case one of them fails. This
+ * is enough to get reasonably random numbers, but is not
+ * strong enough to be used for cryptography.
  */
 static __attribute__ ((constructor)) void liblustreapi_init(void)
 {
  */
 static __attribute__ ((constructor)) void liblustreapi_init(void)
 {
@@ -53,10 +68,6 @@ static __attribute__ ((constructor)) void liblustreapi_init(void)
        struct timeval  tv;
        int             fd;
 
        struct timeval  tv;
        int             fd;
 
-       /* Initializes the random number generator (random()). Get
-        * data from different places in case one of them fails. This
-        * is enough to get reasonably random numbers, but is not
-        * strong enough to be used for cryptography. */
        seed = syscall(SYS_gettid);
 
        if (gettimeofday(&tv, NULL) == 0) {
        seed = syscall(SYS_gettid);
 
        if (gettimeofday(&tv, NULL) == 0) {
@@ -77,3 +88,94 @@ static __attribute__ ((constructor)) void liblustreapi_init(void)
        srandom(seed);
        liblustreapi_initialized = true;
 }
        srandom(seed);
        liblustreapi_initialized = true;
 }
+
+/**
+ * Return the release version for the Lustre modules, e.g. 2.6.92.
+ *
+ * The "version" file in /proc currently returns only the line:
+ * lustre: 2.8.52
+ *
+ * but in the past it also returned more lines that should be ignored:
+ * kernel: patchless_client
+ * build: v2_6_92_0-gadb3ee4-2.6.32-431.29.2.el6_lustre.g36cd22b.x86_64
+ *
+ * \param version[in,out]      buffer to store build version string
+ * \param version_size[in]     size of \a version
+ *
+ * \retval                     0 on success
+ * \retval                     -1 on failure, errno set
+ */
+int llapi_get_version_string(char *version, unsigned int version_size)
+{
+       char buffer[4096];
+       char *ptr;
+       int rc;
+
+       if (version == NULL || version_size == 0) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       rc = get_lustre_param_value(NULL, NULL, FILTER_BY_NONE, buffer,
+                                   "version", sizeof(buffer));
+       if (rc < 0) {
+               errno = -rc;
+               return -1;
+       }
+
+       ptr = strstr(buffer, "lustre:");
+       if (ptr != NULL) {
+               llapi_chomp_string(ptr);
+               ptr += strlen("lustre:");
+               while (*ptr == ' ' || *ptr == '\t')
+                       ptr++;
+
+               if (strlcpy(version, ptr, version_size) >= version_size) {
+                       errno = EOVERFLOW;
+                       return -1;
+               }
+       } else {
+               errno = ENODATA;
+               return -1;
+       }
+
+       return 0;
+}
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 4, 53, 0)
+/**
+ * Return the build version of the Lustre code.
+ *
+ * The **version argument is pointless, so llapi_get_version_string() is
+ * better to use in the future, but give users a few versions to fix * it.
+ *
+ * \param buffer[in]           temporary buffer to hold version string
+ * \param buffer_size[in]      length of the \a buffer
+ * \param version[out]         pointer to the start of build version string
+ *
+ * \retval                     0 on success
+ * \retval                     -ve errno on failure
+ */
+int llapi_get_version(char *buffer, int buffer_size, char **version)
+{
+       int rc;
+#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 8, 53, 0)
+       static bool printed;
+       if (!printed) {
+               fprintf(stderr,
+                       "%s deprecated, use llapi_get_version_string()\n",
+                       __func__);
+               printed = true;
+       }
+#endif
+
+       rc = llapi_get_version_string(buffer, buffer_size);
+       /* keep old return style for this legacy function */
+       if (rc == -1)
+               rc = -errno;
+       else
+               *version = buffer;
+
+       return rc;
+}
+#endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 4, 53, 0) */
index 6730a9d..cff4860 100644 (file)
@@ -65,6 +65,7 @@ int root_ioctl(const char *mdtname, int opc, void *data, int *mdtidxp,
  *                   path as is.
  */
 enum param_filter {
  *                   path as is.
  */
 enum param_filter {
+       FILTER_BY_NONE,
        FILTER_BY_EXACT,
        FILTER_BY_FS_NAME,
        FILTER_BY_PATH
        FILTER_BY_EXACT,
        FILTER_BY_FS_NAME,
        FILTER_BY_PATH
index 1ca0932..37a9b8e 100644 (file)
@@ -927,21 +927,19 @@ int jt_obd_abort_recovery(int argc, char **argv)
 
 int jt_get_version(int argc, char **argv)
 {
 
 int jt_get_version(int argc, char **argv)
 {
-        int rc;
-        char rawbuf[MAX_IOC_BUFLEN];
-        char *version;
+       char version[128];
+       int rc;
 
 
-        if (argc != 1)
-                return CMD_HELP;
+       if (argc != 1)
+               return CMD_HELP;
 
 
-        rc = llapi_get_version(rawbuf, MAX_IOC_BUFLEN, &version);
-        if (rc)
-                fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
-                        strerror(-rc));
+       rc = llapi_get_version_string(version, sizeof(version));
+       if (rc)
+               printf("Lustre version: %s\n", LUSTRE_VERSION_STRING);
        else
                printf("Lustre version: %s\n", version);
 
        else
                printf("Lustre version: %s\n", version);
 
-       return rc;
+       return 0;
 }
 
 static void print_obd_line(char *s)
 }
 
 static void print_obd_line(char *s)