Update core ZFS code from build 121 to build 141.
[zfs.git] / lib / libzpool / kernel.c
index 89108fe..5284c12 100644 (file)
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -42,6 +42,7 @@
  * Emulation of kernel services in userland.
  */
 
+int aok;
 uint64_t physmem;
 vnode_t *rootdir = (vnode_t *)0xabcd1234;
 char hw_serial[HW_HOSTID_LEN];
@@ -50,6 +51,9 @@ struct utsname utsname = {
        "userland", "libzpool", "1", "1", "na"
 };
 
+/* this only exists to have its address taken */
+struct proc p0;
+
 /*
  * =========================================================================
  * threads
@@ -269,7 +273,7 @@ cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
        clock_t delta;
 
 top:
-       delta = abstime - lbolt;
+       delta = abstime - ddi_get_lbolt();
        if (delta <= 0)
                return (-1);
 
@@ -444,6 +448,24 @@ vn_close(vnode_t *vp)
        umem_free(vp, sizeof (vnode_t));
 }
 
+/*
+ * At a minimum we need to update the size since vdev_reopen()
+ * will no longer call vn_openat().
+ */
+int
+fop_getattr(vnode_t *vp, vattr_t *vap)
+{
+       struct stat64 st;
+
+       if (fstat64(vp->v_fd, &st) == -1) {
+               close(vp->v_fd);
+               return (errno);
+       }
+
+       vap->va_size = st.st_size;
+       return (0);
+}
+
 #ifdef ZFS_DEBUG
 
 /*
@@ -754,6 +776,17 @@ ddi_strtoul(const char *hw_serial, char **nptr, int base, unsigned long *result)
        return (0);
 }
 
+int
+ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result)
+{
+       char *end;
+
+       *result = strtoull(str, &end, base);
+       if (*result == 0)
+               return (errno);
+       return (0);
+}
+
 /*
  * =========================================================================
  * kernel emulation setup & teardown
@@ -779,7 +812,8 @@ kernel_init(int mode)
        dprintf("physmem = %llu pages (%.2f GB)\n", physmem,
            (double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
 
-       (void) snprintf(hw_serial, sizeof (hw_serial), "%ld", gethostid());
+       (void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
+           (mode & FWRITE) ? gethostid() : 0);
 
        VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1);
        VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1);
@@ -794,6 +828,8 @@ kernel_fini(void)
 {
        spa_fini();
 
+       system_taskq_fini();
+
        close(random_fd);
        close(urandom_fd);
 
@@ -884,3 +920,27 @@ ksiddomain_rele(ksiddomain_t *ksid)
        spa_strfree(ksid->kd_name);
        umem_free(ksid, sizeof (ksiddomain_t));
 }
+
+/*
+ * Do not change the length of the returned string; it must be freed
+ * with strfree().
+ */
+char *
+kmem_asprintf(const char *fmt, ...)
+{
+       int size;
+       va_list adx;
+       char *buf;
+
+       va_start(adx, fmt);
+       size = vsnprintf(NULL, 0, fmt, adx) + 1;
+       va_end(adx);
+
+       buf = kmem_alloc(size, KM_SLEEP);
+
+       va_start(adx, fmt);
+       size = vsnprintf(buf, size, fmt, adx);
+       va_end(adx);
+
+       return (buf);
+}