40 #include <sys/sa_impl.h>
41 #include <sys/vdev.h>
42 #include <sys/vdev_impl.h>
43 #include <sys/metaslab_impl.h>
44 #include <sys/dmu_objset.h>
45 #include <sys/dsl_dir.h>
46 #include <sys/dsl_dataset.h>
47 #include <sys/dsl_pool.h>
48 #include <sys/dbuf.h>
49 #include <sys/zil.h>
50 #include <sys/zil_impl.h>
51 #include <sys/stat.h>
52 #include <sys/resource.h>
53 #include <sys/dmu_traverse.h>
54 #include <sys/zio_checksum.h>
55 #include <sys/zio_compress.h>
56 #include <sys/zfs_fuid.h>
57 #include <sys/arc.h>
58 #include <sys/ddt.h>
59 #include <sys/zfeature.h>
60 #undef ZFS_MAXNAMELEN
61 #undef verify
62 #include <libzfs.h>
63
64 #define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
65 zio_compress_table[(idx)].ci_name : "UNKNOWN")
66 #define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
67 zio_checksum_table[(idx)].ci_name : "UNKNOWN")
68 #define ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
69 dmu_ot[(idx)].ot_name : DMU_OT_IS_VALID(idx) ? \
70 dmu_ot_byteswap[DMU_OT_BYTESWAP(idx)].ob_name : "UNKNOWN")
71 #define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES)
72
73 #ifndef lint
74 extern int zfs_recover;
75 #else
76 int zfs_recover;
77 #endif
78
79 const char cmdname[] = "zdb";
187
188 /* ARGSUSED */
189 static void
190 dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
191 {
192 nvlist_t *nv;
193 size_t nvsize = *(uint64_t *)data;
194 char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
195
196 VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
197
198 VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
199
200 umem_free(packed, nvsize);
201
202 dump_nvlist(nv, 8);
203
204 nvlist_free(nv);
205 }
206
207 static void
208 zdb_nicenum(uint64_t num, char *buf)
209 {
210 if (dump_opt['P'])
211 (void) sprintf(buf, "%llu", (longlong_t)num);
212 else
213 nicenum(num, buf);
214 }
215
216 const char dump_zap_stars[] = "****************************************";
217 const int dump_zap_width = sizeof (dump_zap_stars) - 1;
218
219 static void
220 dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
221 {
222 int i;
223 int minidx = ZAP_HISTOGRAM_SIZE - 1;
224 int maxidx = 0;
225 uint64_t max = 0;
226
836
837 do {
838 len = sizeof (buf);
839
840 if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
841 (void) fprintf(stderr, "Unable to read history: "
842 "error %d\n", error);
843 return;
844 }
845
846 if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
847 break;
848
849 off -= resid;
850 } while (len != 0);
851
852 (void) printf("\nHistory:\n");
853 for (int i = 0; i < num; i++) {
854 uint64_t time, txg, ievent;
855 char *cmd, *intstr;
856
857 if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
858 &time) != 0)
859 continue;
860 if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
861 &cmd) != 0) {
862 if (nvlist_lookup_uint64(events[i],
863 ZPOOL_HIST_INT_EVENT, &ievent) != 0)
864 continue;
865 verify(nvlist_lookup_uint64(events[i],
866 ZPOOL_HIST_TXG, &txg) == 0);
867 verify(nvlist_lookup_string(events[i],
868 ZPOOL_HIST_INT_STR, &intstr) == 0);
869 if (ievent >= LOG_END)
870 continue;
871
872 (void) snprintf(internalstr,
873 sizeof (internalstr),
874 "[internal %s txg:%lld] %s",
875 zfs_history_event_names[ievent], txg,
876 intstr);
877 cmd = internalstr;
878 }
879 tsec = time;
880 (void) localtime_r(&tsec, &t);
881 (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
882 (void) printf("%s %s\n", tbuf, cmd);
883 }
884 }
885
886 /*ARGSUSED*/
887 static void
888 dump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
889 {
890 }
891
892 static uint64_t
893 blkid2offset(const dnode_phys_t *dnp, const blkptr_t *bp, const zbookmark_t *zb)
894 {
895 if (dnp == NULL) {
896 ASSERT(zb->zb_level < 0);
897 if (zb->zb_object == 0)
898 return (zb->zb_blkid);
899 return (zb->zb_blkid * BP_GET_LSIZE(bp));
900 }
901
902 ASSERT(zb->zb_level >= 0);
1439 dump_dnode, /* DMU dnode */
1440 dump_dmu_objset, /* DMU objset */
1441 dump_dsl_dir, /* DSL directory */
1442 dump_zap, /* DSL directory child map */
1443 dump_zap, /* DSL dataset snap map */
1444 dump_zap, /* DSL props */
1445 dump_dsl_dataset, /* DSL dataset */
1446 dump_znode, /* ZFS znode */
1447 dump_acl, /* ZFS V0 ACL */
1448 dump_uint8, /* ZFS plain file */
1449 dump_zpldir, /* ZFS directory */
1450 dump_zap, /* ZFS master node */
1451 dump_zap, /* ZFS delete queue */
1452 dump_uint8, /* zvol object */
1453 dump_zap, /* zvol prop */
1454 dump_uint8, /* other uint8[] */
1455 dump_uint64, /* other uint64[] */
1456 dump_zap, /* other ZAP */
1457 dump_zap, /* persistent error log */
1458 dump_uint8, /* SPA history */
1459 dump_uint64, /* SPA history offsets */
1460 dump_zap, /* Pool properties */
1461 dump_zap, /* DSL permissions */
1462 dump_acl, /* ZFS ACL */
1463 dump_uint8, /* ZFS SYSACL */
1464 dump_none, /* FUID nvlist */
1465 dump_packed_nvlist, /* FUID nvlist size */
1466 dump_zap, /* DSL dataset next clones */
1467 dump_zap, /* DSL scrub queue */
1468 dump_zap, /* ZFS user/group used */
1469 dump_zap, /* ZFS user/group quota */
1470 dump_zap, /* snapshot refcount tags */
1471 dump_ddt_zap, /* DDT ZAP object */
1472 dump_zap, /* DDT statistics */
1473 dump_znode, /* SA object */
1474 dump_zap, /* SA Master Node */
1475 dump_sa_attrs, /* SA attribute registration */
1476 dump_sa_layouts, /* SA attribute layouts */
1477 dump_zap, /* DSL scrub translations */
1478 dump_none, /* fake dedup BP */
1479 dump_zap, /* deadlist */
|
40 #include <sys/sa_impl.h>
41 #include <sys/vdev.h>
42 #include <sys/vdev_impl.h>
43 #include <sys/metaslab_impl.h>
44 #include <sys/dmu_objset.h>
45 #include <sys/dsl_dir.h>
46 #include <sys/dsl_dataset.h>
47 #include <sys/dsl_pool.h>
48 #include <sys/dbuf.h>
49 #include <sys/zil.h>
50 #include <sys/zil_impl.h>
51 #include <sys/stat.h>
52 #include <sys/resource.h>
53 #include <sys/dmu_traverse.h>
54 #include <sys/zio_checksum.h>
55 #include <sys/zio_compress.h>
56 #include <sys/zfs_fuid.h>
57 #include <sys/arc.h>
58 #include <sys/ddt.h>
59 #include <sys/zfeature.h>
60 #include <zfs_comutil.h>
61 #undef ZFS_MAXNAMELEN
62 #undef verify
63 #include <libzfs.h>
64
65 #define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
66 zio_compress_table[(idx)].ci_name : "UNKNOWN")
67 #define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
68 zio_checksum_table[(idx)].ci_name : "UNKNOWN")
69 #define ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
70 dmu_ot[(idx)].ot_name : DMU_OT_IS_VALID(idx) ? \
71 dmu_ot_byteswap[DMU_OT_BYTESWAP(idx)].ob_name : "UNKNOWN")
72 #define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES)
73
74 #ifndef lint
75 extern int zfs_recover;
76 #else
77 int zfs_recover;
78 #endif
79
80 const char cmdname[] = "zdb";
188
189 /* ARGSUSED */
190 static void
191 dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
192 {
193 nvlist_t *nv;
194 size_t nvsize = *(uint64_t *)data;
195 char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
196
197 VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
198
199 VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
200
201 umem_free(packed, nvsize);
202
203 dump_nvlist(nv, 8);
204
205 nvlist_free(nv);
206 }
207
208 /* ARGSUSED */
209 static void
210 dump_history_offsets(objset_t *os, uint64_t object, void *data, size_t size)
211 {
212 spa_history_phys_t *shp = data;
213
214 if (shp == NULL)
215 return;
216
217 (void) printf("\t\tpool_create_len = %llu\n",
218 (u_longlong_t)shp->sh_pool_create_len);
219 (void) printf("\t\tphys_max_off = %llu\n",
220 (u_longlong_t)shp->sh_phys_max_off);
221 (void) printf("\t\tbof = %llu\n",
222 (u_longlong_t)shp->sh_bof);
223 (void) printf("\t\teof = %llu\n",
224 (u_longlong_t)shp->sh_eof);
225 (void) printf("\t\trecords_lost = %llu\n",
226 (u_longlong_t)shp->sh_records_lost);
227 }
228
229 static void
230 zdb_nicenum(uint64_t num, char *buf)
231 {
232 if (dump_opt['P'])
233 (void) sprintf(buf, "%llu", (longlong_t)num);
234 else
235 nicenum(num, buf);
236 }
237
238 const char dump_zap_stars[] = "****************************************";
239 const int dump_zap_width = sizeof (dump_zap_stars) - 1;
240
241 static void
242 dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
243 {
244 int i;
245 int minidx = ZAP_HISTOGRAM_SIZE - 1;
246 int maxidx = 0;
247 uint64_t max = 0;
248
858
859 do {
860 len = sizeof (buf);
861
862 if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
863 (void) fprintf(stderr, "Unable to read history: "
864 "error %d\n", error);
865 return;
866 }
867
868 if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
869 break;
870
871 off -= resid;
872 } while (len != 0);
873
874 (void) printf("\nHistory:\n");
875 for (int i = 0; i < num; i++) {
876 uint64_t time, txg, ievent;
877 char *cmd, *intstr;
878 boolean_t printed = B_FALSE;
879
880 if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
881 &time) != 0)
882 goto next;
883 if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
884 &cmd) != 0) {
885 if (nvlist_lookup_uint64(events[i],
886 ZPOOL_HIST_INT_EVENT, &ievent) != 0)
887 goto next;
888 verify(nvlist_lookup_uint64(events[i],
889 ZPOOL_HIST_TXG, &txg) == 0);
890 verify(nvlist_lookup_string(events[i],
891 ZPOOL_HIST_INT_STR, &intstr) == 0);
892 if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS)
893 goto next;
894
895 (void) snprintf(internalstr,
896 sizeof (internalstr),
897 "[internal %s txg:%lld] %s",
898 zfs_history_event_names[ievent], txg,
899 intstr);
900 cmd = internalstr;
901 }
902 tsec = time;
903 (void) localtime_r(&tsec, &t);
904 (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
905 (void) printf("%s %s\n", tbuf, cmd);
906 printed = B_TRUE;
907
908 next:
909 if (dump_opt['h'] > 1) {
910 if (!printed)
911 (void) printf("unrecognized record:\n");
912 dump_nvlist(events[i], 2);
913 }
914 }
915 }
916
917 /*ARGSUSED*/
918 static void
919 dump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
920 {
921 }
922
923 static uint64_t
924 blkid2offset(const dnode_phys_t *dnp, const blkptr_t *bp, const zbookmark_t *zb)
925 {
926 if (dnp == NULL) {
927 ASSERT(zb->zb_level < 0);
928 if (zb->zb_object == 0)
929 return (zb->zb_blkid);
930 return (zb->zb_blkid * BP_GET_LSIZE(bp));
931 }
932
933 ASSERT(zb->zb_level >= 0);
1470 dump_dnode, /* DMU dnode */
1471 dump_dmu_objset, /* DMU objset */
1472 dump_dsl_dir, /* DSL directory */
1473 dump_zap, /* DSL directory child map */
1474 dump_zap, /* DSL dataset snap map */
1475 dump_zap, /* DSL props */
1476 dump_dsl_dataset, /* DSL dataset */
1477 dump_znode, /* ZFS znode */
1478 dump_acl, /* ZFS V0 ACL */
1479 dump_uint8, /* ZFS plain file */
1480 dump_zpldir, /* ZFS directory */
1481 dump_zap, /* ZFS master node */
1482 dump_zap, /* ZFS delete queue */
1483 dump_uint8, /* zvol object */
1484 dump_zap, /* zvol prop */
1485 dump_uint8, /* other uint8[] */
1486 dump_uint64, /* other uint64[] */
1487 dump_zap, /* other ZAP */
1488 dump_zap, /* persistent error log */
1489 dump_uint8, /* SPA history */
1490 dump_history_offsets, /* SPA history offsets */
1491 dump_zap, /* Pool properties */
1492 dump_zap, /* DSL permissions */
1493 dump_acl, /* ZFS ACL */
1494 dump_uint8, /* ZFS SYSACL */
1495 dump_none, /* FUID nvlist */
1496 dump_packed_nvlist, /* FUID nvlist size */
1497 dump_zap, /* DSL dataset next clones */
1498 dump_zap, /* DSL scrub queue */
1499 dump_zap, /* ZFS user/group used */
1500 dump_zap, /* ZFS user/group quota */
1501 dump_zap, /* snapshot refcount tags */
1502 dump_ddt_zap, /* DDT ZAP object */
1503 dump_zap, /* DDT statistics */
1504 dump_znode, /* SA object */
1505 dump_zap, /* SA Master Node */
1506 dump_sa_attrs, /* SA attribute registration */
1507 dump_sa_layouts, /* SA attribute layouts */
1508 dump_zap, /* DSL scrub translations */
1509 dump_none, /* fake dedup BP */
1510 dump_zap, /* deadlist */
|