Re: [PATCH 15/30] db: separate out straight buffer IO from map based IO.

Christoph Hellwig
2013-10-31T14:56:11Z

On Wed, Oct 30, 2013 at 03:31:06PM +1100, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> First step in converting to libxfs based IO.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>

The patch description is a little too short, there's not real
explanation of what it actually does.

> - if (read_bbs(XFS_SB_DADDR, 1, &bufp, NULL)) {
> + if (read_buf(XFS_SB_DADDR, 1, bufp)) {

E.g. why isn't this already using the normal libxfs routines?

(there probably is an explanation but I don't quite see it yet..)

> int
> +read_buf(
> + xfs_daddr_t bbno,
> + int count,
> + void *bufp)
> +{

Is read_buf really a good name for something that is a trivial pread
wrapper and doesn't deal with buffers? Should the function have some
comments explaining when to use it? The same also applies to the write
side.

> + int err;
> +
> + err = pwrite64(x.dfd, bufp, BBTOB(count), BBTOB(bbno));
> + if (err < 0)
> + err = errno;
> + else if (err < count)
> + err = -1;
> + return err;
> +}

> +static void
> +write_cur_buf(void)
> +{
> + int ret;
> +
> + ret = write_buf(iocur_top->bb, iocur_top->blen, iocur_top->buf);
> +
> + if (ret == -1)
> + dbprintf(_("incomplete write, block: %lld\n"),
> + (iocur_base + iocur_sp)->bb);
> + else if (ret != 0)
> + dbprintf(_("write error: %s\n"), strerror(ret));
> +
> + /* re-read buffer from disk */
> + ret = read_buf(iocur_top->bb, iocur_top->blen, iocur_top->buf);
> + if (ret == -1)
> + dbprintf(_("incomplete read, block: %lld\n"),
> + (iocur_base + iocur_sp)->bb);
> + else if (ret != 0)
> + dbprintf(_("read error: %s\n"), strerror(ret));
> +}

What is the point of the write and re-read cycle?

> + for (j = 0; j < count; j++) {
> + bbno = bbmap->b[j];
> if (lseek64(x.dfd, bbno << BBSHIFT, SEEK_SET) < 0) {
> rval = errno;
> dbprintf(_("can't seek in filesystem at bb %lld\n"), bbno);
> return rval;
> }
> - c = BBTOB(bbmap ? 1 : count);
> + c = BBTOB(1);
> i = (int)write(x.dfd, (char *)bufp + BBTOB(j), c);

Shoiuldn't this use the write_buf helper above?

> + for (j = 0; j < count; j++) {
> + bbno = bbmap->b[j];
> if (lseek64(x.dfd, bbno << BBSHIFT, SEEK_SET) < 0) {
> rval = errno;
> dbprintf(_("can't seek in filesystem at bb %lld\n"), bbno);
> @@ -483,7 +534,7 @@ read_bbs(
> xfree(buf);
> buf = NULL;
> } else {
> - c = BBTOB(bbmap ? 1 : count);
> + c = BBTOB(1);
> i = (int)read(x.dfd, (char *)buf + BBTOB(j), c);

And read_buf here?