Detach a backing device(s) from a cache set
    If no dev is given, all backing devices will be attached.

    Detaching a backing device will flush it's write cache.
    This should leave the underlying device in a consistent state, but might take a while.

    CLI example:

    .. code-block:: bash

        salt '*' bcache.detach sdc
        salt '*' bcache.detach bcache1

def detach(dev=None):
    '''
    Detach a backing device(s) from a cache set
    If no dev is given, all backing devices will be attached.

    Detaching a backing device will flush it's write cache.
    This should leave the underlying device in a consistent state, but might take a while.

    CLI example:

    .. code-block:: bash

        salt '*' bcache.detach sdc
        salt '*' bcache.detach bcache1

    '''
    if dev is None:
        res = {}
        for dev, data in status(alldevs=True).items():
            if 'cache' in data:
                res[dev] = detach(dev)

        return res if res else None

    log.debug('Detaching %s', dev)
    if not _bcsys(dev, 'detach', 'goaway', 'error', 'Error detaching {0}'.format(dev)):
        return False
    return _wait(lambda: uuid(dev) is False, 'error', '{0} received detach, but did not comply'.format(dev), 300)