<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ensure_backend(resource, backend, backends, opt, managed=True):
 """Ensure the backend for a resource is properly in context"""

    existing_mount = find_backend(resource.mount, backends)
    if not existing_mount:
        new_mount = backend(resource, opt, managed=managed)
        backends.append(new_mount)
        return new_mount

    return existing_mount