static int vdev_file_io_done(zio_t *zio) { vdev_t *vd = zio->io_vd; if (zio_injection_enabled && zio->io_error == 0) zio->io_error = zio_handle_device_injection(vd, EIO); /* * If an error has been encountered then attempt to probe the device * to determine if it's still accessible. */ if (zio->io_error == EIO && vdev_probe(vd) != 0) { if (!vd->vdev_is_failing) { vd->vdev_is_failing = B_TRUE; zfs_ereport_post(FM_EREPORT_ZFS_PROBE_FAILURE, vd->vdev_spa, vd, zio, 0, 0); } } vdev_queue_io_done(zio); if (zio->io_type == ZIO_TYPE_WRITE) vdev_cache_write(zio); return (ZIO_PIPELINE_CONTINUE); }
static EFI_STATUS probe(dev_info_t *dev) { spa_t *spa; dev_info_t *tdev; EFI_STATUS status; /* ZFS consumes the dev on success so we need a copy. */ if ((status = bs->AllocatePool(EfiLoaderData, sizeof(*dev), (void**)&tdev)) != EFI_SUCCESS) { DPRINTF("Failed to allocate tdev (%lu)\n", EFI_ERROR_CODE(status)); return (status); } memcpy(tdev, dev, sizeof(*dev)); if (vdev_probe(vdev_read, tdev, &spa) != 0) { (void)bs->FreePool(tdev); return (EFI_UNSUPPORTED); } dev->devdata = spa; add_device(&devices, dev); return (EFI_SUCCESS); }
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); }
int main(int argc, char** argv) { char buf[512], hash[33]; MD5_CTX ctx; struct stat sb; struct zfsmount zfsmnt; dnode_phys_t dn; #if 0 uint64_t rootobj; #endif spa_t *spa; off_t off; ssize_t n; int i, failures, *fd; zfs_init(); if (argc == 1) { static char *av[] = { "zfsboottest", "/dev/gpt/system0", "/dev/gpt/system1", "-", "/boot/zfsloader", "/boot/support.4th", "/boot/kernel/kernel", NULL, }; argc = sizeof(av) / sizeof(av[0]) - 1; argv = av; } for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-") == 0) break; } fd = malloc(sizeof(fd[0]) * (i - 1)); if (fd == NULL) errx(1, "Unable to allocate memory."); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-") == 0) break; fd[i - 1] = open(argv[i], O_RDONLY); if (fd[i - 1] == -1) { warn("open(%s) failed", argv[i]); continue; } if (vdev_probe(vdev_read, &fd[i - 1], NULL) != 0) { warnx("vdev_probe(%s) failed", argv[i]); close(fd[i - 1]); } } spa_all_status(); spa = STAILQ_FIRST(&zfs_pools); if (spa == NULL) { fprintf(stderr, "no pools\n"); exit(1); } if (zfs_spa_init(spa)) { fprintf(stderr, "can't init pool\n"); exit(1); } #if 0 if (zfs_get_root(spa, &rootobj)) { fprintf(stderr, "can't get root\n"); exit(1); } if (zfs_mount(spa, rootobj, &zfsmnt)) { #else if (zfs_mount(spa, 0, &zfsmnt)) { fprintf(stderr, "can't mount\n"); exit(1); } #endif printf("\n"); for (++i, failures = 0; i < argc; i++) { if (zfs_lookup(&zfsmnt, argv[i], &dn)) { fprintf(stderr, "%s: can't lookup\n", argv[i]); failures++; continue; } if (zfs_dnode_stat(spa, &dn, &sb)) { fprintf(stderr, "%s: can't stat\n", argv[i]); failures++; continue; } off = 0; MD5Init(&ctx); do { n = sb.st_size - off; n = n > sizeof(buf) ? sizeof(buf) : n; n = zfs_read(spa, &dn, buf, n, off); if (n < 0) { fprintf(stderr, "%s: zfs_read failed\n", argv[i]); failures++; break; } MD5Update(&ctx, buf, n); off += n; } while (off < sb.st_size); if (off < sb.st_size) continue; MD5End(&ctx, hash); printf("%s %s\n", hash, argv[i]); } return (failures == 0 ? 0 : 1); }
int main(int argc, char** argv) { char buf[512]; int fd[100]; struct stat sb; dnode_phys_t dn; spa_t *spa; off_t off; ssize_t n; int i; zfs_init(); if (argc == 1) { static char *av[] = { "zfstest", "COPYRIGHT", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2", NULL, }; argc = 5; argv = av; } for (i = 2; 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 == NULL) { fprintf(stderr, "no pools\n"); exit(1); } if (zfs_mount_pool(spa)) { fprintf(stderr, "can't mount pool\n"); exit(1); } if (zfs_lookup(spa, argv[1], &dn)) { fprintf(stderr, "can't lookup\n"); exit(1); } if (zfs_dnode_stat(spa, &dn, &sb)) { fprintf(stderr, "can't stat\n"); exit(1); } off = 0; do { n = sb.st_size - off; n = n > sizeof(buf) ? sizeof(buf) : n; n = zfs_read(spa, &dn, buf, n, off); if (n < 0) { fprintf(stderr, "zfs_read failed\n"); exit(1); } write(1, buf, n); off += n; } while (off < sb.st_size); return (0); }