[sheepdog] [PATCH 2/3] sheep, recovery: fix wrong size for xrealloc()

Christoph Hellwig hch at infradead.org
Tue Jun 12 17:53:46 CEST 2012


> @@ -267,9 +267,11 @@ static inline void prepare_schedule_oid(uint64_t oid)
>  	/* The oid is currently being recovered */
>  	if (rw->oids[rw->done] == oid)
>  		return;
> -
> -	rw->prio_oids = xrealloc(rw->prio_oids, ++rw->nr_prio_oids);
> +	rw->nr_prio_oids++;
> +	rw->prio_oids = xrealloc(rw->prio_oids,
> +				 rw->nr_prio_oids * sizeof(uint64_t));
>  	rw->prio_oids[rw->nr_prio_oids - 1] = oid;
> +

This looks fine.

> -	memmove(new_oids, rw->oids, nr_recovered * sizeof(uint64_t));
> -	memmove(new_oids + nr_recovered, rw->prio_oids,
> -		rw->nr_prio_oids * sizeof(uint64_t));
> +	memcpy(new_oids, rw->oids, nr_recovered * sizeof(uint64_t));
> +	memcpy(new_oids + nr_recovered, rw->prio_oids,
> +	       rw->nr_prio_oids * sizeof(uint64_t));

This also looks fine, but shouldn't it be a separate patch?

> -		nr_recovered, rw->nr_prio_oids, rw->count, new_idx);
> +	/* rw->count should eq new_idx, otherwise something is wrong */
> +	dprintf("%snr_recovered %d, nr_prio_oids %d, count %d = new %d\n",
> +		rw->count == new_idx ? "" : "WARN: ", nr_recovered,
> +		rw->nr_prio_oids, rw->count, new_idx);

Same here.




More information about the sheepdog mailing list