Lines Matching +full:p +full:- +full:mos

1 /*-
28 * Stand-alone ZFS file reader.
60 * For plain (non-mirror) top-level vdevs (i.e. is_vdev is not a mirror),
61 * ic_vdev is the same as is_vdev. However, for mirror top-level vdevs,
71 * indirect vdev. For non-split (contiguously-mapped) blocks, there will be
84 vdev_t *is_vdev; /* top-level vdev */
95 indirect_child_t is_child[1]; /* variable-length */
100 * It is the "Vdev-Specific Data" in the zio_t's io_vsd.
115 * List of supported read-incompatible ZFS features. Do not add here features
116 * marked as ZFEATURE_FLAG_READONLY_COMPAT, they are irrelevant for read-only!
133 "org.open-zfs:large_blocks",
203 data = (nvs_data_t *)features->nv_data; in nvlist_check_features_for_read()
204 nvp = &data->nvl_pair; /* first pair in nvlist */ in nvlist_check_features_for_read()
206 while (nvp->encoded_size != 0 && nvp->decoded_size != 0) { in nvlist_check_features_for_read()
213 if (memcmp(nvp_name->nv_data, features_for_read[i], in nvlist_check_features_for_read()
214 nvp_name->nv_size) == 0) { in nvlist_check_features_for_read()
222 nvp_name->nv_size, nvp_name->nv_data); in nvlist_check_features_for_read()
225 nvp = (nvp_header_t *)((uint8_t *)nvp + nvp->encoded_size); in nvlist_check_features_for_read()
239 if (vdev->v_phys_read == NULL) in vdev_read_phys()
248 rc = vdev->v_phys_read(vdev, vdev->v_priv, offset, buf, psize); in vdev_read_phys()
251 rc = zio_checksum_verify(vdev->v_spa, bp, buf); in vdev_read_phys()
260 if (vdev->v_phys_write == NULL) in vdev_write_phys()
263 return (vdev->v_phys_write(vdev, offset, buf, size)); in vdev_write_phys()
280 rs->rs_vd = vd; in rs_alloc()
281 rs->rs_offset = offset; in rs_alloc()
282 rs->rs_asize = asize; in rs_alloc()
283 rs->rs_split_offset = split_offset; in rs_alloc()
301 vim->vim_dn = calloc(1, sizeof (*vim->vim_dn)); in vdev_indirect_mapping_open()
302 if (vim->vim_dn == NULL) { in vdev_indirect_mapping_open()
307 rc = objset_get_dnode(spa, os, mapping_object, vim->vim_dn); in vdev_indirect_mapping_open()
309 free(vim->vim_dn); in vdev_indirect_mapping_open()
314 vim->vim_spa = spa; in vdev_indirect_mapping_open()
315 vim->vim_phys = malloc(sizeof (*vim->vim_phys)); in vdev_indirect_mapping_open()
316 if (vim->vim_phys == NULL) { in vdev_indirect_mapping_open()
317 free(vim->vim_dn); in vdev_indirect_mapping_open()
322 vim_phys = (vdev_indirect_mapping_phys_t *)DN_BONUS(vim->vim_dn); in vdev_indirect_mapping_open()
323 *vim->vim_phys = *vim_phys; in vdev_indirect_mapping_open()
325 vim->vim_objset = os; in vdev_indirect_mapping_open()
326 vim->vim_object = mapping_object; in vdev_indirect_mapping_open()
327 vim->vim_entries = NULL; in vdev_indirect_mapping_open()
329 vim->vim_havecounts = in vdev_indirect_mapping_open()
330 (vim->vim_dn->dn_bonuslen > VDEV_INDIRECT_MAPPING_SIZE_V0); in vdev_indirect_mapping_open()
342 * mapping entry and -1 will be returned.
375 return (-1); in dva_mapping_overlap_compare()
376 } else if (*key < src_offset + DVA_GET_ASIZE(&array_elem->vimep_dst)) { in dva_mapping_overlap_compare()
393 if (vim->vim_phys->vimp_num_entries == 0) in vdev_indirect_mapping_entry()
396 if (vim->vim_entries == NULL) { in vdev_indirect_mapping_entry()
399 bsize = vim->vim_dn->dn_datablkszsec << SPA_MINBLOCKSHIFT; in vdev_indirect_mapping_entry()
400 size = vim->vim_phys->vimp_num_entries * in vdev_indirect_mapping_entry()
401 sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
403 size = bsize / sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
404 size *= sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
406 vim->vim_entries = malloc(size); in vdev_indirect_mapping_entry()
407 if (vim->vim_entries == NULL) in vdev_indirect_mapping_entry()
409 vim->vim_num_entries = size / sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
410 offset = index * sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
415 if (index >= vim->vim_entry_offset && in vdev_indirect_mapping_entry()
416 index <= vim->vim_entry_offset + vim->vim_num_entries) { in vdev_indirect_mapping_entry()
417 index -= vim->vim_entry_offset; in vdev_indirect_mapping_entry()
418 return (&vim->vim_entries[index]); in vdev_indirect_mapping_entry()
420 offset = index * sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
423 vim->vim_entry_offset = index; in vdev_indirect_mapping_entry()
424 size = vim->vim_num_entries * sizeof (*vim->vim_entries); in vdev_indirect_mapping_entry()
425 rc = dnode_read(vim->vim_spa, vim->vim_dn, offset, vim->vim_entries, in vdev_indirect_mapping_entry()
429 free(vim->vim_entries); in vdev_indirect_mapping_entry()
430 vim->vim_entries = NULL; in vdev_indirect_mapping_entry()
433 index -= vim->vim_entry_offset; in vdev_indirect_mapping_entry()
434 return (&vim->vim_entries[index]); in vdev_indirect_mapping_entry()
460 ASSERT(vim->vim_phys->vimp_num_entries > 0); in vdev_indirect_mapping_entry_for_offset()
464 uint64_t last = vim->vim_phys->vimp_num_entries - 1; in vdev_indirect_mapping_entry_for_offset()
475 mid = base + ((last - base) >> 1); in vdev_indirect_mapping_entry_for_offset()
485 last = mid - 1; in vdev_indirect_mapping_entry_for_offset()
507 vdev_indirect_mapping_t *vim = vd->v_mapping; in vdev_indirect_mapping_duplicate_adjacent_entries()
516 uint64_t size = DVA_GET_ASIZE(&m->vimep_dst); in vdev_indirect_mapping_duplicate_adjacent_entries()
517 uint64_t inner_offset = offset - DVA_MAPPING_GET_SRC_OFFSET(m); in vdev_indirect_mapping_duplicate_adjacent_entries()
518 uint64_t inner_size = MIN(asize, size - inner_offset); in vdev_indirect_mapping_duplicate_adjacent_entries()
521 asize -= inner_size; in vdev_indirect_mapping_duplicate_adjacent_entries()
544 vlist = &spa->spa_root_vdev->v_children; in vdev_lookup_top()
546 if (rvd->v_id == vdev) in vdev_lookup_top()
562 indirect_vsd_t *iv = zio->io_vsd; in vdev_indirect_gather_splits()
564 if (vd->v_read == vdev_indirect_read) in vdev_indirect_gather_splits()
567 if (vd->v_read == vdev_mirror_read) in vdev_indirect_gather_splits()
568 n = vd->v_nchildren; in vdev_indirect_gather_splits()
573 zio->io_error = ENOMEM; in vdev_indirect_gather_splits()
578 is->is_children = n; in vdev_indirect_gather_splits()
579 is->is_size = size; in vdev_indirect_gather_splits()
580 is->is_split_offset = split_offset; in vdev_indirect_gather_splits()
581 is->is_target_offset = offset; in vdev_indirect_gather_splits()
582 is->is_vdev = vd; in vdev_indirect_gather_splits()
590 if (vd->v_read == vdev_mirror_read) { in vdev_indirect_gather_splits()
594 STAILQ_FOREACH(kid, &vd->v_children, v_childlink) { in vdev_indirect_gather_splits()
595 is->is_child[i++].ic_vdev = kid; in vdev_indirect_gather_splits()
598 is->is_child[0].ic_vdev = vd; in vdev_indirect_gather_splits()
601 list_insert_tail(&iv->iv_splits, is); in vdev_indirect_gather_splits()
608 spa_t *spa = vd->v_spa; in vdev_indirect_remap()
618 zio->io_error = ENOMEM; in vdev_indirect_remap()
621 vdev_t *v = rs->rs_vd; in vdev_indirect_remap()
623 /* vdev_indirect_mapping_t *vim = v->v_mapping; */ in vdev_indirect_remap()
626 rs->rs_offset, rs->rs_asize, &num_entries); in vdev_indirect_remap()
629 zio->io_error = ENOMEM; in vdev_indirect_remap()
633 uint64_t size = DVA_GET_ASIZE(&m->vimep_dst); in vdev_indirect_remap()
634 uint64_t dst_offset = DVA_GET_OFFSET(&m->vimep_dst); in vdev_indirect_remap()
635 uint64_t dst_vdev = DVA_GET_VDEV(&m->vimep_dst); in vdev_indirect_remap()
636 uint64_t inner_offset = rs->rs_offset - in vdev_indirect_remap()
639 MIN(rs->rs_asize, size - inner_offset); in vdev_indirect_remap()
642 if (dst_v->v_read == vdev_indirect_read) { in vdev_indirect_remap()
646 inner_size, rs->rs_split_offset); in vdev_indirect_remap()
650 zio->io_error = ENOMEM; in vdev_indirect_remap()
656 vdev_indirect_gather_splits(rs->rs_split_offset, dst_v, in vdev_indirect_remap()
664 if (zio->io_error != 0) in vdev_indirect_remap()
666 rs->rs_offset += inner_size; in vdev_indirect_remap()
667 rs->rs_asize -= inner_size; in vdev_indirect_remap()
668 rs->rs_split_offset += inner_size; in vdev_indirect_remap()
673 if (zio->io_error != 0) in vdev_indirect_remap()
683 indirect_vsd_t *iv = zio->io_vsd; in vdev_indirect_map_free()
686 while ((is = list_head(&iv->iv_splits)) != NULL) { in vdev_indirect_map_free()
687 for (int c = 0; c < is->is_children; c++) { in vdev_indirect_map_free()
688 indirect_child_t *ic = &is->is_child[c]; in vdev_indirect_map_free()
689 free(ic->ic_data); in vdev_indirect_map_free()
691 list_remove(&iv->iv_splits, is); in vdev_indirect_map_free()
702 spa_t *spa = vdev->v_spa; in vdev_indirect_read()
711 list_create(&iv->iv_splits, in vdev_indirect_read()
723 if (vdev->v_mapping == NULL) { in vdev_indirect_read()
726 vic = &vdev->vdev_indirect_config; in vdev_indirect_read()
727 vdev->v_mapping = vdev_indirect_mapping_open(spa, in vdev_indirect_read()
728 spa->spa_mos, vic->vic_mapping_object); in vdev_indirect_read()
735 first = list_head(&iv->iv_splits); in vdev_indirect_read()
736 if (first->is_size == zio.io_size) { in vdev_indirect_read()
748 * on non-indirect vdevs. This allows us to be less strict in vdev_indirect_read()
751 rc = first->is_vdev->v_read(first->is_vdev, zio.io_bp, in vdev_indirect_read()
752 zio.io_data, first->is_target_offset, bytes); in vdev_indirect_read()
754 iv->iv_split_block = B_TRUE; in vdev_indirect_read()
757 * top-level vdev. Since we don't know the in vdev_indirect_read()
764 for (indirect_split_t *is = list_head(&iv->iv_splits); in vdev_indirect_read()
765 is != NULL; is = list_next(&iv->iv_splits, is)) { in vdev_indirect_read()
768 rc = is->is_vdev->v_read(is->is_vdev, zio.io_bp, in vdev_indirect_read()
769 ptr + is->is_split_offset, is->is_target_offset, in vdev_indirect_read()
770 is->is_size); in vdev_indirect_read()
810 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) { in vdev_mirror_read()
811 if (kid->v_state != VDEV_STATE_HEALTHY) in vdev_mirror_read()
813 rc = kid->v_read(kid, bp, buf, offset, bytes); in vdev_mirror_read()
834 kid = STAILQ_FIRST(&vdev->v_children); in vdev_replacing_read()
837 if (kid->v_state != VDEV_STATE_HEALTHY) in vdev_replacing_read()
839 return (kid->v_read(kid, bp, buf, offset, bytes)); in vdev_replacing_read()
848 if (vdev->v_guid == guid) in vdev_find()
862 STAILQ_INIT(&vdev->v_children); in vdev_create()
863 vdev->v_guid = guid; in vdev_create()
864 vdev->v_read = _read; in vdev_create()
872 vic = &vdev->vdev_indirect_config; in vdev_create()
873 vic->vic_prev_indirect_vdev = UINT64_MAX; in vdev_create()
903 vdev->v_state = VDEV_STATE_OFFLINE; in vdev_set_initial_state()
905 vdev->v_state = VDEV_STATE_REMOVED; in vdev_set_initial_state()
907 vdev->v_state = VDEV_STATE_FAULTED; in vdev_set_initial_state()
909 vdev->v_state = VDEV_STATE_DEGRADED; in vdev_set_initial_state()
911 vdev->v_state = VDEV_STATE_CANT_OPEN; in vdev_set_initial_state()
913 vdev->v_islog = is_log != 0; in vdev_set_initial_state()
958 vdev->v_state = VDEV_STATE_HEALTHY; in vdev_init()
959 vic = &vdev->vdev_indirect_config; in vdev_init()
964 NULL, &vic->vic_mapping_object, NULL); in vdev_init()
968 NULL, &vic->vic_births_object, NULL); in vdev_init()
972 NULL, &vic->vic_prev_indirect_vdev, NULL); in vdev_init()
984 vdev->v_id = id; in vdev_init()
987 vdev->v_ashift = ashift; in vdev_init()
991 vdev->v_psize = asize + in vdev_init()
997 vdev->v_nparity = nparity; in vdev_init()
1006 pathlen -= len; in vdev_init()
1011 vdev->v_name = name; in vdev_init()
1015 if (vdev->v_nparity < 1 || in vdev_init()
1016 vdev->v_nparity > 3) { in vdev_init()
1018 vdev->v_nparity); in vdev_init()
1021 (void) asprintf(&name, "%.*s%d-%" PRIu64, len, type, in vdev_init()
1022 vdev->v_nparity, id); in vdev_init()
1024 (void) asprintf(&name, "%.*s-%" PRIu64, len, type, id); in vdev_init()
1026 vdev->v_name = name; in vdev_init()
1042 if (STAILQ_EMPTY(&top_vdev->v_children)) in vdev_find_previous()
1046 STAILQ_FOREACH(v, &top_vdev->v_children, v_childlink) { in vdev_find_previous()
1047 if (v->v_id > vdev->v_id) in vdev_find_previous()
1050 if (v->v_id == vdev->v_id) in vdev_find_previous()
1053 if (v->v_id < vdev->v_id) in vdev_find_previous()
1066 STAILQ_FOREACH(v, &vdev->v_children, v_childlink) { in vdev_child_count()
1091 STAILQ_INSERT_HEAD(&top_vdev->v_children, vdev, v_childlink); in vdev_insert()
1092 } else if (previous->v_id == vdev->v_id) { in vdev_insert()
1099 STAILQ_INSERT_AFTER(&top_vdev->v_children, previous, vdev, in vdev_insert()
1104 if (top_vdev->v_nchildren < count) in vdev_insert()
1105 top_vdev->v_nchildren = count; in vdev_insert()
1121 top_vdev->v_spa = spa; in vdev_from_nvlist()
1122 top_vdev->v_top = top_vdev; in vdev_from_nvlist()
1123 vdev_insert(spa->spa_root_vdev, top_vdev); in vdev_from_nvlist()
1142 vdev->v_spa = spa; in vdev_from_nvlist()
1143 vdev->v_top = top_vdev; in vdev_from_nvlist()
1192 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) { in vdev_set_state()
1201 if (STAILQ_FIRST(&vdev->v_children)) { in vdev_set_state()
1204 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) { in vdev_set_state()
1205 if (kid->v_state == VDEV_STATE_HEALTHY) in vdev_set_state()
1211 vdev->v_state = VDEV_STATE_HEALTHY; in vdev_set_state()
1213 if (vdev->v_read == vdev_mirror_read) { in vdev_set_state()
1215 vdev->v_state = VDEV_STATE_DEGRADED; in vdev_set_state()
1217 vdev->v_state = VDEV_STATE_OFFLINE; in vdev_set_state()
1219 } else if (vdev->v_read == vdev_raidz_read) { in vdev_set_state()
1220 if (bad_kids > vdev->v_nparity) { in vdev_set_state()
1221 vdev->v_state = VDEV_STATE_OFFLINE; in vdev_set_state()
1223 vdev->v_state = VDEV_STATE_DEGRADED; in vdev_set_state()
1288 if (spa->spa_guid != pool_guid) { in vdev_init_from_nvlist()
1293 spa->spa_root_vdev->v_nchildren = vdev_children; in vdev_init_from_nvlist()
1300 * MOS config has at least one child for root vdev. in vdev_init_from_nvlist()
1331 * Re-evaluate top-level vdev state. in vdev_init_from_nvlist()
1333 vdev_set_state(spa->spa_root_vdev); in vdev_init_from_nvlist()
1344 if (spa->spa_guid == guid) in spa_find_by_guid()
1356 if (strcmp(spa->spa_name, name) == 0) in spa_find_by_name()
1369 if ((spa->spa_name = strdup(name)) == NULL) { in spa_create()
1373 spa->spa_uberblock = &spa->spa_uberblock_master; in spa_create()
1374 spa->spa_mos = &spa->spa_mos_master; in spa_create()
1375 spa->spa_guid = guid; in spa_create()
1376 spa->spa_root_vdev = vdev_create(guid, NULL); in spa_create()
1377 if (spa->spa_root_vdev == NULL) { in spa_create()
1378 free(spa->spa_name); in spa_create()
1382 spa->spa_root_vdev->v_name = strdup("root"); in spa_create()
1445 if (vdev->v_islog) { in vdev_status()
1450 ret = print_state(indent, vdev->v_name, vdev->v_state); in vdev_status()
1454 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) { in vdev_status()
1472 ret = pager_printf(" pool: %s\n", spa->spa_name); in spa_status()
1479 ret = pager_printf("bootfs: %s\n", spa->spa_name); in spa_status()
1481 ret = pager_printf("bootfs: %s/%s\n", spa->spa_name, in spa_status()
1496 vlist = &spa->spa_root_vdev->v_children; in spa_status()
1498 if (vdev->v_state == VDEV_STATE_HEALTHY) in spa_status()
1500 else if (vdev->v_state == VDEV_STATE_DEGRADED) in spa_status()
1512 ret = print_state(0, spa->spa_name, state); in spa_status()
1552 label_offset = psize - VDEV_LABELS * sizeof (vdev_label_t); in vdev_label_offset()
1562 int cmp = AVL_CMP(ub1->ub_txg, ub2->ub_txg); in vdev_uberblock_compare()
1567 cmp = AVL_CMP(ub1->ub_timestamp, ub2->ub_timestamp); in vdev_uberblock_compare()
1583 if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC)) { in uberblock_verify()
1587 if (ub->ub_magic != UBERBLOCK_MAGIC || in uberblock_verify()
1588 !SPA_VERSION_IS_SUPPORTED(ub->ub_version)) in uberblock_verify()
1601 off = vdev_label_offset(vd->v_psize, l, offset); in vdev_label_read()
1624 * Next best thing is vdev_phys - it is just after bootenv. It still may
1636 off = vdev_label_offset(vd->v_psize, l, o_phys); in vdev_label_write_validate()
1639 if (vdev_label_offset(vd->v_psize, l, offset) + VDEV_PAD_SIZE != off) in vdev_label_write_validate()
1661 if (vd->v_phys_write == NULL) in vdev_label_write()
1664 off = vdev_label_offset(vd->v_psize, l, offset); in vdev_label_write()
1672 be->vbe_zbt.zec_magic = ZEC_MAGIC; in vdev_label_write()
1673 zio_checksum_label_verifier(&be->vbe_zbt.zec_cksum, off); in vdev_label_write()
1674 ci->ci_func[0](be, size, NULL, &cksum); in vdev_label_write()
1675 be->vbe_zbt.zec_cksum = cksum; in vdev_label_write()
1686 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) { in vdev_write_bootenv_impl()
1687 if (kid->v_state != VDEV_STATE_HEALTHY) in vdev_write_bootenv_impl()
1695 * Non-leaf vdevs do not have v_phys_write. in vdev_write_bootenv_impl()
1697 if (vdev->v_phys_write == NULL) in vdev_write_bootenv_impl()
1705 vdev->v_name ? vdev->v_name : "unknown", l, err); in vdev_write_bootenv_impl()
1720 if (nvl->nv_size > sizeof(be->vbe_bootenv)) in vdev_write_bootenv()
1735 be->vbe_version = version; in vdev_write_bootenv()
1742 be->vbe_bootenv, NULL); in vdev_write_bootenv()
1747 nv.nv_header = nvl->nv_header; in vdev_write_bootenv()
1748 nv.nv_asize = nvl->nv_asize; in vdev_write_bootenv()
1749 nv.nv_size = nvl->nv_size; in vdev_write_bootenv()
1751 bcopy(&nv.nv_header, be->vbe_bootenv, sizeof(nv.nv_header)); in vdev_write_bootenv()
1752 nv.nv_data = be->vbe_bootenv + sizeof(nvs_header_t); in vdev_write_bootenv()
1753 bcopy(nvl->nv_data, nv.nv_data, nv.nv_size); in vdev_write_bootenv()
1763 be->vbe_version = htobe64(be->vbe_version); in vdev_write_bootenv()
1784 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) { in vdev_read_bootenv()
1785 if (kid->v_state != VDEV_STATE_HEALTHY) in vdev_read_bootenv()
1810 be->vbe_version = be64toh(be->vbe_version); in vdev_read_bootenv()
1811 switch (be->vbe_version) { in vdev_read_bootenv()
1819 if (*be->vbe_bootenv == '\0') { in vdev_read_bootenv()
1825 be->vbe_bootenv[sizeof (be->vbe_bootenv) - 1] = '\0'; in vdev_read_bootenv()
1826 nvlist_add_string(benv, GRUB_ENVMAP, be->vbe_bootenv); in vdev_read_bootenv()
1831 benv = nvlist_import(be->vbe_bootenv, sizeof(be->vbe_bootenv)); in vdev_read_bootenv()
1935 tmp = nvlist_import(label->vp_nvlist, in vdev_label_read_config()
1936 sizeof(label->vp_nvlist)); in vdev_label_read_config()
1960 vd->v_psize = asize; in vdev_label_read_config()
2072 * Cache and spare devices end up here - just ignore in vdev_probe()
2101 spa->spa_root_vdev->v_nchildren = vdev_children; in vdev_probe()
2103 if (pool_txg > spa->spa_txg) in vdev_probe()
2104 spa->spa_txg = pool_txg; in vdev_probe()
2107 * Get the vdev tree and create our in-core copy of it. in vdev_probe()
2119 if (vdev && vdev->v_phys_read) { in vdev_probe()
2135 vdev->v_phys_read = _read; in vdev_probe()
2136 vdev->v_phys_write = _write; in vdev_probe()
2137 vdev->v_priv = priv; in vdev_probe()
2138 vdev->v_psize = vtmp.v_psize; in vdev_probe()
2142 if (vdev->v_state == VDEV_STATE_UNKNOWN) in vdev_probe()
2143 vdev->v_state = VDEV_STATE_HEALTHY; in vdev_probe()
2149 if (vdev->v_islog) in vdev_probe()
2150 spa->spa_with_log = vdev->v_islog; in vdev_probe()
2153 * Re-evaluate top-level vdev state. in vdev_probe()
2155 vdev_set_state(vdev->v_top); in vdev_probe()
2162 vdev_uberblock_load(vdev, spa->spa_uberblock); in vdev_probe()
2177 return (-1); in ilog2()
2251 printf("ZFS: i/o error - unable to decompress " in zio_read()
2259 const dva_t *dva = &bp->blk_dva[i]; in zio_read()
2265 if (!dva->dva_word[0] && !dva->dva_word[1]) in zio_read()
2270 vlist = &spa->spa_root_vdev->v_children; in zio_read()
2272 if (vdev->v_id == vdevid) in zio_read()
2275 if (!vdev || !vdev->v_read) in zio_read()
2279 if (vdev->v_read == vdev_raidz_read) { in zio_read()
2280 align = 1ULL << vdev->v_ashift; in zio_read()
2297 error = vdev->v_read(vdev, bp, pbuf, offset, size); in zio_read()
2313 printf("ZFS: i/o error - all block copies unavailable\n"); in zio_read()
2322 int ibshift = dnode->dn_indblkshift - SPA_BLKPTRSHIFT; in dnode_read()
2323 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in dnode_read()
2324 int nlevels = dnode->dn_nlevels; in dnode_read()
2328 printf("ZFS: I/O error - blocks larger than %llu are not " in dnode_read()
2338 if (dnode->dn_maxblkid == 0) { in dnode_read()
2341 newbuflen = offset > bsize ? 0 : MIN(buflen, bsize - offset); in dnode_read()
2342 bzero((char *)buf + newbuflen, buflen - newbuflen); in dnode_read()
2357 if (bn > dnode->dn_maxblkid) in dnode_read()
2363 indbp = dnode->dn_blkptr; in dnode_read()
2367 * we can re-use the scratch buffer for multi-level in dnode_read()
2370 ibn = bn >> ((nlevels - i - 1) * ibshift); in dnode_read()
2371 ibn &= ((1 << ibshift) - 1); in dnode_read()
2390 i = bsize - boff; in dnode_read()
2395 buflen -= i; in dnode_read()
2415 chunks = size / MZAP_ENT_LEN - 1; in mzap_lookup()
2417 mze = &mz->mz_chunk[i]; in mzap_lookup()
2418 if (strcmp(mze->mze_name, name) == 0) { in mzap_lookup()
2419 *value = mze->mze_value; in mzap_lookup()
2428 * Compare a name with a zap leaf entry. Return non-zero if the name
2437 const char *p; in fzap_name_equal() local
2439 namelen = zc->l_entry.le_name_numints; in fzap_name_equal()
2441 nc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_name_chunk); in fzap_name_equal()
2442 p = name; in fzap_name_equal()
2449 if (memcmp(p, nc->l_array.la_array, len)) in fzap_name_equal()
2451 p += len; in fzap_name_equal()
2452 namelen -= len; in fzap_name_equal()
2453 nc = &ZAP_LEAF_CHUNK(zl, nc->l_array.la_next); in fzap_name_equal()
2468 const uint8_t *p; in fzap_leaf_value() local
2470 vc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_value_chunk); in fzap_leaf_value()
2471 for (i = 0, value = 0, p = vc->l_array.la_array; i < 8; i++) { in fzap_leaf_value()
2472 value = (value << 8) | p[i]; in fzap_leaf_value()
2504 uint64_t array_int_len = zc->l_entry.le_value_intlen; in fzap_leaf_array()
2507 char *p = buf; in fzap_leaf_array() local
2508 int len = MIN(zc->l_entry.le_value_numints, num_integers); in fzap_leaf_array()
2509 int chunk = zc->l_entry.le_value_chunk; in fzap_leaf_array()
2523 value = (value << 8) | la->la_array[i]; in fzap_leaf_array()
2526 stv(integer_size, p, value); in fzap_leaf_array()
2528 len--; in fzap_leaf_array()
2531 p += integer_size; in fzap_leaf_array()
2534 chunk = la->la_next; in fzap_leaf_array()
2561 free(leaf->l_phys); in zap_leaf_free()
2575 (*lp)->l_bs = bs; in zap_get_leaf_byblk()
2576 (*lp)->l_phys = malloc(1 << bs); in zap_get_leaf_byblk()
2578 if ((*lp)->l_phys == NULL) { in zap_get_leaf_byblk()
2582 err = dnode_read(zap->zap_spa, zap->zap_dnode, blk << bs, (*lp)->l_phys, in zap_get_leaf_byblk()
2595 uint64_t blk = idx >> (bs - 3); in zap_table_load()
2596 uint64_t off = idx & ((1 << (bs - 3)) - 1); in zap_table_load()
2600 buf = malloc(1 << zap->zap_block_shift); in zap_table_load()
2603 rc = dnode_read(zap->zap_spa, zap->zap_dnode, (tbl->zt_blk + blk) << bs, in zap_table_load()
2604 buf, 1 << zap->zap_block_shift); in zap_table_load()
2614 if (zap->zap_phys->zap_ptrtbl.zt_numblks == 0) { in zap_idx_to_blk()
2618 return (zap_table_load(zap, &zap->zap_phys->zap_ptrtbl, in zap_idx_to_blk()
2623 #define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n))))
2630 idx = ZAP_HASH_IDX(h, zap->zap_phys->zap_ptrtbl.zt_shift); in zap_deref_leaf()
2639 ((ZAP_LEAF_HASH_NUMENTRIES(l)-1) & \
2641 (64 - ZAP_LEAF_HASH_SHIFT(l) - (l)->l_phys->l_hdr.lh_prefix_len)))
2642 #define LEAF_HASH_ENTPTR(l, h) (&(l)->l_phys->l_hash[LEAF_HASH(l, h)])
2655 if (zl->l_phys->l_hdr.lh_prefix_len > 0 && in zap_leaf_lookup()
2656 zl->l_phys->l_hdr.lh_prefix != in zap_leaf_lookup()
2657 hash >> (64 - zl->l_phys->l_hdr.lh_prefix_len)) in zap_leaf_lookup()
2662 *chunkp != CHAIN_END; chunkp = &le->le_next) { in zap_leaf_lookup()
2667 if (le->le_hash != hash) in zap_leaf_lookup()
2671 if (zc->l_entry.le_value_intlen > integer_size) { in zap_leaf_lookup()
2692 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in fzap_lookup()
2698 if (zh->zap_magic != ZAP_MAGIC) in fzap_lookup()
2710 hash = zap_hash(zh->zap_salt, name); in fzap_lookup()
2730 size_t size = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in zap_lookup()
2740 switch (zap->zap_block_type) { in zap_lookup()
2750 zap->zap_block_type); in zap_lookup()
2773 chunks = size / MZAP_ENT_LEN - 1; in mzap_list()
2775 mze = &mz->mz_chunk[i]; in mzap_list()
2776 if (mze->mze_name[0]) { in mzap_list()
2777 rc = callback(mze->mze_name, mze->mze_value); in mzap_list()
2793 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in fzap_list()
2798 if (zh->zap_magic != ZAP_MAGIC) in fzap_list()
2814 for (i = 0; i < zh->zap_num_leafs; i++) { in fzap_list()
2816 char name[256], *p; in fzap_list() local
2829 if (zc->l_entry.le_type != ZAP_CHUNK_ENTRY) in fzap_list()
2831 namelen = zc->l_entry.le_name_numints; in fzap_list()
2838 nc = &ZAP_LEAF_CHUNK(&zl, zc->l_entry.le_name_chunk); in fzap_list()
2839 p = name; in fzap_list()
2845 memcpy(p, nc->l_array.la_array, len); in fzap_list()
2846 p += len; in fzap_list()
2847 namelen -= len; in fzap_list()
2848 nc = &ZAP_LEAF_CHUNK(&zl, nc->l_array.la_next); in fzap_list()
2885 size_t size = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in zap_list()
2894 if (zap->zap_block_type == ZBT_MICRO) in zap_list()
2911 return dnode_read(spa, &os->os_meta_dnode, offset, in objset_get_dnode()
2928 chunks = size / MZAP_ENT_LEN - 1; in mzap_rlookup()
2930 mze = &mz->mz_chunk[i]; in mzap_rlookup()
2931 if (value == mze->mze_value) { in mzap_rlookup()
2932 strcpy(name, mze->mze_name); in mzap_rlookup()
2945 char *p; in fzap_name_copy() local
2947 namelen = zc->l_entry.le_name_numints; in fzap_name_copy()
2949 nc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_name_chunk); in fzap_name_copy()
2950 p = name; in fzap_name_copy()
2956 memcpy(p, nc->l_array.la_array, len); in fzap_name_copy()
2957 p += len; in fzap_name_copy()
2958 namelen -= len; in fzap_name_copy()
2959 nc = &ZAP_LEAF_CHUNK(zl, nc->l_array.la_next); in fzap_name_copy()
2962 *p = '\0'; in fzap_name_copy()
2969 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in fzap_rlookup()
2974 if (zh->zap_magic != ZAP_MAGIC) in fzap_rlookup()
2990 for (i = 0; i < zh->zap_num_leafs; i++) { in fzap_rlookup()
3001 if (zc->l_entry.le_type != ZAP_CHUNK_ENTRY) in fzap_rlookup()
3003 if (zc->l_entry.le_value_intlen != 8 || in fzap_rlookup()
3004 zc->l_entry.le_value_numints != 1) in fzap_rlookup()
3025 size_t size = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT; in zap_rlookup()
3034 if (zap->zap_block_type == ZBT_MICRO) in zap_rlookup()
3053 char *p; in zfs_rlookup() local
3057 p = &name[sizeof(name) - 1]; in zfs_rlookup()
3058 *p = '\0'; in zfs_rlookup()
3060 if (objset_get_dnode(spa, spa->spa_mos, objnum, &dataset)) { in zfs_rlookup()
3065 dir_obj = ds->ds_dir_obj; in zfs_rlookup()
3066 if (ds->ds_snapnames_zapobj == 0) in zfs_rlookup()
3070 if (objset_get_dnode(spa, spa->spa_mos, dir_obj, &dir) != 0) in zfs_rlookup()
3075 parent_obj = dd->dd_parent_obj; in zfs_rlookup()
3079 if (objset_get_dnode(spa, spa->spa_mos, parent_obj, in zfs_rlookup()
3091 if (objset_get_dnode(spa, spa->spa_mos, in zfs_rlookup()
3092 dd->dd_head_dataset_obj, &dataset)) in zfs_rlookup()
3095 if (objset_get_dnode(spa, spa->spa_mos, in zfs_rlookup()
3096 ds->ds_snapnames_zapobj, &snapnames_zap) != 0) in zfs_rlookup()
3103 p -= len; in zfs_rlookup()
3104 memcpy(p, component, len); in zfs_rlookup()
3105 --p; in zfs_rlookup()
3106 *p = '@'; in zfs_rlookup()
3111 child_dir_zapobj = dd->dd_child_dir_zapobj; in zfs_rlookup()
3112 if (objset_get_dnode(spa, spa->spa_mos, child_dir_zapobj, in zfs_rlookup()
3119 p -= len; in zfs_rlookup()
3120 memcpy(p, component, len); in zfs_rlookup()
3121 --p; in zfs_rlookup()
3122 *p = '/'; in zfs_rlookup()
3128 if (*p != '\0') in zfs_rlookup()
3129 ++p; in zfs_rlookup()
3130 strcpy(result, p); in zfs_rlookup()
3143 const char *p, *q; in zfs_lookup_dataset() local
3146 if (objset_get_dnode(spa, spa->spa_mos, in zfs_lookup_dataset()
3153 p = name; in zfs_lookup_dataset()
3155 if (objset_get_dnode(spa, spa->spa_mos, dir_obj, &dir)) in zfs_lookup_dataset()
3159 while (*p == '/') in zfs_lookup_dataset()
3160 p++; in zfs_lookup_dataset()
3162 if (*p == '\0') in zfs_lookup_dataset()
3165 q = strchr(p, '/'); in zfs_lookup_dataset()
3167 memcpy(element, p, q - p); in zfs_lookup_dataset()
3168 element[q - p] = '\0'; in zfs_lookup_dataset()
3169 p = q + 1; in zfs_lookup_dataset()
3171 strcpy(element, p); in zfs_lookup_dataset()
3172 p += strlen(p); in zfs_lookup_dataset()
3176 if (objset_get_dnode(spa, spa->spa_mos, in zfs_lookup_dataset()
3177 dd->dd_head_dataset_obj, &dataset)) in zfs_lookup_dataset()
3180 if (objset_get_dnode(spa, spa->spa_mos, in zfs_lookup_dataset()
3181 ds->ds_snapnames_zapobj, &snapnames_zap) != 0) in zfs_lookup_dataset()
3191 element[q - element] = '\0'; in zfs_lookup_dataset()
3192 p = q + 1; in zfs_lookup_dataset()
3194 child_dir_zapobj = dd->dd_child_dir_zapobj; in zfs_lookup_dataset()
3195 if (objset_get_dnode(spa, spa->spa_mos, child_dir_zapobj, in zfs_lookup_dataset()
3205 *objnum = dd->dd_head_dataset_obj; in zfs_lookup_dataset()
3218 if (objset_get_dnode(spa, spa->spa_mos, objnum, &dataset)) { in zfs_list_dataset()
3223 dir_obj = ds->ds_dir_obj; in zfs_list_dataset()
3225 if (objset_get_dnode(spa, spa->spa_mos, dir_obj, &dir)) { in zfs_list_dataset()
3231 child_dir_zapobj = dd->dd_child_dir_zapobj; in zfs_list_dataset()
3232 if (objset_get_dnode(spa, spa->spa_mos, child_dir_zapobj, in zfs_list_dataset()
3253 err = objset_get_dnode(spa, spa->spa_mos, objnum, &dataset); in zfs_callback_dataset()
3259 dir_obj = ds->ds_dir_obj; in zfs_callback_dataset()
3261 err = objset_get_dnode(spa, spa->spa_mos, dir_obj, &dir); in zfs_callback_dataset()
3268 child_dir_zapobj = dd->dd_child_dir_zapobj; in zfs_callback_dataset()
3269 err = objset_get_dnode(spa, spa->spa_mos, child_dir_zapobj, in zfs_callback_dataset()
3283 if (zap->zap_block_type == ZBT_MICRO) in zfs_callback_dataset()
3307 if (objset_get_dnode(spa, spa->spa_mos, objnum, &dataset)) { in zfs_mount_dataset()
3313 if (zio_read(spa, &ds->ds_bp, objset)) { in zfs_mount_dataset()
3335 * Start with the MOS directory object. in zfs_get_root()
3337 if (objset_get_dnode(spa, spa->spa_mos, in zfs_get_root()
3339 printf("ZFS: can't read MOS object directory\n"); in zfs_get_root()
3348 objset_get_dnode(spa, spa->spa_mos, props, &propdir) == 0 && in zfs_get_root()
3359 objset_get_dnode(spa, spa->spa_mos, root, &dir)) { in zfs_get_root()
3369 *objid = dd->dd_head_dataset_obj; in zfs_get_root()
3377 mount->spa = spa; in zfs_mount_impl()
3387 if (zfs_mount_dataset(spa, rootobj, &mount->objset)) { in zfs_mount_impl()
3392 mount->rootobj = rootobj; in zfs_mount_impl()
3419 * Checks whether the MOS features that are active are supported.
3430 if ((rc = objset_get_dnode(spa, spa->spa_mos, DMU_OT_OBJECT_DIRECTORY, in check_mos_features()
3442 if ((rc = objset_get_dnode(spa, spa->spa_mos, objnum, &dir)) != 0) in check_mos_features()
3458 if (zap->zap_block_type == ZBT_MICRO) in check_mos_features()
3476 if ((rc = objset_get_dnode(spa, spa->spa_mos, obj, &dir)) != 0) in load_nvlist()
3511 if (zio_read(spa, &spa->spa_uberblock->ub_rootbp, spa->spa_mos)) { in zfs_spa_init()
3512 printf("ZFS: can't read MOS of pool %s\n", spa->spa_name); in zfs_spa_init()
3515 if (spa->spa_mos->os_type != DMU_OST_META) { in zfs_spa_init()
3516 printf("ZFS: corrupted MOS of pool %s\n", spa->spa_name); in zfs_spa_init()
3520 if (objset_get_dnode(spa, &spa->spa_mos_master, in zfs_spa_init()
3523 spa->spa_name); in zfs_spa_init()
3528 sizeof (spa->spa_cksum_salt.zcs_bytes), in zfs_spa_init()
3529 spa->spa_cksum_salt.zcs_bytes); in zfs_spa_init()
3533 printf("ZFS: pool %s is not supported\n", spa->spa_name); in zfs_spa_init()
3540 printf("ZFS: can not read MOS %s\n", DMU_POOL_CONFIG); in zfs_spa_init()
3551 memcpy(&spa->spa_uberblock_checkpoint, &checkpoint, in zfs_spa_init()
3553 if (zio_read(spa, &spa->spa_uberblock_checkpoint.ub_rootbp, in zfs_spa_init()
3554 &spa->spa_mos_checkpoint)) { in zfs_spa_init()
3561 * Update vdevs from MOS config. Note, we do skip encoding bytes in zfs_spa_init()
3573 if (dn->dn_bonustype != DMU_OT_SA) { in zfs_dnode_stat()
3574 znode_phys_t *zp = (znode_phys_t *)dn->dn_bonus; in zfs_dnode_stat()
3576 sb->st_mode = zp->zp_mode; in zfs_dnode_stat()
3577 sb->st_uid = zp->zp_uid; in zfs_dnode_stat()
3578 sb->st_gid = zp->zp_gid; in zfs_dnode_stat()
3579 sb->st_size = zp->zp_size; in zfs_dnode_stat()
3586 if (dn->dn_bonuslen != 0) in zfs_dnode_stat()
3589 if ((dn->dn_flags & DNODE_FLAG_SPILL_BLKPTR) != 0) { in zfs_dnode_stat()
3610 sb->st_mode = *(uint64_t *)((char *)sahdrp + hdrsize + in zfs_dnode_stat()
3612 sb->st_uid = *(uint64_t *)((char *)sahdrp + hdrsize + in zfs_dnode_stat()
3614 sb->st_gid = *(uint64_t *)((char *)sahdrp + hdrsize + in zfs_dnode_stat()
3616 sb->st_size = *(uint64_t *)((char *)sahdrp + hdrsize + in zfs_dnode_stat()
3629 if (dn->dn_bonustype == DMU_OT_SA) { in zfs_dnode_readlink()
3634 char *p; in zfs_dnode_readlink() local
3636 if (dn->dn_bonuslen != 0) { in zfs_dnode_readlink()
3641 if ((dn->dn_flags & DNODE_FLAG_SPILL_BLKPTR) == 0) in zfs_dnode_readlink()
3658 p = (char *)((uintptr_t)sahdrp + hdrsize + SA_SYMLINK_OFFSET); in zfs_dnode_readlink()
3659 memcpy(path, p, psize); in zfs_dnode_readlink()
3667 if (psize + sizeof(znode_phys_t) <= dn->dn_bonuslen && in zfs_dnode_readlink()
3668 sizeof(znode_phys_t) <= sizeof(dn->dn_bonus)) { in zfs_dnode_readlink()
3669 memcpy(path, &dn->dn_bonus[sizeof(znode_phys_t)], psize); in zfs_dnode_readlink()
3691 const char *p, *q; in zfs_lookup() local
3699 spa = mount->spa; in zfs_lookup()
3700 if (mount->objset.os_type != DMU_OST_ZFS) { in zfs_lookup()
3702 (uintmax_t)mount->objset.os_type); in zfs_lookup()
3712 rc = objset_get_dnode(spa, &mount->objset, MASTER_NODE_OBJ, &dn); in zfs_lookup()
3723 entry->objnum = objnum; in zfs_lookup()
3726 rc = objset_get_dnode(spa, &mount->objset, objnum, &dn); in zfs_lookup()
3730 p = upath; in zfs_lookup()
3731 while (p && *p) { in zfs_lookup()
3732 rc = objset_get_dnode(spa, &mount->objset, objnum, &dn); in zfs_lookup()
3736 while (*p == '/') in zfs_lookup()
3737 p++; in zfs_lookup()
3738 if (*p == '\0') in zfs_lookup()
3740 q = p; in zfs_lookup()
3745 if (p + 1 == q && p[0] == '.') { in zfs_lookup()
3746 p++; in zfs_lookup()
3750 if (p + 2 == q && p[0] == '.' && p[1] == '.') { in zfs_lookup()
3751 p += 2; in zfs_lookup()
3760 objnum = (STAILQ_FIRST(&on_cache))->objnum; in zfs_lookup()
3763 if (q - p + 1 > sizeof(element)) { in zfs_lookup()
3767 memcpy(element, p, q - p); in zfs_lookup()
3768 element[q - p] = 0; in zfs_lookup()
3769 p = q; in zfs_lookup()
3787 entry->objnum = objnum; in zfs_lookup()
3789 rc = objset_get_dnode(spa, &mount->objset, objnum, &dn); in zfs_lookup()
3810 if (sb.st_size + strlen(p) + 1 > sizeof(path)) { in zfs_lookup()
3814 strcpy(&path[sb.st_size], p); in zfs_lookup()
3825 p = path; in zfs_lookup()
3826 if (*p == '/') { in zfs_lookup()
3838 objnum = (STAILQ_FIRST(&on_cache))->objnum; in zfs_lookup()
3860 if (spa->spa_bootenv == NULL) { in zfs_get_bootenv_spa()
3861 STAILQ_FOREACH(vd, &spa->spa_root_vdev->v_children, in zfs_get_bootenv_spa()
3868 spa->spa_bootenv = benv; in zfs_get_bootenv_spa()
3870 benv = spa->spa_bootenv; in zfs_get_bootenv_spa()
3887 STAILQ_FOREACH(vd, &spa->spa_root_vdev->v_children, v_childlink) { in zfs_set_bootenv_spa()
3891 spa->spa_bootenv = benv; in zfs_set_bootenv_spa()