[CS449] Ex8 Study KVM internal 4

Study KVM internal 4

Part 1: Study KVM block drivers’ code.

  • bdrv_read()

Read data file from disk. First check BlockDriver, If BlockDriver not exists return –ENOMEDIUM;. Next, check length and accuracy of offset in ‘check byte request’ otherwise return –EIO. Finally, call  drv->bdrv_read() read data from disk and store at buffer.

  • bdrv_write()

Write data file onto disk. Check BlockDriver and ‘check byte request’ as bdrv_read(). If read_only return -EACCES;. Next, check if dirty bitmap exist, set dirty bitmap. Finally, call drv->bdrv_write()

  • do_commit() and bdrv_commit()

Commit is an action of merge file from overlay image to base image. In this stage virtual machine shall must stop running before commit process. ‘do_commit’ use all drivers to commit in bdrv_commit(). ‘bdrv_commit()’ compares change in each sector on overlay with base image. If any a sector on base image will be overwrite with data from the same sector of overlay image.


Part 2: Virtual Machine migration.

Use ubuntu base image file created in previous Ex as a test source.

Assign base OS image as host, copy base OS image as agent.

We will migrate the agent.

Run bolt VM. We can notice that each VM has the same data.

Create in_BASE_HOST.txt file on base_host to test migration process.

Stop agent VM and re-run again with…

$kvm –m 512 –had base_host.img –incoming tcp://0:<port>

to let agent VM in waiting state at <assigned port>

Press Ctrl+Alt+2 in base_host window to switch in cmd mode.

Migrate with… command.

(qemu) migrate –d tcp://127.0.0.1:<agent waiting port>

*127.0.0.1 is localhost.

*‘(qemu) info migrate’ to view migration status.

Close agent VM after finished migration.

Run agent VM in normal mode again. We will notice that ‘in_BASE_HOST.txt’ has been existed in agent VM.

Reference :

http://www.linux-kvm.org/page/Migration

http://www.puysoft.com/kvm/p2.php

Salisa

Posted in Uncategorized | Leave a comment

[CS449] Ex7 Study KVM internal 3

Study KVM internal 3

1.     Describe the function call sequence when bdrv_open2() get called.

By trace bdrv_open2() with adding printf() in

bdrv_open()

bdrv_open2()

qcow_open()

raw_open()

2.     Use source navigator program (Ref. Exercise 6) to edit source code.

3.     Compile qemu code. (Ref. Exercise 3)

Go to qemu-kvm directory then

~/qemu-kvm-0.12.4$ ./configure <–prefix=/usr/local/kvm>

~/qemu-kvm-0.12.4$ make

~/qemu-kvm-0.12.4$ sudo make install

4.     Run overlay.img (Ref. Exercise 4)

Printf() will exist in Terminal window.

เริ่มแรกจะตรวจสอบดูว่า เป็นการทำงานแบบ snapshot หรือไม่ ถ้าใช่จะสร้าง temporary backing file แทยการเรียกไฟล์นั้นโดยตรง หลังจากนั้นก็จะหา protocol หรือหา driver จาก find_hdev_driver(filename) ถ้าไม่เจอก็จะค้นด้วย  find_image_format(filename) [ถ้าสุดท้ายแล้วยังไม่เจอจะ jump ไปทำ unlink(filename)] จะวนเข้ามาที่ bdrv_open2() อีกครั้งเพื่อเรียก find_protocol() ของ driver ที่จะเข้ามา โดยใช้ raw_open() เพื่อเปิดไฟล์ Raw จากนั้นก็ ออกจาก function bdrv_open2() และเข้าไปที่ function qcow_open() เนื่องจากว่า ฟอร์แมตของ driver เป็นชนิด qcow จากนั้นก็จะเรียก function ต่างๆ จนไปหยุดที่ raw_open() เปิดมาเป็น text file เพื่อใช้เข้าไปค้นหาตำแหน่งไฟล์ เพื่อบอกว่าเป็น file ชนิดใด ใช้ qcow_open() เพราะ format ของ driver เป็น qcow ใน function qcow_open()จะ return ค่าออกมาสองอย่างคือ 0 แทน success, -1 แทน fail เนื่องจาก run file ที่เป็น overlay จึงมีการทำงานวนอีกรอบ เพื่อเปิดไฟล์ img จริงสิ้นสุดการทำงาน

5.      Describe what occur with the following data structures during the above

BlockDriverState

มี pointer drv ชี้ไปยัง BlockDriver

มี pointer backing_hd ชี้ไปยัง BlockState

มี pointer opaqe ชี้ไปยัง BDRVRawState (เกิดขึ้นในการทำงานรอบถัดไป)

BlockDriver

รับ drv มาจาก BlockDriverState และทำงานเหมือนกับใน function bdrv_open2() ข้างต้น หาว่าเป็น sanpshot ไหม หา protocol, format, driver และเรียก function ที่เกี่ยวข้องเข้ามาทำงาน

BDRVQcowState

มี pointer hd ชี้ไปยัง BlockDriverState

มี pointer s ชี้ไปยัง opaque ใน BlockDriverState

BDRVRawState

มี pointer FD (File Descriptor) ชี้ไปยังตำแหน่งที่เก็บไฟล์

Salisa

Posted in Uncategorized | Leave a comment

[CS449] Ex6 Study KVM internal 2

Study KVM internal 2

1. Write program to notice how constructor work then run it.

$ gcc –E <code file>

After constructor was executed, it changed

block_init(bdrv_qcow2_init);

===> void __attribute__ ((constructor)) my_init(void);

block_init(bdrv_raw_init);

===> void __attribute__ ((destructor)) my_fini(void);

Let’s look at its process by add printf() in constructor and main function in test program.

$ gcc –o constructor  <code file> z

$ ./constructor

Constructor process are executed before dlopen returns (before main() is started).


2. bdrv_open()

Passing 3 parameters – bs, filename and flags.

Call bdrv_open2() function to begin BlockDriverState process.

bdrv_close()

Passing 1 parameter – bs.

Close opened BlockDriverState.


Data structure of BlockDriverState and BlockDriver in block_int.h

BlockDriverState – keep status of driver for virtual hardware.

BlockDriver – virtual hardware connector and BlockDriverState& BlockDriver data memory.


3. bdrv_open() function is called when…

4. Function call graph of the bdrv_open().

5. The data structure in 2. when the bdrv_open() function is called

Salisa

Posted in Uncategorized | Leave a comment

[CS449] Ex5 Study KVM internal 1

Study KVM internal 1

Continue from previous Exercise.

Download ‘sourcenavigator’

http://sourcenav.sourceforge.net/

Install sourcenavigator

$ tar xjf sourcenavigator-NG<version>.tar.bz2

$ cd sourcenavigator-NG<version>

$ ./configure

$ make

$ sudo make install

Run source navigator

$ snavigator

Create new project

Project File:        Save project destination

Add Directory:   Source destination          (This Ex notified KVM operation.)

All source in destination.

Open vl.c

Selected vl.c source

Windows  menu, select Add View ->  Editor

3. Study the file vl.c and describe what happen when KVM detect “-hda” option.

Ans Use ‘file’ as IDE hard disk 0/1 image.

4. Also, answer which function read the “-hda” option string?

Ans bdrv_new();

5. Draw function call graph involving the “-hda” option as deep as you can and

describe the functions in the graph.

Ans Some Error exist, so can’t use Xref function…..

6. The three important functions that control KVM operations are main(), main_loop(), and main_loop_wait(). What do you think these function do?

Function main() ในการกำหนดค่าเริ่มต้นต่างๆ ของโปรแกรม และเป็นตัวเชื่อมโยงการทำงานของ function ย่อยต่างๆมาทำงานเพื่อให้บรรลุวัตถุประสงค์

Function main_loop() เป็นตัวกำหนดการทำงานเรื่องของเวลาและ event หลักๆ ของ KVM :- Debug, event request, etc…

Function main_loop_wait() ตัวควบคุมการทำงานของอุปกรณ์ I/O (I/O handler)ตามระยะเวลาที่ถูกจัดสรรมา และจัดเก็บ record การ delete, read, write ของ I/O event

Resource :

http://sourcenav.sourceforge.net/

http://sourcenav.sourceforge.net/online-docs/userguide/tutorial.html

Kvm Vl.c sourcecode [main,main_loop,main_loop_wait]:

http://www.mediafire.com/?93iy35lhz53dy

Salisa

Posted in Uncategorized | Leave a comment

[CS449]Ex4 Create a COW Overlay Disk and use QEMU’s commit command

Create a COW Overlay Disk and use QEMU’s commit command

Continue from Exercise 3

Create qemu path for easily access

$ export PATH=/opt/kvm/bin:$PATH

Create Disk Base Image

Create image file for Guest OS

$ qemu-img create -f qcow2 <image_name.img> <size>

Install Guest OS on Base Image

Download ubuntu/centOS for install as Guest OS

Install OS by qemu-system-x86_64

$ qemu-system-x86_64 -hda <image_base.img> -cdrom <OSfile.iso> -boot d -m 256

We’ll get Base OS image when finished install.

Create Overlay Disk

Create overlay disk form Base OS Image (size~2.5)

$ qemu-img create -f qcow2 -b <Base_OS_Image> <Overlay_name>


Create a directory on Overlay

Run Ubuntu/ CentOS over Overlay disk image

$ qemu-system-x86_64 -hda <Overlay_name.img> -boot c -m 256

Create a directory at desktop with a file inside. (size about 256Mb up for easily notice the difference)

Notice that Overlay Image size increased.

Qemu’s Commit Command

Run KVM command mode by Ctrl+Alt+2 then Enter ‘commit all’.

Any activity exist on Overlay will exist on Base OS.

(qemu) commit all

After finite commit, quit ubuntu overlay by enter ‘q’ or ‘quit’

(qemu) quit

Notice that Base OS Image size increased.

On Ubuntu/ CentOS Base OS Image, we will find that a directory with file(s) which created on Overlay also exist on Base OS Image.

Create new Overlay

Delete exist Overlay Image created earlier.

Create Overlay disk form Base OS Image. (Likely previous step)

Run Ubuntu/ CentOS over new Overlay disk image.

We will notice that a directory with file(s) which created on previous Overlay also exist on new Overlay.

Salisa

Posted in Uncategorized | Leave a comment

[Ex3] Compile and Install KVM on your Ubuntu system

Compile and Install KVM on your Ubuntu system

1. Install software packets. (On Ubuntu virtual maching)

$ sudo apt-get install gcc libsdl1.2-dev zlib1g-dev libasound2-dev pkg-config libgnutls-dev libpci-dev

2. Download and Install qemu

Using a recent kernel (2.6.25+)

$ tar xzf qemu-kvm-<version>.tar.gz       ;extract qemu file

$ cd qemu-kvm--<version>

$ ./configure <–prefix=/usr/local/kvm>

$ make

$ sudo make install

3. Or download and install KVM source code.

(Using an older kernel.)

$ tar xjf kvm-kmod-<version>.tar.bz2

$ cd kvm-kmod-<version>

$./configure

$ make

$ sudo make install

4. Creating a disk image.

$ ~/qemu-img create -f qcow2  ~/<file-name> <disk image size>

5. Installing a guest operating system.

Download boot image file. Eg. DSL.iso (Damn Small Linux)

$ sudo /usr/local/kvm/bin/qemu-system-x86_64 -hda <virtual disk image>
 -cdrom < boot-media.iso> \ -boot d  -m <memory size>

6. Running the newly-installed guest.

$ sudo /usr/local/kvm/bin/qemu-system-x86_64 <virtual disk image> -m <memory size>

Boot start….

Finished boot virtual machine.

Note*

Some instruction may differ depend on hardware/software in each computer.

Reference :

http://www. sourceforge.net

http://www.linux-kvm.org/

http://qemu-forum.ipi.fi/viewtopic.php?f=4&t=5367&start=0&st=0&sk=t&sd=a

http://www.linux-kvm.org/page/HOWTO1

http://damnsmalllinux.org/download.html

Salisa

1. Install software packets. (On Ubuntu virtual maching)

$ sudo apt-get install gcc libsdl1.2-dev zlib1g-dev libasound2-dev pkg-config libgnutls-dev libpci-dev

Posted in Uncategorized | Leave a comment

CS449: [Ex2] Virtualization

1. Computer Virtualization คืออะไรตามความเข้าใจของคุณ
Ans
เป็นการจำลองเครื่องคอมพิวเตอร์บนเครื่องคอมพิวเตอร์เครื่องหนึ่ง ทำให้เหมือนมีคอมพิวเตอร์หลายตัวบน Hardware เพียงเครื่องเดียว โดยสามารถแยกการทำงานต่างๆของระบบได้อย่างอิสระต่อกัน

2. จงอธิบายประโยชน์ และข้อเสียของ Virtualization ว่ามีอะไรบ้าง
Ans

ประโยชน์ ข้อเสีย
  1. รวมการทำงานและง่ายต่อการบริหารจัดการ
  2. ลดต้นทุนค่าใช้จ่ายด้าน Hardware& Human resource& Energy
  3. จัดสรรและใช้ทรัพยากรของ Hardware ได้เต็มประสิทธิภาพ
  4. ประสิทธิภาพในการป้องกันระบบและกู้ข้อมูลเพิ่มขึ้น
  5. ใช้งาน OS ได้หลากหลาย
  6. สามารถปรับปรุงเครื่องแม่ข่ายได้โดยไม่ต้องปิดระบบ
  1. หากHardware เสียจะมีผลต่อระบบทั้งหมด (Single point of failure) วิธีแก้คือต้องมีระบบสำรอง support
  2. ไม่สนันสนุนการทำงานของ เทคโนโลยีบางอย่าง
  3. Hardware จะต้องมีสเปกสูงเพื่อรองรับการทำงาน
  4. ค่า ใช้จ่ายด้านลิขสิทธิ์สูง(Full Version)
  5. การประมวลผลช้าลง

3. Process Virtual Machine มีลักษณะอย่างไร
Ans
เป็น virtual machines ที่ออกแบบมาให้รองรับโปรแกรมหรือการประมวลผลแบบใดแบบหนึ่ง (Process เดียว) Process VM ถูกสร้างขึ้นเฉพาะขณะ process ทำงาน

4. System Virtual Machine มีลักษณะอย่างไร
Ans
เป็น Virtual Machine  ที่ทำงานโดยการจำลองระบบทั้งระบบเพื่อแยกการทำงานให้เป็นอิสระต่อกัน ไม่ว่าจะเป็นการเข้าถึงข้อมูลในฮาร์ดิส การเข้าถึงแรม การใช้คำสั่งประมวลผล ระบบปฏิบัติการ และอุปกรณ์อื่นๆ

5. Classic Virtual Machine Monitor (VMM) แตกต่างจาก Hosted Virtual Machine อย่างไร
Ans

Virtual Machine Monitor (VMM) จะสร้าง Software VM อยู่ระหว่าง Hardware ของ Host และ Software ของ Guest  หน้าที่หลักของ VMM คือจัดสรรทรัพยากร virtualized Hardware  ให้กับ guest  เช่น การจำลอง ISA ของ Hardware ให้ Guest สามารถ excute ISA ที่แตกต่างจากที่อยู่บน Host ได้

Hosted Virtual Machine  หรือ จะสร้าง Software VM ด้านบน OS Host ทำหน้าที่จัด Driver Device และ Service ระดับล่าง

6. จงอธิบายว่า Virtualization Software ต่อไปนี้มีลักษณะอย่างไรและสร้าง Virtual
Machine แบบใหน
Ans

Virtualization Software ลักษณะ VM แบบ
Xen System Virtual Machine Classic Virtual Machine Monitor
Hyper-V System Virtual Machine Classic Virtual Machine Monitor
Vmware-Esx System Virtual Machine Classic Virtual Machine Monitor
Kernel-based Virtual Machine System Virtual Machine Hosted Virtual Machine Monitor
OpenVZ System Virtual Machine Hosted Virtual Machine Monitor

Resources:

http://vpslink.com/compare/openvz-vs-xen-vps-hosting/

http://en.wikipedia.org

http://www.phet.in.th/2009/11/virtual-machine-concept/

http://www.oknation.net/blog/itlabour/2009/06/03/entry-4

Posted in Uncategorized | Leave a comment