千家信息网

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

发表于:2024-10-23 作者:千家信息网编辑
千家信息网最后更新 2024年10月23日,这篇文章给大家分享的是有关如何修复nova的后端镜像文件挂ceph、生成虚拟机文件变大1024倍bug的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。前端界面生成虚拟机:1、
千家信息网最后更新 2024年10月23日如何修复nova的后端镜像文件挂ceph、生成虚拟机文件变大1024倍bug

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



前端界面生成虚拟机:


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:

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

执行完此命令:

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


修复bug:

将图1.2-1中的

size = int(size) * units.Ki

屏蔽掉:



再次实验:


问题解决。

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

0