virtio驅動分析之libvirt層的參數配置

一直在研究kvm的para-virtualization driver - virtio,可能是太熟的原因吧,今天突然發現不知道咋在libvirt層配置kvm採用virtio驅動了,問題在於,看到下面這個配置文件,我竟不能確定此配置是否是採用了virtio驅動,先來看下配置文件的virtio相關的部分:

<disk type='file' device='disk'>

<source file='/data0/0/21/disk.0'/>

<target dev='vda'/>

<driver name='qemu' type='qcow2' cache='default'/>

</disk>


於是,我就google一個網上的採用virtio驅動的配置文件:

<disk type='file' device='disk'>

<driver name='qemu' cache='none'/>

<source file='/opt/p_w_picpaths/win7.img'/>

<target dev='vda' bus='virtio'/>

</disk>

然後,問題就更多了:

(1)是不是在target item中增加bus='virtio'就說明採用了virtio驅動

(2)google的這個例子的p_w_picpath文件win7.img是什麼格式的,我的例子可以從driver item的type參數看出是qcow2,google的例子怎麼看出來?(可能有人會說,可以通過file命令來查看),但是這並不符合我的風格,寫個配置文件必須能解決所有疑問才行,要file下才知道啥意思,那隻能說這個配置文件寫的太失敗了。

帶着以上問題,我閱讀了下libvirt documents,下了如下總結。

1. 配置項說明

disk常用的配置參數:type,device,snapshot等

(1)type屬性可以設置爲:file,block,dir,network等值,這主要取決於底層的實現

(2)device屬性用來表示Guest OS看來,disk表現爲什麼類型的設備,其值爲:floppy,disk,cdrom,lun等,默認值爲disk

(3)snapshot屬性用來描述與磁盤快照相關的功能時的一些默認的行爲:

snapshot='internal',表示snapshot與data存儲在同一個文件中,比如一個qcow2文件,即鏡像和數據是一體的,沒有單獨的snapshot文件

snapshot='external',表示鏡像文件和data分離存儲,即有單獨的snapshot文件

snapshot='no',表示禁止disk的snapshot的功能

read-only的disk不支持快照的功能,另外,這些屬性是否生效還要取決於hypervisor。

2. 說明

source常用的配置參數:dev,file,dir,protocol等,如果disk的type='file',那麼source的file屬性指向p_w_picpath文件的完整路徑;如果disk的type='block',那麼source的dev屬性指向host上的某個設備,如/dev/sdb;如果disk的type='dir',那麼source的dir指向host上的某一個目錄,此目錄用來做vm的鏡像;如果disk的type='network',那麼source的protocol參數,該參數用來指定訪問remote p_w_picpath的協議,其值可以爲:nbd,rbd,sheepdog或gluster,此時,另外一個mandatory屬性必須設置爲remote端的哪一個volume/p_w_picpath將被使用

(1)file attribute

<disk type='file' device='disk'>

<driver name='qemu' type='qcow2'/>

<source file='/data2/vms/ubuntu.qcow2'/>

<target dev='vda' bus='virtio'/>

</disk>

(2)dev attribute

<disk type='block' device='lun'>

<driver name='qemu' type='raw'/>

<source dev='/dev/sda'/>

<target dev='sda' bus='scsi'/>

<address type='drive' controller='0' bus='0' target='3' unit='0'/>

</disk>

(3)dir attribute (use a directory as floppy)

<disk type='dir' device='floppy'>

<source dir='/tmp/test'/>

<target dev='fda' bus='fdc'/>

<readonly/>

</disk>

(4)protocol attribute

<disk type='network'>

<driver name="qemu" type="raw" io="threads" ioeventfd="on" event_idx="off"/>

<source protocol="sheepdog" name="p_w_picpath_name">

<host name="hostname" port="7000"/>

</source>

<target dev="hdb" bus="ide"/>

<boot order='1'/>

<transient/>

<address type='drive' controller='0' bus='1' unit='0'/>

</disk>

3. 說明

target item用來說明disk所掛載的總線的類型,此總線是guest os中看到的總線類型,比如從guest os中看到的硬盤是ide還是scsi的,這取決於設備掛載的總線。 target常用的attribute有:dev和bus.

(1) dev attribute

disk設備的logical name,比方說:hdx,sdx,vdx等

(2) bus attribute

此用來描述仿真的設備的類型,其值可以爲:ide,scsi,virtio,xen,usb,sata等,此attribute value可以通過dev的value來推斷 出來,如果dev='hdb',那麼bus='ide';如果dev='vda',那麼bus='virtio'

4. 說明

this item更詳細的描述了hypervisor爲disk提供的driver,其common used attribute包括:name,type,cache等

(1)name attribute

對於kvm來說,name has an unique value - 'qemu',xen可以支持很多值,不錯詳細介紹。

(2)type attribute

kvm支持raw,qcow2,qed,bochs等多種鏡像格式,不同的鏡像格式對應着不同的驅動類型。另外,kvm是目前支持的鏡像格式最全的一種hypervisor。

(3)cache attribute

cache控制着guest os對disk的cache機制,cache的方式有:default,none,writethrough,writeback,directsync,unsafe等,cache的類型影響着guest os的性能,所以需要根據實際應用場景來選擇,比較常用的類型爲:none,writethrough,writeback.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章