Commit add4a7ce authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

sma: register devices based on config file



This allows a user to specify the types of devices to support.  Those
not specified in the config, won't get initialized and will not service
user's requests.

Additionally, each device manager can now receive its own configuration
in its init() method.

The device configuration is structured as a list of objects with two
properties: "name" and "params".  The former identifies a device to
enable, while the latter contains a set of options (if any) specific to
that device manager.  For instance:

```
devices:
  - name: 'nvmf-tcp'
    params:
      max_queue_depth: 256
      io_unit_size: 8192
  - name: 'nvmf-vfiouser'
```

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I967016502ad93c243b3a7af58992bde14c44953c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11713


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent d2db3959
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -50,26 +50,40 @@ def get_build_client(sock):
    return build_client


def register_device(agent, device):
    device.init(None)
    agent.register_device(device)


def load_plugins(agent, client, plugins):
def register_devices(agent, devices, config):
    for device_config in config.get('devices') or []:
        name = device_config.get('name')
        device_manager = next(filter(lambda s: s.name == name, devices), None)
        if device_manager is None:
            logging.error(f'Couldn\'t find device: {name}')
            sys.exit(1)
        logging.info(f'Registering device: {name}')
        device_manager.init(device_config.get('params'))
        agent.register_device(device_manager)


def load_plugins(plugins, client):
    devices = []
    for plugin in plugins:
        module = importlib.import_module(plugin)
        for device in getattr(module, 'devices', []):
            logging.debug(f'Loading external device: {plugin}.{device.__name__}')
            register_device(agent, device(client))
            devices.append(device(client))
    return devices


if __name__ == '__main__':
    logging.basicConfig(level=os.environ.get('SMA_LOGLEVEL', 'WARNING').upper())

    config = parse_argv()
    client = get_build_client(config['socket'])

    agent = sma.StorageManagementAgent(config['address'], config['port'])
    register_device(agent, sma.NvmfTcpDeviceManager(get_build_client(config['socket'])))
    load_plugins(agent, get_build_client(config['socket']), config.get('plugins') or [])
    load_plugins(agent, get_build_client(config['socket']),
                 filter(None, os.environ.get('SMA_PLUGINS', '').split(':')))

    devices = [sma.NvmfTcpDeviceManager(client)]
    devices += load_plugins(config.get('plugins') or [], client)
    devices += load_plugins(filter(None, os.environ.get('SMA_PLUGINS', '').split(':')),
                            client)
    register_devices(agent, devices, config)

    agent.run()