物理机有两种重启方式:一种从操作系统中重启,一种直接先断电然后再接通电源。虚机的重启也有类似的两种方式:Soft Reboot 和 Hard Reboot。nova reboot 命令在不使用 “-hard” 情况下,默认会 Soft Reboot,如果失败则会 Hard reboot;如果使用了 “-hard”,则直接 Hard reboot。

1.1 Soft reboot

Soft reboot 完全依赖于虚机的操作系统和 ACPI。其过程为:

  1. Shutdown domain (domain.shutdown)
  2. Launch domain (domain.createWithFlags)

关于 shutdown API ,它会shutdown一个虚机,但是虚机的各种附件(object)依然可以使用,只是虚机的操作系统被停止了。注意,虚机的操作系统可能会忽略该请求。这时候,shutdown 不会成功(在 CONF.libvirt.wait_soft_reboot_seconds 指定的时间内,nova发现虚机没有被 shutdown),得转到 hard reboot 了。(Shutdown a domain, the domain object is still usable thereafter, but the domain OS is being stopped. Note that the guest OS may ignore the request.)

1.2 Hard reboot

Hard reboot 比 Soft reboot 复杂、耗时长。其主要过程为:

  1. Destroy domain (virt_dom.destroy())。Destroy 和 Shutdown 两个 API 的区别是:shutdown domain 以后,客户机的磁盘存储处于可用状态,而且该 API 在命令发给 Guest OS 后立即返回,客户程序需要不断检查其状态来判断是否shutdown 成功;而 destroy API 执行后,客户机的所有资源都会被归还给 Hypervisor (all resources used by it are given back to the hypervisor),它的过程是首先给客户机发送一个terminate 指令比如SIGTERM,如果在一定的时间内未成功则直接发送 SIGKILL 指令将虚机杀掉。
  2. 根据 domain 的信息(instance, network_info, disk_info,image_meta, block_device_info)重新生成 domain 的配置 xml
  3. 根据 image 重新生成各镜像文件(包括 disk,disk.local 和 disk.swap)
  4. 连接各个 volume
  5. 将各个 interface 挂到 OVS 上
  6. 重新生成和应用 iptales 规则
  7. Define domain (conn.defineXML)
  8. Launch domain (domain.createWithFlags)

可见,hard reboot 是真正的 reboot 一个虚机。来比较一下 hard reboot 前后的虚机的磁盘和xml 文件:

#reboot 前
root@compute2:/var/lib/nova/instances/8352e969-0a25-4abf-978f-d9d0ec4de0cd# ls -l
total 2608
-rw-rw---- 1 root root 20126 Jun 10 12:38 console.log
-rw-r--r-- 1 libvirt-qemu kvm 2162688 Jun 10 12:40 disk
-rw-r--r-- 1 nova nova 246 Jun 10 07:54 disk.info
-rw-r--r-- 1 libvirt-qemu kvm 393216 Jun 10 12:39 disk.local
-rw-r--r-- 1 libvirt-qemu kvm 197120 Jun 10 07:54 disk.swap
-rw-r--r-- 1 nova nova 3452 Jun 10 12:39 libvirt.xml

#reboot 后
root@compute2:/var/lib/nova/instances/8352e969-0a25-4abf-978f-d9d0ec4de0cd# ls -l
total 2608
-rw-rw---- 1 root root 20126 Jun 10 12:38 console.log
-rw-r--r-- 1 libvirt-qemu kvm 2162688 Jun 10 12:57 disk
-rw-r--r-- 1 nova nova 246 Jun 10 07:54 disk.info
-rw-r--r-- 1 libvirt-qemu kvm 393216 Jun 10 12:57 disk.local
-rw-r--r-- 1 libvirt-qemu kvm 197120 Jun 10 07:54 disk.swap
-rw-r--r-- 1 nova nova 3452 Jun 10 12:57 libvirt.xml root@compute2:/var/lib/nova/instances/8352e969-0a25-4abf-978f-d9d0ec4de0cd# diff libvirt.xml libvirt.xml.ori
10c10
< <nova:creationTime>2015-06-10 04:57:25</nova:creationTime> #domain 除了创建时间不同别的都相同
---
> <nova:creationTime>2015-06-10 04:39:14</nova:creationTime>
84c84
< <source host="127.0.0.1" mode="bind" service="10002"/>
---
> <source host="127.0.0.1" mode="bind" service="10001"/>

最新文章

  1. socket编程学习step1
  2. java中volatile关键字的含义
  3. WebSocket通信协议
  4. duxcms SQL Injection In /admin/module/loginMod.class.php
  5. url地址中 &quot;&amp;&quot; &quot;/&quot;等符号的转义处理(转)
  6. Windows无法安装到GPT分区形式磁盘,怎么办?
  7. OV7725学习(二)
  8. POJ 2482 Stars in Your Window 线段树扫描线
  9. 大学生IT博客大赛最技术50强与最生活10强文章
  10. Equal 和==比较
  11. 正确决解Hibernate4.*中:Connection cannot be null when &#39;hibernate.dialect&#39; not set
  12. Angular2组件与指令的小实践
  13. Qt 打开文件的默认路径 QFileDialog::getOpenFileName()
  14. UVA424高精度加法
  15. 对Javascript到底了解多少,一测便知道
  16. eclipse 中git无法https下载提交代码
  17. 南阳236----心急的C小加
  18. Eclipse文件路径
  19. SectionList的使用
  20. Service Mesh简介

热门文章

  1. RabbitMQ中Queue详细介绍
  2. influxDB 变换类函数
  3. border inset outset ,border-radius
  4. Mac下最好用的文本编辑器
  5. mysql数据库补充知识4 数据备份和pymysql模块
  6. Python编码规范 -- Python Style Guide
  7. C# 面向对象三大特性:封装、继承、多态
  8. Django:popup弹出框简单应用实例
  9. (C#)ListView双击Item事件
  10. 01 Spring框架 基本介绍