'Return a device to backup.
If it is to backup from snapshot, back it up directly.
Otherwise for in-use volume, create a temp snapshot and back it up.'

def _get_backup_volume_temp_snapshot(self, context, backup):

    volume = objects.Volume.get_by_id(context, backup.volume_id)
    snapshot = None
    if backup.snapshot_id:
        snapshot = objects.Snapshot.get_by_id(context, backup.snapshot_id)
    LOG.debug('Creating    a    new    backup    for    volume    %s.', volume['name'])
    device_to_backup = volume
    is_snapshot = False
    temp_snapshot = None
    if snapshot:
        device_to_backup = snapshot
        is_snapshot = True
    else:
        previous_status = volume.get('previous_status')
        if (previous_status == 'in-use'):
            temp_snapshot = self._create_temp_snapshot(context, volume)
            backup.temp_snapshot_id = temp_snapshot.id
            backup.save()
            device_to_backup = temp_snapshot
            is_snapshot = True
    return (device_to_backup, is_snapshot)
