[sheepdog] [PATCH Update] sheep: introduce journal file to boost IO performance

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Nov 13 10:07:58 CET 2012


At Mon, 12 Nov 2012 13:43:24 +0800,
Liu Yuan wrote:
> +
> +int journal_file_write(uint64_t oid, const char *buf, size_t size,
> +		       off_t offset, bool create)
> +{
> +	struct journal_descriptor jd = { };

(snip)

> +
> +	jd.magic = JOURNAL_DESC_MAGIC;
> +	jd.offset = offset;
> +	jd.size = size;
> +	jd.oid = oid;
> +	jd.create = create;

I think it is simpler to use C99 style initialization.

        struct journal_descriptor jd = {
                .magic = JOURNAL_DESC_MAGIC,
                .offset = offset,
                .size = size,
                .oid = oid,
                .create = create,
        };

With this initialization, .pad will also be filled with zero.

> +
> +	pthread_spin_lock(&jfile_lock);
> +	if (!jfile_enough_space(wsize))
> +		switch_journal_file();
> +	woff = jfile.pos;
> +	jfile.pos += wsize;
> +	pthread_spin_unlock(&jfile_lock);
> +
> +	p = wbuffer = valloc(wsize);
> +	if (!wbuffer)
> +		panic("%m\n");
> +	memcpy(p, &jd, JOURNAL_DESC_SIZE);
> +	p += JOURNAL_DESC_SIZE;
> +	memcpy(p, buf, size);
> +	p += size;
> +	if (size < rusize)
> +		p += rusize - size;

Adding 'memset(p, 0, rusize - size)' is better to avoid writing
uninitialized data to the journal file.  This also removes a valgrind
error.

Other parts look good to me.

Thanks,

Kazutaka



More information about the sheepdog mailing list