Skip to content

Commit 6f5be68

Browse files
author
Martin Belanger
committed
fix: adapt to new libnvme nvme.ctrl() dict-based constructor
The libnvme Python bindings changed nvme.ctrl() to accept a single dict instead of individual keyword arguments. Consolidate _get_cfg() to build the complete parameter dict (transport ID fields + fabrics config), then pass it directly to nvme.ctrl(). The connect() call no longer takes a cfg argument. Also fix dhchap_key -> dhchap_ctrl_key to match the renamed property in the new bindings (the old name silently created a shadow Python attribute instead of calling the C setter). Signed-off-by: Martin Belanger <Martin.Belanger@dell.com> Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 694d9ca commit 6f5be68

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

staslib/ctrl.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,24 @@ def _on_ctrl_removed(self, udev_obj):
174174
self._retry_connect_tmr.start(self.FAST_CONNECT_RETRY_PERIOD_SEC)
175175

176176
def _get_cfg(self):
177-
'''Get configuration parameters. These may either come from the [Global]
178-
section or from a "controller" entry in the configuration file. A
179-
definition found in a "controller" entry overrides the same definition
180-
found in the [Global] section.
177+
'''Get all parameters needed to create and connect an nvme.ctrl object.
178+
Transport ID parameters are included directly. Fabrics config parameters
179+
may come from the [Global] section or from a "controller" entry in the
180+
configuration file; a "controller" entry overrides the [Global] section.
181181
'''
182-
cfg = {}
183182
service_conf = conf.SvcConf()
183+
cfg = {
184+
'subsysnqn': self.tid.subsysnqn,
185+
'transport': self.tid.transport,
186+
'traddr': self.tid.traddr,
187+
}
188+
if self.tid.trsvcid:
189+
cfg['trsvcid'] = self.tid.trsvcid
190+
if self.tid.host_traddr:
191+
cfg['host_traddr'] = self.tid.host_traddr
192+
if self.tid.host_iface and not service_conf.ignore_iface and self._nvme_options.host_iface_supp:
193+
cfg['host_iface'] = self.tid.host_iface
194+
184195
for option, keyword in (
185196
('kato', 'keep_alive_tmo'),
186197
('queue-size', 'queue_size'),
@@ -206,21 +217,8 @@ def _get_cfg(self):
206217
return cfg
207218

208219
def _do_connect(self):
209-
service_conf = conf.SvcConf()
210-
host_iface = (
211-
self.tid.host_iface
212-
if (self.tid.host_iface and not service_conf.ignore_iface and self._nvme_options.host_iface_supp)
213-
else None
214-
)
215-
self._ctrl = nvme.ctrl(
216-
self._root,
217-
subsysnqn=self.tid.subsysnqn,
218-
transport=self.tid.transport,
219-
traddr=self.tid.traddr,
220-
trsvcid=self.tid.trsvcid if self.tid.trsvcid else None,
221-
host_traddr=self.tid.host_traddr if self.tid.host_traddr else None,
222-
host_iface=host_iface,
223-
)
220+
cfg = self._get_cfg()
221+
self._ctrl = nvme.ctrl(self._root, cfg)
224222

225223
self._ctrl.discovery_ctrl = self._discovery_ctrl
226224

@@ -238,7 +236,7 @@ def _do_connect(self):
238236
# This is used for bidirectional authentication
239237
dhchap_ctrl_key = self.tid.cfg.get('dhchap-ctrl-secret')
240238
if dhchap_ctrl_key and self._nvme_options.dhchap_ctrlkey_supp:
241-
self._ctrl.dhchap_key = dhchap_ctrl_key
239+
self._ctrl.dhchap_ctrl_key = dhchap_ctrl_key
242240

243241
# Audit existing nvme devices. If we find a match, then
244242
# we'll just borrow that device instead of creating a new one.
@@ -253,12 +251,9 @@ def _do_connect(self):
253251
self._on_connect_success, self._on_connect_fail, self._ctrl.init, self._host, int(udev_obj.sys_number)
254252
)
255253
else:
256-
cfg = self._get_cfg()
257-
logging.debug(
258-
'Controller._do_connect() - %s Connecting to nvme control with cfg=%s', self.id, cfg
259-
)
254+
logging.debug('Controller._do_connect() - %s Connecting to nvme control with cfg=%s', self.id, cfg)
260255
self._connect_op = gutil.AsyncTask(
261-
self._on_connect_success, self._on_connect_fail, self._ctrl.connect, self._host, cfg
256+
self._on_connect_success, self._on_connect_fail, self._ctrl.connect, self._host
262257
)
263258

264259
self._connect_op.run_async()

0 commit comments

Comments
 (0)