glusterfs.py文件html
cinder/volume/drivers/glusterfs.py就是cinder調用glusterfs的驅動了python
glusterfs.py只有一個GlusterfsDriver class,以下圖所示linux
from os_brick.remotefs import remotefs as remotefs_brick # client端操做 from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging from oslo_utils import fileutils from oslo_utils import units from cinder import exception from cinder.i18n import _, _LE, _LI, _LW from cinder.p_w_picpath import p_w_picpath_utils from cinder import utils from cinder.volume import driver # 不少定義的方法還沒具體實現 from cinder.volume.drivers import remotefs as remotefs_drv # 基類 class GlusterfsDriver(remotefs_drv.RemoteFSSnapDriver, driver.CloneableVD, driver.ExtendVD): """Gluster based cinder driver. Creates file on Gluster share for using it as block device on hypervisor. Operations such as create/delete/extend volume/snapshot use locking on a per-process basis to prevent multiple threads from modifying qcow2 chains or the snapshot .info file simultaneously. """
class GlusterfsDriver的父類remotefs_drv.RemoteFSSnapDriver(主要看這個)後端
cinder/volume/drivers/remotefs.py有兩個class,類RemoteFSSnapDriver從類RemoteFSDriver繼承安全
class RemoteFSSnapDriver(RemoteFSDriver, driver.SnapshotVD): """Base class for remotefs drivers implementing qcow2 snapshots. Driver must implement: _local_volume_dir(self, volume) """
類RemoteFSSnapDriver主要是針對volume snapshot的一系列操做。ide
類RemoteFSDriver能夠認爲是一個base class,裏面定義了不少基本方法ui
上面提到的class都是關於server端的封裝。spa
client端的封裝已經獨立爲一個項目:os-brick
.net
os_brick/remotefs/remotefs.py,只有一個class RemoteFsClient,右邊是類中定義的方法。
3d
cinder後端是glusterfs做爲openstack的附加盤來使用,glusterfs自己沒有快照機制,雲硬盤快照是經過qemu來實現的,代碼位置:
cinder作快照的時候,分爲兩種:
一、volume available的時候,cinder使用qemu-img直接作快照
二、volume in-use的時候,cinder會call nova來完成
cinder/volume/drivers/remotefs.py
qemu-img rebase的做用見這裏:http://linux.die.net/man/1/qemu-img
-u是非安全模式,適用於backing-file重命名和移動
簡而言之,就是對比backing_filename和舊的backing_filename的差別部分寫入new_snap_path
關於Cinder QuiescedSnapshot介紹:
https://wiki.openstack.org/wiki/Cinder/QuiescedSnapshotWithQemuGuestAgent
cinder刪除快照的時候,分爲兩種:
一、volume available的時候,cinder使用qemu-img直接刪除快照
二、volume in-use的時候,cinder會先計算快照鏈如何整合( 須要Libvirt版本'1.2.7'以上),最終call nova來完成
大體流程:
cinder/volume/drivers/remotefs.py ->> cinder/volume/drivers/glusterfs.py ->> cinder/compute/nova.py ->> novaclient/v1_1/contrib/assisted_volume_snapshots.py ->> novaclient/base.py ->> nova/virt/libvirt/driver.py
nova/virt/libvirt/driver.py:
這裏能夠看到Cinder QuiescedSnapshot,第一次會先嚐試作Quiesce快照,若是拋異常了,就執行下面不帶Quiesce的快照。
cinder run unit test http://docs.openstack.org/developer/cinder/devref/unit_tests.html