text stringlengths 0 14.1k |
|---|
* Retrieve the persistent error log, uniquify the members, and return to the |
* caller. |
*/ |
int |
zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp) |
{ |
zfs_cmd_t zc = { 0 }; |
uint64_t count; |
zbookmark_t *zb = NULL; |
int i; |
/* |
* Retrieve the raw error list from the kernel. If the number of errors |
* has increased, allocate more space and continue until we get the |
* entire list. |
*/ |
verify(nvlist_lookup_uint64(zhp->zpool_config, ZPOOL_CONFIG_ERRCOUNT, |
&count) == 0); |
if (count == 0) |
return (0); |
if ((zc.zc_nvlist_dst = (uintptr_t)zfs_alloc(zhp->zpool_hdl, |
count * sizeof (zbookmark_t))) == (uintptr_t)NULL) |
return (-1); |
zc.zc_nvlist_dst_size = count; |
(void) strcpy(zc.zc_name, zhp->zpool_name); |
for (;;) { |
if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_ERROR_LOG, |
&zc) != 0) { |
free((void *)(uintptr_t)zc.zc_nvlist_dst); |
if (errno == ENOMEM) { |
count = zc.zc_nvlist_dst_size; |
if ((zc.zc_nvlist_dst = (uintptr_t) |
zfs_alloc(zhp->zpool_hdl, count * |
sizeof (zbookmark_t))) == (uintptr_t)NULL) |
return (-1); |
} else { |
return (-1); |
} |
} else { |
break; |
} |
} |
/* |
* Sort the resulting bookmarks. This is a little confusing due to the |
* implementation of ZFS_IOC_ERROR_LOG. The bookmarks are copied last |
* to first, and 'zc_nvlist_dst_size' indicates the number of boomarks |
* _not_ copied as part of the process. So we point the start of our |
* array appropriate and decrement the total number of elements. |
*/ |
zb = ((zbookmark_t *)(uintptr_t)zc.zc_nvlist_dst) + |
zc.zc_nvlist_dst_size; |
count -= zc.zc_nvlist_dst_size; |
void *nvlist_dst = (void *)(uintptr_t) zc.zc_nvlist_dst; |
qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare); |
verify(nvlist_alloc(nverrlistp, 0, KM_SLEEP) == 0); |
/* |
* Fill in the nverrlistp with nvlist's of dataset and object numbers. |
*/ |
for (i = 0; i < count; i++) { |
nvlist_t *nv; |
/* ignoring zb_blkid and zb_level for now */ |
if (i > 0 && zb[i-1].zb_objset == zb[i].zb_objset && |
zb[i-1].zb_object == zb[i].zb_object) |
continue; |
if (nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) != 0) |
goto nomem; |
if (nvlist_add_uint64(nv, ZPOOL_ERR_DATASET, |
zb[i].zb_objset) != 0) { |
nvlist_free(nv); |
goto nomem; |
} |
if (nvlist_add_uint64(nv, ZPOOL_ERR_OBJECT, |
zb[i].zb_object) != 0) { |
nvlist_free(nv); |
goto nomem; |
} |
if (nvlist_add_nvlist(*nverrlistp, ""ejk"", nv) != 0) { |
nvlist_free(nv); |
goto nomem; |
} |
nvlist_free(nv); |
} |
free(nvlist_dst); |
return (0); |
nomem: |
free(nvlist_dst); |
free((void *)(uintptr_t)zc.zc_nvlist_dst); |
return (no_memory(zhp->zpool_hdl)); |
} |
/* |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.