[Ocfs2-tools-devel] Re: [PATCH 1/2] The io_cache implementation
tao.ma
tao.ma at oracle.com
Mon Mar 26 23:48:45 PDT 2007
Joel Becker wrote:
> +static errcode_t io_cache_read_block(io_channel *channel, int64_t blkno,
> + int count, char *data)
> +
> +{
> + int i;
> + errcode_t ret = 0;
> +
> + for (i = 0; i < count; i++, blkno++) {
> + ret = io_cache_read_one_block(channel, blkno, data);
>
Should data change accordingly? data + i * channel->io_blksize?
The same error happens in io_cache_write_block.
> + if (ret)
> + break;
> + }
> +
> + return ret;
> +}
> +
> +static errcode_t io_cache_write_one_block(io_channel *channel,
> + int64_t blkno, const char *data)
> +{
> + errcode_t ret;
> + struct io_cache *ic = channel->io_cache;
> + struct io_cache_block *icb;
> +
> + icb = io_cache_lookup(ic, blkno);
> + if (icb)
> + goto found;
> +
> + /*
> + * Ok, this blkno isn't in the cache. Steal something.
> + */
> + icb = list_entry(ic->ic_lru.next, struct io_cache_block, icb_list);
> + if (icb->icb_node.rb_parent) {
> + rb_erase(&icb->icb_node, &ic->ic_lookup);
> + memset(&icb->icb_node, 0, sizeof(struct rb_node));
> + }
> +
> + icb->icb_blkno = blkno;
> + io_cache_insert(ic, icb);
> +
> +found:
> + memcpy(icb->icb_buf, data, channel->io_blksize);
> + io_cache_seen(ic, icb);
> +
> + ret = unix_io_write_block(channel, blkno, 1, icb->icb_buf);
> + return ret;
> +}
>
I think the "memcpy" should be moved after the success of
"unix_io_write_block" so that we can keep consistent of the buffer and
the real content on the disk.
> +
> +static errcode_t io_cache_write_block(io_channel *channel, int64_t blkno,
> + int count, const char *data)
> +
> +{
> + int i;
> + errcode_t ret = 0;
> +
> + for (i = 0; i < count; i++, blkno++) {
> + ret = io_cache_write_one_block(channel, blkno, data);
> + if (ret)
> + break;
> + }
> +
> + return ret;
> +}
> +
> +
Tao
More information about the Ocfs2-tools-devel
mailing list