Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvmeof-gw: add cli commands to get/enable/disable SPDK logs #238

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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_DISABLE_VPCLMULQDQ=
SPDK_CENTOS_BASE="https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/"
Expand Down
33 changes: 33 additions & 0 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,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()
Expand Down
70 changes: 70 additions & 0 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
Expand Down Expand Up @@ -779,3 +780,72 @@ def get_subsystems_safe(self, request, context):
def get_subsystems(self, request, context):
with self.rpc_lock:
return self.get_subsystems_safe(request, context)

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))
26 changes: 26 additions & 0 deletions control/proto/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -115,6 +124,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 {
Expand All @@ -134,3 +155,8 @@ message nsid_status {
message subsystems_info {
string subsystems = 1;
}

message spdk_nvmf_log_flags_and_level_info {
string flags_level =1;
}