基本配置信息:
虚拟机是由qemu启动,qemu使用kernel kvm启动虚拟机,VM是普通的linux系统。
qemu通过virtio-9p在host和guest之间共享文件
qemu 参数:
-fsdev local,id=exp1,path=/tmp/,security_model=none
-device virtio-9p-pci,fsdev=exp1,mount_tag=v_tmp
On the client it can be mounted with:
$ mount -t 9p -o trans=virtio v_tmp /mnt
在VM中通过linux aio访问文件,用户程序使用libaio,如下
const char* content1 = "hello world!";
int main(void)
{
int output_fd;
struct iocb io, *p=&io;
io_context_t ctx;
const char content[]="hello world again!";
char *content2 = malloc(SIZE_TEST);
snprintf(content2, sizeof(content2), "%s", "hello again\n");
memset(&ctx, 0, sizeof(ctx));
io_setup(10, &ctx);
output_fd=open("foobar.txt", O_CREAT|O_WRONLY, 0644))
#if LOG_TO_FILE
io_prep_pwrite(&io, output_fd, (void*)content, strlen(content), 0);
//io.data = content;
#endif
io_submit(ctx, 1, &p)
// 4. wait IO finish.
io_getevents(ctx, 0, 1, &e, &timeout);
io_destroy(ctx);
return 0;
}
用户程序的一个write设计的大概过程是,用户程序->aio_commit syscall->guest kernel process-> aio_commit->vfs->9p fs driver->virtio->switch from non-root mode (guest) to root mode (host)