I’m still working hard on vmx-manager, and I think it’s coming along pretty well. I spent a good chunk of last week writing my own code for creating VMware Virtual Disks. The VMDK specification is pretty straightforward, but implementing it proved to be more tedious than I expected (”the devil is in the details”). The end result seems to work pretty well, so now vmx-manager can create disks without relying on qemu or vmware-vdiskmanager. Soon I might try to add a couple more features in this area, such as the ability to grow an existing disk (which in theory should be easy — just add extents). I’ve made a screencast of the app as I put it through its paces, and you can find up-to-date screenshots here.
When I was writing the flat extent support (used for pre-allocated disks), I wanted to do something different than just writing a bunch of zeros out to a file (which is slow). It seemed to me that it should be possible to ask the filesystem to quickly give me a file of a specific size. I didn’t care what was in it, so it should be able to just find a bunch of unused sectors (or whatever) and mark them as mine, right? I was able to find no such feature in ext3 or Linux in general, and I guess the reason is probably due to security concerns. You obviously don’t want to give people a way to read deleted data. It would be nice, though, if the fs could mark the data in such a way that it would be zeros until you write to it. Maybe that’s just too expensive, I don’t know. Anyway, if anyone knows how I could accomplish such a thing, please let me know.
8 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
lseek() is your friend.
To see its effect without coding:
dd of=image-flat.vmdk seek=4200000 count=0 bs=1024
Unfortunately, size is not preallocated (du image-flat.vmdk), which means if you don’t have enough space in the future, you may have bad surprises.
glandium: Thanks. Actually I knew about lseek() already. What I need is a file which actually is preallocated, so it doesn’t help me there. I have been informed by Mr. Robert Love, however, that mmap will work. I’m going to try that now and see.
Dude, create the file as a sparse file. Google for sparse files, and O_SPARSE. It won’t allocate physical sectors until they’re written to, though.
Rudd-O: Dude, I know about that already. I want the file to be fully allocated.
vmx-manager rocks. Love the DnD to create .desktop launchers.
XFS has had this feature for a very long time - there’s even a POSIX call for it - posix_fallocate() - which isn’t implemented well in glibc (it just writes zeros).
But, XFS has this idea of an “unwritten extent”. It’s a flag for each extent to say if it’s been written yet. If it has, then a read reads from disk and a write writes to disk. If it has not, a read returns a zerod page and a write writes to disk (with appropriate changing of extent stuff around to not show dirty data).
Basically, to do this, you do:
#include
#include
#include
#include
int main(int argc, char **argv)
{
int fd, err;
xfs_flock64_t fl;
fl.l_whence = 0;
fl.l_start = 0;
fl.l_len = (off64_t)(1000ULL * 1024ULL * 1024ULL); /* 20M */
if(argc != 2)
return fprintf(stderr, “Filename expected.\n”), 1;
fd = open(argv[1], O_RDWR|O_CREAT|O_SYNC, 0666);
if (fd
gah - seems to have cut off some of what i wrote… hopefully you can edit and recover, if not - mail me
Continuing the Discussion