kvESX.py 文件源码

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

项目:vsphere-storage-for-docker 作者: vmware 项目源码 文件源码
def save(volpath, kv_dict, key=None, value=None):
    """
    Save the dictionary to side car.
    """
    meta_file = lib.DiskLib_SidecarMakeFileName(volpath.encode(),
                                                DVOL_KEY.encode())
    kv_str = json.dumps(kv_dict)

    retry_count = 0
    vol_name = vmdk_utils.get_volname_from_vmdk_path(volpath)
    while True:
        try:
            if key:
                with open(meta_file, "r") as rfh:
                    kv_val = rfh.read()
                    try:
                        kv_match = json.loads(kv_val)
                    except ValueError:
                        logging.exception("load:Failed to decode meta-data for %s", volpath)
                        return False

                    if key in kv_match and kv_match[key] != value:
                        return False
            with open(meta_file, "w") as fh:
                fh.write(align_str(kv_str, KV_ALIGN))
            break
        except IOError as open_error:
            # This is a workaround to the timing/locking with metadata files issue #626
            if open_error.errno == errno.EBUSY and retry_count <= vmdk_utils.VMDK_RETRY_COUNT:
                logging.warning("Meta file %s busy for save(), retrying...", meta_file)
                vmdk_utils.log_volume_lsof(vol_name)
                retry_count += 1
                time.sleep(vmdk_utils.VMDK_RETRY_SLEEP)
            else:
                logging.exception("Failed to save meta-data for %s", volpath)
                return False

    return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号