วันจันทร์ที่ 15 พฤศจิกายน พ.ศ. 2553

Project -> Overlay Disk Renew Machanism

รายงานสรุป
เรื่อง Overlay Disk Renew Machanism

จัดทำโดย
1.นางรุจรดา เย็นเยือก รหัส 5109035427
2.นายพิทักษ์ แท่นแก้ว รหัส 5209035194
3.นายวสันต์ กุลดิลก รหัส 5209035053

นำเสนอ
อาจารย์ ดร.กษิดิศ ชาญเชี่ยว

รายงานนี้เป็นส่วนหนึ่งของวิชา
CS797 Introduction to Computer Virtualizations เทอม 1/2553
ปริญญาโท ภาควิชาวิทยาการคอมพิวเตอร์
คณะวิทยาศาสตร์ มหาวิทยาลัยธรรมศาสตร์


Project 2 :: Overlay Disk Renew Mechanism1. To automatically use overlay disk image in KVM, users can invoke KVM
with the “-snapshot” option. In this project, you will add new capabilities to KVM disk emulation mechanisms to manage the above overlay disk.
In the current implementation of KVM, the overlay disk remain the same after users issue the “commit” command on qemu monitor to merge its contents to the base disk image. Therefore, as VM computation proceeds, the size of the overlay would grow bigger.
This project intends to modify the mechanism of KVM commit operation by
renewing the overlay disk after the merging of contents in the original commit
operation completes. You are required to create a new function namely the
bdrv_renew() to do the task. You are free to define any parameter for it.
This function would be called after the original commit operation is conducted.
To renew a disk, the bdrv_renew() function would create an empty overlay disk
on top of the base image that you have just committed contents to, and replace the
current overlay disk with the new one.
(The previous overlay disk must be deleted from host computers' file system.)

จากโจทย์ที่ได้รับ ได้ทำการแก้ไข Source-Code ในไฟล์
• 1.block.h
• 2.block.c
แสดงการทำงานด้วย Flow Chart ดังนี้



















ทำการแก้ไข Source-Code
1. ทำการแก้ไข code ใน block.c เพื่อให้สามารถมองเห็นไฟล์ ที่ถูกสร้างขึ้นมา
ภายใต้ path file /tmp/…. จำนวน 3 จุดดังนี้ ที่บรรทัด 480 , 488 , 533
ตามภาพที่จะแสดงดังนี้






2. ในฟังก์ชั่น bdrv_commit()
ทำการสร้าง ฟังก์ชั่นใหม่ชื่อ bdrv_renew() แสดง source-code ตามรูปนี้



















เพื่อให้ทำงานภายหลังจากการ Commit ให้ทำการเปิด Overlay Image ใหม่ ได้


3.ใน block.h ทำการเขียนประกาศโครงสร้างของฟังก์ใหม่ ตามรูปดังนี้
4.ใน bdrv_commit() ทำการเพิ่มฟังก์ชั่นการทำงานของ bdrv_renew()



























สร้าง ovl ขึ้นมาใหม่ โดยอาศัย bdrv_renew() (ไปเรียกใช้ bdrv_open2()) ช่วยสร้าง snapshot ด้วยการกำหนดให้ flags มีค่า 72 ซึ่งได้จากการดำเนินการระดับ bit แบบ or ของค่าคงที่ BDRV_O_SNAPSHOT (0x0008) และ BDRV_O_CACHE_WB (0x0040) คำนวณแล้วได้ 0x0048 นั่นคือ 72 ฐาน 10 นั่นเอง
ทำการ Compile โปรแกรม ด้วยคำสั่ง
./configure
make
sudo make install

แสดงลำดับการทำงานดังนี้
1. Start Overlay Image
ด้วยคำสั่ง
Qemu-system-x86_64 –had had.img –m 256 –boot c –snapshot



2. จากคำสั่งนี้จะได้ไฟล์ vl.* มา ภายใต้ path file :/tmp/….
ตรวจสอบด้วยคำสั่ง
$ls –alh /tmp/vl.* (มี 1 ไฟล์)


3. บน Guest OS ทดลองสร้างไฟล์ ขนาด 5 MB
ด้วยคำสั่ง
$dd if=/dev/zero of=test.img bs=1024 count=5
4. ทำการตรวจสอบขนาดไฟล์
ด้วยคำสั่ง $ls –alh /tmp/vl.* พบว่าไฟล์มีขนาดใหญ่ขึ้น

5.ทำการสลับ mode การทำงาน ใช้คำสั่ง
Ctrl + Alt + 2
แล้วพิมพ์คำสั่ง commit all


6. ทำการตรวจสอบไฟล์ vl.* ว่ามี 2 ไฟล์
ด้วยคำสั่ง $ls –alh /tmp/vl.*


7. ทำการตรวจสอบ base image ว่ามีขนาดใหญ่ขึ้น
ด้วยคำสั่ง $ls –alh hda.img (ไฟล์มีขนาดใหญ่ขึ้น 5 MB)






8. ที่ QEMU ทำการออกจากระบบ พิมพ์ Quit






9. พิมพ์คำสั่งที่ 1 อีกครั้ง (Start การทำงานของ VM อีกครั้ง) พบว่า test.img ยังอยู่















Conclusion and Future Work
>>ยังมี code ในส่วนฟังก์ชั่นการทำงานของ Undo ที่ต้องศึกษาต่อตามนี้\
แบบที่ 1
1.นับจำนวน sector ที่ต้องการจะเขียนไปที่ base file
2. เช็คค่าแต่ละ sector ว่ามีขนาดเท่าใด
3. ทำการเก็บเลข sector และขนาด
4. ทำการ Deallocated sector ต่างๆที่ได้ทำการ commit ไป ด้วยการตัด link-list
ที่ทำการเชื่อมในแต่ละ sector ที่ต่อกันออก แล้วชี้ไปที Sector สุดท้ายของ Base แทน เพื่อทำการจบ base file
แบบที่ 2
1. สำเนา base image ขึ้นมา 1 ชุด (เก็บไว้ใน directory backup)
2. ขณะ commit จะมี empty ovl เกิดขึ้นมา
3. จากนั้นทำการย้าย ovl ตัวเก่าไปเก็บไว้ที่ backup
4. สร้างไฟล์ log เก็บลำดับของ ovl ที่ได้ทำการ commit แล้ว (อาจมีการเก็บ timestamp)
5. การ commit ครั้งต่อ ๆ ไป ให้ดำเนินการตามข้อ 2. – 4.
6. เขียน script รับ input จากผู้ใช้ ระบุ เวลา/ลำดับ ของ base image ที่ต้องการ
7. วน loop เพื่อ ทยอย commit ทีละไฟล์ (เรียกใช้คำสั่ง qemu-img commit) ตามจำนวน input ของผู้ใช้
8. ผลที่ได้คือ base image ณ เวลา/ลำดับ ที่ผู้ใช้ต้องการ








Link for blog