Search code examples
network-programmingblockdevicedefinitions

What does NBD_SET_SIZE set the size of? The channel or the size of the block device?


I'm using Network Block Device (NBD) and I couldn't find any documentation on what NBD_SET_SIZE refers to. I suspect that it's the size of the block device, and then NBD_SET_BLKSIZE is the hint for the underlying device's block size. So then what's NBD_SET_SIZE_BLOCKS?

Is there someplace where I can get a definition for all the ioctl flags defined in nbd.h? Doing a google search turns up nothing, and the nbd.h contains no comments about these flags.


Solution

  • You can read the code here.

    Basically, there are two modes of setting a size: one is in bytes, the other is in blocks.

    The former is NBD_SET_SIZE. The latter requires you to do two ioctls, one to set the blocksize (NBD_SET_BLKSIZE), another one to set the size in blocks (NBD_SET_SIZE_BLOCKS).

    It's really not that difficult once you understand where the names come from :-)

    I'm not sure how well NBD_SET_SIZE is still supported though, seen as most nbd implementations that I know of use NBD_SET_BLKSIZE.