Skip to content

Commit

Permalink
Merge "SPDK drivers: Update RPC calls to match latest SPDK changes"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Jan 16, 2020
2 parents 3b0f1cb + 01d8401 commit 13a5b7f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 56 deletions.
20 changes: 10 additions & 10 deletions cinder/tests/unit/targets/test_spdknvmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,16 @@ def __init__(self, message):

class JSONRPCClient(object):
def __init__(self, addr=None, port=None):
self.methods = {"get_bdevs": self.get_bdevs,
self.methods = {"bdev_get_bdevs": self.get_bdevs,
"construct_nvmf_subsystem":
self.construct_nvmf_subsystem,
"delete_nvmf_subsystem": self.delete_nvmf_subsystem,
"nvmf_subsystem_create": self.nvmf_subsystem_create,
"nvmf_delete_subsystem": self.delete_nvmf_subsystem,
"nvmf_create_subsystem": self.nvmf_subsystem_create,
"nvmf_subsystem_add_listener":
self.nvmf_subsystem_add_listener,
"nvmf_subsystem_add_ns":
self.nvmf_subsystem_add_ns,
"get_nvmf_subsystems": self.get_nvmf_subsystems}
"nvmf_get_subsystems": self.get_nvmf_subsystems}
self.bdevs = copy.deepcopy(BDEVS)
self.nvmf_subsystems = copy.deepcopy(NVMF_SUBSYSTEMS)

Expand Down Expand Up @@ -362,7 +362,7 @@ def setUp(self):
def test__get_spdk_volume_name(self):
with mock.patch.object(self.driver, "_rpc_call",
self.jsonrpcclient.call):
bdevs = self.driver._rpc_call("get_bdevs")
bdevs = self.driver._rpc_call("bdev_get_bdevs")
bdev_name = bdevs[0]['name']
volume_name = self.driver._get_spdk_volume_name(bdev_name)
self.assertEqual(bdev_name, volume_name)
Expand All @@ -373,7 +373,7 @@ def test__get_nqn_with_volume_name(self):
with mock.patch.object(self.driver, "_rpc_call",
self.jsonrpcclient.call):
nqn = self.driver._get_nqn_with_volume_name("Nvme0n1p0")
nqn_tmp = self.driver._rpc_call("get_nvmf_subsystems")[1]['nqn']
nqn_tmp = self.driver._rpc_call("nvmf_get_subsystems")[1]['nqn']
self.assertEqual(nqn, nqn_tmp)
nqn = self.driver._get_nqn_with_volume_name("fake")
self.assertIsNone(nqn)
Expand All @@ -387,21 +387,21 @@ def test__get_first_free_node(self):
def test_create_nvmeof_target(self):
with mock.patch.object(self.driver, "_rpc_call",
self.jsonrpcclient.call):
subsystems_first = self.driver._rpc_call("get_nvmf_subsystems")
subsystems_first = self.driver._rpc_call("nvmf_get_subsystems")
self.driver.create_nvmeof_target("Nvme0n1p1",
"nqn.2016-06.io.spdk",
"192.168.0.1",
4420, "rdma", -1, -1, "")
subsystems_last = self.driver._rpc_call("get_nvmf_subsystems")
subsystems_last = self.driver._rpc_call("nvmf_get_subsystems")
self.assertEqual(len(subsystems_first) + 1, len(subsystems_last))

def test_delete_nvmeof_target(self):
with mock.patch.object(self.driver, "_rpc_call",
self.jsonrpcclient.call):
subsystems_first = self.driver._rpc_call("get_nvmf_subsystems")
subsystems_first = self.driver._rpc_call("nvmf_get_subsystems")
target = Target()
self.driver.delete_nvmeof_target(target)
subsystems_last = self.driver._rpc_call("get_nvmf_subsystems")
subsystems_last = self.driver._rpc_call("nvmf_get_subsystems")
self.assertEqual(len(subsystems_first) - 1, len(subsystems_last))
target.name = "fake"
self.driver.delete_nvmeof_target(target)
Expand Down
40 changes: 20 additions & 20 deletions cinder/tests/unit/volume/drivers/test_spdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,23 @@ def __init__(self, message):

class JSONRPCClient(object):
def __init__(self, addr=None, port=None):
self.methods = {"get_bdevs": self.get_bdevs,
"get_lvol_stores": self.get_lvol_stores,
"destroy_lvol_bdev": self.destroy_lvol_bdev,
"snapshot_lvol_bdev": self.snapshot_lvol_bdev,
"clone_lvol_bdev": self.clone_lvol_bdev,
"construct_lvol_bdev": self.construct_lvol_bdev,
"resize_lvol_bdev": self.resize_lvol_bdev,
"get_nvmf_subsystems": self.get_nvmf_subsystems,
self.methods = {"bdev_get_bdevs": self.get_bdevs,
"bdev_lvol_get_lvstores": self.get_lvol_stores,
"bdev_lvol_delete": self.destroy_lvol_bdev,
"bdev_lvol_snapshot": self.snapshot_lvol_bdev,
"bdev_lvol_clone": self.clone_lvol_bdev,
"bdev_lvol_create": self.construct_lvol_bdev,
"bdev_lvol_resize": self.resize_lvol_bdev,
"nvmf_get_subsystems": self.get_nvmf_subsystems,
"construct_nvmf_subsystem":
self.construct_nvmf_subsystem,
"nvmf_subsystem_create":
"nvmf_create_subsystem":
self.nvmf_subsystem_create,
"nvmf_subsystem_add_listener":
self.nvmf_subsystem_add_listener,
"nvmf_subsystem_add_ns":
self.nvmf_subsystem_add_ns,
"inflate_lvol_bdev": self.inflate_lvol_bdev}
"bdev_lvol_inflate": self.inflate_lvol_bdev}
self.bdevs = copy.deepcopy(BDEVS)
self.nvmf_subsystems = copy.deepcopy(NVMF_SUBSYSTEMS)
self.lvol_stores = copy.deepcopy(LVOL_STORES)
Expand Down Expand Up @@ -536,7 +536,7 @@ def test__get_spdk_lvs_uuid(self):
with mock.patch.object(self.driver, "_rpc_call",
self.jsonrpcclient.call):
bdev = self.driver._rpc_call(
"get_bdevs", params={"name": "lvs_test/lvol0"})
"bdev_get_bdevs", params={"name": "lvs_test/lvol0"})
self.assertEqual(
bdev[0]['driver_specific']['lvol']['lvol_store_uuid'],
self.driver._get_spdk_lvs_uuid(
Expand All @@ -547,7 +547,7 @@ def test__get_spdk_lvs_uuid(self):
def test__get_spdk_lvs_free_space(self):
with mock.patch.object(self.driver, "_rpc_call",
self.jsonrpcclient.call):
lvs = self.driver._rpc_call("get_lvol_stores")
lvs = self.driver._rpc_call("bdev_lvol_get_lvstores")
lvol_store = None
for lvol in lvs:
if lvol['name'] == "lvs_test":
Expand Down Expand Up @@ -583,7 +583,7 @@ def test__create_volume(self):
bdev)
volume_clone = Volume()
volume_clone.name = "clone0"
self.driver._rpc_call("snapshot_lvol_bdev",
self.driver._rpc_call("bdev_lvol_snapshot",
params={'snapshot_name': "snapshot0",
'lvol_name': "lvs_test/lvol2"})
bdev = self.driver._get_spdk_volume_name("lvs_test/snapshot0")
Expand Down Expand Up @@ -628,19 +628,19 @@ def test_delete_volume(self, volume_get):
db_volume = objects.Volume._from_db_object(ctxt, objects.Volume(),
db_volume)
volume_get.return_value = db_volume
start_bdevs_len = len(self.driver._rpc_call('get_bdevs'))
start_bdevs_len = len(self.driver._rpc_call('bdev_get_bdevs'))
self.driver.create_volume(db_volume)
tmp_bdevs = self.driver._rpc_call('get_bdevs')
tmp_bdevs = self.driver._rpc_call('bdev_get_bdevs')
self.assertEqual(start_bdevs_len + 1, len(tmp_bdevs))
volume = Volume()
volume.name = "lvs_test/%s" % db_volume.name
volume_name = self.driver._get_spdk_volume_name(volume.name)
self.driver._rpc_call('destroy_lvol_bdev', {"name": volume_name})
self.driver._rpc_call('bdev_lvol_delete', {"name": volume_name})
self.driver.delete_volume(volume)
bdev = self.driver._get_spdk_volume_name("lvs_test/%s"
% db_volume.name)
self.assertIsNone(bdev)
tmp_bdevs = self.driver._rpc_call('get_bdevs')
tmp_bdevs = self.driver._rpc_call('bdev_get_bdevs')
self.assertEqual(start_bdevs_len, len(tmp_bdevs))

def get_volume_stats(self):
Expand All @@ -654,7 +654,7 @@ def test_create_volume_from_snapshot(self):
self.jsonrpcclient.call):
volume_clone = Volume()
volume_clone.name = "clone0"
self.driver._rpc_call("snapshot_lvol_bdev",
self.driver._rpc_call("bdev_lvol_snapshot",
params={'snapshot_name': "snapshot0",
'lvol_name': "lvs_test/lvol2"})
snapshot = Snapshot()
Expand Down Expand Up @@ -688,7 +688,7 @@ def test_delete_snapshot(self):
self.jsonrpcclient.call):
snapshot = Snapshot()
snapshot.name = "snapshot0"
self.driver._rpc_call("snapshot_lvol_bdev",
self.driver._rpc_call("bdev_lvol_snapshot",
params = {'snapshot_name': snapshot.name})
self.driver.delete_snapshot(snapshot)
snapshot = self.driver._get_spdk_volume_name("lvs_test/" +
Expand Down Expand Up @@ -750,7 +750,7 @@ def test_extend_volume(self):
volume = Volume()
volume.name = "lvs_test/lvol0"
self.driver.extend_volume(volume, 2)
bdev = self.driver._rpc_call("get_bdevs",
bdev = self.driver._rpc_call("bdev_get_bdevs",
params={"name": "lvs_test/lvol0"})
self.assertEqual(2 * units.Gi,
bdev[0]['num_blocks'] * bdev[0]['block_size'])
Expand Down
40 changes: 20 additions & 20 deletions cinder/volume/drivers/spdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _update_volume_stats(self):
pools_status = []
self.lvs = []

output = self._rpc_call('get_lvol_stores')
output = self._rpc_call('bdev_lvol_get_lvstores')
if output:
for lvs in output:
pool = {}
Expand Down Expand Up @@ -128,14 +128,14 @@ def _update_volume_stats(self):
lvs['free_size'])

def _get_spdk_volume_name(self, name):
output = self._rpc_call('get_bdevs')
output = self._rpc_call('bdev_get_bdevs')
for bdev in output:
for alias in bdev['aliases']:
if name in alias:
return bdev['name']

def _get_spdk_lvs_uuid(self, spdk_name):
output = self._rpc_call('get_bdevs')
output = self._rpc_call('bdev_get_bdevs')
for bdev in output:
if spdk_name in bdev['name']:
return bdev['driver_specific']['lvol']['lvol_store_uuid']
Expand All @@ -153,13 +153,13 @@ def _delete_bdev(self, name):
spdk_name = self._get_spdk_volume_name(name)
if spdk_name is not None:
params = {'name': spdk_name}
self._rpc_call('destroy_lvol_bdev', params)
self._rpc_call('bdev_lvol_delete', params)
LOG.debug('SPDK bdev %s deleted', spdk_name)
else:
LOG.debug('Could not find volume %s using SPDK driver', name)

def _create_volume(self, volume, snapshot=None):
output = self._rpc_call('get_lvol_stores')
output = self._rpc_call('bdev_lvol_get_lvstores')
for lvs in output:
free_size = (lvs['free_clusters'] * lvs['cluster_size'])
if free_size / units.Gi >= volume.size:
Expand All @@ -168,22 +168,22 @@ def _create_volume(self, volume, snapshot=None):
'lvol_name': volume.name,
'size': volume.size * units.Gi,
'uuid': lvs['uuid']}
output2 = self._rpc_call('construct_lvol_bdev', params)
output2 = self._rpc_call('bdev_lvol_create', params)
else:
snapshot_spdk_name = (
self._get_spdk_volume_name(snapshot.name))
params = {
'clone_name': volume.name,
'snapshot_name': snapshot_spdk_name}
output2 = self._rpc_call('clone_lvol_bdev', params)
output2 = self._rpc_call('bdev_lvol_clone', params)
spdk_name = self._get_spdk_volume_name(volume.name)
params = {'name': spdk_name}
self._rpc_call('inflate_lvol_bdev', params)
self._rpc_call('bdev_lvol_inflate', params)

if volume.size > snapshot.volume_size:
params = {'name': spdk_name,
'size': volume.size * units.Gi}
self._rpc_call('resize_lvol_bdev', params)
self._rpc_call('bdev_lvol_resize', params)

LOG.debug('SPDK created lvol: %s', output2)

Expand All @@ -196,7 +196,7 @@ def _create_volume(self, volume, snapshot=None):

def do_setup(self, context):
try:
payload = {'method': 'get_bdevs', 'jsonrpc': '2.0', 'id': 1}
payload = {'method': 'bdev_get_bdevs', 'jsonrpc': '2.0', 'id': 1}
self.url = ('http://%(ip)s:%(port)s/' %
{'ip': self.configuration.spdk_rpc_ip,
'port': self.configuration.spdk_rpc_port})
Expand All @@ -217,7 +217,7 @@ def check_for_setup_error(self):
"""Verify that requirements are in place to use LVM driver."""

# If configuration is incorrect we will get exception here
self._rpc_call('get_bdevs')
self._rpc_call('bdev_get_bdevs')

def create_volume(self, volume):
"""Creates a logical volume."""
Expand Down Expand Up @@ -269,10 +269,10 @@ def create_snapshot(self, snapshot):
params = {
'lvol_name': spdk_name,
'snapshot_name': snapshot['name']}
self._rpc_call('snapshot_lvol_bdev', params)
self._rpc_call('bdev_lvol_snapshot', params)

params = {'name': spdk_name}
self._rpc_call('inflate_lvol_bdev', params)
self._rpc_call('bdev_lvol_inflate', params)

def delete_snapshot(self, snapshot):
"""Deletes a snapshot."""
Expand All @@ -281,12 +281,12 @@ def delete_snapshot(self, snapshot):
return

params = {'name': spdk_name}
bdev = self._rpc_call('get_bdevs', params)
bdev = self._rpc_call('bdev_get_bdevs', params)
if 'clones' in bdev[0]['driver_specific']['lvol']:
for clone in bdev[0]['driver_specific']['lvol']['clones']:
spdk_name = self._get_spdk_volume_name(clone)
params = {'name': spdk_name}
self._rpc_call('inflate_lvol_bdev', params)
self._rpc_call('bdev_lvol_inflate', params)

self._delete_bdev(snapshot.name)

Expand All @@ -306,21 +306,21 @@ def create_cloned_volume(self, volume, src_volume):
params = {
'lvol_name': spdk_name,
'snapshot_name': snapshot_name}
self._rpc_call('snapshot_lvol_bdev', params)
self._rpc_call('bdev_lvol_snapshot', params)

params = {'name': spdk_name}
self._rpc_call('inflate_lvol_bdev', params)
self._rpc_call('bdev_lvol_inflate', params)

snapshot_spdk_name = self._get_spdk_volume_name(snapshot_name)
params = {
'clone_name': volume.name,
'snapshot_name': snapshot_spdk_name}

self._rpc_call('clone_lvol_bdev', params)
self._rpc_call('bdev_lvol_clone', params)

spdk_name = self._get_spdk_volume_name(volume.name)
params = {'name': spdk_name}
self._rpc_call('inflate_lvol_bdev', params)
self._rpc_call('bdev_lvol_inflate', params)

self._delete_bdev(snapshot_name)

Expand Down Expand Up @@ -387,7 +387,7 @@ def extend_volume(self, volume, new_size):
"""Extend an existing volume's size."""
spdk_name = self._get_spdk_volume_name(volume.name)
params = {'name': spdk_name, 'size': new_size * units.Gi}
self._rpc_call('resize_lvol_bdev', params)
self._rpc_call('bdev_lvol_resize', params)

# ####### Interface methods for DataPath (Target Driver) ########
def ensure_export(self, context, volume):
Expand Down
10 changes: 5 additions & 5 deletions cinder/volume/targets/spdknvmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ def _rpc_call(self, method, params=None):
return req.json()['result']

def _get_spdk_volume_name(self, name):
output = self._rpc_call('get_bdevs')
output = self._rpc_call('bdev_get_bdevs')

for bdev in output:
for alias in bdev['aliases']:
if name in alias:
return bdev['name']

def _get_nqn_with_volume_name(self, name):
output = self._rpc_call('get_nvmf_subsystems')
output = self._rpc_call('nvmf_get_subsystems')

spdk_name = self._get_spdk_volume_name(name)

Expand All @@ -112,7 +112,7 @@ def _get_nqn_with_volume_name(self, name):
def _get_first_free_node(self):
cnode_num = []

output = self._rpc_call('get_nvmf_subsystems')
output = self._rpc_call('nvmf_get_subsystems')

# Get node numbers for nqn string like this: nqn.2016-06.io.spdk:cnode1

Expand Down Expand Up @@ -149,7 +149,7 @@ def create_nvmeof_target(self,
'allow_any_host': True,
'serial_number': serial,
}
self._rpc_call('nvmf_subsystem_create', params)
self._rpc_call('nvmf_create_subsystem', params)

listen_address = {
'trtype': transport_type,
Expand Down Expand Up @@ -189,7 +189,7 @@ def delete_nvmeof_target(self, target_name):
if nqn is not None:
try:
params = {'nqn': nqn}
self._rpc_call('delete_nvmf_subsystem', params)
self._rpc_call('nvmf_delete_subsystem', params)
LOG.debug('SPDK subsystem %s deleted', nqn)
except Exception as e:
LOG.debug('SPDK ERROR: subsystem not deleted: %s', e)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ SPDK NVMe-oF target installation
--------------------------------

Follow instructions available on https://spdk.io/doc/nvmf.html to install
and configure environment with SPDK NVMe-oF target application.
and configure environment with SPDK NVMe-oF target application. Starting
from Ussuri release SPDK release v19.10 or higher is required.

Storage pools configuration
---------------------------
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/rpc-update-50bef83f48d4f96f.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
upgrade:
- |
SPDK target and volume drivers have been updated with new SPDK specific
RPC calls due to deprecation of some old RPC calls. Starting from Ussuri
release SPDK release v19.10 or higher is required.

0 comments on commit 13a5b7f

Please sign in to comment.