[sheepdog] [PATCH v3 1/3] sheep: handle VID overflow correctly

Liu Yuan namei.unix at gmail.com
Fri Feb 27 09:51:21 CET 2015

On Fri, Feb 27, 2015 at 01:46:14PM +0900, Hitoshi Mitake wrote:
> Current sheep cannot handle a case like this:
> 1. iterate snapshot creation and let latest working VDI have VID 0xffffff
> 2. create one more snapshot
> This problem comes from invalid usage of find_next_zero_bit() of sheep.
> Current sheep checks its VID bitmap with find_next_zero_bit(). But the
> function has a subtle point we must care about. If we check a bitmap
> and whose right most bit is 1, it returns a number of the bit though
> the bit is not 0. It means
>     /* the right most bit of sys->vdi_inuse is 1*/
>     find_next_zero_bit(sys->vdi_inuse, SD_NR_VDIS, 0);
> will return SD_NR_VDIS - 1 (not SD_NR_VDIS, of course). So it is not
> possible to check the right most bit is used or not by simply calling
> find_next_zero_bit(). So the existing code cannot handle the case of
> overflow.

I did a small test, it looks like following:

int main()
	long i = 0b111111;
	printf("%lu\n", find_next_zero_bit(&i, 6, 5));
	printf("%lu\n", find_next_zero_bit(&i, 6, 0));

It mimics what you described. But the result is

yliu at ubuntu-trusty:~/sheepdog$ ./a.out 

which means find_next_zero_bit does return SD_NR_VDIS in your case. Am I missing


More information about the sheepdog mailing list