[Sheepdog] [Qemu-devel] [PATCH] sheepdog: add data preallocation support

Stefan Hajnoczi stefanha at gmail.com
Mon May 23 15:23:35 CEST 2011


On Mon, May 23, 2011 at 12:13 PM, MORITA Kazutaka
<morita.kazutaka at lab.ntt.co.jp> wrote:
> At Mon, 23 May 2011 10:19:13 +0100,
> Stefan Hajnoczi wrote:
>>
>> On Sat, May 21, 2011 at 1:35 PM, MORITA Kazutaka
>> <morita.kazutaka at lab.ntt.co.jp> wrote:
>> > +static int sd_prealloc(uint32_t vid, int64_t vdi_size)
>> > +{
>> > +    int fd, ret;
>> > +    SheepdogInode *inode;
>> > +    char *buf;
>> > +    unsigned long idx, max_idx;
>> [...]
>> > +    max_idx = (vdi_size + SD_DATA_OBJ_SIZE - 1) / SD_DATA_OBJ_SIZE;
>> > +
>> > +    for (idx = 0; idx < max_idx; idx++) {
>>
>> Do you want to use uint64_t here instead of unsigned long, which may
>> be too small on 32-bit hosts?
>
> The index of a Sheepdog data object is within 32-bit range, so using
> an unsigned long is safe here.

You are right:

#define MAX_DATA_OBJS (UINT64_C(1) << 20)
#define SD_DATA_OBJ_SIZE (UINT64_C(1) << 22)
#define SD_MAX_VDI_SIZE (SD_DATA_OBJ_SIZE * MAX_DATA_OBJS)

So the max_idx is MAX_DATA_OBJS, which is <32-bit.  It just looked suspicious.

Stefan



More information about the sheepdog mailing list