summaryrefslogtreecommitdiffstats
path: root/contrib/opensolaris/lib
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2007-04-08 16:29:25 +0000
committerpjd <pjd@FreeBSD.org>2007-04-08 16:29:25 +0000
commit2b260dcd5e356a3d85c66dff3715260105c412f7 (patch)
tree414979d8bf91ece25474dc6b933621fc94bb051b /contrib/opensolaris/lib
parent4b06e89211feda93bee19a93c165c0d4b9911622 (diff)
downloadFreeBSD-src-2b260dcd5e356a3d85c66dff3715260105c412f7.zip
FreeBSD-src-2b260dcd5e356a3d85c66dff3715260105c412f7.tar.gz
MFp4: Synchronize with recent OpenSolaris changes.
Diffstat (limited to 'contrib/opensolaris/lib')
-rw-r--r--contrib/opensolaris/lib/libzfs/common/libzfs.h2
-rw-r--r--contrib/opensolaris/lib/libzfs/common/libzfs_import.c33
-rw-r--r--contrib/opensolaris/lib/libzfs/common/libzfs_status.c28
-rw-r--r--contrib/opensolaris/lib/libzfs/common/libzfs_util.c7
-rw-r--r--contrib/opensolaris/lib/libzpool/common/kernel.c19
-rw-r--r--contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h8
6 files changed, 89 insertions, 8 deletions
diff --git a/contrib/opensolaris/lib/libzfs/common/libzfs.h b/contrib/opensolaris/lib/libzfs/common/libzfs.h
index 8e9a848..4a282b7 100644
--- a/contrib/opensolaris/lib/libzfs/common/libzfs.h
+++ b/contrib/opensolaris/lib/libzfs/common/libzfs.h
@@ -98,6 +98,7 @@ enum {
EZFS_POOLPROPS, /* couldn't retrieve pool props */
EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */
EZFS_POOL_INVALARG, /* invalid argument for this pool operation */
+ EZFS_NAMETOOLONG, /* dataset name is too long */
EZFS_UNKNOWN
};
@@ -192,6 +193,7 @@ typedef enum {
ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */
ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */
ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */
+ ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */
/*
* The following are not faults per se, but still an error possibly
diff --git a/contrib/opensolaris/lib/libzfs/common/libzfs_import.c b/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
index cab969b..26d15e9 100644
--- a/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
+++ b/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
@@ -379,7 +379,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl)
uint_t i, nspares;
boolean_t config_seen;
uint64_t best_txg;
- char *name;
+ char *name, *hostname;
zfs_cmd_t zc = { 0 };
uint64_t version, guid;
size_t len;
@@ -388,6 +388,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl)
nvlist_t **child = NULL;
uint_t c;
boolean_t isactive;
+ uint64_t hostid;
if (nvlist_alloc(&ret, 0, 0) != 0)
goto nomem;
@@ -430,6 +431,8 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl)
* pool guid
* name
* pool state
+ * hostid (if available)
+ * hostname (if available)
*/
uint64_t state;
@@ -453,6 +456,20 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl)
if (nvlist_add_uint64(config,
ZPOOL_CONFIG_POOL_STATE, state) != 0)
goto nomem;
+ hostid = 0;
+ if (nvlist_lookup_uint64(tmp,
+ ZPOOL_CONFIG_HOSTID, &hostid) == 0) {
+ if (nvlist_add_uint64(config,
+ ZPOOL_CONFIG_HOSTID, hostid) != 0)
+ goto nomem;
+ verify(nvlist_lookup_string(tmp,
+ ZPOOL_CONFIG_HOSTNAME,
+ &hostname) == 0);
+ if (nvlist_add_string(config,
+ ZPOOL_CONFIG_HOSTNAME,
+ hostname) != 0)
+ goto nomem;
+ }
config_seen = B_TRUE;
}
@@ -622,6 +639,20 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl)
}
/*
+ * Restore the original information read from the actual label.
+ */
+ (void) nvlist_remove(config, ZPOOL_CONFIG_HOSTID,
+ DATA_TYPE_UINT64);
+ (void) nvlist_remove(config, ZPOOL_CONFIG_HOSTNAME,
+ DATA_TYPE_STRING);
+ if (hostid != 0) {
+ verify(nvlist_add_uint64(config, ZPOOL_CONFIG_HOSTID,
+ hostid) == 0);
+ verify(nvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME,
+ hostname) == 0);
+ }
+
+ /*
* Add this pool to the list of configs.
*/
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
diff --git a/contrib/opensolaris/lib/libzfs/common/libzfs_status.c b/contrib/opensolaris/lib/libzfs/common/libzfs_status.c
index 2a41649..3eba97a 100644
--- a/contrib/opensolaris/lib/libzfs/common/libzfs_status.c
+++ b/contrib/opensolaris/lib/libzfs/common/libzfs_status.c
@@ -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.
*/
@@ -43,6 +43,7 @@
#include <libzfs.h>
#include <string.h>
+#include <unistd.h>
#include "libzfs_impl.h"
/*
@@ -50,7 +51,7 @@
* in libzfs.h. Note that there are some status results which go past the end
* of this table, and hence have no associated message ID.
*/
-static char *msgid_table[] = {
+static char *zfs_msgid_table[] = {
"ZFS-8000-14",
"ZFS-8000-2Q",
"ZFS-8000-3C",
@@ -60,7 +61,8 @@ static char *msgid_table[] = {
"ZFS-8000-72",
"ZFS-8000-8A",
"ZFS-8000-9P",
- "ZFS-8000-A5"
+ "ZFS-8000-A5",
+ "ZFS-8000-EY"
};
/*
@@ -69,7 +71,7 @@ static char *msgid_table[] = {
* and the article referred to by 'zpool status' must match that indicated by
* the syslog error message. We override missing data as well as corrupt pool.
*/
-static char *msgid_table_active[] = {
+static char *zfs_msgid_table_active[] = {
"ZFS-8000-14",
"ZFS-8000-D3", /* overridden */
"ZFS-8000-D3", /* overridden */
@@ -82,7 +84,7 @@ static char *msgid_table_active[] = {
"ZFS-8000-CS", /* overridden */
};
-#define NMSGID (sizeof (msgid_table) / sizeof (msgid_table[0]))
+#define NMSGID (sizeof (zfs_msgid_table) / sizeof (zfs_msgid_table[0]))
/* ARGSUSED */
static int
@@ -178,6 +180,8 @@ check_status(nvlist_t *config, boolean_t isimport)
uint_t vsc;
uint64_t nerr;
uint64_t version;
+ uint64_t stateval;
+ uint64_t hostid = 0;
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
&version) == 0);
@@ -185,6 +189,16 @@ check_status(nvlist_t *config, boolean_t isimport)
&nvroot) == 0);
verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
(uint64_t **)&vs, &vsc) == 0);
+ verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
+ &stateval) == 0);
+ (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
+
+ /*
+ * Pool last accessed by another system.
+ */
+ if (hostid != 0 && (unsigned long)hostid != gethostid() &&
+ stateval == POOL_STATE_ACTIVE)
+ return (ZPOOL_STATUS_HOSTID_MISMATCH);
/*
* Newer on-disk version.
@@ -270,7 +284,7 @@ zpool_get_status(zpool_handle_t *zhp, char **msgid)
if (ret >= NMSGID)
*msgid = NULL;
else
- *msgid = msgid_table_active[ret];
+ *msgid = zfs_msgid_table_active[ret];
return (ret);
}
@@ -283,7 +297,7 @@ zpool_import_status(nvlist_t *config, char **msgid)
if (ret >= NMSGID)
*msgid = NULL;
else
- *msgid = msgid_table[ret];
+ *msgid = zfs_msgid_table[ret];
return (ret);
}
diff --git a/contrib/opensolaris/lib/libzfs/common/libzfs_util.c b/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
index b9d8b97..c706126 100644
--- a/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
+++ b/contrib/opensolaris/lib/libzfs/common/libzfs_util.c
@@ -167,6 +167,8 @@ libzfs_error_description(libzfs_handle_t *hdl)
case EZFS_POOL_INVALARG:
return (dgettext(TEXT_DOMAIN, "invalid argument for "
"this pool operation"));
+ case EZFS_NAMETOOLONG:
+ return (dgettext(TEXT_DOMAIN, "dataset name is too long"));
case EZFS_UNKNOWN:
return (dgettext(TEXT_DOMAIN, "unknown error"));
default:
@@ -306,6 +308,11 @@ zfs_standard_error_fmt(libzfs_handle_t *hdl, int error, const char *fmt, ...)
"dataset is busy"));
zfs_verror(hdl, EZFS_BUSY, fmt, ap);
break;
+
+ case ENAMETOOLONG:
+ zfs_verror(hdl, EZFS_NAMETOOLONG, fmt, ap);
+ break;
+
default:
zfs_error_aux(hdl, strerror(errno));
zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap);
diff --git a/contrib/opensolaris/lib/libzpool/common/kernel.c b/contrib/opensolaris/lib/libzpool/common/kernel.c
index 086f33e..1fafe5f 100644
--- a/contrib/opensolaris/lib/libzpool/common/kernel.c
+++ b/contrib/opensolaris/lib/libzpool/common/kernel.c
@@ -37,6 +37,7 @@
#include <sys/processor.h>
#include <sys/zfs_context.h>
#include <sys/zmod.h>
+#include <sys/utsname.h>
/*
* Emulation of kernel services in userland.
@@ -45,6 +46,11 @@
int hz = 119; /* frequency when using gethrtime() >> 23 for lbolt */
uint64_t physmem;
vnode_t *rootdir = (vnode_t *)0xabcd1234;
+char hw_serial[11];
+
+struct utsname utsname = {
+ "userland", "libzpool", "1", "1", "na"
+};
/*
* =========================================================================
@@ -770,6 +776,17 @@ random_get_pseudo_bytes(uint8_t *ptr, size_t len)
return (random_get_bytes_common(ptr, len, "/dev/urandom"));
}
+int
+ddi_strtoul(const char *hw_serial, char **nptr, int base, unsigned long *result)
+{
+ char *end;
+
+ *result = strtoul(hw_serial, &end, base);
+ if (*result == 0)
+ return (errno);
+ return (0);
+}
+
/*
* =========================================================================
* kernel emulation setup & teardown
@@ -795,6 +812,8 @@ kernel_init(int mode)
dprintf("physmem = %llu pages (%.2f GB)\n", physmem,
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
+ snprintf(hw_serial, sizeof (hw_serial), "%ld", gethostid());
+
spa_init(mode);
}
diff --git a/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h b/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h
index 6b9783f..749ff5f 100644
--- a/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h
+++ b/contrib/opensolaris/lib/libzpool/common/sys/zfs_context.h
@@ -436,6 +436,14 @@ typedef struct callb_cpr {
#define zone_dataset_visible(x, y) (1)
#define INGLOBALZONE(z) (1)
+/*
+ * Hostname information
+ */
+extern struct utsname utsname;
+extern char hw_serial[];
+extern int ddi_strtoul(const char *str, char **nptr, int base,
+ unsigned long *result);
+
#ifdef __cplusplus
}
#endif
OpenPOWER on IntegriCloud