openstack Havana及之后的版本中,cinder组件提供了在线备份数据卷的功能,由cinder调用nova接口(os-assisted-volume-snapshots),nova调用libvirt snapshotCreateXML接口实现:
-
snap_flags = (libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY |
-
libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA |
-
libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT)
-
-
QUIESCE = libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE
-
-
try:
-
domain.snapshotCreateXML(snapshot_xml,
-
snap_flags | QUIESCE)
-
-
return
-
except libvirt.libvirtError:
-
LOG.exception(_LE('Unable to create quiesced VM snapshot, '
-
'attempting again with quiescing disabled.'))
-
-
try:
-
domain.snapshotCreateXML(snapshot_xml, snap_flags)
-
except libvirt.libvirtError:
-
LOG.exception(_LE('Unable to create VM snapshot, '
-
'failing volume_snapshot operation.'))
-
-
raise
它这里的逻辑是,先带VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE执行一遍,如果出错,再不带VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE flag执行,在libvirt过程中,VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE会在流程中加入通过qga接口冻结虚机文件系统的过程:
-
/* If quiesce was requested, then issue a freeze command, and a
-
* counterpart thaw command when it is actually sent to agent.
-
* The command will fail if the guest is paused or the guest agent
-
* is not running, or is already quiesced. */
-
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE) {
-
int freeze = qemuDomainSnapshotFSFreeze(driver, vm, NULL, 0);
-
if (freeze < 0) {
-
/* the helper reported the error */
-
if (freeze == -2)
-
thaw = -1; /* the command is sent but agent failed */
-
goto endjob;
-
}
-
thaw = 1;
-
}
这也是qemu链表式快照推荐的使用流程,参考 或 http://blog.chinaunix.net/uid-20940095-id-3588831.html
按字面意思来理解,
尝试静默方式失败后,就应该是动静更大、更粗暴的方式咯,可是后一次尝试的flags组合确不会做暂停虚机等保护动作,直接调用qemu的blkdev-snapshot接口;所以对他这个做法有点疑问,希望高手指点,最后是libvirt对这个接口的一部分注释:
-
If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY, then the
-
snapshot will be limited to the disks described in @xmlDesc, and no
-
VM state will be saved. For an active guest, the disk image may be
-
inconsistent (as if power had been pulled), and specifying this
-
with the VIR_DOMAIN_SNAPSHOT_CREATE_HALT flag risks data loss.
-
-
If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE, then the
-
libvirt will attempt to use guest agent to freeze and thaw all
-
file systems in use within domain OS. However, if the guest agent
-
is not present, an error is thrown. Moreover, this flag requires
-
VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY to be passed as well.
阅读(3280) | 评论(0) | 转发(0) |