def get_block_device_info(instance, block_device_mapping):
    """Converts block device mappings for an instance to driver format.

    Virt drivers expect block device mapping to be presented in the format
    of a dict containing the following keys:

    - root_device_name: device name of the root disk
    - ephemerals: a (potentially empty) list of DriverEphemeralBlockDevice
                  instances
    - swap: An instance of DriverSwapBlockDevice or None
    - block_device_mapping: a (potentially empty) list of
                            DriverVolumeBlockDevice or any of it's more
                            specialized subclasses.
    """
    from nova.virt import block_device as virt_block_device
    block_device_info = {'root_device_name': instance.root_device_name,
        'ephemerals': virt_block_device.convert_ephemerals(
        block_device_mapping), 'block_device_mapping': virt_block_device.
        convert_all_volumes(*block_device_mapping)}
    swap_list = virt_block_device.convert_swap(block_device_mapping)
    block_device_info['swap'] = virt_block_device.get_swap(swap_list)
    return block_device_info
