diff --git a/examples/discover-loop.py b/examples/discover-loop.py index 8481e821f..3657a7fa1 100644 --- a/examples/discover-loop.py +++ b/examples/discover-loop.py @@ -2,19 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 ''' Example script for nvme discovery - -Copyright (c) 2021 Hannes Reinecke, SUSE Software Solutions -Licensed under the Apache License, Version 2.0 (the "License"); you may -not use this file except in compliance with the License. You may obtain -a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations -under the License. ''' import sys @@ -29,17 +16,24 @@ def disc_supp_str(dlp_supp_opts): } return [txt for msk, txt in d.items() if dlp_supp_opts & msk] -r = nvme.root() -h = nvme.host(r) -c = nvme.ctrl(r, nvme.NVME_DISC_SUBSYS_NAME, 'loop') +root = nvme.root() +host = nvme.host(root) + +subsysnqn = nvme.NVME_DISC_SUBSYS_NAME +transport = 'tcp' +traddr = '127.0.0.1' +trsvcid = '4420' + +ctrl = nvme.ctrl(root, subsysnqn=subsysnqn, transport=transport, traddr=traddr, trsvcid=trsvcid) + try: - c.connect(h) + ctrl.connect(host) except Exception as e: sys.exit(f'Failed to connect: {e}') -print("connected to %s subsys %s" % (c.name, c.subsystem.name)) +print(f'{ctrl.name} connected to subsys {ctrl.subsystem}') -slp = c.supported_log_pages() +slp = ctrl.supported_log_pages() try: dlp_supp_opts = slp[nvme.NVME_LOG_LID_DISCOVER] >> 16 @@ -50,16 +44,20 @@ def disc_supp_str(dlp_supp_opts): try: lsp = nvme.NVMF_LOG_DISC_LSP_PLEO if dlp_supp_opts & nvme.NVMF_LOG_DISC_LID_PLEOS else 0 - d = c.discover(lsp=lsp) - print(pprint.pformat(d)) + disc_log = ctrl.discover(lsp=lsp) except Exception as e: sys.exit(f'Failed to discover: {e}') + disc_log = [] + pass + +for dlpe in disc_log: + print(f'log entry {dlpe["portid"]}: {dlpe["subtype"]} {dlpe["subnqn"]}') try: - c.disconnect() + ctrl.disconnect() except Exception as e: sys.exit(f'Failed to disconnect: {e}') -c = None -h = None -r = None +for s in host.subsystems(): + for c in s.controllers(): + print(f'{s}: {c.name}') diff --git a/libnvme/nvme.i b/libnvme/nvme.i index bed0859c7..6754a88e7 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -415,16 +415,24 @@ struct nvme_host { }; struct nvme_subsystem { + %immutable sysfs_dir; %immutable subsysnqn; %immutable model; %immutable serial; %immutable firmware; - %immutable application; + %immutable subsystype; + %immutable iopolicy; char *subsysnqn; char *model; char *serial; char *firmware; - char *application; + char *subsystype; + + %extend { + const char *sysfs_dir; + const char *application; + const char *iopolicy; + } }; struct nvme_ctrl { @@ -703,6 +711,18 @@ struct nvme_ns { struct nvme_host *nvme_subsystem_host_get(struct nvme_subsystem *s) { return nvme_subsystem_get_host(s); } + const char *nvme_subsystem_sysfs_dir_get(struct nvme_subsystem *s) { + return nvme_subsystem_get_sysfs_dir(s); + } + const char *nvme_subsystem_iopolicy_get(struct nvme_subsystem *s) { + return nvme_subsystem_get_iopolicy(s); + } + const char *nvme_subsystem_application_get(struct nvme_subsystem *s) { + return nvme_subsystem_get_application(s); + } + void nvme_subsystem_application_set(struct nvme_subsystem *s, const char *a) { + nvme_subsystem_set_application(s, a); + } %}; %extend ctrl_iter { @@ -831,7 +851,7 @@ struct nvme_ns { }; dev = nvme_ctrl_get_name($self); - if (dev) { + if (!dev) { discover_err = 1; return NULL; }