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

MORITA Kazutaka morita.kazutaka at gmail.com
Tue Nov 13 23:17:03 CET 2012


At Tue, 13 Nov 2012 17:45:38 +0800,
Liu Yuan wrote:
> 
> +int journal_file_write(uint64_t oid, const char *buf, size_t size,
> +		       off_t offset, bool create)
> +{
> +	uint32_t marker = JOURNAL_END_MARKER;
> +	int ret = SD_RES_SUCCESS;
> +	ssize_t written, rusize = roundup(size, SECTOR_SIZE),
> +		wsize = JOURNAL_META_SIZE + rusize;
> +	off_t woff;
> +	char *wbuffer, *p;
> +	struct journal_descriptor jd = {
> +		.magic = JOURNAL_DESC_MAGIC,
> +		.offset = offset,
> +		.size = size,
> +		.oid = oid,
> +		.create = create,
> +	};
> +
> +	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;
> +		memset(p, 0, rusize - size);
> +	}

Call memset before moving p.

Thanks,

Kazutaka



More information about the sheepdog mailing list