From ed5ddbb68d23599a065568f0f47e4cd175dbe01b Mon Sep 17 00:00:00 2001 From: Wenchao Hao Date: Sat, 29 Jan 2022 15:41:41 +0800 Subject: Add conn_xxx() macros to print connection info in more details conn_info() conn_warn() conn_error() and conn_debug() are added. conn_xxx() macros would print session id and connection id in log. Signed-off-by: Wenchao Hao --- usr/initiator.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'usr') diff --git a/usr/initiator.h b/usr/initiator.h index dbf6f2b..a4e01a2 100644 --- a/usr/initiator.h +++ b/usr/initiator.h @@ -32,6 +32,7 @@ #include "config.h" #include "actor.h" #include "list.h" +#include "log.h" #define ISCSI_CONFIG_ROOT "/etc/iscsi/" @@ -45,6 +46,46 @@ #define LOCK_FILE LOCK_DIR"/lock" #define LOCK_WRITE_FILE LOCK_DIR"/lock.write" +#define conn_info(conn, fmt, ...) \ +do { \ + if (conn->session == NULL) { \ + log_info(fmt, ##__VA_ARGS__); \ + break; \ + } \ + log_info("connection%d:%d " fmt, \ + conn->session->id, conn->id, ##__VA_ARGS__); \ +} while(0) + +#define conn_warn(conn, fmt, ...) \ +do { \ + if (conn->session == NULL) { \ + log_warning(fmt, ##__VA_ARGS__); \ + break; \ + } \ + log_warning("connection%d:%d " fmt, \ + conn->session->id, conn->id, ##__VA_ARGS__); \ +} while(0) + +#define conn_error(conn, fmt, ...) \ +do { \ + if (conn->session == NULL) { \ + log_error(fmt, ##__VA_ARGS__); \ + break; \ + } \ + log_error("connection%d:%d " fmt, \ + conn->session->id, conn->id, ##__VA_ARGS__); \ +} while(0) + +#define conn_debug(level, conn, fmt, ...) \ +do { \ + if (conn->session == NULL) { \ + log_debug(level, fmt, ##__VA_ARGS__); \ + break; \ + } \ + log_debug(level, "connection%d:%d " fmt, \ + conn->session->id, conn->id, ##__VA_ARGS__); \ +} while(0) + typedef enum iscsi_session_r_stage_e { R_STAGE_NO_CHANGE, R_STAGE_SESSION_CLEANUP, -- cgit v1.2.1