做项目要修改blktap中block-sync.c 的 tdsync_queue_write函数 

在用write向镜像写入自己新分配的buffer数据时报错 errno 为22 

参考write函数错误号发现

EINVAL fd is attached to an object which is unsuitable for writing; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified incount, or the current file offset is not suitably aligned.

比较原有buf变量内存地址发现其内存对其大小为4096字节 而自己使用Malloc默认采用8字节

改用 memalign(4096,size) 分配内存 写入buffer成功

 

环境:openSUSE 12.1 X86_64 XEN 4.1.2 DomU:openSUSE 12.1(PV)

 

p.s 后来经测试,由于原始磁盘镜像每个扇区为512字节,内存对齐512即可

posted on 2012-05-25 23:32  Macworld  阅读(180)  评论(2编辑  收藏  举报