如何修复nova的后端镜像文件挂ceph、生成虚拟机文件变大1024倍bug

79次阅读
没有评论

共计 1857 个字符,预计需要花费 5 分钟才能阅读完成。

行业资讯    
服务器    
云计算    
如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug

这篇文章给大家分享的是有关如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug 的内容。丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,一起跟随丸趣 TV 小编过来看看吧。

前端界面生成虚拟机:

1、直接从 nova/virt/libvirt/imagebackend.py 的 RBD 类的 create_image 函数开始讲解

附上源码:

   
     def create_image(self, prepare_template, base, size, *args, **kwargs):
   

        import pydevd
   

        pydevd.settrace(192.168.10.10 , port=51234, stdoutToServer=True, stderrToServer=True)
   

        if self.rbd is None:
   

            raise RuntimeError(_( rbd python libraries not found))
   

   

        if not os.path.exists(base):
     # 检查路径是否存在
   

            prepare_template(target=base, max_size=size, *args, **kwargs)
   

        else:
   

            self.verify_base_size(base, size)
     # 验证 size 是否满足要求,同之前博客本地 file 创建分析一致
   

   

        # keep using the command line import instead of librbd since it
   

        # detects zeroes to preserve sparseness in the image
   

        args = [–pool , self.pool, base, self.rbd_name]
     # 构造虚拟机文件生成参数
   

        if self._supports_layering():
   

            args += [–new-format]
   

        args += self._ceph_args()
   

        libvirt_utils.import_rbd_image(*args)
     # 根据到 1.1
   

   

        base_size = disk.get_disk_size(base)
     # 求出 base 镜像模板文件大小
   

   

        if size and size base_size:
     # 见图 1 -1:
   

            self._resize(self.rbd_name, size)
     # 跟进到 1.2
   

1.1:

(rbd import –pool , nova , /var/lib/nova/instances/_base/8b925177989924ee3e316b28b3abc03a829fbb29 , fec8e16e-0055-4117-aa5c-afbd845773f2_disk , –new-format , –id , admin , –conf , /etc/ceph/ceph.conf)
   

在执行此命令前:

执行命令之后:

rbd info:

图 1 -1:

其中 size 为页面传递过来的 falvor 参数 1G。即(1024*1024*1024),base_size 为镜像文件 cirros_ceph 大小。

1.2:

 
      def _resize(self, volume_name, size):
   

        size = int(size) * units.Ki 
     # 见图 1.2-1
   

   

        with RBDVolumeProxy(self, volume_name) as vol:
   

            vol.resize(size)
     # 根据见 1.3
   

图 1.2-1:

1.3:

如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug

此处纳闷之后找不到 resize 函数(后续有时间在研究,先以解决问题为主。)

执行完此命令:

如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug

发现 size 为 1024GB,比预期打了 1024 倍。

修复 bug:

将图 1.2- 1 中的

size = int(size) * units.Ki

屏蔽掉:

如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug

再次实验:

如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug

如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug

问题解决。

感谢各位的阅读!关于“如何修复 nova 的后端镜像文件挂 ceph、生成虚拟机文件变大 1024 倍 bug”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-16发表,共计1857字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)