[sheepdog] [PATCH v2 08/11] sheep: introduce sparse objects

MORITA Kazutaka morita.kazutaka at gmail.com
Mon Jul 1 02:13:48 CEST 2013


At Sun, 30 Jun 2013 15:37:21 +0800,
Kai Zhang wrote:
> 
> On Jun 19, 2013, at 1:14 AM, MORITA Kazutaka <morita.kazutaka at gmail.com> wrote:
> 
> > -	if (iocb->offset != 0 || iocb->length != get_objsize(oid)) {
> > -		ret = prealloc(fd, get_objsize(oid));
> > +	trim_zero_blocks(iocb->buf, &offset, &len);
> > +
> > +	if (offset != 0 || len != get_objsize(oid)) {
> > +		if (is_sparse_object(oid))
> > +			ret = xftruncate(fd, get_objsize(oid));
> > +		else
> > +			ret = prealloc(fd, get_objsize(oid));
> > +
> > 		if (ret < 0) {
> > 			ret = err_to_sderr(path, oid, errno);
> > 			goto out;
> > 		}
> > 	}
> 
> Would you like to explain why we should use xftruncate if the object is sparse?
> Based on my understanding, fd is pointed to a new file, there should be no 
> difference between xfruncate and prealloc.

prealloc() calls fallocate/2, which allocates space to the object.
xftruncate() calls ftruncate/2, which extends the size of the object
but doesn't allocate spaces (the object becomes a sparse file).

Thanks,

Kazutaka



More information about the sheepdog mailing list