Makes sure that a btrfs subvolume is present.

    name
        Name of the subvolume to add

    device
        Device where to create the subvolume

    qgroupids
         Add the newly created subcolume to a qgroup. This parameter
         is a list

    set_default
        If True, this new subvolume will be set as default when
        mounted, unless subvol option in mount is used

    copy_on_write
        If false, set the subvolume with chattr +C

    force_set_default
        If false and the subvolume is already present, it will not
        force it as default if ``set_default`` is True

def subvolume_created(name, device, qgroupids=None, set_default=False,
                      copy_on_write=True, force_set_default=True,
                      __dest=None):
    '''
    Makes sure that a btrfs subvolume is present.

    name
        Name of the subvolume to add

    device
        Device where to create the subvolume

    qgroupids
         Add the newly created subcolume to a qgroup. This parameter
         is a list

    set_default
        If True, this new subvolume will be set as default when
        mounted, unless subvol option in mount is used

    copy_on_write
        If false, set the subvolume with chattr +C

    force_set_default
        If false and the subvolume is already present, it will not
        force it as default if ``set_default`` is True

    '''
    ret = {
        'name': name,
        'result': False,
        'changes': {},
        'comment': [],
    }
    path = os.path.join(__dest, name)

    exists = __salt__['btrfs.subvolume_exists'](path)
    if exists:
        ret['comment'].append('Subvolume {} already present'.format(name))

    # Resolve first the test case. The check is not complete, but at
    # least we will report if a subvolume needs to be created. Can
    # happend that the subvolume is there, but we also need to set it
    # as default, or persist in fstab.
    if __opts__['test']:
        ret['result'] = None
        if not exists:
            ret['comment'].append('Subvolume {} will be created'.format(name))
        return ret

    if not exists:
        # Create the directories where the subvolume lives
        _path = os.path.dirname(path)
        res = __states__['file.directory'](_path, makedirs=True)
        if not res['result']:
            ret['comment'].append('Error creating {} directory'.format(_path))
            return ret

        try:
            __salt__['btrfs.subvolume_create'](name, dest=__dest,
                                               qgroupids=qgroupids)
        except CommandExecutionError:
            ret['comment'].append('Error creating subvolume {}'.format(name))
            return ret

        ret['changes'][name] = 'Created subvolume {}'.format(name)

    # If the volume was already present, we can opt-out the check for
    # default subvolume.
    if (not exists or (exists and force_set_default)) and \
       set_default and not _is_default(path, __dest, name):
        ret['changes'][name + '_default'] = _set_default(path, __dest, name)

    if not copy_on_write and _is_cow(path):
        ret['changes'][name + '_no_cow'] = _unset_cow(path)

    ret['result'] = True
    return ret