Whamcloud - gitweb
LU-5170 utils: Add utility and command name to llapi messages 71/28571/8
authorSteve Guminski <stephenx.guminski@intel.com>
Thu, 3 Aug 2017 13:33:39 +0000 (09:33 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 9 Jan 2018 05:35:48 +0000 (05:35 +0000)
Allow error and info messages printed by llapi functions to
include the name of the utility and the command that caused
the error.  The command name is provided by the caller before
invoking any llapi functions through the use of the new function
llapi_set_command_name().  After the command has completed, the
utility should reset the name using llapi_clear_command_name().
If no command name is provided, only the utility name is printed.

The lfs and lctl utilities have been updated with the new functions.
They will print both the utility name and the command name while
in non-interactive mode.  In interactive mode, only the utility
name is printed.

Test-Parameters: trivial
Signed-off-by: Steve Guminski <stephenx.guminski@intel.com>
Change-Id: Ifaa1549f9bac6fdb25120f5721f69a8e1a7a52e1
Reviewed-on: https://review.whamcloud.com/28571
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre/lustreapi.h
lustre/utils/lctl.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 59253dd..8821b7f 100644 (file)
@@ -139,6 +139,8 @@ int llapi_get_poolmembers(const char *poolname, char **members, int list_size,
                          char *buffer, int buffer_size);
 int llapi_file_get_stripe(const char *path, struct lov_user_md *lum);
 int llapi_file_lookup(int dirfd, const char *name);
+void llapi_set_command_name(const char *cmd);
+void llapi_clear_command_name(void);
 
 #define VERBOSE_COUNT             0x1
 #define VERBOSE_SIZE              0x2
index 8df6e7b..32473b5 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/lnet/lnetctl.h>
 #include "obdctl.h"
 #include <linux/lustre/lustre_ver.h>
+#include <lustre/lustreapi.h>
 
 static int lctl_list_commands(int argc, char **argv);
 
@@ -546,7 +547,9 @@ int lctl_main(int argc, char **argv)
        Parser_init("lctl > ", cmdlist);
 
         if (argc > 1) {
+               llapi_set_command_name(argv[1]);
                 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
+               llapi_clear_command_name();
         } else {
                 rc = Parser_commands();
         }
index 16dead2..b99ee0c 100644 (file)
@@ -6829,11 +6829,14 @@ int main(int argc, char **argv)
 
        Parser_init("lfs > ", cmdlist);
 
-       progname = argv[0]; /* Used in error messages */
-       if (argc > 1)
+       progname = program_invocation_short_name; /* Used in error messages */
+       if (argc > 1) {
+               llapi_set_command_name(argv[1]);
                rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
-       else
+               llapi_clear_command_name();
+       } else {
                rc = Parser_commands();
+       }
 
        return rc < 0 ? -rc : rc;
 }
index fcc6014..4479092 100644 (file)
@@ -79,6 +79,7 @@
 #include "lustreapi_internal.h"
 
 static int llapi_msg_level = LLAPI_MSG_MAX;
+const char *liblustreapi_cmd;
 
 char *mdt_hash_name[] = { "none",
                          LMV_HASH_NAME_ALL_CHARS,
@@ -100,9 +101,24 @@ int llapi_msg_get_level(void)
        return llapi_msg_level;
 }
 
+void llapi_set_command_name(const char *cmd)
+{
+       liblustreapi_cmd = cmd;
+}
+
+void llapi_clear_command_name(void)
+{
+       liblustreapi_cmd = NULL;
+}
+
 static void error_callback_default(enum llapi_message_level level, int err,
                                   const char *fmt, va_list ap)
 {
+       if (liblustreapi_cmd != NULL)
+               fprintf(stderr, "%s %s: ", program_invocation_short_name,
+                       liblustreapi_cmd);
+       else
+               fprintf(stderr, "%s: ", program_invocation_short_name);
        vfprintf(stderr, fmt, ap);
        if (level & LLAPI_MSG_NO_ERRNO)
                fprintf(stderr, "\n");
@@ -113,6 +129,11 @@ static void error_callback_default(enum llapi_message_level level, int err,
 static void info_callback_default(enum llapi_message_level level, int err,
                                  const char *fmt, va_list ap)
 {
+       if (liblustreapi_cmd != NULL)
+               fprintf(stderr, "%s %s: ", program_invocation_short_name,
+                       liblustreapi_cmd);
+       else
+               fprintf(stderr, "%s: ", program_invocation_short_name);
        vfprintf(stdout, fmt, ap);
 }