multipath-tools: libdmmp improvements.
cover multipath-tools: libdmmp improvements.
* Patch 1/4 is a resend.
* Patch 2/4, 3/4, and 4/4 add new functions to libdmmp library.
Gris Ge (4):
multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
multipath-tools: libdmmp: Allow log function as NULL.
multipath-tools: libdmmp: Add new function dmmp_last_error_msg()
multipath-tools: libdmmp: Add new error DMMP_ERR_PERMISSION_DENY
libdmmp/Makefile | 2 +- libdmmp/libdmmp.c | 20 ++++++++++++++++++++ libdmmp/libdmmp/libdmmp.h | 23 ++++++++++++++++++++++- libdmmp/libdmmp_misc.c | 1 + libdmmp/test/libdmmp_test.c | 12 ++++++++---- multipathd/cli.c | 2 +- 6 files changed, 53 insertions(+), 7 deletions(-)
Signature · 1 line
2.15.0
PATCH 1/4 multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
Issue:
When multipathd is starting up, it will reply "timeout\n" immediatly when got any IPC command from socket. The expected way is to wait uxsock_timeout/1000 seconds.
Root cause:
pthread_mutex_timedlock() is expecting a CLOCK_REALTIME time.
Fix:
Use CLOCK_REALTIME for pthread_mutex_timedlock().
--- multipathd/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
multipathd/cli.c +1 -1
@@ -480,7 +480,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )/* * execute handler */ -if (clock_gettime (CLOCK_MONOTONIC , &tmo) ==0 ) { +if (clock_gettime (CLOCK_REALTIME , &tmo) ==0 ) { tmo.tv_sec += timeout; }else { tmo.tv_sec =0 ;
Signature · 1 line
2.15.0
PATCH 2/4 multipath-tools: libdmmp: Allow log function as NULL.
In reply to Gris Ge * Do nothing when user set log function to NULL.
* Update document to reflect so.
--- libdmmp/libdmmp.c | 3 +++ libdmmp/libdmmp/libdmmp.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
libdmmp/libdmmp.c +3 -0
@@ -89,6 +89,9 @@ void _dmmp_log(struct dmmp_context *ctx, int priority, const char *file, {va_list args; +if (ctx->log_func ==NULL ) +return ; +va_start (args, format); ctx->log_func (ctx, priority, file, line, func_name, format, args);va_end (args);
libdmmp/libdmmp/libdmmp.h +2 -1
@@ -258,7 +258,8 @@ DMMP_DLL_EXPORT int dmmp_context_log_priority_get(struct dmmp_context *ctx);* Pointer of 'struct dmmp_context'. * If this pointer is NULL, your program will be terminated by assert. * @log_func: -* Pointer of log handler function. +* Pointer of log handler function. If set to NULL, all log will be +* ignored. * * Return: * void
Signature · 1 line
2.15.0
PATCH 3/4 multipath-tools: libdmmp: Add new function dmmp_last_error_msg()
In reply to Gris Ge * New function dmmp_last_error_msg() to retrieve the last error message.
--- libdmmp/libdmmp.c | 9 +++++++++ libdmmp/libdmmp/libdmmp.h | 15 +++++++++++++++ libdmmp/test/libdmmp_test.c | 12 ++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-)
libdmmp/libdmmp.c +9 -0
@@ -48,6 +48,7 @@#define _ERRNO_STR_BUFF_SIZE 256#define _IPC_MAX_CMD_LEN 512/* ^ Was _MAX_CMD_LEN in ./libmultipath/uxsock.h */ +#define _LAST_ERR_MSG_BUFF_SIZE 1024struct dmmp_context { void (*log_func)(struct dmmp_context *ctx, int priority,
@@ -56,6 +57,7 @@ struct dmmp_context {int log_priority;void *userdata;unsigned int tmo; +char last_err_msg[_LAST_ERR_MSG_BUFF_SIZE]; };/*
@@ -81,6 +83,9 @@ _dmmp_getter_func_gen(dmmp_context_userdata_get, struct dmmp_context, ctx, _dmmp_getter_func_gen(dmmp_context_timeout_get, struct dmmp_context, ctx, tmo, unsigned int); +_dmmp_getter_func_gen(dmmp_last_error_msg, struct dmmp_context, ctx, + last_err_msg, const char *); + _dmmp_array_free_func_gen(dmmp_mpath_array_free, struct dmmp_mpath, _dmmp_mpath_free);
@@ -94,6 +99,9 @@ void _dmmp_log(struct dmmp_context *ctx, int priority, const char *file,va_start (args, format); ctx->log_func (ctx, priority, file, line, func_name, format, args); +if (priority ==DMMP_LOG_PRIORITY_ERROR ) +vsnprintf (ctx->last_err_msg, _LAST_ERR_MSG_BUFF_SIZE, + format, args);va_end (args); }
@@ -110,6 +118,7 @@ struct dmmp_context *dmmp_context_new(void) ctx->log_priority =DMMP_LOG_PRIORITY_DEFAULT ; ctx->userdata =NULL ; ctx->tmo = _DEFAULT_UXSOCK_TIMEOUT; +memset (ctx->last_err_msg,0 , _LAST_ERR_MSG_BUFF_SIZE);return ctx; }
libdmmp/libdmmp/libdmmp.h +15 -0
@@ -708,6 +708,21 @@ DMMP_DLL_EXPORT int dmmp_flush_mpath(struct dmmp_context *ctx,*/ DMMP_DLL_EXPORT int dmmp_reconfig(struct dmmp_context *ctx); +/** +* dmmp_last_error_msg() - Retrieves the last error message. +* +* Retrieves the last error message. +* +* @ctx: +* Pointer of 'struct dmmp_context'. +* If this pointer is NULL, your program will be terminated by assert. +* +* Return: +* const char *. No need to free this memory, the resources will get +* freed when dmmp_context_free(). +*/ +DMMP_DLL_EXPORT const char *dmmp_last_error_msg(struct dmmp_context *ctx); + #ifdef __cplusplus }/* End of extern "C" */ #endif
libdmmp/test/libdmmp_test.c +8 -4
@@ -126,7 +126,8 @@ int main(int argc, char *argv[]) "timeout to %u\n", TMO);if (dmmp_mpath_array_get (ctx, &dmmp_mps, &dmmp_mp_count) !=0 ) -FAIL (rc, out,"dmmp_mpath_array_get(): rc != 0\n" ); +FAIL (rc, out,"dmmp_mpath_array_get() failed: %s\n" , +dmmp_last_error_msg (ctx));if (dmmp_mp_count ==0 )FAIL (rc, out,"dmmp_mpath_array_get(): " "Got no multipath devices\n" );
@@ -154,17 +155,20 @@ int main(int argc, char *argv[])dmmp_mpath_array_free (dmmp_mps, dmmp_mp_count);if (dmmp_flush_mpath (ctx, old_name) !=DMMP_OK ) -FAIL (rc, out,"dmmp_flush_mpath(): Failed\n" ); +FAIL (rc, out,"dmmp_flush_mpath(): failed %s\n" , +dmmp_last_error_msg (ctx));PASS ("dmmp_flush_mpath(): OK\n" );if (dmmp_reconfig (ctx) !=DMMP_OK ) -FAIL (rc, out,"dmmp_reconfig(): Failed\n" ); +FAIL (rc, out,"dmmp_reconfig() failed: %s\n" , +dmmp_last_error_msg (ctx));PASS ("dmmp_reconfig(): OK\n" );if (dmmp_mpath_array_get (ctx, &dmmp_mps, &dmmp_mp_count) !=0 ) -FAIL (rc, out,"dmmp_mpath_array_get(): rc != 0\n" ); +FAIL (rc, out,"dmmp_mpath_array_get() failed: %s\n" , +dmmp_last_error_msg (ctx));if (dmmp_mp_count ==0 )FAIL (rc, out,"dmmp_mpath_array_get(): " "Got no multipath devices\n" );
Signature · 1 line
2.15.0
PATCH 4/4 multipath-tools: libdmmp: Add new error DMMP_ERR_PERMISSION_DENY
In reply to Gris Ge * Indicate user does not have privilege to flush mpath or invoke reconfig.
* Bump API version to 0.2.0 for this API addition.
--- libdmmp/Makefile | 2 +- libdmmp/libdmmp.c | 8 ++++++++ libdmmp/libdmmp/libdmmp.h | 5 +++++ libdmmp/libdmmp_misc.c | 1 + 4 files changed, 15 insertions(+), 1 deletion(-)
libdmmp/Makefile +1 -1
@@ -5,7 +5,7 @@ # include ../Makefile.inc -LIBDMMP_VERSION=0.1.0 +LIBDMMP_VERSION=0.2.0 SONAME=$(LIBDMMP_VERSION) DEVLIB = libdmmp.so LIBS = $(DEVLIB).$(SONAME)
libdmmp/libdmmp.c +8 -0
@@ -364,6 +364,14 @@ invoke: } } +if ((*output !=NULL ) && +strncmp (*output,"permission deny" , +strlen ("permission deny" )) ==0 ) { +_error (ctx,"Permission deny, need to be root" ); + rc =DMMP_ERR_PERMISSION_DENY ; + goto out; + } + out:if (rc !=DMMP_OK ) {free (*output);
libdmmp/libdmmp/libdmmp.h +5 -0
@@ -42,6 +42,7 @@ extern "C" {#define DMMP_ERR_MPATH_BUSY 7#define DMMP_ERR_MPATH_NOT_FOUND 8#define DMMP_ERR_INVALID_ARGUMENT 9 +#define DMMP_ERR_PERMISSION_DENY 10/* * Use the syslog severity level as log priority
@@ -679,6 +680,8 @@ DMMP_DLL_EXPORT const char *dmmp_path_status_str(uint32_t path_status);* * * DMMP_ERR_INVALID_ARGUMENT * +* * DMMP_ERR_PERMISSION_DENY +* * Error number could be converted to string by dmmp_strerror(). */ DMMP_DLL_EXPORT int dmmp_flush_mpath(struct dmmp_context *ctx,
@@ -704,6 +707,8 @@ DMMP_DLL_EXPORT int dmmp_flush_mpath(struct dmmp_context *ctx,* * * DMMP_ERR_NO_DAEMON * +* * DMMP_ERR_PERMISSION_DENY +* * Error number could be converted to string by dmmp_strerror(). */ DMMP_DLL_EXPORT int dmmp_reconfig(struct dmmp_context *ctx);
libdmmp/libdmmp_misc.c +1 -0
@@ -49,6 +49,7 @@ static const struct _num_str_conv _DMMP_RC_MSG_CONV[] = { {DMMP_ERR_MPATH_BUSY, "Specified multipath device map is in use"}, {DMMP_ERR_MPATH_NOT_FOUND, "Specified multipath not found"}, {DMMP_ERR_INVALID_ARGUMENT, "Invalid argument"}, + {DMMP_ERR_PERMISSION_DENY, "Permission deny"}, };_dmmp_str_func_gen (dmmp_strerror, int, rc, _DMMP_RC_MSG_CONV);
Signature · 1 line
2.15.0
Merged.
Thanks.
Quoted 25 lines · Gris Ge
* Patch 1/4 is a resend.
* Patch 2/4, 3/4, and 4/4 add new functions to libdmmp library.Gris Ge (4):
multipathd daemon: Fix incorrect use ofCLOCK_MONOTONICin pthread
multipath-tools: libdmmp: Allow log function as NULL.
multipath-tools: libdmmp: Add new functiondmmp_last_error_msg()
multipath-tools: libdmmp: Add new errorDMMP_ERR_PERMISSION_DENYlibdmmp/Makefile | 2 +- libdmmp/libdmmp.c | 20 ++++++++++++++++++++ libdmmp/libdmmp/libdmmp.h | 23 ++++++++++++++++++++++- libdmmp/libdmmp_misc.c | 1 + libdmmp/test/libdmmp_test.c | 12 ++++++++---- multipathd/cli.c | 2 +- 6 files changed, 53 insertions(+), 7 deletions(-)--
2.15.0--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel