From ca947f45570692628dbe8b3d643846104abbffe6 Mon Sep 17 00:00:00 2001 From: Roy Sahar Date: Tue, 19 Sep 2023 18:18:18 +0300 Subject: [PATCH 1/2] nvmeof-gw: add cli commands to get/enable/disable SPDK logs Signed-off-by: Roy Sahar --- control/cli.py | 33 +++++++++++++++++ control/grpc.py | 70 +++++++++++++++++++++++++++++++++++++ control/proto/gateway.proto | 26 ++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/control/cli.py b/control/cli.py index e9e086b0..e7c022a1 100644 --- a/control/cli.py +++ b/control/cli.py @@ -318,6 +318,39 @@ def get_subsystems(self, args): formatted_subsystems = json.dumps(subsystems, indent=4) self.logger.info(f"Get subsystems:\n{formatted_subsystems}") + @cli.cmd() + def get_spdk_nvmf_log_flags_and_level(self, args): + """Gets spdk nvmf log levels and flags""" + req = pb2.get_spdk_nvmf_log_flags_and_level_req() + ret = self.stub.get_spdk_nvmf_log_flags_and_level(req) + formatted_flags_log_level = json.dumps(json.loads(ret.flags_level), indent=4) + self.logger.info( + f"Get SPDK nvmf log flags and level:\n{formatted_flags_log_level}") + + @cli.cmd() + def disable_spdk_nvmf_logs(self, args): + """Disables spdk nvmf logs and flags""" + req = pb2.disable_spdk_nvmf_logs_req() + ret = self.stub.disable_spdk_nvmf_logs(req) + self.logger.info( + f"Disable SPDK nvmf logs: {ret.status}") + + @cli.cmd([ + argument("-f", "--flags", help="SPDK nvmf enable flags", \ + action='store_true', required=True), + argument("-l", "--log_level", \ + help="SPDK nvmf log level (ERROR, WARNING, NOTICE, INFO, DEBUG)", required=False), + argument("-p", "--log_print_level", \ + help="SPDK nvmf log print level (ERROR, WARNING, NOTICE, INFO, DEBUG)", \ + required=False), + ]) + def set_spdk_nvmf_logs(self, args): + """Set spdk nvmf log and flags""" + req = pb2.set_spdk_nvmf_logs_req(flags=args.flags, log_level=args.log_level, \ + print_level=args.log_print_level) + ret = self.stub.set_spdk_nvmf_logs(req) + self.logger.info( + f"Set SPDK nvmf logs : {ret.status}") def main(args=None): client = GatewayClient() diff --git a/control/grpc.py b/control/grpc.py index 871ab56f..dd12fda8 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -16,6 +16,7 @@ import spdk.rpc.bdev as rpc_bdev import spdk.rpc.nvmf as rpc_nvmf +import spdk.rpc.log as rpc_log from google.protobuf import json_format from .proto import gateway_pb2 as pb2 @@ -511,3 +512,72 @@ def get_subsystems(self, request, context): return pb2.subsystems_info() return pb2.subsystems_info(subsystems=json.dumps(ret)) + + def get_spdk_nvmf_log_flags_and_level(self, request, context): + """Gets spdk nvmf log flags, log level and log print level""" + self.logger.info(f"Received request to get SPDK nvmf log flags and level") + try: + nvmf_log_flags = {key: value for key, value in rpc_log.log_get_flags( + self.spdk_rpc_client).items() if key.startswith('nvmf')} + spdk_log_level = {'log_level': rpc_log.log_get_level(self.spdk_rpc_client)} + spdk_log_print_level = {'log_print_level': rpc_log.log_get_print_level( + self.spdk_rpc_client)} + flags_log_level = {**nvmf_log_flags, **spdk_log_level, **spdk_log_print_level} + self.logger.info(f"spdk log flags: {nvmf_log_flags}, " + f"spdk log level: {spdk_log_level}, " + f"spdk log print level: {spdk_log_print_level}") + except Exception as ex: + self.logger.error(f"get_spdk_nvmf_log_flags_and_level failed with: \n {ex}") + context.set_code(grpc.StatusCode.INTERNAL) + context.set_details(f"{ex}") + return pb2.spdk_nvmf_log_flags_and_level_info() + + return pb2.spdk_nvmf_log_flags_and_level_info( + flags_level=json.dumps(flags_log_level)) + + def set_spdk_nvmf_logs(self, request, context): + """Enables spdk nvmf logs""" + self.logger.info(f"Received request to set SPDK nvmf logs") + try: + nvmf_log_flags = [key for key in rpc_log.log_get_flags(self.spdk_rpc_client).keys() \ + if key.startswith('nvmf')] + ret = [rpc_log.log_set_flag( + self.spdk_rpc_client, flag=flag) for flag in nvmf_log_flags] + self.logger.info(f"Set SPDK log flags {nvmf_log_flags} to TRUE") + if request.log_level: + ret_log = rpc_log.log_set_level(self.spdk_rpc_client, level=request.log_level) + self.logger.info(f"Set log level to: {request.log_level}") + ret.append(ret_log) + if request.print_level: + ret_print = rpc_log.log_set_print_level( + self.spdk_rpc_client, level=request.print_level) + self.logger.info(f"Set log print level to: {request.print_level}") + ret.append(ret_print) + except Exception as ex: + self.logger.error(f"set_spdk_nvmf_logs failed with: \n {ex}") + context.set_code(grpc.StatusCode.INTERNAL) + context.set_details(f"{ex}") + for flag in nvmf_log_flags: + rpc_log.log_clear_flag(self.spdk_rpc_client, flag=flag) + return pb2.req_status() + + return pb2.req_status(status=all(ret)) + + def disable_spdk_nvmf_logs(self, request, context): + """Disables spdk nvmf logs""" + self.logger.info(f"Received request to disable SPDK nvmf logs") + try: + nvmf_log_flags = [key for key in rpc_log.log_get_flags(self.spdk_rpc_client).keys() \ + if key.startswith('nvmf')] + ret = [rpc_log.log_clear_flag( + self.spdk_rpc_client, flag=flag) for flag in nvmf_log_flags] + logs_level = [rpc_log.log_set_level(self.spdk_rpc_client, level='NOTICE'), + rpc_log.log_set_print_level(self.spdk_rpc_client, level='INFO')] + ret.extend(logs_level) + except Exception as ex: + self.logger.error(f"disable_spdk_nvmf_logs failed with: \n {ex}") + context.set_code(grpc.StatusCode.INTERNAL) + context.set_details(f"{ex}") + return pb2.req_status() + + return pb2.req_status(status=all(ret)) diff --git a/control/proto/gateway.proto b/control/proto/gateway.proto index c361e3e1..951cd0de 100644 --- a/control/proto/gateway.proto +++ b/control/proto/gateway.proto @@ -43,6 +43,15 @@ service Gateway { // Gets subsystems rpc get_subsystems(get_subsystems_req) returns(subsystems_info) {} + + // Gets spdk nvmf log flags and level + rpc get_spdk_nvmf_log_flags_and_level(get_spdk_nvmf_log_flags_and_level_req) returns(spdk_nvmf_log_flags_and_level_info) {} + + // Disables spdk nvmf logs + rpc disable_spdk_nvmf_logs(disable_spdk_nvmf_logs_req) returns(req_status) {} + + // Set spdk nvmf logs + rpc set_spdk_nvmf_logs(set_spdk_nvmf_logs_req) returns(req_status) {} } // Request messages @@ -112,6 +121,18 @@ message delete_listener_req { message get_subsystems_req { } +message get_spdk_nvmf_log_flags_and_level_req { +} + +message disable_spdk_nvmf_logs_req { +} + +message set_spdk_nvmf_logs_req { + bool flags = 1; + optional string log_level = 2; + optional string print_level = 3; +} + // Return messages message bdev { @@ -131,3 +152,8 @@ message nsid { message subsystems_info { string subsystems = 1; } + +message spdk_nvmf_log_flags_and_level_info { + string flags_level =1; +} + From 1d3c9f3eda6fdeb3f8c2bbee45cd779f97463b9e Mon Sep 17 00:00:00 2001 From: Roy Sahar Date: Wed, 20 Sep 2023 10:48:44 +0300 Subject: [PATCH 2/2] nvmeof-gw: Update env file for compiling SPDK with enble debug Signed-off-by: Roy Sahar --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index a7dbc404..bd43ab4b 100644 --- a/.env +++ b/.env @@ -45,7 +45,7 @@ SPDK_DESCRIPTION="The Storage Performance Development Kit (SPDK) provides a set SPDK_URL="https://spdk.io" SPDK_PKGDEP_ARGS="--rbd" -SPDK_CONFIGURE_ARGS="--with-rbd --disable-tests --disable-unit-tests --disable-examples" +SPDK_CONFIGURE_ARGS="--with-rbd --disable-tests --disable-unit-tests --disable-examples --enable-debug" SPDK_MAKEFLAGS= SPDK_CENTOS_BASE="https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/" SPDK_CENTOS_REPO_VER="9.0-21.el9"