Skip to content

Commit 90d1601

Browse files
committed
storage: add dynamic managed storage dispatcher
Add an optional "adapter" field in the ManagedVolumeConnection struct, allowing dispatching to vendor managedvolume-helper adapters.
1 parent 39a3b48 commit 90d1601

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

lib/vdsm/api/vdsm-api.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,11 @@ types:
11851185
volume type.
11861186
name: data
11871187
type: *StringMap
1188+
- defaultvalue: null
1189+
description: Adapter vendor
1190+
name: adapter
1191+
type: string
1192+
added: '4.5.6'
11881193
type: object
11891194

11901195
ManagedVolumeAttachement: &ManagedVolumeAttachement

lib/vdsm/storage/managedvolume.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def attach_volume(sd_id, vol_id, connection_info):
9494
vol_id, connection_info)
9595

9696
try:
97-
attachment = run_helper("attach", connection_info)
97+
attachment = run_helper("attach", connection_info, connection_info.get("adapter"))
9898
try:
9999
path = _resolve_path(vol_id, connection_info, attachment)
100100
db.update_volume(
@@ -137,8 +137,12 @@ def detach_volume(sd_id, vol_id):
137137

138138
log.debug("Starting detach volume %s vol_info=%s", vol_id, vol_info)
139139

140+
adapter = None
141+
if connection_info := vol_info.get("connection_info"):
142+
adapter = connection_info.get("adapter")
143+
140144
if "path" in vol_info and os.path.exists(vol_info["path"]):
141-
run_helper("detach", vol_info)
145+
run_helper("detach", vol_info, adapter)
142146

143147
_remove_udev_rule(sd_id, vol_info['vol_id'])
144148
_remove_run_link(sd_id, vol_id)
@@ -181,17 +185,24 @@ def volumes_info(vol_ids=()):
181185
# supervdsm interface
182186

183187

184-
def run_helper(sub_cmd, cmd_input=None):
188+
def run_helper(sub_cmd, cmd_input=None, adapter=None):
185189
if os.geteuid() != 0:
186190
return supervdsm.getProxy().managedvolume_run_helper(
187-
sub_cmd, cmd_input=cmd_input)
191+
sub_cmd, cmd_input=cmd_input, adapter=adapter)
188192
try:
189193
if cmd_input:
190194
cmd_input = json.dumps(cmd_input).encode("utf-8")
195+
helper = HELPER
196+
if adapter:
197+
helper = f"{HELPER}-{adapter}"
198+
if not os.path.exists(helper):
199+
raise se.ManagedVolumeHelperFailed(
200+
f"Helper for adapter '{adapter}' not found"
201+
f" at '{helper}'")
191202
# This is the only sane way to run python scripts that work with both
192203
# python2 and python3 in the tests.
193204
# TODO: Remove when we drop python 2.
194-
cmd = [sys.executable, HELPER, sub_cmd]
205+
cmd = [sys.executable, helper, sub_cmd]
195206
result = commands.run(cmd, input=cmd_input)
196207
except cmdutils.Error as e:
197208
raise se.ManagedVolumeHelperFailed("Error executing helper: %s" % e)

lib/vdsm/supervdsm_api/managedvolume.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010

1111
@expose
12-
def managedvolume_run_helper(cmd, cmd_input=None):
13-
return managedvolume.run_helper(cmd, cmd_input=cmd_input)
12+
def managedvolume_run_helper(cmd, cmd_input=None, adapter=None):
13+
return managedvolume.run_helper(cmd, cmd_input=cmd_input, adapter=adapter)

0 commit comments

Comments
 (0)