Chinaunix首页 | 论坛 | 博客
  • 博客访问: 109007
  • 博文数量: 15
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 210
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-21 11:44
文章分类

全部博文(15)

文章存档

2016年(3)

2015年(1)

2014年(11)

我的朋友

分类: 虚拟化

2014-08-29 19:08:31

openstack Havana及之后的版本中,cinder组件提供了在线备份数据卷的功能,由cinder调用nova接口(os-assisted-volume-snapshots),nova调用libvirt snapshotCreateXML接口实现:


点击(此处)折叠或打开

  1. snap_flags = (libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY |
  2.                       libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA |
  3.                       libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT)

  4.         QUIESCE = libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE

  5.         try:
  6.             domain.snapshotCreateXML(snapshot_xml,
  7.                                      snap_flags | QUIESCE)

  8.             return
  9.         except libvirt.libvirtError:
  10.             LOG.exception(_LE('Unable to create quiesced VM snapshot, '
  11.                               'attempting again with quiescing disabled.'))

  12.         try:
  13.             domain.snapshotCreateXML(snapshot_xml, snap_flags)
  14.         except libvirt.libvirtError:
  15.             LOG.exception(_LE('Unable to create VM snapshot, '
  16.                               'failing volume_snapshot operation.'))

  17.             raise

它这里的逻辑是,先带VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE执行一遍,如果出错,再不带VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE flag执行,在libvirt过程中,VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE会在流程中加入通过qga接口冻结虚机文件系统的过程:


点击(此处)折叠或打开

  1. /* If quiesce was requested, then issue a freeze command, and a
  2.      * counterpart thaw command when it is actually sent to agent.
  3.      * The command will fail if the guest is paused or the guest agent
  4.      * is not running, or is already quiesced. */
  5.     if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE) {
  6.         int freeze = qemuDomainSnapshotFSFreeze(driver, vm, NULL, 0);
  7.         if (freeze < 0) {
  8.             /* the helper reported the error */
  9.             if (freeze == -2)
  10.                 thaw = -1; /* the command is sent but agent failed */
  11.             goto endjob;
  12.         }
  13.         thaw = 1;
  14.     }

这也是qemu链表式快照推荐的使用流程,参考 或 http://blog.chinaunix.net/uid-20940095-id-3588831.html

按字面意思来理解,尝试静默方式失败后,就应该是动静更大、更粗暴的方式咯,可是后一次尝试的flags组合确不会做暂停虚机等保护动作,直接调用qemu的blkdev-snapshot接口;所以对他这个做法有点疑问,希望高手指点,最后是libvirt对这个接口的一部分注释:

点击(此处)折叠或打开

  1. If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY, then the
  2.         snapshot will be limited to the disks described in @xmlDesc, and no
  3.         VM state will be saved. For an active guest, the disk image may be
  4.         inconsistent (as if power had been pulled), and specifying this
  5.         with the VIR_DOMAIN_SNAPSHOT_CREATE_HALT flag risks data loss.
  6.         
  7.         If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE, then the
  8.         libvirt will attempt to use guest agent to freeze and thaw all
  9.         file systems in use within domain OS. However, if the guest agent
  10.         is not present, an error is thrown. Moreover, this flag requires
  11.         VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY to be passed as well.



阅读(3182) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~