32 #include <stdlib.h>
33 #include <string.h>
34 #include <zlib.h>
35 #include <libgen.h>
36 #include <sys/spa.h>
37 #include <sys/stat.h>
38 #include <sys/processor.h>
39 #include <sys/zfs_context.h>
40 #include <sys/rrwlock.h>
41 #include <sys/zmod.h>
42 #include <sys/utsname.h>
43 #include <sys/systeminfo.h>
44
45 extern void system_taskq_init(void);
46 extern void system_taskq_fini(void);
47
48 /*
49 * Emulation of kernel services in userland.
50 */
51
52 pgcnt_t physmem;
53 vnode_t *rootdir = (vnode_t *)0xabcd1234;
54 char hw_serial[HW_HOSTID_LEN];
55 kmutex_t cpu_lock;
56 vmem_t *zio_arena = NULL;
57
58 /* If set, all blocks read will be copied to the specified directory. */
59 char *vn_dumpdir = NULL;
60
61 struct utsname utsname = {
62 "userland", "libzpool", "1", "1", "na"
63 };
64
65 /*
66 * =========================================================================
67 * vnode operations
68 * =========================================================================
69 */
70 /*
71 * Note: for the xxxat() versions of these functions, we assume that the
72 * starting vp is always rootdir (which is true for spa_directory.c, the only
444 (void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
445 (mode & FWRITE) ? gethostid() : 0);
446
447 system_taskq_init();
448
449 mutex_init(&cpu_lock, NULL, MUTEX_DEFAULT, NULL);
450
451 spa_init(mode);
452
453 tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
454 }
455
456 void
457 kernel_fini(void)
458 {
459 spa_fini();
460
461 system_taskq_fini();
462 }
463
464 /* ARGSUSED */
465 uint32_t
466 zone_get_hostid(void *zonep)
467 {
468 /*
469 * We're emulating the system's hostid in userland.
470 */
471 return (strtoul(hw_serial, NULL, 10));
472 }
473
474 int
475 z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
476 {
477 int ret;
478 uLongf len = *dstlen;
479
480 if ((ret = uncompress(dst, &len, src, srclen)) == Z_OK)
481 *dstlen = (size_t)len;
482
483 return (ret);
484 }
485
486 int
487 z_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen,
488 int level)
489 {
490 int ret;
491 uLongf len = *dstlen;
492
493 if ((ret = compress2(dst, &len, src, srclen, level)) == Z_OK)
|
32 #include <stdlib.h>
33 #include <string.h>
34 #include <zlib.h>
35 #include <libgen.h>
36 #include <sys/spa.h>
37 #include <sys/stat.h>
38 #include <sys/processor.h>
39 #include <sys/zfs_context.h>
40 #include <sys/rrwlock.h>
41 #include <sys/zmod.h>
42 #include <sys/utsname.h>
43 #include <sys/systeminfo.h>
44
45 extern void system_taskq_init(void);
46 extern void system_taskq_fini(void);
47
48 /*
49 * Emulation of kernel services in userland.
50 */
51
52 volatile pgcnt_t physmem;
53 vnode_t *rootdir = (vnode_t *)0xabcd1234;
54 char hw_serial[HW_HOSTID_LEN];
55 kmutex_t cpu_lock;
56 vmem_t *zio_arena = NULL;
57
58 /* If set, all blocks read will be copied to the specified directory. */
59 char *vn_dumpdir = NULL;
60
61 struct utsname utsname = {
62 "userland", "libzpool", "1", "1", "na"
63 };
64
65 /*
66 * =========================================================================
67 * vnode operations
68 * =========================================================================
69 */
70 /*
71 * Note: for the xxxat() versions of these functions, we assume that the
72 * starting vp is always rootdir (which is true for spa_directory.c, the only
444 (void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
445 (mode & FWRITE) ? gethostid() : 0);
446
447 system_taskq_init();
448
449 mutex_init(&cpu_lock, NULL, MUTEX_DEFAULT, NULL);
450
451 spa_init(mode);
452
453 tsd_create(&rrw_tsd_key, rrw_tsd_destroy);
454 }
455
456 void
457 kernel_fini(void)
458 {
459 spa_fini();
460
461 system_taskq_fini();
462 }
463
464 int
465 z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
466 {
467 int ret;
468 uLongf len = *dstlen;
469
470 if ((ret = uncompress(dst, &len, src, srclen)) == Z_OK)
471 *dstlen = (size_t)len;
472
473 return (ret);
474 }
475
476 int
477 z_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen,
478 int level)
479 {
480 int ret;
481 uLongf len = *dstlen;
482
483 if ((ret = compress2(dst, &len, src, srclen, level)) == Z_OK)
|