Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 May 2010 15:49:47 +0100
From:      Doug Rabson <dfr@rabson.org>
To:        Andriy Gapon <avg@icyb.net.ua>
Cc:        freebsd-fs@freebsd.org, freebsd-hackers@freebsd.org, Robert Noland <rnoland@freebsd.org>
Subject:   Re: bin/144214: zfsboot fails on gang block after upgrade to zfs v14
Message-ID:  <AANLkTileSJSXWJ_zUbKjOUkQgqHTS5JXLXQ7JvQhLXlD@mail.gmail.com>
In-Reply-To: <4BFE8C07.9010303@icyb.net.ua>
References:  <4BEBA334.6080101@icyb.net.ua> <4BEC040E.9080303@FreeBSD.org> <4BFE2ED6.1070402@freebsd.org> <AANLkTinza8LKXH5BrlhHsTtAwzeAgcgwOKSlpPBnuFLM@mail.gmail.com> <4BFE8C07.9010303@icyb.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On 27 May 2010 16:13, Andriy Gapon <avg@icyb.net.ua> wrote:

> on 27/05/2010 17:40 Doug Rabson said the following:
> >
> > Excellent work - thanks for looking into this. I still think its easier
> > to debug this code in userland using a shim that redirects the zfsboot
> > i/o calls to simple read system calls...
>
> Absolutely! That should much easier.
> Do you have such a shim that you could share?
> I'd be much obliged for it.  And not only I, I think.
> Thanks!
>

Attached. I thought I sent it to the list before but perhaps I only sent to
one of the participants in the last gang block thread.

[-- Attachment #2 --]
#include <sys/param.h>
#include <sys/queue.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <errno.h>

#define NBBY 8

void
pager_output(const char *line)
{
	printf("%s", line);
}

#include "zfsimpl.c"

static int
vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
{
	int fd = *(int *) priv;

	if (pread(fd, buf, bytes, off) != bytes)
		return -1;
	return 0;
}

static int
zfs_read(spa_t *spa, dnode_phys_t *dn, void *buf, size_t size, off_t off)
{
	const znode_phys_t *zp = (const znode_phys_t *) dn->dn_bonus;
	size_t n;
	int rc;

	n = size;
	if (off + n > zp->zp_size)
		n = zp->zp_size - off;
	
	rc = dnode_read(spa, dn, off, buf, n);
	if (rc)
		return (rc);

	return (n);
}

int
main(int argc, char** argv)
{
	int i, n, off;
	int fd[99];
	spa_t *spa;
	dnode_phys_t dn;
	char buf[512];

	zfs_init();
	if (argc == 1) {
		static char *av[] = {
			"zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
			NULL,
		};
		argc = 4;
		argv = av;
	}
	for (i = 1; i < argc; i++) {
		fd[i] = open(argv[i], O_RDONLY);
		if (fd[i] < 0)
			continue;
		if (vdev_probe(vdev_read, &fd[i], NULL) != 0)
			close(fd[i]);
	}
	spa_all_status();

	spa = STAILQ_FIRST(&zfs_pools);
	if (!spa || zfs_mount_pool(spa))
		exit(1);

	if (zfs_lookup(spa, "zfs.c", &dn))
		exit(1);

	off = 0;
	do {
		n = zfs_read(spa, &dn, buf, 512, off);
		write(1, buf, n);
		off += n;
	} while (n == 512);
}

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTileSJSXWJ_zUbKjOUkQgqHTS5JXLXQ7JvQhLXlD>