summaryrefslogtreecommitdiff
path: root/usr/src/lib/libzfs
diff options
context:
space:
mode:
authorek110237 <none@none>2007-01-18 14:25:26 -0800
committerek110237 <none@none>2007-01-18 14:25:26 -0800
commit55434c770c89aa1b84474f2559a106803511aba0 (patch)
tree0b264887f9fd7111732d95873d02a27dc5c4e8c0 /usr/src/lib/libzfs
parentbf7c2d400a7b538aed6f356c7107284378a19fa8 (diff)
downloadillumos-joyent-55434c770c89aa1b84474f2559a106803511aba0.tar.gz
6410433 'zpool status -v' would be more useful with filenames
6504702 zdb -dddv <poolname> chokes on xattrs 6506506 spa_history.c: LE_64(reclen) needs to be cast to uint64_t in case of 32-bit big-endian kernel
Diffstat (limited to 'usr/src/lib/libzfs')
-rw-r--r--usr/src/lib/libzfs/common/libzfs.h7
-rw-r--r--usr/src/lib/libzfs/common/libzfs_impl.h4
-rw-r--r--usr/src/lib/libzfs/common/libzfs_mount.c16
-rw-r--r--usr/src/lib/libzfs/common/libzfs_pool.c177
-rw-r--r--usr/src/lib/libzfs/common/mapfile-vers3
5 files changed, 86 insertions, 121 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs.h b/usr/src/lib/libzfs/common/libzfs.h
index 220c280369..2dd7326918 100644
--- a/usr/src/lib/libzfs/common/libzfs.h
+++ b/usr/src/lib/libzfs/common/libzfs.h
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -203,7 +203,7 @@ extern zpool_status_t zpool_import_status(nvlist_t *, char **);
*/
extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
-extern int zpool_get_errlog(zpool_handle_t *, nvlist_t ***, size_t *);
+extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
/*
* Import and export functions
@@ -225,6 +225,8 @@ extern int zpool_upgrade(zpool_handle_t *);
extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
extern void zpool_log_history(libzfs_handle_t *, int, char **, const char *,
boolean_t, boolean_t);
+extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
+ size_t len);
/*
* Basic handle manipulations. These functions do not create or destroy the
@@ -321,6 +323,7 @@ extern int zfs_enable(zfs_handle_t *);
/*
* Mount support functions.
*/
+extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
extern int zfs_mount(zfs_handle_t *, const char *, int);
extern int zfs_unmount(zfs_handle_t *, const char *, int);
diff --git a/usr/src/lib/libzfs/common/libzfs_impl.h b/usr/src/lib/libzfs/common/libzfs_impl.h
index c3dc95c2fb..dfc5706e6a 100644
--- a/usr/src/lib/libzfs/common/libzfs_impl.h
+++ b/usr/src/lib/libzfs/common/libzfs_impl.h
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -82,8 +82,6 @@ struct zpool_handle {
size_t zpool_config_size;
nvlist_t *zpool_config;
nvlist_t *zpool_old_config;
- nvlist_t **zpool_error_log;
- size_t zpool_error_count;
};
int zfs_error(libzfs_handle_t *, int, const char *);
diff --git a/usr/src/lib/libzfs/common/libzfs_mount.c b/usr/src/lib/libzfs/common/libzfs_mount.c
index b0e1aa6439..39c5492125 100644
--- a/usr/src/lib/libzfs/common/libzfs_mount.c
+++ b/usr/src/lib/libzfs/common/libzfs_mount.c
@@ -162,7 +162,7 @@ dir_is_empty(const char *dirname)
* 0.
*/
boolean_t
-zfs_is_mounted(zfs_handle_t *zhp, char **where)
+is_mounted(libzfs_handle_t *zfs_hdl, const char *special, char **where)
{
struct mnttab search = { 0 }, entry;
@@ -171,19 +171,25 @@ zfs_is_mounted(zfs_handle_t *zhp, char **where)
* mountpoint, as we can just search for the special device. This will
* also let us find mounts when the mountpoint is 'legacy'.
*/
- search.mnt_special = (char *)zfs_get_name(zhp);
+ search.mnt_special = (char *)special;
search.mnt_fstype = MNTTYPE_ZFS;
- rewind(zhp->zfs_hdl->libzfs_mnttab);
- if (getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) != 0)
+ rewind(zfs_hdl->libzfs_mnttab);
+ if (getmntany(zfs_hdl->libzfs_mnttab, &entry, &search) != 0)
return (B_FALSE);
if (where != NULL)
- *where = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
+ *where = zfs_strdup(zfs_hdl, entry.mnt_mountp);
return (B_TRUE);
}
+boolean_t
+zfs_is_mounted(zfs_handle_t *zhp, char **where)
+{
+ return (is_mounted(zhp->zfs_hdl, zfs_get_name(zhp), where));
+}
+
/*
* Returns true if the given dataset is mountable, false otherwise. Returns the
* mountpoint in 'buf'.
diff --git a/usr/src/lib/libzfs/common/libzfs_pool.c b/usr/src/lib/libzfs/common/libzfs_pool.c
index 87e8105e98..8466cd7573 100644
--- a/usr/src/lib/libzfs/common/libzfs_pool.c
+++ b/usr/src/lib/libzfs/common/libzfs_pool.c
@@ -277,12 +277,6 @@ zpool_close(zpool_handle_t *zhp)
nvlist_free(zhp->zpool_config);
if (zhp->zpool_old_config)
nvlist_free(zhp->zpool_old_config);
- if (zhp->zpool_error_log) {
- int i;
- for (i = 0; i < zhp->zpool_error_count; i++)
- nvlist_free(zhp->zpool_error_log[i]);
- free(zhp->zpool_error_log);
- }
free(zhp);
}
@@ -1573,19 +1567,12 @@ zbookmark_compare(const void *a, const void *b)
* caller.
*/
int
-zpool_get_errlog(zpool_handle_t *zhp, nvlist_t ***list, size_t *nelem)
+zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp)
{
zfs_cmd_t zc = { 0 };
uint64_t count;
zbookmark_t *zb = NULL;
- libzfs_handle_t *hdl = zhp->zpool_hdl;
- int i, j;
-
- if (zhp->zpool_error_log != NULL) {
- *list = zhp->zpool_error_log;
- *nelem = zhp->zpool_error_count;
- return (0);
- }
+ int i;
/*
* Retrieve the raw error list from the kernel. If the number of errors
@@ -1626,123 +1613,45 @@ zpool_get_errlog(zpool_handle_t *zhp, nvlist_t ***list, size_t *nelem)
zb = ((zbookmark_t *)(uintptr_t)zc.zc_nvlist_dst) +
zc.zc_nvlist_dst_size;
count -= zc.zc_nvlist_dst_size;
- zc.zc_nvlist_dst = 0ULL;
qsort(zb, count, sizeof (zbookmark_t), zbookmark_compare);
- /*
- * Count the number of unique elements
- */
- j = 0;
- for (i = 0; i < count; i++) {
- if (i > 0 && memcmp(&zb[i - 1], &zb[i],
- sizeof (zbookmark_t)) == 0)
- continue;
- j++;
- }
-
- /*
- * If the user has only requested the number of items, return it now
- * without bothering with the extra work.
- */
- if (list == NULL) {
- *nelem = j;
- free((void *)(uintptr_t)zc.zc_nvlist_dst);
- return (0);
- }
-
- zhp->zpool_error_count = j;
+ verify(nvlist_alloc(nverrlistp, 0, KM_SLEEP) == 0);
/*
- * Allocate an array of nvlists to hold the results
+ * Fill in the nverrlistp with nvlist's of dataset and object numbers.
*/
- if ((zhp->zpool_error_log = zfs_alloc(zhp->zpool_hdl,
- j * sizeof (nvlist_t *))) == NULL) {
- free((void *)(uintptr_t)zc.zc_nvlist_dst);
- return (-1);
- }
-
- /*
- * Fill in the results with names from the kernel.
- */
- j = 0;
for (i = 0; i < count; i++) {
- char buf[64];
nvlist_t *nv;
if (i > 0 && memcmp(&zb[i - 1], &zb[i],
sizeof (zbookmark_t)) == 0)
continue;
- if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
+ 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;
-
- zc.zc_bookmark = zb[i];
- for (;;) {
- if (ioctl(zhp->zpool_hdl->libzfs_fd,
- ZFS_IOC_BOOKMARK_NAME, &zc) != 0) {
- if (errno == ENOMEM) {
- if (zcmd_expand_dst_nvlist(hdl, &zc)
- != 0) {
- zcmd_free_nvlists(&zc);
- goto nomem;
- }
-
- continue;
- } else {
- if (nvlist_alloc(&nv, NV_UNIQUE_NAME,
- 0) != 0)
- goto nomem;
-
- zhp->zpool_error_log[j] = nv;
- (void) snprintf(buf, sizeof (buf),
- "%llx", (longlong_t)
- zb[i].zb_objset);
- if (nvlist_add_string(nv,
- ZPOOL_ERR_DATASET, buf) != 0)
- goto nomem;
- (void) snprintf(buf, sizeof (buf),
- "%llx", (longlong_t)
- zb[i].zb_object);
- if (nvlist_add_string(nv,
- ZPOOL_ERR_OBJECT, buf) != 0)
- goto nomem;
- (void) snprintf(buf, sizeof (buf),
- "lvl=%u blkid=%llu",
- (int)zb[i].zb_level,
- (long long)zb[i].zb_blkid);
- if (nvlist_add_string(nv,
- ZPOOL_ERR_RANGE, buf) != 0)
- goto nomem;
- }
- } else {
- if (zcmd_read_dst_nvlist(hdl, &zc,
- &zhp->zpool_error_log[j]) != 0) {
- zcmd_free_nvlists(&zc);
- goto nomem;
- }
- }
-
- break;
}
-
- zcmd_free_nvlists(&zc);
-
- j++;
+ 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);
}
- *list = zhp->zpool_error_log;
- *nelem = zhp->zpool_error_count;
free((void *)(uintptr_t)zc.zc_nvlist_dst);
-
return (0);
nomem:
free((void *)(uintptr_t)zc.zc_nvlist_dst);
- for (i = 0; i < zhp->zpool_error_count; i++)
- nvlist_free(zhp->zpool_error_log[i]);
- free(zhp->zpool_error_log);
- zhp->zpool_error_log = NULL;
return (no_memory(zhp->zpool_hdl));
}
@@ -1938,3 +1847,51 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
return (err);
}
+
+void
+zpool_obj_to_path(zpool_handle_t *zhp, uint64_t dsobj, uint64_t obj,
+ char *pathname, size_t len)
+{
+ zfs_cmd_t zc = { 0 };
+ boolean_t mounted = B_FALSE;
+ char *mntpnt = NULL;
+ char dsname[MAXNAMELEN];
+
+ if (dsobj == 0) {
+ /* special case for the MOS */
+ (void) snprintf(pathname, len, "<metadata>:<0x%llx>", obj);
+ return;
+ }
+
+ /* get the dataset's name */
+ (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
+ zc.zc_obj = dsobj;
+ if (ioctl(zhp->zpool_hdl->libzfs_fd,
+ ZFS_IOC_DSOBJ_TO_DSNAME, &zc) != 0) {
+ /* just write out a path of two object numbers */
+ (void) snprintf(pathname, len, "<0x%llx>:<0x%llx>",
+ dsobj, obj);
+ return;
+ }
+ (void) strlcpy(dsname, zc.zc_value, sizeof (dsname));
+
+ /* find out if the dataset is mounted */
+ mounted = is_mounted(zhp->zpool_hdl, dsname, &mntpnt);
+
+ /* get the corrupted object's path */
+ (void) strlcpy(zc.zc_name, dsname, sizeof (zc.zc_name));
+ zc.zc_obj = obj;
+ if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_OBJ_TO_PATH,
+ &zc) == 0) {
+ if (mounted) {
+ (void) snprintf(pathname, len, "%s%s", mntpnt,
+ zc.zc_value);
+ } else {
+ (void) snprintf(pathname, len, "%s:%s",
+ dsname, zc.zc_value);
+ }
+ } else {
+ (void) snprintf(pathname, len, "%s:<0x%llx>", dsname, obj);
+ }
+ free(mntpnt);
+}
diff --git a/usr/src/lib/libzfs/common/mapfile-vers b/usr/src/lib/libzfs/common/mapfile-vers
index 2ff28c912b..1c3efe8e44 100644
--- a/usr/src/lib/libzfs/common/mapfile-vers
+++ b/usr/src/lib/libzfs/common/mapfile-vers
@@ -19,7 +19,7 @@
# CDDL HEADER END
#
#
-# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -123,6 +123,7 @@ SUNWprivate_1.1 {
zpool_iter;
zpool_log_history;
zpool_mount_datasets;
+ zpool_obj_to_path;
zpool_open;
zpool_open_canfail;
zpool_read_label;