zhack.c (f67950b21e185934ccabe311516f4dcbdb00ef79) zhack.c (d8ab6e129d75d7c3f21a7909bf811a3de65faea8)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 35 unchanged lines hidden (view full) ---

44#include <sys/fs/zfs.h>
45#include <sys/dmu_objset.h>
46#include <sys/dsl_pool.h>
47#include <sys/zio_checksum.h>
48#include <sys/zio_compress.h>
49#include <sys/zfeature.h>
50#include <sys/dmu_tx.h>
51#undef verify
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 35 unchanged lines hidden (view full) ---

44#include <sys/fs/zfs.h>
45#include <sys/dmu_objset.h>
46#include <sys/dsl_pool.h>
47#include <sys/zio_checksum.h>
48#include <sys/zio_compress.h>
49#include <sys/zfeature.h>
50#include <sys/dmu_tx.h>
51#undef verify
52#include <libzfs.h>
52#include <libzutil.h>
53
54extern boolean_t zfeature_checks_disable;
55
56const char cmdname[] = "zhack";
53
54extern boolean_t zfeature_checks_disable;
55
56const char cmdname[] = "zhack";
57libzfs_handle_t *g_zfs;
58static importargs_t g_importargs;
59static char *g_pool;
60static boolean_t g_readonly;
61
62static void
63usage(void)
64{
65 (void) fprintf(stderr,

--- 57 unchanged lines hidden (view full) ---

123static void
124zhack_import(char *target, boolean_t readonly)
125{
126 nvlist_t *config;
127 nvlist_t *props;
128 int error;
129
130 kernel_init(readonly ? FREAD : (FREAD | FWRITE));
57static importargs_t g_importargs;
58static char *g_pool;
59static boolean_t g_readonly;
60
61static void
62usage(void)
63{
64 (void) fprintf(stderr,

--- 57 unchanged lines hidden (view full) ---

122static void
123zhack_import(char *target, boolean_t readonly)
124{
125 nvlist_t *config;
126 nvlist_t *props;
127 int error;
128
129 kernel_init(readonly ? FREAD : (FREAD | FWRITE));
131 g_zfs = libzfs_init();
132 ASSERT(g_zfs != NULL);
133
134 dmu_objset_register_type(DMU_OST_ZFS, space_delta_cb);
135
136 g_readonly = readonly;
130
131 dmu_objset_register_type(DMU_OST_ZFS, space_delta_cb);
132
133 g_readonly = readonly;
137 g_importargs.unique = B_TRUE;
138 g_importargs.can_be_active = readonly;
139 g_pool = strdup(target);
140
134 g_importargs.can_be_active = readonly;
135 g_pool = strdup(target);
136
141 error = zpool_tryimport(g_zfs, target, &config, &g_importargs);
137 error = zpool_find_config(NULL, target, &config, &g_importargs,
138 &libzpool_config_ops);
142 if (error)
139 if (error)
143 fatal(NULL, FTAG, "cannot import '%s': %s", target,
144 libzfs_error_description(g_zfs));
140 fatal(NULL, FTAG, "cannot import '%s'", target);
145
146 props = NULL;
147 if (readonly) {
148 VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
149 VERIFY(nvlist_add_uint64(props,
150 zpool_prop_to_name(ZPOOL_PROP_READONLY), 1) == 0);
151 }
152

--- 370 unchanged lines hidden (view full) ---

523 usage();
524 }
525
526 if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_FALSE) != 0) {
527 fatal(NULL, FTAG, "pool export failed; "
528 "changes may not be committed to disk\n");
529 }
530
141
142 props = NULL;
143 if (readonly) {
144 VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
145 VERIFY(nvlist_add_uint64(props,
146 zpool_prop_to_name(ZPOOL_PROP_READONLY), 1) == 0);
147 }
148

--- 370 unchanged lines hidden (view full) ---

519 usage();
520 }
521
522 if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_FALSE) != 0) {
523 fatal(NULL, FTAG, "pool export failed; "
524 "changes may not be committed to disk\n");
525 }
526
531 libzfs_fini(g_zfs);
532 kernel_fini();
533
534 return (rv);
535}
527 kernel_fini();
528
529 return (rv);
530}