loopback.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:charm-plumgrid-gateway 作者: openstack 项目源码 文件源码
def ensure_loopback_device(path, size):
    '''
    Ensure a loopback device exists for a given backing file path and size.
    If it a loopback device is not mapped to file, a new one will be created.

    TODO: Confirm size of found loopback device.

    :returns: str: Full path to the ensured loopback device (eg, /dev/loop0)
    '''
    for d, f in six.iteritems(loopback_devices()):
        if f == path:
            return d

    if not os.path.exists(path):
        cmd = ['truncate', '--size', size, path]
        check_call(cmd)

    return create_loopback(path)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号