author | eschrock |
Mon, 21 May 2012 13:37:21 -0700 | |
changeset 13701 | 1949b688d5fb |
child 13743 | 95aba6e49b9f |
permissions | -rw-r--r-- |
13701
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
1 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
2 |
* CDDL HEADER START |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
3 |
* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
4 |
* The contents of this file are subject to the terms of the |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
7 |
* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
9 |
* or http://www.opensolaris.org/os/licensing. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
10 |
* See the License for the specific language governing permissions |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
11 |
* and limitations under the License. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
12 |
* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
18 |
* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
19 |
* CDDL HEADER END |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
20 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
21 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
22 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
23 |
* Copyright (c) 2012 by Delphix. All rights reserved. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
24 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
25 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
26 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
27 |
* zhack is a debugging tool that can write changes to ZFS pool using libzpool |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
28 |
* for testing purposes. Altering pools with zhack is unsupported and may |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
29 |
* result in corrupted pools. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
30 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
31 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
32 |
#include <stdio.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
33 |
#include <stdlib.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
34 |
#include <ctype.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
35 |
#include <sys/zfs_context.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
36 |
#include <sys/spa.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
37 |
#include <sys/spa_impl.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
38 |
#include <sys/dmu.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
39 |
#include <sys/zap.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
40 |
#include <sys/zfs_znode.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
41 |
#include <sys/dsl_synctask.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
42 |
#include <sys/vdev.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
43 |
#include <sys/fs/zfs.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
44 |
#include <sys/dmu_objset.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
45 |
#include <sys/dsl_pool.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
46 |
#include <sys/zio_checksum.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
47 |
#include <sys/zio_compress.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
48 |
#include <sys/zfeature.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
49 |
#undef ZFS_MAXNAMELEN |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
50 |
#undef verify |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
51 |
#include <libzfs.h> |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
52 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
53 |
extern boolean_t zfeature_checks_disable; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
54 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
55 |
const char cmdname[] = "zhack"; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
56 |
libzfs_handle_t *g_zfs; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
57 |
static importargs_t g_importargs; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
58 |
static char *g_pool; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
59 |
static boolean_t g_readonly; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
60 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
61 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
62 |
usage(void) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
63 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
64 |
(void) fprintf(stderr, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
65 |
"Usage: %s [-c cachefile] [-d dir] <subcommand> <args> ...\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
66 |
"where <subcommand> <args> is one of the following:\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
67 |
"\n", cmdname); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
68 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
69 |
(void) fprintf(stderr, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
70 |
" feature stat <pool>\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
71 |
" print information about enabled features\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
72 |
" feature enable [-d desc] <pool> <feature>\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
73 |
" add a new enabled feature to the pool\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
74 |
" -d <desc> sets the feature's description\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
75 |
" feature ref [-md] <pool> <feature>\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
76 |
" change the refcount on the given feature\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
77 |
" -d decrease instead of increase the refcount\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
78 |
" -m add the feature to the label if increasing refcount\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
79 |
"\n" |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
80 |
" <feature> : should be a feature guid\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
81 |
exit(1); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
82 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
83 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
84 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
85 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
86 |
fatal(const char *fmt, ...) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
87 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
88 |
va_list ap; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
89 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
90 |
va_start(ap, fmt); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
91 |
(void) fprintf(stderr, "%s: ", cmdname); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
92 |
(void) vfprintf(stderr, fmt, ap); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
93 |
va_end(ap); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
94 |
(void) fprintf(stderr, "\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
95 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
96 |
exit(1); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
97 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
98 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
99 |
/* ARGSUSED */ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
100 |
static int |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
101 |
space_delta_cb(dmu_object_type_t bonustype, void *data, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
102 |
uint64_t *userp, uint64_t *groupp) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
103 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
104 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
105 |
* Is it a valid type of object to track? |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
106 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
107 |
if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
108 |
return (ENOENT); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
109 |
(void) fprintf(stderr, "modifying object that needs user accounting"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
110 |
abort(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
111 |
/* NOTREACHED */ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
112 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
113 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
114 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
115 |
* Target is the dataset whose pool we want to open. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
116 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
117 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
118 |
import_pool(const char *target, boolean_t readonly) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
119 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
120 |
nvlist_t *config; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
121 |
nvlist_t *pools; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
122 |
int error; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
123 |
char *sepp; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
124 |
spa_t *spa; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
125 |
nvpair_t *elem; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
126 |
nvlist_t *props; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
127 |
const char *name; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
128 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
129 |
kernel_init(readonly ? FREAD : (FREAD | FWRITE)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
130 |
g_zfs = libzfs_init(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
131 |
ASSERT(g_zfs != NULL); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
132 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
133 |
dmu_objset_register_type(DMU_OST_ZFS, space_delta_cb); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
134 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
135 |
g_readonly = readonly; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
136 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
137 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
138 |
* If we only want readonly access, it's OK if we find |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
139 |
* a potentially-active (ie, imported into the kernel) pool from the |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
140 |
* default cachefile. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
141 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
142 |
if (readonly && spa_open(target, &spa, FTAG) == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
143 |
spa_close(spa, FTAG); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
144 |
return; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
145 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
146 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
147 |
g_importargs.unique = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
148 |
g_importargs.can_be_active = readonly; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
149 |
g_pool = strdup(target); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
150 |
if ((sepp = strpbrk(g_pool, "/@")) != NULL) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
151 |
*sepp = '\0'; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
152 |
g_importargs.poolname = g_pool; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
153 |
pools = zpool_search_import(g_zfs, &g_importargs); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
154 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
155 |
if (pools == NULL || nvlist_next_nvpair(pools, NULL) == NULL) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
156 |
if (!g_importargs.can_be_active) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
157 |
g_importargs.can_be_active = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
158 |
if (zpool_search_import(g_zfs, &g_importargs) != NULL || |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
159 |
spa_open(target, &spa, FTAG) == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
160 |
fatal("cannot import '%s': pool is active; run " |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
161 |
"\"zpool export %s\" first\n", |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
162 |
g_pool, g_pool); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
163 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
164 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
165 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
166 |
fatal("cannot import '%s': no such pool available\n", g_pool); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
167 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
168 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
169 |
elem = nvlist_next_nvpair(pools, NULL); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
170 |
name = nvpair_name(elem); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
171 |
verify(nvpair_value_nvlist(elem, &config) == 0); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
172 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
173 |
props = NULL; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
174 |
if (readonly) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
175 |
verify(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
176 |
verify(nvlist_add_uint64(props, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
177 |
zpool_prop_to_name(ZPOOL_PROP_READONLY), 1) == 0); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
178 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
179 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
180 |
zfeature_checks_disable = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
181 |
error = spa_import(name, config, props, ZFS_IMPORT_NORMAL); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
182 |
zfeature_checks_disable = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
183 |
if (error == EEXIST) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
184 |
error = 0; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
185 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
186 |
if (error) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
187 |
fatal("can't import '%s': %s", name, strerror(error)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
188 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
189 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
190 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
191 |
zhack_spa_open(const char *target, boolean_t readonly, void *tag, spa_t **spa) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
192 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
193 |
int err; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
194 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
195 |
import_pool(target, readonly); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
196 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
197 |
zfeature_checks_disable = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
198 |
err = spa_open(target, spa, tag); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
199 |
zfeature_checks_disable = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
200 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
201 |
if (err != 0) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
202 |
fatal("cannot open '%s': %s", target, strerror(err)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
203 |
if (spa_version(*spa) < SPA_VERSION_FEATURES) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
204 |
fatal("'%s' has version %d, features not enabled", target, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
205 |
(int)spa_version(*spa)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
206 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
207 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
208 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
209 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
210 |
dump_obj(objset_t *os, uint64_t obj, const char *name) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
211 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
212 |
zap_cursor_t zc; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
213 |
zap_attribute_t za; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
214 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
215 |
(void) printf("%s_obj:\n", name); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
216 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
217 |
for (zap_cursor_init(&zc, os, obj); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
218 |
zap_cursor_retrieve(&zc, &za) == 0; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
219 |
zap_cursor_advance(&zc)) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
220 |
if (za.za_integer_length == 8) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
221 |
ASSERT(za.za_num_integers == 1); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
222 |
(void) printf("\t%s = %llu\n", |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
223 |
za.za_name, (u_longlong_t)za.za_first_integer); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
224 |
} else { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
225 |
ASSERT(za.za_integer_length == 1); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
226 |
char val[1024]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
227 |
VERIFY(zap_lookup(os, obj, za.za_name, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
228 |
1, sizeof (val), val) == 0); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
229 |
(void) printf("\t%s = %s\n", za.za_name, val); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
230 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
231 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
232 |
zap_cursor_fini(&zc); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
233 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
234 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
235 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
236 |
dump_mos(spa_t *spa) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
237 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
238 |
nvlist_t *nv = spa->spa_label_features; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
239 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
240 |
(void) printf("label config:\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
241 |
for (nvpair_t *pair = nvlist_next_nvpair(nv, NULL); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
242 |
pair != NULL; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
243 |
pair = nvlist_next_nvpair(nv, pair)) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
244 |
(void) printf("\t%s\n", nvpair_name(pair)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
245 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
246 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
247 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
248 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
249 |
zhack_do_feature_stat(int argc, char **argv) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
250 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
251 |
spa_t *spa; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
252 |
objset_t *os; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
253 |
char *target; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
254 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
255 |
argc--; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
256 |
argv++; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
257 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
258 |
if (argc < 1) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
259 |
(void) fprintf(stderr, "error: missing pool name\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
260 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
261 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
262 |
target = argv[0]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
263 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
264 |
zhack_spa_open(target, B_TRUE, FTAG, &spa); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
265 |
os = spa->spa_meta_objset; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
266 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
267 |
dump_obj(os, spa->spa_feat_for_read_obj, "for_read"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
268 |
dump_obj(os, spa->spa_feat_for_write_obj, "for_write"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
269 |
dump_obj(os, spa->spa_feat_desc_obj, "descriptions"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
270 |
dump_mos(spa); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
271 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
272 |
spa_close(spa, FTAG); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
273 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
274 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
275 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
276 |
feature_enable_sync(void *arg1, void *arg2, dmu_tx_t *tx) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
277 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
278 |
spa_t *spa = arg1; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
279 |
zfeature_info_t *feature = arg2; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
280 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
281 |
spa_feature_enable(spa, feature, tx); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
282 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
283 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
284 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
285 |
zhack_do_feature_enable(int argc, char **argv) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
286 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
287 |
char c; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
288 |
char *desc, *target; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
289 |
spa_t *spa; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
290 |
objset_t *mos; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
291 |
zfeature_info_t feature; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
292 |
zfeature_info_t *nodeps[] = { NULL }; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
293 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
294 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
295 |
* Features are not added to the pool's label until their refcounts |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
296 |
* are incremented, so fi_mos can just be left as false for now. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
297 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
298 |
desc = NULL; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
299 |
feature.fi_uname = "zhack"; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
300 |
feature.fi_mos = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
301 |
feature.fi_can_readonly = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
302 |
feature.fi_depends = nodeps; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
303 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
304 |
optind = 1; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
305 |
while ((c = getopt(argc, argv, "rmd:")) != -1) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
306 |
switch (c) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
307 |
case 'r': |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
308 |
feature.fi_can_readonly = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
309 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
310 |
case 'd': |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
311 |
desc = strdup(optarg); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
312 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
313 |
default: |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
314 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
315 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
316 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
317 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
318 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
319 |
if (desc == NULL) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
320 |
desc = strdup("zhack injected"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
321 |
feature.fi_desc = desc; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
322 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
323 |
argc -= optind; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
324 |
argv += optind; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
325 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
326 |
if (argc < 2) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
327 |
(void) fprintf(stderr, "error: missing feature or pool name\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
328 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
329 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
330 |
target = argv[0]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
331 |
feature.fi_guid = argv[1]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
332 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
333 |
if (!zfeature_is_valid_guid(feature.fi_guid)) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
334 |
fatal("invalid feature guid: %s", feature.fi_guid); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
335 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
336 |
zhack_spa_open(target, B_FALSE, FTAG, &spa); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
337 |
mos = spa->spa_meta_objset; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
338 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
339 |
if (0 == zfeature_lookup_guid(feature.fi_guid, NULL)) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
340 |
fatal("'%s' is a real feature, will not enable"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
341 |
if (0 == zap_contains(mos, spa->spa_feat_desc_obj, feature.fi_guid)) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
342 |
fatal("feature already enabled: %s", feature.fi_guid); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
343 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
344 |
VERIFY3U(0, ==, dsl_sync_task_do(spa->spa_dsl_pool, NULL, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
345 |
feature_enable_sync, spa, &feature, 5)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
346 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
347 |
spa_close(spa, FTAG); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
348 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
349 |
free(desc); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
350 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
351 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
352 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
353 |
feature_incr_sync(void *arg1, void *arg2, dmu_tx_t *tx) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
354 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
355 |
spa_t *spa = arg1; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
356 |
zfeature_info_t *feature = arg2; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
357 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
358 |
spa_feature_incr(spa, feature, tx); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
359 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
360 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
361 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
362 |
feature_decr_sync(void *arg1, void *arg2, dmu_tx_t *tx) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
363 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
364 |
spa_t *spa = arg1; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
365 |
zfeature_info_t *feature = arg2; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
366 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
367 |
spa_feature_decr(spa, feature, tx); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
368 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
369 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
370 |
static void |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
371 |
zhack_do_feature_ref(int argc, char **argv) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
372 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
373 |
char c; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
374 |
char *target; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
375 |
boolean_t decr = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
376 |
spa_t *spa; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
377 |
objset_t *mos; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
378 |
zfeature_info_t feature; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
379 |
zfeature_info_t *nodeps[] = { NULL }; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
380 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
381 |
/* |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
382 |
* fi_desc does not matter here because it was written to disk |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
383 |
* when the feature was enabled, but we need to properly set the |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
384 |
* feature for read or write based on the information we read off |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
385 |
* disk later. |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
386 |
*/ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
387 |
feature.fi_uname = "zhack"; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
388 |
feature.fi_mos = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
389 |
feature.fi_desc = NULL; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
390 |
feature.fi_depends = nodeps; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
391 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
392 |
optind = 1; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
393 |
while ((c = getopt(argc, argv, "md")) != -1) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
394 |
switch (c) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
395 |
case 'm': |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
396 |
feature.fi_mos = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
397 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
398 |
case 'd': |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
399 |
decr = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
400 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
401 |
default: |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
402 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
403 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
404 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
405 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
406 |
argc -= optind; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
407 |
argv += optind; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
408 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
409 |
if (argc < 2) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
410 |
(void) fprintf(stderr, "error: missing feature or pool name\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
411 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
412 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
413 |
target = argv[0]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
414 |
feature.fi_guid = argv[1]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
415 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
416 |
if (!zfeature_is_valid_guid(feature.fi_guid)) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
417 |
fatal("invalid feature guid: %s", feature.fi_guid); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
418 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
419 |
zhack_spa_open(target, B_FALSE, FTAG, &spa); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
420 |
mos = spa->spa_meta_objset; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
421 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
422 |
if (0 == zfeature_lookup_guid(feature.fi_guid, NULL)) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
423 |
fatal("'%s' is a real feature, will not change refcount"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
424 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
425 |
if (0 == zap_contains(mos, spa->spa_feat_for_read_obj, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
426 |
feature.fi_guid)) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
427 |
feature.fi_can_readonly = B_FALSE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
428 |
} else if (0 == zap_contains(mos, spa->spa_feat_for_write_obj, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
429 |
feature.fi_guid)) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
430 |
feature.fi_can_readonly = B_TRUE; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
431 |
} else { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
432 |
fatal("feature is not enabled: %s", feature.fi_guid); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
433 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
434 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
435 |
if (decr && !spa_feature_is_active(spa, &feature)) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
436 |
fatal("feature refcount already 0: %s", feature.fi_guid); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
437 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
438 |
VERIFY3U(0, ==, dsl_sync_task_do(spa->spa_dsl_pool, NULL, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
439 |
decr ? feature_decr_sync : feature_incr_sync, spa, &feature, 5)); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
440 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
441 |
spa_close(spa, FTAG); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
442 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
443 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
444 |
static int |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
445 |
zhack_do_feature(int argc, char **argv) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
446 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
447 |
char *subcommand; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
448 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
449 |
argc--; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
450 |
argv++; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
451 |
if (argc == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
452 |
(void) fprintf(stderr, |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
453 |
"error: no feature operation specified\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
454 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
455 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
456 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
457 |
subcommand = argv[0]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
458 |
if (strcmp(subcommand, "stat") == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
459 |
zhack_do_feature_stat(argc, argv); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
460 |
} else if (strcmp(subcommand, "enable") == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
461 |
zhack_do_feature_enable(argc, argv); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
462 |
} else if (strcmp(subcommand, "ref") == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
463 |
zhack_do_feature_ref(argc, argv); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
464 |
} else { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
465 |
(void) fprintf(stderr, "error: unknown subcommand: %s\n", |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
466 |
subcommand); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
467 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
468 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
469 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
470 |
return (0); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
471 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
472 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
473 |
#define MAX_NUM_PATHS 1024 |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
474 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
475 |
int |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
476 |
main(int argc, char **argv) |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
477 |
{ |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
478 |
extern void zfs_prop_init(void); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
479 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
480 |
char *path[MAX_NUM_PATHS]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
481 |
const char *subcommand; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
482 |
int rv = 0; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
483 |
char c; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
484 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
485 |
g_importargs.path = path; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
486 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
487 |
dprintf_setup(&argc, argv); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
488 |
zfs_prop_init(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
489 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
490 |
while ((c = getopt(argc, argv, "c:d:")) != -1) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
491 |
switch (c) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
492 |
case 'c': |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
493 |
g_importargs.cachefile = optarg; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
494 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
495 |
case 'd': |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
496 |
assert(g_importargs.paths < MAX_NUM_PATHS); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
497 |
g_importargs.path[g_importargs.paths++] = optarg; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
498 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
499 |
default: |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
500 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
501 |
break; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
502 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
503 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
504 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
505 |
argc -= optind; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
506 |
argv += optind; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
507 |
optind = 1; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
508 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
509 |
if (argc == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
510 |
(void) fprintf(stderr, "error: no command specified\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
511 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
512 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
513 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
514 |
subcommand = argv[0]; |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
515 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
516 |
if (strcmp(subcommand, "feature") == 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
517 |
rv = zhack_do_feature(argc, argv); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
518 |
} else { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
519 |
(void) fprintf(stderr, "error: unknown subcommand: %s\n", |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
520 |
subcommand); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
521 |
usage(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
522 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
523 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
524 |
if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_TRUE) != 0) { |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
525 |
fatal("pool export failed; " |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
526 |
"changes may not be committed to disk\n"); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
527 |
} |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
528 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
529 |
libzfs_fini(g_zfs); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
530 |
kernel_fini(); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
531 |
|
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
532 |
return (rv); |
1949b688d5fb
2619 asynchronous destruction of ZFS file systems (missed files)
eschrock
parents:
diff
changeset
|
533 |
} |