author | maybee |
Thu, 09 Nov 2006 11:33:08 -0800 | |
changeset 3080 | deef42200cee |
parent 3063 | b252896b372b |
child 3245 | 0c86ad4b2673 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1175
diff
changeset
|
22 |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
/* |
|
29 |
* ZFS volume emulation driver. |
|
30 |
* |
|
31 |
* Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes. |
|
32 |
* Volumes are accessed through the symbolic links named: |
|
33 |
* |
|
34 |
* /dev/zvol/dsk/<pool_name>/<dataset_name> |
|
35 |
* /dev/zvol/rdsk/<pool_name>/<dataset_name> |
|
36 |
* |
|
37 |
* These links are created by the ZFS-specific devfsadm link generator. |
|
38 |
* Volumes are persistent through reboot. No user command needs to be |
|
39 |
* run before opening and using a device. |
|
40 |
*/ |
|
41 |
||
42 |
#include <sys/types.h> |
|
43 |
#include <sys/param.h> |
|
44 |
#include <sys/errno.h> |
|
45 |
#include <sys/aio_req.h> |
|
46 |
#include <sys/uio.h> |
|
47 |
#include <sys/buf.h> |
|
48 |
#include <sys/modctl.h> |
|
49 |
#include <sys/open.h> |
|
50 |
#include <sys/kmem.h> |
|
51 |
#include <sys/conf.h> |
|
52 |
#include <sys/cmn_err.h> |
|
53 |
#include <sys/stat.h> |
|
54 |
#include <sys/zap.h> |
|
55 |
#include <sys/spa.h> |
|
56 |
#include <sys/zio.h> |
|
57 |
#include <sys/dsl_prop.h> |
|
58 |
#include <sys/dkio.h> |
|
59 |
#include <sys/efi_partition.h> |
|
60 |
#include <sys/byteorder.h> |
|
61 |
#include <sys/pathname.h> |
|
62 |
#include <sys/ddi.h> |
|
63 |
#include <sys/sunddi.h> |
|
64 |
#include <sys/crc32.h> |
|
65 |
#include <sys/dirent.h> |
|
66 |
#include <sys/policy.h> |
|
67 |
#include <sys/fs/zfs.h> |
|
68 |
#include <sys/zfs_ioctl.h> |
|
69 |
#include <sys/mkdev.h> |
|
1141 | 70 |
#include <sys/zil.h> |
2237 | 71 |
#include <sys/refcount.h> |
789 | 72 |
|
73 |
#include "zfs_namecheck.h" |
|
74 |
||
75 |
#define ZVOL_OBJ 1ULL |
|
76 |
#define ZVOL_ZAP_OBJ 2ULL |
|
77 |
||
78 |
static void *zvol_state; |
|
79 |
||
80 |
/* |
|
81 |
* This lock protects the zvol_state structure from being modified |
|
82 |
* while it's being used, e.g. an open that comes in before a create |
|
83 |
* finishes. It also protects temporary opens of the dataset so that, |
|
84 |
* e.g., an open doesn't get a spurious EBUSY. |
|
85 |
*/ |
|
86 |
static kmutex_t zvol_state_lock; |
|
87 |
static uint32_t zvol_minors; |
|
88 |
||
89 |
/* |
|
90 |
* The in-core state of each volume. |
|
91 |
*/ |
|
92 |
typedef struct zvol_state { |
|
93 |
char zv_name[MAXPATHLEN]; /* pool/dd name */ |
|
94 |
uint64_t zv_volsize; /* amount of space we advertise */ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
95 |
uint64_t zv_volblocksize; /* volume block size */ |
789 | 96 |
minor_t zv_minor; /* minor number */ |
97 |
uint8_t zv_min_bs; /* minimum addressable block shift */ |
|
98 |
uint8_t zv_readonly; /* hard readonly; like write-protect */ |
|
99 |
objset_t *zv_objset; /* objset handle */ |
|
100 |
uint32_t zv_mode; /* DS_MODE_* flags at open time */ |
|
101 |
uint32_t zv_open_count[OTYPCNT]; /* open counts */ |
|
102 |
uint32_t zv_total_opens; /* total open count */ |
|
1141 | 103 |
zilog_t *zv_zilog; /* ZIL handle */ |
104 |
uint64_t zv_txg_assign; /* txg to assign during ZIL replay */ |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
105 |
krwlock_t zv_dslock; /* dmu_sync() rwlock */ |
789 | 106 |
} zvol_state_t; |
107 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
108 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
109 |
* zvol maximum transfer in one DMU tx. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
110 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
111 |
int zvol_maxphys = DMU_MAX_ACCESS/2; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
112 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
113 |
int zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
114 |
|
789 | 115 |
static void |
116 |
zvol_size_changed(zvol_state_t *zv, dev_t dev) |
|
117 |
{ |
|
118 |
dev = makedevice(getmajor(dev), zv->zv_minor); |
|
119 |
||
120 |
VERIFY(ddi_prop_update_int64(dev, zfs_dip, |
|
121 |
"Size", zv->zv_volsize) == DDI_SUCCESS); |
|
122 |
VERIFY(ddi_prop_update_int64(dev, zfs_dip, |
|
123 |
"Nblocks", lbtodb(zv->zv_volsize)) == DDI_SUCCESS); |
|
124 |
} |
|
125 |
||
126 |
int |
|
2676 | 127 |
zvol_check_volsize(uint64_t volsize, uint64_t blocksize) |
789 | 128 |
{ |
2676 | 129 |
if (volsize == 0) |
789 | 130 |
return (EINVAL); |
131 |
||
2676 | 132 |
if (volsize % blocksize != 0) |
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
133 |
return (EINVAL); |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
134 |
|
789 | 135 |
#ifdef _ILP32 |
2676 | 136 |
if (volsize - 1 > SPEC_MAXOFFSET_T) |
789 | 137 |
return (EOVERFLOW); |
138 |
#endif |
|
139 |
return (0); |
|
140 |
} |
|
141 |
||
142 |
int |
|
2676 | 143 |
zvol_check_volblocksize(uint64_t volblocksize) |
789 | 144 |
{ |
2676 | 145 |
if (volblocksize < SPA_MINBLOCKSIZE || |
146 |
volblocksize > SPA_MAXBLOCKSIZE || |
|
147 |
!ISP2(volblocksize)) |
|
789 | 148 |
return (EDOM); |
149 |
||
150 |
return (0); |
|
151 |
} |
|
152 |
||
153 |
static void |
|
154 |
zvol_readonly_changed_cb(void *arg, uint64_t newval) |
|
155 |
{ |
|
156 |
zvol_state_t *zv = arg; |
|
157 |
||
158 |
zv->zv_readonly = (uint8_t)newval; |
|
159 |
} |
|
160 |
||
161 |
int |
|
2885 | 162 |
zvol_get_stats(objset_t *os, nvlist_t *nv) |
789 | 163 |
{ |
164 |
int error; |
|
165 |
dmu_object_info_t doi; |
|
2885 | 166 |
uint64_t val; |
789 | 167 |
|
168 |
||
2885 | 169 |
error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val); |
789 | 170 |
if (error) |
171 |
return (error); |
|
172 |
||
2885 | 173 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLSIZE, val); |
174 |
||
789 | 175 |
error = dmu_object_info(os, ZVOL_OBJ, &doi); |
176 |
||
2885 | 177 |
if (error == 0) { |
178 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLBLOCKSIZE, |
|
179 |
doi.doi_data_block_size); |
|
180 |
} |
|
789 | 181 |
|
182 |
return (error); |
|
183 |
} |
|
184 |
||
185 |
/* |
|
186 |
* Find a free minor number. |
|
187 |
*/ |
|
188 |
static minor_t |
|
189 |
zvol_minor_alloc(void) |
|
190 |
{ |
|
191 |
minor_t minor; |
|
192 |
||
193 |
ASSERT(MUTEX_HELD(&zvol_state_lock)); |
|
194 |
||
195 |
for (minor = 1; minor <= ZVOL_MAX_MINOR; minor++) |
|
196 |
if (ddi_get_soft_state(zvol_state, minor) == NULL) |
|
197 |
return (minor); |
|
198 |
||
199 |
return (0); |
|
200 |
} |
|
201 |
||
202 |
static zvol_state_t * |
|
2676 | 203 |
zvol_minor_lookup(const char *name) |
789 | 204 |
{ |
205 |
minor_t minor; |
|
206 |
zvol_state_t *zv; |
|
207 |
||
208 |
ASSERT(MUTEX_HELD(&zvol_state_lock)); |
|
209 |
||
210 |
for (minor = 1; minor <= ZVOL_MAX_MINOR; minor++) { |
|
211 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
212 |
if (zv == NULL) |
|
213 |
continue; |
|
214 |
if (strcmp(zv->zv_name, name) == 0) |
|
215 |
break; |
|
216 |
} |
|
217 |
||
218 |
return (zv); |
|
219 |
} |
|
220 |
||
221 |
void |
|
222 |
zvol_create_cb(objset_t *os, void *arg, dmu_tx_t *tx) |
|
223 |
{ |
|
2676 | 224 |
zfs_create_data_t *zc = arg; |
789 | 225 |
int error; |
2676 | 226 |
uint64_t volblocksize, volsize; |
789 | 227 |
|
2676 | 228 |
VERIFY(nvlist_lookup_uint64(zc->zc_props, |
229 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) == 0); |
|
230 |
if (nvlist_lookup_uint64(zc->zc_props, |
|
231 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &volblocksize) != 0) |
|
232 |
volblocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE); |
|
233 |
||
234 |
/* |
|
235 |
* These properites must be removed from the list so the generic |
|
236 |
* property setting step won't apply to them. |
|
237 |
*/ |
|
238 |
VERIFY(nvlist_remove_all(zc->zc_props, |
|
239 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE)) == 0); |
|
240 |
(void) nvlist_remove_all(zc->zc_props, |
|
241 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE)); |
|
242 |
||
243 |
error = dmu_object_claim(os, ZVOL_OBJ, DMU_OT_ZVOL, volblocksize, |
|
789 | 244 |
DMU_OT_NONE, 0, tx); |
245 |
ASSERT(error == 0); |
|
246 |
||
247 |
error = zap_create_claim(os, ZVOL_ZAP_OBJ, DMU_OT_ZVOL_PROP, |
|
248 |
DMU_OT_NONE, 0, tx); |
|
249 |
ASSERT(error == 0); |
|
250 |
||
2676 | 251 |
error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize, tx); |
789 | 252 |
ASSERT(error == 0); |
253 |
} |
|
254 |
||
255 |
/* |
|
1141 | 256 |
* Replay a TX_WRITE ZIL transaction that didn't get committed |
257 |
* after a system failure |
|
258 |
*/ |
|
259 |
static int |
|
260 |
zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap) |
|
261 |
{ |
|
262 |
objset_t *os = zv->zv_objset; |
|
263 |
char *data = (char *)(lr + 1); /* data follows lr_write_t */ |
|
264 |
uint64_t off = lr->lr_offset; |
|
265 |
uint64_t len = lr->lr_length; |
|
266 |
dmu_tx_t *tx; |
|
267 |
int error; |
|
268 |
||
269 |
if (byteswap) |
|
270 |
byteswap_uint64_array(lr, sizeof (*lr)); |
|
271 |
||
272 |
tx = dmu_tx_create(os); |
|
273 |
dmu_tx_hold_write(tx, ZVOL_OBJ, off, len); |
|
274 |
error = dmu_tx_assign(tx, zv->zv_txg_assign); |
|
275 |
if (error) { |
|
276 |
dmu_tx_abort(tx); |
|
277 |
} else { |
|
278 |
dmu_write(os, ZVOL_OBJ, off, len, data, tx); |
|
279 |
dmu_tx_commit(tx); |
|
280 |
} |
|
281 |
||
282 |
return (error); |
|
283 |
} |
|
284 |
||
285 |
/* ARGSUSED */ |
|
286 |
static int |
|
287 |
zvol_replay_err(zvol_state_t *zv, lr_t *lr, boolean_t byteswap) |
|
288 |
{ |
|
289 |
return (ENOTSUP); |
|
290 |
} |
|
291 |
||
292 |
/* |
|
293 |
* Callback vectors for replaying records. |
|
294 |
* Only TX_WRITE is needed for zvol. |
|
295 |
*/ |
|
296 |
zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE] = { |
|
297 |
zvol_replay_err, /* 0 no such transaction type */ |
|
298 |
zvol_replay_err, /* TX_CREATE */ |
|
299 |
zvol_replay_err, /* TX_MKDIR */ |
|
300 |
zvol_replay_err, /* TX_MKXATTR */ |
|
301 |
zvol_replay_err, /* TX_SYMLINK */ |
|
302 |
zvol_replay_err, /* TX_REMOVE */ |
|
303 |
zvol_replay_err, /* TX_RMDIR */ |
|
304 |
zvol_replay_err, /* TX_LINK */ |
|
305 |
zvol_replay_err, /* TX_RENAME */ |
|
306 |
zvol_replay_write, /* TX_WRITE */ |
|
307 |
zvol_replay_err, /* TX_TRUNCATE */ |
|
308 |
zvol_replay_err, /* TX_SETATTR */ |
|
309 |
zvol_replay_err, /* TX_ACL */ |
|
310 |
}; |
|
311 |
||
312 |
/* |
|
789 | 313 |
* Create a minor node for the specified volume. |
314 |
*/ |
|
315 |
int |
|
2676 | 316 |
zvol_create_minor(const char *name, dev_t dev) |
789 | 317 |
{ |
318 |
zvol_state_t *zv; |
|
319 |
objset_t *os; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
320 |
dmu_object_info_t doi; |
789 | 321 |
uint64_t volsize; |
322 |
minor_t minor = 0; |
|
323 |
struct pathname linkpath; |
|
324 |
int ds_mode = DS_MODE_PRIMARY; |
|
325 |
vnode_t *vp = NULL; |
|
326 |
char *devpath; |
|
327 |
size_t devpathlen = strlen(ZVOL_FULL_DEV_DIR) + 1 + strlen(name) + 1; |
|
328 |
char chrbuf[30], blkbuf[30]; |
|
329 |
int error; |
|
330 |
||
331 |
mutex_enter(&zvol_state_lock); |
|
332 |
||
333 |
if ((zv = zvol_minor_lookup(name)) != NULL) { |
|
334 |
mutex_exit(&zvol_state_lock); |
|
335 |
return (EEXIST); |
|
336 |
} |
|
337 |
||
338 |
if (strchr(name, '@') != 0) |
|
339 |
ds_mode |= DS_MODE_READONLY; |
|
340 |
||
341 |
error = dmu_objset_open(name, DMU_OST_ZVOL, ds_mode, &os); |
|
342 |
||
343 |
if (error) { |
|
344 |
mutex_exit(&zvol_state_lock); |
|
345 |
return (error); |
|
346 |
} |
|
347 |
||
348 |
error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize); |
|
349 |
||
350 |
if (error) { |
|
351 |
dmu_objset_close(os); |
|
352 |
mutex_exit(&zvol_state_lock); |
|
353 |
return (error); |
|
354 |
} |
|
355 |
||
356 |
/* |
|
357 |
* If there's an existing /dev/zvol symlink, try to use the |
|
358 |
* same minor number we used last time. |
|
359 |
*/ |
|
360 |
devpath = kmem_alloc(devpathlen, KM_SLEEP); |
|
361 |
||
362 |
(void) sprintf(devpath, "%s/%s", ZVOL_FULL_DEV_DIR, name); |
|
363 |
||
364 |
error = lookupname(devpath, UIO_SYSSPACE, NO_FOLLOW, NULL, &vp); |
|
365 |
||
366 |
kmem_free(devpath, devpathlen); |
|
367 |
||
368 |
if (error == 0 && vp->v_type != VLNK) |
|
369 |
error = EINVAL; |
|
370 |
||
371 |
if (error == 0) { |
|
372 |
pn_alloc(&linkpath); |
|
373 |
error = pn_getsymlink(vp, &linkpath, kcred); |
|
374 |
if (error == 0) { |
|
375 |
char *ms = strstr(linkpath.pn_path, ZVOL_PSEUDO_DEV); |
|
376 |
if (ms != NULL) { |
|
377 |
ms += strlen(ZVOL_PSEUDO_DEV); |
|
378 |
minor = stoi(&ms); |
|
379 |
} |
|
380 |
} |
|
381 |
pn_free(&linkpath); |
|
382 |
} |
|
383 |
||
384 |
if (vp != NULL) |
|
385 |
VN_RELE(vp); |
|
386 |
||
387 |
/* |
|
388 |
* If we found a minor but it's already in use, we must pick a new one. |
|
389 |
*/ |
|
390 |
if (minor != 0 && ddi_get_soft_state(zvol_state, minor) != NULL) |
|
391 |
minor = 0; |
|
392 |
||
393 |
if (minor == 0) |
|
394 |
minor = zvol_minor_alloc(); |
|
395 |
||
396 |
if (minor == 0) { |
|
397 |
dmu_objset_close(os); |
|
398 |
mutex_exit(&zvol_state_lock); |
|
399 |
return (ENXIO); |
|
400 |
} |
|
401 |
||
402 |
if (ddi_soft_state_zalloc(zvol_state, minor) != DDI_SUCCESS) { |
|
403 |
dmu_objset_close(os); |
|
404 |
mutex_exit(&zvol_state_lock); |
|
405 |
return (EAGAIN); |
|
406 |
} |
|
407 |
||
2676 | 408 |
(void) ddi_prop_update_string(minor, zfs_dip, ZVOL_PROP_NAME, |
409 |
(char *)name); |
|
789 | 410 |
|
411 |
(void) sprintf(chrbuf, "%uc,raw", minor); |
|
412 |
||
413 |
if (ddi_create_minor_node(zfs_dip, chrbuf, S_IFCHR, |
|
414 |
minor, DDI_PSEUDO, 0) == DDI_FAILURE) { |
|
415 |
ddi_soft_state_free(zvol_state, minor); |
|
416 |
dmu_objset_close(os); |
|
417 |
mutex_exit(&zvol_state_lock); |
|
418 |
return (EAGAIN); |
|
419 |
} |
|
420 |
||
421 |
(void) sprintf(blkbuf, "%uc", minor); |
|
422 |
||
423 |
if (ddi_create_minor_node(zfs_dip, blkbuf, S_IFBLK, |
|
424 |
minor, DDI_PSEUDO, 0) == DDI_FAILURE) { |
|
425 |
ddi_remove_minor_node(zfs_dip, chrbuf); |
|
426 |
ddi_soft_state_free(zvol_state, minor); |
|
427 |
dmu_objset_close(os); |
|
428 |
mutex_exit(&zvol_state_lock); |
|
429 |
return (EAGAIN); |
|
430 |
} |
|
431 |
||
432 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
433 |
||
434 |
(void) strcpy(zv->zv_name, name); |
|
435 |
zv->zv_min_bs = DEV_BSHIFT; |
|
436 |
zv->zv_minor = minor; |
|
437 |
zv->zv_volsize = volsize; |
|
438 |
zv->zv_objset = os; |
|
439 |
zv->zv_mode = ds_mode; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
440 |
zv->zv_zilog = zil_open(os, zvol_get_data); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
441 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
442 |
/* get and cache the blocksize */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
443 |
error = dmu_object_info(os, ZVOL_OBJ, &doi); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
444 |
ASSERT(error == 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
445 |
zv->zv_volblocksize = doi.doi_data_block_size; |
1141 | 446 |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
447 |
rw_init(&zv->zv_dslock, NULL, RW_DEFAULT, NULL); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
448 |
|
1141 | 449 |
zil_replay(os, zv, &zv->zv_txg_assign, zvol_replay_vector, NULL); |
789 | 450 |
|
451 |
zvol_size_changed(zv, dev); |
|
452 |
||
1544 | 453 |
/* XXX this should handle the possible i/o error */ |
789 | 454 |
VERIFY(dsl_prop_register(dmu_objset_ds(zv->zv_objset), |
455 |
"readonly", zvol_readonly_changed_cb, zv) == 0); |
|
456 |
||
457 |
zvol_minors++; |
|
458 |
||
459 |
mutex_exit(&zvol_state_lock); |
|
460 |
||
461 |
return (0); |
|
462 |
} |
|
463 |
||
464 |
/* |
|
465 |
* Remove minor node for the specified volume. |
|
466 |
*/ |
|
467 |
int |
|
2676 | 468 |
zvol_remove_minor(const char *name) |
789 | 469 |
{ |
470 |
zvol_state_t *zv; |
|
471 |
char namebuf[30]; |
|
472 |
||
473 |
mutex_enter(&zvol_state_lock); |
|
474 |
||
2676 | 475 |
if ((zv = zvol_minor_lookup(name)) == NULL) { |
789 | 476 |
mutex_exit(&zvol_state_lock); |
477 |
return (ENXIO); |
|
478 |
} |
|
479 |
||
480 |
if (zv->zv_total_opens != 0) { |
|
481 |
mutex_exit(&zvol_state_lock); |
|
482 |
return (EBUSY); |
|
483 |
} |
|
484 |
||
485 |
(void) sprintf(namebuf, "%uc,raw", zv->zv_minor); |
|
486 |
ddi_remove_minor_node(zfs_dip, namebuf); |
|
487 |
||
488 |
(void) sprintf(namebuf, "%uc", zv->zv_minor); |
|
489 |
ddi_remove_minor_node(zfs_dip, namebuf); |
|
490 |
||
491 |
VERIFY(dsl_prop_unregister(dmu_objset_ds(zv->zv_objset), |
|
492 |
"readonly", zvol_readonly_changed_cb, zv) == 0); |
|
493 |
||
1141 | 494 |
zil_close(zv->zv_zilog); |
495 |
zv->zv_zilog = NULL; |
|
789 | 496 |
dmu_objset_close(zv->zv_objset); |
497 |
zv->zv_objset = NULL; |
|
498 |
||
499 |
ddi_soft_state_free(zvol_state, zv->zv_minor); |
|
500 |
||
501 |
zvol_minors--; |
|
502 |
||
503 |
mutex_exit(&zvol_state_lock); |
|
504 |
||
505 |
return (0); |
|
506 |
} |
|
507 |
||
508 |
int |
|
2676 | 509 |
zvol_set_volsize(const char *name, dev_t dev, uint64_t volsize) |
789 | 510 |
{ |
511 |
zvol_state_t *zv; |
|
512 |
dmu_tx_t *tx; |
|
513 |
int error; |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
514 |
dmu_object_info_t doi; |
789 | 515 |
|
516 |
mutex_enter(&zvol_state_lock); |
|
517 |
||
2676 | 518 |
if ((zv = zvol_minor_lookup(name)) == NULL) { |
789 | 519 |
mutex_exit(&zvol_state_lock); |
520 |
return (ENXIO); |
|
521 |
} |
|
522 |
||
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
523 |
if ((error = dmu_object_info(zv->zv_objset, ZVOL_OBJ, &doi)) != 0 || |
2676 | 524 |
(error = zvol_check_volsize(volsize, |
525 |
doi.doi_data_block_size)) != 0) { |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
526 |
mutex_exit(&zvol_state_lock); |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
527 |
return (error); |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
528 |
} |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
529 |
|
789 | 530 |
if (zv->zv_readonly || (zv->zv_mode & DS_MODE_READONLY)) { |
531 |
mutex_exit(&zvol_state_lock); |
|
532 |
return (EROFS); |
|
533 |
} |
|
534 |
||
535 |
tx = dmu_tx_create(zv->zv_objset); |
|
1544 | 536 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
2676 | 537 |
dmu_tx_hold_free(tx, ZVOL_OBJ, volsize, DMU_OBJECT_END); |
789 | 538 |
error = dmu_tx_assign(tx, TXG_WAIT); |
539 |
if (error) { |
|
540 |
dmu_tx_abort(tx); |
|
541 |
mutex_exit(&zvol_state_lock); |
|
542 |
return (error); |
|
543 |
} |
|
544 |
||
545 |
error = zap_update(zv->zv_objset, ZVOL_ZAP_OBJ, "size", 8, 1, |
|
2676 | 546 |
&volsize, tx); |
1544 | 547 |
if (error == 0) { |
2676 | 548 |
error = dmu_free_range(zv->zv_objset, ZVOL_OBJ, volsize, |
789 | 549 |
DMU_OBJECT_END, tx); |
1544 | 550 |
} |
789 | 551 |
|
552 |
dmu_tx_commit(tx); |
|
553 |
||
554 |
if (error == 0) { |
|
2676 | 555 |
zv->zv_volsize = volsize; |
789 | 556 |
zvol_size_changed(zv, dev); |
557 |
} |
|
558 |
||
559 |
mutex_exit(&zvol_state_lock); |
|
560 |
||
561 |
return (error); |
|
562 |
} |
|
563 |
||
564 |
int |
|
2676 | 565 |
zvol_set_volblocksize(const char *name, uint64_t volblocksize) |
789 | 566 |
{ |
567 |
zvol_state_t *zv; |
|
568 |
dmu_tx_t *tx; |
|
569 |
int error; |
|
570 |
||
571 |
mutex_enter(&zvol_state_lock); |
|
572 |
||
2676 | 573 |
if ((zv = zvol_minor_lookup(name)) == NULL) { |
789 | 574 |
mutex_exit(&zvol_state_lock); |
575 |
return (ENXIO); |
|
576 |
} |
|
577 |
||
578 |
if (zv->zv_readonly || (zv->zv_mode & DS_MODE_READONLY)) { |
|
579 |
mutex_exit(&zvol_state_lock); |
|
580 |
return (EROFS); |
|
581 |
} |
|
582 |
||
583 |
tx = dmu_tx_create(zv->zv_objset); |
|
584 |
dmu_tx_hold_bonus(tx, ZVOL_OBJ); |
|
585 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
586 |
if (error) { |
|
587 |
dmu_tx_abort(tx); |
|
588 |
} else { |
|
589 |
error = dmu_object_set_blocksize(zv->zv_objset, ZVOL_OBJ, |
|
2676 | 590 |
volblocksize, 0, tx); |
789 | 591 |
if (error == ENOTSUP) |
592 |
error = EBUSY; |
|
593 |
dmu_tx_commit(tx); |
|
594 |
} |
|
595 |
||
596 |
mutex_exit(&zvol_state_lock); |
|
597 |
||
598 |
return (error); |
|
599 |
} |
|
600 |
||
601 |
/*ARGSUSED*/ |
|
602 |
int |
|
603 |
zvol_open(dev_t *devp, int flag, int otyp, cred_t *cr) |
|
604 |
{ |
|
605 |
minor_t minor = getminor(*devp); |
|
606 |
zvol_state_t *zv; |
|
607 |
||
608 |
if (minor == 0) /* This is the control device */ |
|
609 |
return (0); |
|
610 |
||
611 |
mutex_enter(&zvol_state_lock); |
|
612 |
||
613 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
614 |
if (zv == NULL) { |
|
615 |
mutex_exit(&zvol_state_lock); |
|
616 |
return (ENXIO); |
|
617 |
} |
|
618 |
||
619 |
ASSERT(zv->zv_objset != NULL); |
|
620 |
||
621 |
if ((flag & FWRITE) && |
|
622 |
(zv->zv_readonly || (zv->zv_mode & DS_MODE_READONLY))) { |
|
623 |
mutex_exit(&zvol_state_lock); |
|
624 |
return (EROFS); |
|
625 |
} |
|
626 |
||
627 |
if (zv->zv_open_count[otyp] == 0 || otyp == OTYP_LYR) { |
|
628 |
zv->zv_open_count[otyp]++; |
|
629 |
zv->zv_total_opens++; |
|
630 |
} |
|
631 |
||
632 |
mutex_exit(&zvol_state_lock); |
|
633 |
||
634 |
return (0); |
|
635 |
} |
|
636 |
||
637 |
/*ARGSUSED*/ |
|
638 |
int |
|
639 |
zvol_close(dev_t dev, int flag, int otyp, cred_t *cr) |
|
640 |
{ |
|
641 |
minor_t minor = getminor(dev); |
|
642 |
zvol_state_t *zv; |
|
643 |
||
644 |
if (minor == 0) /* This is the control device */ |
|
645 |
return (0); |
|
646 |
||
647 |
mutex_enter(&zvol_state_lock); |
|
648 |
||
649 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
650 |
if (zv == NULL) { |
|
651 |
mutex_exit(&zvol_state_lock); |
|
652 |
return (ENXIO); |
|
653 |
} |
|
654 |
||
655 |
/* |
|
656 |
* The next statement is a workaround for the following DDI bug: |
|
657 |
* 6343604 specfs race: multiple "last-close" of the same device |
|
658 |
*/ |
|
659 |
if (zv->zv_total_opens == 0) { |
|
660 |
mutex_exit(&zvol_state_lock); |
|
661 |
return (0); |
|
662 |
} |
|
663 |
||
664 |
/* |
|
665 |
* If the open count is zero, this is a spurious close. |
|
666 |
* That indicates a bug in the kernel / DDI framework. |
|
667 |
*/ |
|
668 |
ASSERT(zv->zv_open_count[otyp] != 0); |
|
669 |
ASSERT(zv->zv_total_opens != 0); |
|
670 |
||
671 |
/* |
|
672 |
* You may get multiple opens, but only one close. |
|
673 |
*/ |
|
674 |
zv->zv_open_count[otyp]--; |
|
675 |
zv->zv_total_opens--; |
|
676 |
||
677 |
mutex_exit(&zvol_state_lock); |
|
678 |
||
679 |
return (0); |
|
680 |
} |
|
681 |
||
1141 | 682 |
/* |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
683 |
* Create and return an immediate write ZIL transaction. |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
684 |
*/ |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
685 |
itx_t * |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
686 |
zvol_immediate_itx(offset_t off, ssize_t len, char *addr) |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
687 |
{ |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
688 |
itx_t *itx; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
689 |
lr_write_t *lr; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
690 |
|
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
691 |
itx = zil_itx_create(TX_WRITE, sizeof (*lr) + len); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
692 |
lr = (lr_write_t *)&itx->itx_lr; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
693 |
lr->lr_foid = ZVOL_OBJ; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
694 |
lr->lr_offset = off; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
695 |
lr->lr_length = len; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
696 |
lr->lr_blkoff = 0; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
697 |
BP_ZERO(&lr->lr_blkptr); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
698 |
bcopy(addr, (char *)itx + offsetof(itx_t, itx_lr) + |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
699 |
sizeof (*lr), len); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
700 |
itx->itx_wr_state = WR_COPIED; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
701 |
return (itx); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
702 |
} |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
703 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
704 |
void |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
705 |
zvol_get_done(dmu_buf_t *db, void *vzgd) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
706 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
707 |
zgd_t *zgd = (zgd_t *)vzgd; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
708 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
709 |
dmu_buf_rele(db, vzgd); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
710 |
zil_add_vdev(zgd->zgd_zilog, DVA_GET_VDEV(BP_IDENTITY(zgd->zgd_bp))); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
711 |
kmem_free(zgd, sizeof (zgd_t)); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
712 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
713 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
714 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
715 |
* Get data to generate a TX_WRITE intent log record. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
716 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
717 |
int |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
718 |
zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
719 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
720 |
zvol_state_t *zv = arg; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
721 |
objset_t *os = zv->zv_objset; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
722 |
dmu_buf_t *db; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
723 |
zgd_t *zgd; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
724 |
int dlen = lr->lr_length; /* length of user data */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
725 |
int error; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
726 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
727 |
ASSERT(zio); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
728 |
ASSERT(dlen != 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
729 |
ASSERT(buf == NULL); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
730 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
731 |
zgd = (zgd_t *)kmem_alloc(sizeof (zgd_t), KM_SLEEP); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
732 |
zgd->zgd_zilog = zv->zv_zilog; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
733 |
zgd->zgd_bp = &lr->lr_blkptr; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
734 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
735 |
VERIFY(0 == dmu_buf_hold(os, ZVOL_OBJ, lr->lr_offset, zgd, &db)); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
736 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
737 |
* Have to lock to ensure when when the data is |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
738 |
* written out and it's checksum is being calculated |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
739 |
* that no one can change the data. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
740 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
741 |
rw_enter(&zv->zv_dslock, RW_READER); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
742 |
error = dmu_sync(zio, db, &lr->lr_blkptr, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
743 |
lr->lr_common.lrc_txg, zvol_get_done, zgd); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
744 |
rw_exit(&zv->zv_dslock); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
745 |
if (error == 0) { |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
746 |
zil_add_vdev(zv->zv_zilog, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
747 |
DVA_GET_VDEV(BP_IDENTITY(&lr->lr_blkptr))); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
748 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
749 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
750 |
* If we get EINPROGRESS, then we need to wait for a |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
751 |
* write IO initiated by dmu_sync() to complete before |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
752 |
* we can release this dbuf. We will finish everything |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
753 |
* up in the zvol_get_done() callback. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
754 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
755 |
if (error == EINPROGRESS) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
756 |
return (0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
757 |
dmu_buf_rele(db, zgd); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
758 |
kmem_free(zgd, sizeof (zgd_t)); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
759 |
return (error); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
760 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
761 |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
762 |
/* |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
763 |
* zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions. |
1141 | 764 |
* |
765 |
* We store data in the log buffers if it's small enough. |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
766 |
* Otherwise we will later flush the data out via dmu_sync(). |
1141 | 767 |
*/ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
768 |
ssize_t zvol_immediate_write_sz = 32768; |
1141 | 769 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
770 |
void |
1141 | 771 |
zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, offset_t off, ssize_t len, |
772 |
char *addr) |
|
773 |
{ |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
774 |
ssize_t nbytes; |
1141 | 775 |
itx_t *itx; |
776 |
lr_write_t *lr; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
777 |
zilog_t *zilog = zv->zv_zilog; |
2237 | 778 |
uint64_t boff; |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
779 |
uint32_t blocksize; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
780 |
|
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
781 |
/* handle common case */ |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
782 |
if (len <= zvol_immediate_write_sz) { |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
783 |
itx = zvol_immediate_itx(off, len, addr); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
784 |
(void) zil_itx_assign(zilog, itx, tx); |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
785 |
} |
1141 | 786 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
787 |
blocksize = zv->zv_volblocksize; |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
788 |
|
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
789 |
while (len) { |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
790 |
nbytes = MIN(len, blocksize - P2PHASE(off, blocksize)); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
791 |
if (nbytes <= zvol_immediate_write_sz) { |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
792 |
itx = zvol_immediate_itx(off, nbytes, addr); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
793 |
} else { |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
794 |
boff = P2ALIGN_TYPED(off, blocksize, uint64_t); |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
795 |
itx = zil_itx_create(TX_WRITE, sizeof (*lr)); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
796 |
itx->itx_wr_state = WR_INDIRECT; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
797 |
itx->itx_private = zv; |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
798 |
lr = (lr_write_t *)&itx->itx_lr; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
799 |
lr->lr_foid = ZVOL_OBJ; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
800 |
lr->lr_offset = off; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
801 |
lr->lr_length = nbytes; |
2237 | 802 |
lr->lr_blkoff = off - boff; |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
803 |
BP_ZERO(&lr->lr_blkptr); |
1141 | 804 |
} |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
805 |
(void) zil_itx_assign(zilog, itx, tx); |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
806 |
len -= nbytes; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
807 |
off += nbytes; |
1141 | 808 |
} |
809 |
} |
|
810 |
||
789 | 811 |
int |
812 |
zvol_strategy(buf_t *bp) |
|
813 |
{ |
|
814 |
zvol_state_t *zv = ddi_get_soft_state(zvol_state, getminor(bp->b_edev)); |
|
815 |
uint64_t off, volsize; |
|
816 |
size_t size, resid; |
|
817 |
char *addr; |
|
1141 | 818 |
objset_t *os; |
789 | 819 |
int error = 0; |
1141 | 820 |
int sync; |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
821 |
int reading; |
789 | 822 |
|
823 |
if (zv == NULL) { |
|
824 |
bioerror(bp, ENXIO); |
|
825 |
biodone(bp); |
|
826 |
return (0); |
|
827 |
} |
|
828 |
||
829 |
if (getminor(bp->b_edev) == 0) { |
|
830 |
bioerror(bp, EINVAL); |
|
831 |
biodone(bp); |
|
832 |
return (0); |
|
833 |
} |
|
834 |
||
2885 | 835 |
if ((zv->zv_readonly || (zv->zv_mode & DS_MODE_READONLY)) && |
836 |
!(bp->b_flags & B_READ)) { |
|
789 | 837 |
bioerror(bp, EROFS); |
838 |
biodone(bp); |
|
839 |
return (0); |
|
840 |
} |
|
841 |
||
842 |
off = ldbtob(bp->b_blkno); |
|
843 |
volsize = zv->zv_volsize; |
|
844 |
||
1141 | 845 |
os = zv->zv_objset; |
846 |
ASSERT(os != NULL); |
|
847 |
sync = !(bp->b_flags & B_ASYNC) && !(zil_disable); |
|
789 | 848 |
|
849 |
bp_mapin(bp); |
|
850 |
addr = bp->b_un.b_addr; |
|
851 |
resid = bp->b_bcount; |
|
852 |
||
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
853 |
/* |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
854 |
* There must be no buffer changes when doing a dmu_sync() because |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
855 |
* we can't change the data whilst calculating the checksum. |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
856 |
* A better approach than a per zvol rwlock would be to lock ranges. |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
857 |
*/ |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
858 |
reading = bp->b_flags & B_READ; |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
859 |
if (reading || resid <= zvol_immediate_write_sz) |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
860 |
rw_enter(&zv->zv_dslock, RW_READER); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
861 |
else |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
862 |
rw_enter(&zv->zv_dslock, RW_WRITER); |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
863 |
|
789 | 864 |
while (resid != 0 && off < volsize) { |
865 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
866 |
size = MIN(resid, zvol_maxphys); /* zvol_maxphys per tx */ |
789 | 867 |
|
868 |
if (size > volsize - off) /* don't write past the end */ |
|
869 |
size = volsize - off; |
|
870 |
||
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
871 |
if (reading) { |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
872 |
error = dmu_read(os, ZVOL_OBJ, off, size, addr); |
789 | 873 |
} else { |
1141 | 874 |
dmu_tx_t *tx = dmu_tx_create(os); |
789 | 875 |
dmu_tx_hold_write(tx, ZVOL_OBJ, off, size); |
876 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
877 |
if (error) { |
|
878 |
dmu_tx_abort(tx); |
|
879 |
} else { |
|
1141 | 880 |
dmu_write(os, ZVOL_OBJ, off, size, addr, tx); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
881 |
/* add a log write transaction */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
882 |
if (sync) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
883 |
zvol_log_write(zv, tx, off, size, addr); |
789 | 884 |
dmu_tx_commit(tx); |
885 |
} |
|
886 |
} |
|
887 |
if (error) |
|
888 |
break; |
|
889 |
off += size; |
|
890 |
addr += size; |
|
891 |
resid -= size; |
|
892 |
} |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
893 |
rw_exit(&zv->zv_dslock); |
789 | 894 |
|
895 |
if ((bp->b_resid = resid) == bp->b_bcount) |
|
896 |
bioerror(bp, off > volsize ? EINVAL : error); |
|
897 |
||
898 |
biodone(bp); |
|
1141 | 899 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
900 |
if (sync) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
901 |
zil_commit(zv->zv_zilog, UINT64_MAX, 0); |
1141 | 902 |
|
789 | 903 |
return (0); |
904 |
} |
|
905 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
906 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
907 |
* Set the buffer count to the zvol maximum transfer. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
908 |
* Using our own routine instead of the default minphys() |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
909 |
* means that for larger writes we write bigger buffers on X86 |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
910 |
* (128K instead of 56K) and flush the disk write cache less often |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
911 |
* (every zvol_maxphys - currently 1MB) instead of minphys (currently |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
912 |
* 56K on X86 and 128K on sparc). |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
913 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
914 |
void |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
915 |
zvol_minphys(struct buf *bp) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
916 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
917 |
if (bp->b_bcount > zvol_maxphys) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
918 |
bp->b_bcount = zvol_maxphys; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
919 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
920 |
|
789 | 921 |
/*ARGSUSED*/ |
922 |
int |
|
923 |
zvol_read(dev_t dev, uio_t *uiop, cred_t *cr) |
|
924 |
{ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
925 |
return (physio(zvol_strategy, NULL, dev, B_READ, zvol_minphys, uiop)); |
789 | 926 |
} |
927 |
||
928 |
/*ARGSUSED*/ |
|
929 |
int |
|
930 |
zvol_write(dev_t dev, uio_t *uiop, cred_t *cr) |
|
931 |
{ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
932 |
return (physio(zvol_strategy, NULL, dev, B_WRITE, zvol_minphys, uiop)); |
789 | 933 |
} |
934 |
||
935 |
/*ARGSUSED*/ |
|
936 |
int |
|
937 |
zvol_aread(dev_t dev, struct aio_req *aio, cred_t *cr) |
|
938 |
{ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
939 |
return (aphysio(zvol_strategy, anocancel, dev, B_READ, zvol_minphys, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
940 |
aio)); |
789 | 941 |
} |
942 |
||
943 |
/*ARGSUSED*/ |
|
944 |
int |
|
945 |
zvol_awrite(dev_t dev, struct aio_req *aio, cred_t *cr) |
|
946 |
{ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
947 |
return (aphysio(zvol_strategy, anocancel, dev, B_WRITE, zvol_minphys, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
948 |
aio)); |
789 | 949 |
} |
950 |
||
951 |
/* |
|
952 |
* Dirtbag ioctls to support mkfs(1M) for UFS filesystems. See dkio(7I). |
|
953 |
*/ |
|
954 |
/*ARGSUSED*/ |
|
955 |
int |
|
956 |
zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) |
|
957 |
{ |
|
958 |
zvol_state_t *zv; |
|
959 |
struct dk_cinfo dkc; |
|
960 |
struct dk_minfo dkm; |
|
961 |
dk_efi_t efi; |
|
962 |
struct uuid uuid = EFI_RESERVED; |
|
963 |
uint32_t crc; |
|
964 |
int error = 0; |
|
965 |
||
966 |
mutex_enter(&zvol_state_lock); |
|
967 |
||
968 |
zv = ddi_get_soft_state(zvol_state, getminor(dev)); |
|
969 |
||
970 |
if (zv == NULL) { |
|
971 |
mutex_exit(&zvol_state_lock); |
|
972 |
return (ENXIO); |
|
973 |
} |
|
974 |
||
975 |
switch (cmd) { |
|
976 |
||
977 |
case DKIOCINFO: |
|
978 |
bzero(&dkc, sizeof (dkc)); |
|
979 |
(void) strcpy(dkc.dki_cname, "zvol"); |
|
980 |
(void) strcpy(dkc.dki_dname, "zvol"); |
|
981 |
dkc.dki_ctype = DKC_UNKNOWN; |
|
1357
46e683ebd8ea
6367517 32-bit kernel VA exhaustion with logging ufs atop zvol
bonwick
parents:
1356
diff
changeset
|
982 |
dkc.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs); |
789 | 983 |
mutex_exit(&zvol_state_lock); |
984 |
if (ddi_copyout(&dkc, (void *)arg, sizeof (dkc), flag)) |
|
985 |
error = EFAULT; |
|
986 |
return (error); |
|
987 |
||
988 |
case DKIOCGMEDIAINFO: |
|
989 |
bzero(&dkm, sizeof (dkm)); |
|
990 |
dkm.dki_lbsize = 1U << zv->zv_min_bs; |
|
991 |
dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs; |
|
992 |
dkm.dki_media_type = DK_UNKNOWN; |
|
993 |
mutex_exit(&zvol_state_lock); |
|
994 |
if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag)) |
|
995 |
error = EFAULT; |
|
996 |
return (error); |
|
997 |
||
998 |
case DKIOCGETEFI: |
|
999 |
if (ddi_copyin((void *)arg, &efi, sizeof (dk_efi_t), flag)) { |
|
1000 |
mutex_exit(&zvol_state_lock); |
|
1001 |
return (EFAULT); |
|
1002 |
} |
|
1003 |
efi.dki_data = (void *)(uintptr_t)efi.dki_data_64; |
|
1004 |
||
3016 | 1005 |
/* |
1006 |
* Some clients may attempt to request a PMBR for the |
|
1007 |
* zvol. Currently this interface will return ENOTTY to |
|
1008 |
* such requests. These requests could be supported by |
|
1009 |
* adding a check for lba == 0 and consing up an appropriate |
|
1010 |
* RMBR. |
|
1011 |
*/ |
|
1012 |
if (efi.dki_lba == 1) { |
|
1013 |
efi_gpt_t gpt; |
|
1014 |
efi_gpe_t gpe; |
|
1015 |
||
1016 |
bzero(&gpt, sizeof (gpt)); |
|
1017 |
bzero(&gpe, sizeof (gpe)); |
|
789 | 1018 |
|
3016 | 1019 |
if (efi.dki_length < sizeof (gpt)) { |
1020 |
mutex_exit(&zvol_state_lock); |
|
1021 |
return (EINVAL); |
|
1022 |
} |
|
1023 |
||
1024 |
gpt.efi_gpt_Signature = LE_64(EFI_SIGNATURE); |
|
1025 |
gpt.efi_gpt_Revision = LE_32(EFI_VERSION_CURRENT); |
|
1026 |
gpt.efi_gpt_HeaderSize = LE_32(sizeof (gpt)); |
|
1027 |
gpt.efi_gpt_FirstUsableLBA = LE_64(34ULL); |
|
1028 |
gpt.efi_gpt_LastUsableLBA = |
|
1029 |
LE_64((zv->zv_volsize >> zv->zv_min_bs) - 1); |
|
1030 |
gpt.efi_gpt_NumberOfPartitionEntries = LE_32(1); |
|
3080
deef42200cee
6490291 Unable to newfs zvols, returns exit code of 32.
maybee
parents:
3063
diff
changeset
|
1031 |
gpt.efi_gpt_PartitionEntryLBA = LE_64(2ULL); |
3016 | 1032 |
gpt.efi_gpt_SizeOfPartitionEntry = LE_32(sizeof (gpe)); |
789 | 1033 |
|
3016 | 1034 |
UUID_LE_CONVERT(gpe.efi_gpe_PartitionTypeGUID, uuid); |
1035 |
gpe.efi_gpe_StartingLBA = gpt.efi_gpt_FirstUsableLBA; |
|
1036 |
gpe.efi_gpe_EndingLBA = gpt.efi_gpt_LastUsableLBA; |
|
1037 |
||
1038 |
CRC32(crc, &gpe, sizeof (gpe), -1U, crc32_table); |
|
1039 |
gpt.efi_gpt_PartitionEntryArrayCRC32 = LE_32(~crc); |
|
1040 |
||
1041 |
CRC32(crc, &gpt, sizeof (gpt), -1U, crc32_table); |
|
1042 |
gpt.efi_gpt_HeaderCRC32 = LE_32(~crc); |
|
1043 |
||
1044 |
mutex_exit(&zvol_state_lock); |
|
1045 |
if (ddi_copyout(&gpt, efi.dki_data, sizeof (gpt), flag)) |
|
1046 |
error = EFAULT; |
|
1047 |
} else if (efi.dki_lba == 2) { |
|
1048 |
efi_gpe_t gpe; |
|
1049 |
||
1050 |
bzero(&gpe, sizeof (gpe)); |
|
789 | 1051 |
|
3016 | 1052 |
if (efi.dki_length < sizeof (gpe)) { |
1053 |
mutex_exit(&zvol_state_lock); |
|
1054 |
return (EINVAL); |
|
1055 |
} |
|
789 | 1056 |
|
3016 | 1057 |
UUID_LE_CONVERT(gpe.efi_gpe_PartitionTypeGUID, uuid); |
1058 |
gpe.efi_gpe_StartingLBA = LE_64(34ULL); |
|
1059 |
gpe.efi_gpe_EndingLBA = |
|
1060 |
LE_64((zv->zv_volsize >> zv->zv_min_bs) - 1); |
|
789 | 1061 |
|
3016 | 1062 |
mutex_exit(&zvol_state_lock); |
1063 |
if (ddi_copyout(&gpe, efi.dki_data, sizeof (gpe), flag)) |
|
1064 |
error = EFAULT; |
|
1065 |
} else { |
|
1066 |
mutex_exit(&zvol_state_lock); |
|
1067 |
error = EINVAL; |
|
1068 |
} |
|
789 | 1069 |
return (error); |
1070 |
||
1071 |
default: |
|
3016 | 1072 |
error = ENOTTY; |
789 | 1073 |
break; |
1074 |
||
1075 |
} |
|
1076 |
mutex_exit(&zvol_state_lock); |
|
1077 |
return (error); |
|
1078 |
} |
|
1079 |
||
1080 |
int |
|
1081 |
zvol_busy(void) |
|
1082 |
{ |
|
1083 |
return (zvol_minors != 0); |
|
1084 |
} |
|
1085 |
||
1086 |
void |
|
1087 |
zvol_init(void) |
|
1088 |
{ |
|
1089 |
VERIFY(ddi_soft_state_init(&zvol_state, sizeof (zvol_state_t), 1) == 0); |
|
1090 |
mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL); |
|
1091 |
} |
|
1092 |
||
1093 |
void |
|
1094 |
zvol_fini(void) |
|
1095 |
{ |
|
1096 |
mutex_destroy(&zvol_state_lock); |
|
1097 |
ddi_soft_state_fini(&zvol_state); |
|
1098 |
} |