author | Chris Kirby <Chris.Kirby@oracle.com> |
Thu, 10 Jun 2010 15:46:47 -0600 | |
changeset 12605 | 6790e683d5a5 |
parent 12527 | 693dd2cad55f |
child 12699 | 36aebb51164a |
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 |
/* |
|
12095
6596d5361407
6891449 zvol_strategy() check for zv == NULL too late
Chris Kirby <Chris.Kirby@sun.com>
parents:
11806
diff
changeset
|
22 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
789 | 23 |
*/ |
24 |
||
12294
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
25 |
/* Portions Copyright 2010 Robert Milkowski */ |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
26 |
|
789 | 27 |
/* |
28 |
* ZFS volume emulation driver. |
|
29 |
* |
|
30 |
* Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes. |
|
31 |
* Volumes are accessed through the symbolic links named: |
|
32 |
* |
|
33 |
* /dev/zvol/dsk/<pool_name>/<dataset_name> |
|
34 |
* /dev/zvol/rdsk/<pool_name>/<dataset_name> |
|
35 |
* |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
36 |
* These links are created by the /dev filesystem (sdev_zvolops.c). |
789 | 37 |
* Volumes are persistent through reboot. No user command needs to be |
38 |
* run before opening and using a device. |
|
39 |
*/ |
|
40 |
||
41 |
#include <sys/types.h> |
|
42 |
#include <sys/param.h> |
|
43 |
#include <sys/errno.h> |
|
44 |
#include <sys/uio.h> |
|
45 |
#include <sys/buf.h> |
|
46 |
#include <sys/modctl.h> |
|
47 |
#include <sys/open.h> |
|
48 |
#include <sys/kmem.h> |
|
49 |
#include <sys/conf.h> |
|
50 |
#include <sys/cmn_err.h> |
|
51 |
#include <sys/stat.h> |
|
52 |
#include <sys/zap.h> |
|
53 |
#include <sys/spa.h> |
|
54 |
#include <sys/zio.h> |
|
6423 | 55 |
#include <sys/dmu_traverse.h> |
56 |
#include <sys/dnode.h> |
|
57 |
#include <sys/dsl_dataset.h> |
|
789 | 58 |
#include <sys/dsl_prop.h> |
59 |
#include <sys/dkio.h> |
|
60 |
#include <sys/efi_partition.h> |
|
61 |
#include <sys/byteorder.h> |
|
62 |
#include <sys/pathname.h> |
|
63 |
#include <sys/ddi.h> |
|
64 |
#include <sys/sunddi.h> |
|
65 |
#include <sys/crc32.h> |
|
66 |
#include <sys/dirent.h> |
|
67 |
#include <sys/policy.h> |
|
68 |
#include <sys/fs/zfs.h> |
|
69 |
#include <sys/zfs_ioctl.h> |
|
70 |
#include <sys/mkdev.h> |
|
1141 | 71 |
#include <sys/zil.h> |
2237 | 72 |
#include <sys/refcount.h> |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
73 |
#include <sys/zfs_znode.h> |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
74 |
#include <sys/zfs_rlock.h> |
6423 | 75 |
#include <sys/vdev_disk.h> |
76 |
#include <sys/vdev_impl.h> |
|
77 |
#include <sys/zvol.h> |
|
78 |
#include <sys/dumphdr.h> |
|
8227 | 79 |
#include <sys/zil_impl.h> |
789 | 80 |
|
81 |
#include "zfs_namecheck.h" |
|
82 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
83 |
void *zfsdev_state; |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
84 |
static char *zvol_tag = "zvol_tag"; |
789 | 85 |
|
6423 | 86 |
#define ZVOL_DUMPSIZE "dumpsize" |
789 | 87 |
|
88 |
/* |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
89 |
* This lock protects the zfsdev_state structure from being modified |
789 | 90 |
* while it's being used, e.g. an open that comes in before a create |
91 |
* finishes. It also protects temporary opens of the dataset so that, |
|
92 |
* e.g., an open doesn't get a spurious EBUSY. |
|
93 |
*/ |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
94 |
kmutex_t zfsdev_state_lock; |
789 | 95 |
static uint32_t zvol_minors; |
96 |
||
6423 | 97 |
typedef struct zvol_extent { |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
98 |
list_node_t ze_node; |
6423 | 99 |
dva_t ze_dva; /* dva associated with this extent */ |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
100 |
uint64_t ze_nblks; /* number of blocks in extent */ |
6423 | 101 |
} zvol_extent_t; |
102 |
||
103 |
/* |
|
789 | 104 |
* The in-core state of each volume. |
105 |
*/ |
|
106 |
typedef struct zvol_state { |
|
107 |
char zv_name[MAXPATHLEN]; /* pool/dd name */ |
|
108 |
uint64_t zv_volsize; /* amount of space we advertise */ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
109 |
uint64_t zv_volblocksize; /* volume block size */ |
789 | 110 |
minor_t zv_minor; /* minor number */ |
111 |
uint8_t zv_min_bs; /* minimum addressable block shift */ |
|
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
112 |
uint8_t zv_flags; /* readonly, dumpified, etc. */ |
789 | 113 |
objset_t *zv_objset; /* objset handle */ |
114 |
uint32_t zv_open_count[OTYPCNT]; /* open counts */ |
|
115 |
uint32_t zv_total_opens; /* total open count */ |
|
1141 | 116 |
zilog_t *zv_zilog; /* ZIL handle */ |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
117 |
list_t zv_extents; /* List of extents for dump */ |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
118 |
znode_t zv_znode; /* for range locking */ |
12123
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
119 |
dmu_buf_t *zv_dbuf; /* bonus handle */ |
789 | 120 |
} zvol_state_t; |
121 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
122 |
/* |
6423 | 123 |
* zvol specific flags |
124 |
*/ |
|
125 |
#define ZVOL_RDONLY 0x1 |
|
126 |
#define ZVOL_DUMPIFIED 0x2 |
|
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
127 |
#define ZVOL_EXCL 0x4 |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
128 |
#define ZVOL_WCE 0x8 |
6423 | 129 |
|
130 |
/* |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
131 |
* zvol maximum transfer in one DMU tx. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
132 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
133 |
int zvol_maxphys = DMU_MAX_ACCESS/2; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
134 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
135 |
extern int zfs_set_prop_nvlist(const char *, zprop_source_t, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
136 |
nvlist_t *, nvlist_t **); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
137 |
static int zvol_remove_zv(zvol_state_t *); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
138 |
static int zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio); |
6423 | 139 |
static int zvol_dumpify(zvol_state_t *zv); |
140 |
static int zvol_dump_fini(zvol_state_t *zv); |
|
141 |
static int zvol_dump_init(zvol_state_t *zv, boolean_t resize); |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
142 |
|
789 | 143 |
static void |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
144 |
zvol_size_changed(uint64_t volsize, major_t maj, minor_t min) |
789 | 145 |
{ |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
146 |
dev_t dev = makedevice(maj, min); |
789 | 147 |
|
148 |
VERIFY(ddi_prop_update_int64(dev, zfs_dip, |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
149 |
"Size", volsize) == DDI_SUCCESS); |
789 | 150 |
VERIFY(ddi_prop_update_int64(dev, zfs_dip, |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
151 |
"Nblocks", lbtodb(volsize)) == DDI_SUCCESS); |
6423 | 152 |
|
153 |
/* Notify specfs to invalidate the cached size */ |
|
154 |
spec_size_invalidate(dev, VBLK); |
|
155 |
spec_size_invalidate(dev, VCHR); |
|
789 | 156 |
} |
157 |
||
158 |
int |
|
2676 | 159 |
zvol_check_volsize(uint64_t volsize, uint64_t blocksize) |
789 | 160 |
{ |
2676 | 161 |
if (volsize == 0) |
789 | 162 |
return (EINVAL); |
163 |
||
2676 | 164 |
if (volsize % blocksize != 0) |
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
165 |
return (EINVAL); |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
166 |
|
789 | 167 |
#ifdef _ILP32 |
2676 | 168 |
if (volsize - 1 > SPEC_MAXOFFSET_T) |
789 | 169 |
return (EOVERFLOW); |
170 |
#endif |
|
171 |
return (0); |
|
172 |
} |
|
173 |
||
174 |
int |
|
2676 | 175 |
zvol_check_volblocksize(uint64_t volblocksize) |
789 | 176 |
{ |
2676 | 177 |
if (volblocksize < SPA_MINBLOCKSIZE || |
178 |
volblocksize > SPA_MAXBLOCKSIZE || |
|
179 |
!ISP2(volblocksize)) |
|
789 | 180 |
return (EDOM); |
181 |
||
182 |
return (0); |
|
183 |
} |
|
184 |
||
185 |
int |
|
2885 | 186 |
zvol_get_stats(objset_t *os, nvlist_t *nv) |
789 | 187 |
{ |
188 |
int error; |
|
189 |
dmu_object_info_t doi; |
|
2885 | 190 |
uint64_t val; |
789 | 191 |
|
2885 | 192 |
error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val); |
789 | 193 |
if (error) |
194 |
return (error); |
|
195 |
||
2885 | 196 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLSIZE, val); |
197 |
||
789 | 198 |
error = dmu_object_info(os, ZVOL_OBJ, &doi); |
199 |
||
2885 | 200 |
if (error == 0) { |
201 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLBLOCKSIZE, |
|
202 |
doi.doi_data_block_size); |
|
203 |
} |
|
789 | 204 |
|
205 |
return (error); |
|
206 |
} |
|
207 |
||
208 |
static zvol_state_t * |
|
2676 | 209 |
zvol_minor_lookup(const char *name) |
789 | 210 |
{ |
211 |
minor_t minor; |
|
212 |
zvol_state_t *zv; |
|
213 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
214 |
ASSERT(MUTEX_HELD(&zfsdev_state_lock)); |
789 | 215 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
216 |
for (minor = 1; minor <= ZFSDEV_MAX_MINOR; minor++) { |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
217 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
789 | 218 |
if (zv == NULL) |
219 |
continue; |
|
220 |
if (strcmp(zv->zv_name, name) == 0) |
|
12095
6596d5361407
6891449 zvol_strategy() check for zv == NULL too late
Chris Kirby <Chris.Kirby@sun.com>
parents:
11806
diff
changeset
|
221 |
return (zv); |
789 | 222 |
} |
223 |
||
12095
6596d5361407
6891449 zvol_strategy() check for zv == NULL too late
Chris Kirby <Chris.Kirby@sun.com>
parents:
11806
diff
changeset
|
224 |
return (NULL); |
789 | 225 |
} |
226 |
||
6423 | 227 |
/* extent mapping arg */ |
228 |
struct maparg { |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
229 |
zvol_state_t *ma_zv; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
230 |
uint64_t ma_blks; |
6423 | 231 |
}; |
232 |
||
233 |
/*ARGSUSED*/ |
|
234 |
static int |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12294
diff
changeset
|
235 |
zvol_map_block(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, arc_buf_t *pbuf, |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
236 |
const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg) |
6423 | 237 |
{ |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
238 |
struct maparg *ma = arg; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
239 |
zvol_extent_t *ze; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
240 |
int bs = ma->ma_zv->zv_volblocksize; |
6423 | 241 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
242 |
if (bp == NULL || zb->zb_object != ZVOL_OBJ || zb->zb_level != 0) |
6423 | 243 |
return (0); |
244 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
245 |
VERIFY3U(ma->ma_blks, ==, zb->zb_blkid); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
246 |
ma->ma_blks++; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
247 |
|
6423 | 248 |
/* Abort immediately if we have encountered gang blocks */ |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
249 |
if (BP_IS_GANG(bp)) |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
250 |
return (EFRAGS); |
6423 | 251 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
252 |
/* |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
253 |
* See if the block is at the end of the previous extent. |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
254 |
*/ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
255 |
ze = list_tail(&ma->ma_zv->zv_extents); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
256 |
if (ze && |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
257 |
DVA_GET_VDEV(BP_IDENTITY(bp)) == DVA_GET_VDEV(&ze->ze_dva) && |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
258 |
DVA_GET_OFFSET(BP_IDENTITY(bp)) == |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
259 |
DVA_GET_OFFSET(&ze->ze_dva) + ze->ze_nblks * bs) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
260 |
ze->ze_nblks++; |
6423 | 261 |
return (0); |
262 |
} |
|
263 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
264 |
dprintf_bp(bp, "%s", "next blkptr:"); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
265 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
266 |
/* start a new extent */ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
267 |
ze = kmem_zalloc(sizeof (zvol_extent_t), KM_SLEEP); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
268 |
ze->ze_dva = bp->blk_dva[0]; /* structure assignment */ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
269 |
ze->ze_nblks = 1; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
270 |
list_insert_tail(&ma->ma_zv->zv_extents, ze); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
271 |
return (0); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
272 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
273 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
274 |
static void |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
275 |
zvol_free_extents(zvol_state_t *zv) |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
276 |
{ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
277 |
zvol_extent_t *ze; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
278 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
279 |
while (ze = list_head(&zv->zv_extents)) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
280 |
list_remove(&zv->zv_extents, ze); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
281 |
kmem_free(ze, sizeof (zvol_extent_t)); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
282 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
283 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
284 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
285 |
static int |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
286 |
zvol_get_lbas(zvol_state_t *zv) |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
287 |
{ |
11689
ac2c63b73009
6917482 zvol_dumpify() needs to ensure no writes are in flight before doing traverse
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
11656
diff
changeset
|
288 |
objset_t *os = zv->zv_objset; |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
289 |
struct maparg ma; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
290 |
int err; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
291 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
292 |
ma.ma_zv = zv; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
293 |
ma.ma_blks = 0; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
294 |
zvol_free_extents(zv); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
295 |
|
11689
ac2c63b73009
6917482 zvol_dumpify() needs to ensure no writes are in flight before doing traverse
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
11656
diff
changeset
|
296 |
/* commit any in-flight changes before traversing the dataset */ |
ac2c63b73009
6917482 zvol_dumpify() needs to ensure no writes are in flight before doing traverse
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
11656
diff
changeset
|
297 |
txg_wait_synced(dmu_objset_pool(os), 0); |
ac2c63b73009
6917482 zvol_dumpify() needs to ensure no writes are in flight before doing traverse
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
11656
diff
changeset
|
298 |
err = traverse_dataset(dmu_objset_ds(os), 0, |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
299 |
TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA, zvol_map_block, &ma); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
300 |
if (err || ma.ma_blks != (zv->zv_volsize / zv->zv_volblocksize)) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
301 |
zvol_free_extents(zv); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
302 |
return (err ? err : EIO); |
6423 | 303 |
} |
304 |
||
305 |
return (0); |
|
306 |
} |
|
307 |
||
4543 | 308 |
/* ARGSUSED */ |
789 | 309 |
void |
4543 | 310 |
zvol_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx) |
789 | 311 |
{ |
5331 | 312 |
zfs_creat_t *zct = arg; |
313 |
nvlist_t *nvprops = zct->zct_props; |
|
789 | 314 |
int error; |
2676 | 315 |
uint64_t volblocksize, volsize; |
789 | 316 |
|
4543 | 317 |
VERIFY(nvlist_lookup_uint64(nvprops, |
2676 | 318 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) == 0); |
4543 | 319 |
if (nvlist_lookup_uint64(nvprops, |
2676 | 320 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &volblocksize) != 0) |
321 |
volblocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE); |
|
322 |
||
323 |
/* |
|
6423 | 324 |
* These properties must be removed from the list so the generic |
2676 | 325 |
* property setting step won't apply to them. |
326 |
*/ |
|
4543 | 327 |
VERIFY(nvlist_remove_all(nvprops, |
2676 | 328 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE)) == 0); |
4543 | 329 |
(void) nvlist_remove_all(nvprops, |
2676 | 330 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE)); |
331 |
||
332 |
error = dmu_object_claim(os, ZVOL_OBJ, DMU_OT_ZVOL, volblocksize, |
|
789 | 333 |
DMU_OT_NONE, 0, tx); |
334 |
ASSERT(error == 0); |
|
335 |
||
336 |
error = zap_create_claim(os, ZVOL_ZAP_OBJ, DMU_OT_ZVOL_PROP, |
|
337 |
DMU_OT_NONE, 0, tx); |
|
338 |
ASSERT(error == 0); |
|
339 |
||
2676 | 340 |
error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize, tx); |
789 | 341 |
ASSERT(error == 0); |
342 |
} |
|
343 |
||
344 |
/* |
|
1141 | 345 |
* Replay a TX_WRITE ZIL transaction that didn't get committed |
346 |
* after a system failure |
|
347 |
*/ |
|
348 |
static int |
|
349 |
zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap) |
|
350 |
{ |
|
351 |
objset_t *os = zv->zv_objset; |
|
352 |
char *data = (char *)(lr + 1); /* data follows lr_write_t */ |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
353 |
uint64_t offset, length; |
1141 | 354 |
dmu_tx_t *tx; |
355 |
int error; |
|
356 |
||
357 |
if (byteswap) |
|
358 |
byteswap_uint64_array(lr, sizeof (*lr)); |
|
359 |
||
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
360 |
offset = lr->lr_offset; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
361 |
length = lr->lr_length; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
362 |
|
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
363 |
/* If it's a dmu_sync() block, write the whole block */ |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
364 |
if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
365 |
uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
366 |
if (length < blocksize) { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
367 |
offset -= offset % blocksize; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
368 |
length = blocksize; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
369 |
} |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
370 |
} |
10800
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
371 |
|
1141 | 372 |
tx = dmu_tx_create(os); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
373 |
dmu_tx_hold_write(tx, ZVOL_OBJ, offset, length); |
8227 | 374 |
error = dmu_tx_assign(tx, TXG_WAIT); |
1141 | 375 |
if (error) { |
376 |
dmu_tx_abort(tx); |
|
377 |
} else { |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
378 |
dmu_write(os, ZVOL_OBJ, offset, length, data, tx); |
1141 | 379 |
dmu_tx_commit(tx); |
380 |
} |
|
381 |
||
382 |
return (error); |
|
383 |
} |
|
384 |
||
385 |
/* ARGSUSED */ |
|
386 |
static int |
|
387 |
zvol_replay_err(zvol_state_t *zv, lr_t *lr, boolean_t byteswap) |
|
388 |
{ |
|
389 |
return (ENOTSUP); |
|
390 |
} |
|
391 |
||
392 |
/* |
|
393 |
* Callback vectors for replaying records. |
|
394 |
* Only TX_WRITE is needed for zvol. |
|
395 |
*/ |
|
396 |
zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE] = { |
|
397 |
zvol_replay_err, /* 0 no such transaction type */ |
|
398 |
zvol_replay_err, /* TX_CREATE */ |
|
399 |
zvol_replay_err, /* TX_MKDIR */ |
|
400 |
zvol_replay_err, /* TX_MKXATTR */ |
|
401 |
zvol_replay_err, /* TX_SYMLINK */ |
|
402 |
zvol_replay_err, /* TX_REMOVE */ |
|
403 |
zvol_replay_err, /* TX_RMDIR */ |
|
404 |
zvol_replay_err, /* TX_LINK */ |
|
405 |
zvol_replay_err, /* TX_RENAME */ |
|
406 |
zvol_replay_write, /* TX_WRITE */ |
|
407 |
zvol_replay_err, /* TX_TRUNCATE */ |
|
408 |
zvol_replay_err, /* TX_SETATTR */ |
|
409 |
zvol_replay_err, /* TX_ACL */ |
|
10800
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
410 |
zvol_replay_err, /* TX_CREATE_ACL */ |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
411 |
zvol_replay_err, /* TX_CREATE_ATTR */ |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
412 |
zvol_replay_err, /* TX_CREATE_ACL_ATTR */ |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
413 |
zvol_replay_err, /* TX_MKDIR_ACL */ |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
414 |
zvol_replay_err, /* TX_MKDIR_ATTR */ |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
415 |
zvol_replay_err, /* TX_MKDIR_ACL_ATTR */ |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
416 |
zvol_replay_err, /* TX_WRITE2 */ |
1141 | 417 |
}; |
418 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
419 |
int |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
420 |
zvol_name2minor(const char *name, minor_t *minor) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
421 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
422 |
zvol_state_t *zv; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
423 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
424 |
mutex_enter(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
425 |
zv = zvol_minor_lookup(name); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
426 |
if (minor && zv) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
427 |
*minor = zv->zv_minor; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
428 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
429 |
return (zv ? 0 : -1); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
430 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
431 |
|
1141 | 432 |
/* |
6423 | 433 |
* Create a minor node (plus a whole lot more) for the specified volume. |
789 | 434 |
*/ |
435 |
int |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
436 |
zvol_create_minor(const char *name) |
789 | 437 |
{ |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
438 |
zfs_soft_state_t *zs; |
789 | 439 |
zvol_state_t *zv; |
440 |
objset_t *os; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
441 |
dmu_object_info_t doi; |
789 | 442 |
minor_t minor = 0; |
443 |
char chrbuf[30], blkbuf[30]; |
|
444 |
int error; |
|
445 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
446 |
mutex_enter(&zfsdev_state_lock); |
789 | 447 |
|
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11022
diff
changeset
|
448 |
if (zvol_minor_lookup(name) != NULL) { |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
449 |
mutex_exit(&zfsdev_state_lock); |
789 | 450 |
return (EEXIST); |
451 |
} |
|
452 |
||
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
453 |
/* lie and say we're read-only */ |
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
454 |
error = dmu_objset_own(name, DMU_OST_ZVOL, B_TRUE, zvol_tag, &os); |
789 | 455 |
|
456 |
if (error) { |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
457 |
mutex_exit(&zfsdev_state_lock); |
789 | 458 |
return (error); |
459 |
} |
|
460 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
461 |
if ((minor = zfsdev_minor_alloc()) == 0) { |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
462 |
dmu_objset_disown(os, zvol_tag); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
463 |
mutex_exit(&zfsdev_state_lock); |
789 | 464 |
return (ENXIO); |
465 |
} |
|
466 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
467 |
if (ddi_soft_state_zalloc(zfsdev_state, minor) != DDI_SUCCESS) { |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
468 |
dmu_objset_disown(os, zvol_tag); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
469 |
mutex_exit(&zfsdev_state_lock); |
789 | 470 |
return (EAGAIN); |
471 |
} |
|
2676 | 472 |
(void) ddi_prop_update_string(minor, zfs_dip, ZVOL_PROP_NAME, |
473 |
(char *)name); |
|
789 | 474 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
475 |
(void) snprintf(chrbuf, sizeof (chrbuf), "%u,raw", minor); |
789 | 476 |
|
477 |
if (ddi_create_minor_node(zfs_dip, chrbuf, S_IFCHR, |
|
478 |
minor, DDI_PSEUDO, 0) == DDI_FAILURE) { |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
479 |
ddi_soft_state_free(zfsdev_state, minor); |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
480 |
dmu_objset_disown(os, zvol_tag); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
481 |
mutex_exit(&zfsdev_state_lock); |
789 | 482 |
return (EAGAIN); |
483 |
} |
|
484 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
485 |
(void) snprintf(blkbuf, sizeof (blkbuf), "%u", minor); |
789 | 486 |
|
487 |
if (ddi_create_minor_node(zfs_dip, blkbuf, S_IFBLK, |
|
488 |
minor, DDI_PSEUDO, 0) == DDI_FAILURE) { |
|
489 |
ddi_remove_minor_node(zfs_dip, chrbuf); |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
490 |
ddi_soft_state_free(zfsdev_state, minor); |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
491 |
dmu_objset_disown(os, zvol_tag); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
492 |
mutex_exit(&zfsdev_state_lock); |
789 | 493 |
return (EAGAIN); |
494 |
} |
|
495 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
496 |
zs = ddi_get_soft_state(zfsdev_state, minor); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
497 |
zs->zss_type = ZSST_ZVOL; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
498 |
zv = zs->zss_data = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
499 |
(void) strlcpy(zv->zv_name, name, MAXPATHLEN); |
789 | 500 |
zv->zv_min_bs = DEV_BSHIFT; |
501 |
zv->zv_minor = minor; |
|
502 |
zv->zv_objset = os; |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
503 |
if (dmu_objset_is_snapshot(os)) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
504 |
zv->zv_flags |= ZVOL_RDONLY; |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
505 |
mutex_init(&zv->zv_znode.z_range_lock, NULL, MUTEX_DEFAULT, NULL); |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
506 |
avl_create(&zv->zv_znode.z_range_avl, zfs_range_compare, |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
507 |
sizeof (rl_t), offsetof(rl_t, r_node)); |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
508 |
list_create(&zv->zv_extents, sizeof (zvol_extent_t), |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
509 |
offsetof(zvol_extent_t, ze_node)); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
510 |
/* get and cache the blocksize */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
511 |
error = dmu_object_info(os, ZVOL_OBJ, &doi); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
512 |
ASSERT(error == 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
513 |
zv->zv_volblocksize = doi.doi_data_block_size; |
1141 | 514 |
|
12294
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
515 |
if (zil_replay_disable) |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
516 |
zil_destroy(dmu_objset_zil(os), B_FALSE); |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
517 |
else |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
518 |
zil_replay(os, zv, zvol_replay_vector); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
519 |
dmu_objset_disown(os, zvol_tag); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
520 |
zv->zv_objset = NULL; |
789 | 521 |
|
522 |
zvol_minors++; |
|
523 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
524 |
mutex_exit(&zfsdev_state_lock); |
789 | 525 |
|
526 |
return (0); |
|
527 |
} |
|
528 |
||
529 |
/* |
|
530 |
* Remove minor node for the specified volume. |
|
531 |
*/ |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
532 |
static int |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
533 |
zvol_remove_zv(zvol_state_t *zv) |
789 | 534 |
{ |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
535 |
char nmbuf[20]; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
536 |
minor_t minor = zv->zv_minor; |
789 | 537 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
538 |
ASSERT(MUTEX_HELD(&zfsdev_state_lock)); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
539 |
if (zv->zv_total_opens != 0) |
789 | 540 |
return (EBUSY); |
541 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
542 |
(void) snprintf(nmbuf, sizeof (nmbuf), "%u,raw", minor); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
543 |
ddi_remove_minor_node(zfs_dip, nmbuf); |
789 | 544 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
545 |
(void) snprintf(nmbuf, sizeof (nmbuf), "%u", minor); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
546 |
ddi_remove_minor_node(zfs_dip, nmbuf); |
789 | 547 |
|
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
548 |
avl_destroy(&zv->zv_znode.z_range_avl); |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
549 |
mutex_destroy(&zv->zv_znode.z_range_lock); |
789 | 550 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
551 |
kmem_free(zv, sizeof (zvol_state_t)); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
552 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
553 |
ddi_soft_state_free(zfsdev_state, minor); |
789 | 554 |
|
555 |
zvol_minors--; |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
556 |
return (0); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
557 |
} |
789 | 558 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
559 |
int |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
560 |
zvol_remove_minor(const char *name) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
561 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
562 |
zvol_state_t *zv; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
563 |
int rc; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
564 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
565 |
mutex_enter(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
566 |
if ((zv = zvol_minor_lookup(name)) == NULL) { |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
567 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
568 |
return (ENXIO); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
569 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
570 |
rc = zvol_remove_zv(zv); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
571 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
572 |
return (rc); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
573 |
} |
789 | 574 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
575 |
int |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
576 |
zvol_first_open(zvol_state_t *zv) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
577 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
578 |
objset_t *os; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
579 |
uint64_t volsize; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
580 |
int error; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
581 |
uint64_t readonly; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
582 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
583 |
/* lie and say we're read-only */ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
584 |
error = dmu_objset_own(zv->zv_name, DMU_OST_ZVOL, B_TRUE, |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
585 |
zvol_tag, &os); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
586 |
if (error) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
587 |
return (error); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
588 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
589 |
error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
590 |
if (error) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
591 |
ASSERT(error == 0); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
592 |
dmu_objset_disown(os, zvol_tag); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
593 |
return (error); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
594 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
595 |
zv->zv_objset = os; |
12123
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
596 |
error = dmu_bonus_hold(os, ZVOL_OBJ, zvol_tag, &zv->zv_dbuf); |
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
597 |
if (error) { |
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
598 |
dmu_objset_disown(os, zvol_tag); |
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
599 |
return (error); |
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
600 |
} |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
601 |
zv->zv_volsize = volsize; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
602 |
zv->zv_zilog = zil_open(os, zvol_get_data); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
603 |
zvol_size_changed(zv->zv_volsize, ddi_driver_major(zfs_dip), |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
604 |
zv->zv_minor); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
605 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
606 |
VERIFY(dsl_prop_get_integer(zv->zv_name, "readonly", &readonly, |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
607 |
NULL) == 0); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
608 |
if (readonly || dmu_objset_is_snapshot(os)) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
609 |
zv->zv_flags |= ZVOL_RDONLY; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
610 |
else |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
611 |
zv->zv_flags &= ~ZVOL_RDONLY; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
612 |
return (error); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
613 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
614 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
615 |
void |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
616 |
zvol_last_close(zvol_state_t *zv) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
617 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
618 |
zil_close(zv->zv_zilog); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
619 |
zv->zv_zilog = NULL; |
12123
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
620 |
dmu_buf_rele(zv->zv_dbuf, zvol_tag); |
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
621 |
zv->zv_dbuf = NULL; |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
622 |
dmu_objset_disown(zv->zv_objset, zvol_tag); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
623 |
zv->zv_objset = NULL; |
789 | 624 |
} |
625 |
||
6423 | 626 |
int |
627 |
zvol_prealloc(zvol_state_t *zv) |
|
628 |
{ |
|
629 |
objset_t *os = zv->zv_objset; |
|
630 |
dmu_tx_t *tx; |
|
631 |
uint64_t refd, avail, usedobjs, availobjs; |
|
632 |
uint64_t resid = zv->zv_volsize; |
|
633 |
uint64_t off = 0; |
|
634 |
||
635 |
/* Check the space usage before attempting to allocate the space */ |
|
636 |
dmu_objset_space(os, &refd, &avail, &usedobjs, &availobjs); |
|
637 |
if (avail < zv->zv_volsize) |
|
638 |
return (ENOSPC); |
|
639 |
||
640 |
/* Free old extents if they exist */ |
|
641 |
zvol_free_extents(zv); |
|
642 |
||
643 |
while (resid != 0) { |
|
644 |
int error; |
|
645 |
uint64_t bytes = MIN(resid, SPA_MAXBLOCKSIZE); |
|
646 |
||
647 |
tx = dmu_tx_create(os); |
|
648 |
dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes); |
|
649 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
650 |
if (error) { |
|
651 |
dmu_tx_abort(tx); |
|
6992 | 652 |
(void) dmu_free_long_range(os, ZVOL_OBJ, 0, off); |
6423 | 653 |
return (error); |
654 |
} |
|
7872
40a9434212f6
6646775 Speed up the dumpifying process for zvols
Tim Haley <Tim.Haley@Sun.COM>
parents:
7837
diff
changeset
|
655 |
dmu_prealloc(os, ZVOL_OBJ, off, bytes, tx); |
6423 | 656 |
dmu_tx_commit(tx); |
657 |
off += bytes; |
|
658 |
resid -= bytes; |
|
659 |
} |
|
660 |
txg_wait_synced(dmu_objset_pool(os), 0); |
|
661 |
||
662 |
return (0); |
|
663 |
} |
|
664 |
||
665 |
int |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
666 |
zvol_update_volsize(objset_t *os, uint64_t volsize) |
6423 | 667 |
{ |
668 |
dmu_tx_t *tx; |
|
669 |
int error; |
|
670 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
671 |
ASSERT(MUTEX_HELD(&zfsdev_state_lock)); |
6423 | 672 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
673 |
tx = dmu_tx_create(os); |
6423 | 674 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
675 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
676 |
if (error) { |
|
677 |
dmu_tx_abort(tx); |
|
678 |
return (error); |
|
679 |
} |
|
680 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
681 |
error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, |
6423 | 682 |
&volsize, tx); |
683 |
dmu_tx_commit(tx); |
|
684 |
||
685 |
if (error == 0) |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
686 |
error = dmu_free_long_range(os, |
6992 | 687 |
ZVOL_OBJ, volsize, DMU_OBJECT_END); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
688 |
return (error); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
689 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
690 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
691 |
void |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
692 |
zvol_remove_minors(const char *name) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
693 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
694 |
zvol_state_t *zv; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
695 |
char *namebuf; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
696 |
minor_t minor; |
6423 | 697 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
698 |
namebuf = kmem_zalloc(strlen(name) + 2, KM_SLEEP); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
699 |
(void) strncpy(namebuf, name, strlen(name)); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
700 |
(void) strcat(namebuf, "/"); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
701 |
mutex_enter(&zfsdev_state_lock); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
702 |
for (minor = 1; minor <= ZFSDEV_MAX_MINOR; minor++) { |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
703 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
704 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
705 |
if (zv == NULL) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
706 |
continue; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
707 |
if (strncmp(namebuf, zv->zv_name, strlen(namebuf)) == 0) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
708 |
(void) zvol_remove_zv(zv); |
6423 | 709 |
} |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
710 |
kmem_free(namebuf, strlen(name) + 2); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
711 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
712 |
mutex_exit(&zfsdev_state_lock); |
6423 | 713 |
} |
714 |
||
789 | 715 |
int |
4787 | 716 |
zvol_set_volsize(const char *name, major_t maj, uint64_t volsize) |
789 | 717 |
{ |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
718 |
zvol_state_t *zv = NULL; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
719 |
objset_t *os; |
789 | 720 |
int error; |
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
721 |
dmu_object_info_t doi; |
6423 | 722 |
uint64_t old_volsize = 0ULL; |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
723 |
uint64_t readonly; |
789 | 724 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
725 |
mutex_enter(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
726 |
zv = zvol_minor_lookup(name); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
727 |
if ((error = dmu_objset_hold(name, FTAG, &os)) != 0) { |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
728 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
729 |
return (error); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
730 |
} |
789 | 731 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
732 |
if ((error = dmu_object_info(os, ZVOL_OBJ, &doi)) != 0 || |
2676 | 733 |
(error = zvol_check_volsize(volsize, |
7265 | 734 |
doi.doi_data_block_size)) != 0) |
735 |
goto out; |
|
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
736 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
737 |
VERIFY(dsl_prop_get_integer(name, "readonly", &readonly, |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
738 |
NULL) == 0); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
739 |
if (readonly) { |
7265 | 740 |
error = EROFS; |
741 |
goto out; |
|
789 | 742 |
} |
743 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
744 |
error = zvol_update_volsize(os, volsize); |
6423 | 745 |
/* |
746 |
* Reinitialize the dump area to the new size. If we |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
747 |
* failed to resize the dump area then restore it back to |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
748 |
* its original size. |
6423 | 749 |
*/ |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
750 |
if (zv && error == 0) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
751 |
if (zv->zv_flags & ZVOL_DUMPIFIED) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
752 |
old_volsize = zv->zv_volsize; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
753 |
zv->zv_volsize = volsize; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
754 |
if ((error = zvol_dumpify(zv)) != 0 || |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
755 |
(error = dumpvp_resize()) != 0) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
756 |
(void) zvol_update_volsize(os, old_volsize); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
757 |
zv->zv_volsize = old_volsize; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
758 |
error = zvol_dumpify(zv); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
759 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
760 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
761 |
if (error == 0) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
762 |
zv->zv_volsize = volsize; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
763 |
zvol_size_changed(volsize, maj, zv->zv_minor); |
6423 | 764 |
} |
789 | 765 |
} |
766 |
||
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
767 |
/* |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
768 |
* Generate a LUN expansion event. |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
769 |
*/ |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
770 |
if (zv && error == 0) { |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
771 |
sysevent_id_t eid; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
772 |
nvlist_t *attr; |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
773 |
char *physpath = kmem_zalloc(MAXPATHLEN, KM_SLEEP); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
774 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
775 |
(void) snprintf(physpath, MAXPATHLEN, "%s%u", ZVOL_PSEUDO_DEV, |
9816
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
776 |
zv->zv_minor); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
777 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
778 |
VERIFY(nvlist_alloc(&attr, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
779 |
VERIFY(nvlist_add_string(attr, DEV_PHYS_PATH, physpath) == 0); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
780 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
781 |
(void) ddi_log_sysevent(zfs_dip, SUNW_VENDOR, EC_DEV_STATUS, |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
782 |
ESC_DEV_DLE, attr, &eid, DDI_SLEEP); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
783 |
|
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
784 |
nvlist_free(attr); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
785 |
kmem_free(physpath, MAXPATHLEN); |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
786 |
} |
847676ec1c5b
PSARC 2008/353 zpool autoexpand property
George Wilson <George.Wilson@Sun.COM>
parents:
9790
diff
changeset
|
787 |
|
7265 | 788 |
out: |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
789 |
dmu_objset_rele(os, FTAG); |
7265 | 790 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
791 |
mutex_exit(&zfsdev_state_lock); |
789 | 792 |
|
793 |
return (error); |
|
794 |
} |
|
795 |
||
796 |
/*ARGSUSED*/ |
|
797 |
int |
|
798 |
zvol_open(dev_t *devp, int flag, int otyp, cred_t *cr) |
|
799 |
{ |
|
800 |
zvol_state_t *zv; |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
801 |
int err = 0; |
789 | 802 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
803 |
mutex_enter(&zfsdev_state_lock); |
789 | 804 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
805 |
zv = zfsdev_get_soft_state(getminor(*devp), ZSST_ZVOL); |
789 | 806 |
if (zv == NULL) { |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
807 |
mutex_exit(&zfsdev_state_lock); |
789 | 808 |
return (ENXIO); |
809 |
} |
|
810 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
811 |
if (zv->zv_total_opens == 0) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
812 |
err = zvol_first_open(zv); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
813 |
if (err) { |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
814 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
815 |
return (err); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
816 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
817 |
if ((flag & FWRITE) && (zv->zv_flags & ZVOL_RDONLY)) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
818 |
err = EROFS; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
819 |
goto out; |
789 | 820 |
} |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
821 |
if (zv->zv_flags & ZVOL_EXCL) { |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
822 |
err = EBUSY; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
823 |
goto out; |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
824 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
825 |
if (flag & FEXCL) { |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
826 |
if (zv->zv_total_opens != 0) { |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
827 |
err = EBUSY; |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
828 |
goto out; |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
829 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
830 |
zv->zv_flags |= ZVOL_EXCL; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
831 |
} |
789 | 832 |
|
833 |
if (zv->zv_open_count[otyp] == 0 || otyp == OTYP_LYR) { |
|
834 |
zv->zv_open_count[otyp]++; |
|
835 |
zv->zv_total_opens++; |
|
836 |
} |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
837 |
mutex_exit(&zfsdev_state_lock); |
789 | 838 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
839 |
return (err); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
840 |
out: |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
841 |
if (zv->zv_total_opens == 0) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
842 |
zvol_last_close(zv); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
843 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
844 |
return (err); |
789 | 845 |
} |
846 |
||
847 |
/*ARGSUSED*/ |
|
848 |
int |
|
849 |
zvol_close(dev_t dev, int flag, int otyp, cred_t *cr) |
|
850 |
{ |
|
851 |
minor_t minor = getminor(dev); |
|
852 |
zvol_state_t *zv; |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
853 |
int error = 0; |
789 | 854 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
855 |
mutex_enter(&zfsdev_state_lock); |
789 | 856 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
857 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
789 | 858 |
if (zv == NULL) { |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
859 |
mutex_exit(&zfsdev_state_lock); |
789 | 860 |
return (ENXIO); |
861 |
} |
|
862 |
||
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
863 |
if (zv->zv_flags & ZVOL_EXCL) { |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
864 |
ASSERT(zv->zv_total_opens == 1); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
865 |
zv->zv_flags &= ~ZVOL_EXCL; |
789 | 866 |
} |
867 |
||
868 |
/* |
|
869 |
* If the open count is zero, this is a spurious close. |
|
870 |
* That indicates a bug in the kernel / DDI framework. |
|
871 |
*/ |
|
872 |
ASSERT(zv->zv_open_count[otyp] != 0); |
|
873 |
ASSERT(zv->zv_total_opens != 0); |
|
874 |
||
875 |
/* |
|
876 |
* You may get multiple opens, but only one close. |
|
877 |
*/ |
|
878 |
zv->zv_open_count[otyp]--; |
|
879 |
zv->zv_total_opens--; |
|
880 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
881 |
if (zv->zv_total_opens == 0) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
882 |
zvol_last_close(zv); |
789 | 883 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
884 |
mutex_exit(&zfsdev_state_lock); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
885 |
return (error); |
789 | 886 |
} |
887 |
||
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
888 |
static void |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
889 |
zvol_get_done(zgd_t *zgd, int error) |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
890 |
{ |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
891 |
if (zgd->zgd_db) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
892 |
dmu_buf_rele(zgd->zgd_db, zgd); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
893 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
894 |
zfs_range_unlock(zgd->zgd_rl); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
895 |
|
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
896 |
if (error == 0 && zgd->zgd_bp) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
897 |
zil_add_block(zgd->zgd_zilog, zgd->zgd_bp); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
898 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
899 |
kmem_free(zgd, sizeof (zgd_t)); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
900 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
901 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
902 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
903 |
* Get data to generate a TX_WRITE intent log record. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
904 |
*/ |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
905 |
static int |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
906 |
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
|
907 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
908 |
zvol_state_t *zv = arg; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
909 |
objset_t *os = zv->zv_objset; |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
910 |
uint64_t object = ZVOL_OBJ; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
911 |
uint64_t offset = lr->lr_offset; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
912 |
uint64_t size = lr->lr_length; /* length of user data */ |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
913 |
blkptr_t *bp = &lr->lr_blkptr; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
914 |
dmu_buf_t *db; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
915 |
zgd_t *zgd; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
916 |
int error; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
917 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
918 |
ASSERT(zio != NULL); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
919 |
ASSERT(size != 0); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
920 |
|
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
921 |
zgd = kmem_zalloc(sizeof (zgd_t), KM_SLEEP); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
922 |
zgd->zgd_zilog = zv->zv_zilog; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
923 |
zgd->zgd_rl = zfs_range_lock(&zv->zv_znode, offset, size, RL_READER); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
924 |
|
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
925 |
/* |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
926 |
* Write records come in two flavors: immediate and indirect. |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
927 |
* For small writes it's cheaper to store the data with the |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
928 |
* log record (immediate); for large writes it's cheaper to |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
929 |
* sync the data and get a pointer to it (indirect) so that |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
930 |
* we don't have to write the data twice. |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
931 |
*/ |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
932 |
if (buf != NULL) { /* immediate write */ |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
933 |
error = dmu_read(os, object, offset, size, buf, |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
934 |
DMU_READ_NO_PREFETCH); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
935 |
} else { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
936 |
size = zv->zv_volblocksize; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
937 |
offset = P2ALIGN(offset, size); |
12285
d736d62dcca2
6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
12123
diff
changeset
|
938 |
error = dmu_buf_hold(os, object, offset, zgd, &db, |
d736d62dcca2
6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
12123
diff
changeset
|
939 |
DMU_READ_NO_PREFETCH); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
940 |
if (error == 0) { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
941 |
zgd->zgd_db = db; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
942 |
zgd->zgd_bp = bp; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
943 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
944 |
ASSERT(db->db_offset == offset); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
945 |
ASSERT(db->db_size == size); |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
946 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
947 |
error = dmu_sync(zio, lr->lr_common.lrc_txg, |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
948 |
zvol_get_done, zgd); |
10800
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
949 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
950 |
if (error == 0) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
951 |
return (0); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
952 |
} |
10800
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
953 |
} |
469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10693
diff
changeset
|
954 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
955 |
zvol_get_done(zgd, error); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
956 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
957 |
return (error); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
958 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
959 |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
960 |
/* |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
961 |
* zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions. |
1141 | 962 |
* |
963 |
* 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
|
964 |
* Otherwise we will later flush the data out via dmu_sync(). |
1141 | 965 |
*/ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
966 |
ssize_t zvol_immediate_write_sz = 32768; |
1141 | 967 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
968 |
static void |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
969 |
zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, offset_t off, ssize_t resid, |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
970 |
boolean_t sync) |
1141 | 971 |
{ |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
972 |
uint32_t blocksize = zv->zv_volblocksize; |
8227 | 973 |
zilog_t *zilog = zv->zv_zilog; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
974 |
boolean_t slogging; |
10310
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
975 |
ssize_t immediate_write_sz; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
976 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
977 |
if (zil_replaying(zilog, tx)) |
8227 | 978 |
return; |
979 |
||
10310
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
980 |
immediate_write_sz = (zilog->zl_logbias == ZFS_LOGBIAS_THROUGHPUT) |
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
981 |
? 0 : zvol_immediate_write_sz; |
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
982 |
|
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
983 |
slogging = spa_has_slogs(zilog->zl_spa) && |
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
984 |
(zilog->zl_logbias == ZFS_LOGBIAS_LATENCY); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
985 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
986 |
while (resid) { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
987 |
itx_t *itx; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
988 |
lr_write_t *lr; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
989 |
ssize_t len; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
990 |
itx_wr_state_t write_state; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
991 |
|
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
992 |
/* |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
993 |
* Unlike zfs_log_write() we can be called with |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
994 |
* upto DMU_MAX_ACCESS/2 (5MB) writes. |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
995 |
*/ |
10310
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
996 |
if (blocksize > immediate_write_sz && !slogging && |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
997 |
resid >= blocksize && off % blocksize == 0) { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
998 |
write_state = WR_INDIRECT; /* uses dmu_sync */ |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
999 |
len = blocksize; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1000 |
} else if (sync) { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1001 |
write_state = WR_COPIED; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1002 |
len = MIN(ZIL_MAX_LOG_DATA, resid); |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1003 |
} else { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1004 |
write_state = WR_NEED_COPY; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1005 |
len = MIN(ZIL_MAX_LOG_DATA, resid); |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1006 |
} |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1007 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1008 |
itx = zil_itx_create(TX_WRITE, sizeof (*lr) + |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1009 |
(write_state == WR_COPIED ? len : 0)); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1010 |
lr = (lr_write_t *)&itx->itx_lr; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1011 |
if (write_state == WR_COPIED && dmu_read(zv->zv_objset, |
9512
64cafcbcc337
6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9401
diff
changeset
|
1012 |
ZVOL_OBJ, off, len, lr + 1, DMU_READ_NO_PREFETCH) != 0) { |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
1013 |
zil_itx_destroy(itx); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1014 |
itx = zil_itx_create(TX_WRITE, sizeof (*lr)); |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1015 |
lr = (lr_write_t *)&itx->itx_lr; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1016 |
write_state = WR_NEED_COPY; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1017 |
} |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1018 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1019 |
itx->itx_wr_state = write_state; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1020 |
if (write_state == WR_NEED_COPY) |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1021 |
itx->itx_sod += len; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1022 |
lr->lr_foid = ZVOL_OBJ; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1023 |
lr->lr_offset = off; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1024 |
lr->lr_length = len; |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
1025 |
lr->lr_blkoff = 0; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1026 |
BP_ZERO(&lr->lr_blkptr); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1027 |
|
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1028 |
itx->itx_private = zv; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1029 |
itx->itx_sync = sync; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1030 |
|
8227 | 1031 |
(void) zil_itx_assign(zilog, itx, tx); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1032 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1033 |
off += len; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1034 |
resid -= len; |
1141 | 1035 |
} |
1036 |
} |
|
1037 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1038 |
static int |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1039 |
zvol_dumpio_vdev(vdev_t *vd, void *addr, uint64_t offset, uint64_t size, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1040 |
boolean_t doread, boolean_t isdump) |
6423 | 1041 |
{ |
1042 |
vdev_disk_t *dvd; |
|
1043 |
int c; |
|
1044 |
int numerrors = 0; |
|
1045 |
||
1046 |
for (c = 0; c < vd->vdev_children; c++) { |
|
9790
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9512
diff
changeset
|
1047 |
ASSERT(vd->vdev_ops == &vdev_mirror_ops || |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9512
diff
changeset
|
1048 |
vd->vdev_ops == &vdev_replacing_ops || |
e276ee006ff6
6747441 GRUB/vdev_get_bootpath, spa_get_rootconf, zpool_get_physpath should take care of spare vdev
Lin Ling <Lin.Ling@Sun.COM>
parents:
9512
diff
changeset
|
1049 |
vd->vdev_ops == &vdev_spare_ops); |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1050 |
int err = zvol_dumpio_vdev(vd->vdev_child[c], |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1051 |
addr, offset, size, doread, isdump); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1052 |
if (err != 0) { |
6423 | 1053 |
numerrors++; |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1054 |
} else if (doread) { |
6423 | 1055 |
break; |
1056 |
} |
|
1057 |
} |
|
1058 |
||
1059 |
if (!vd->vdev_ops->vdev_op_leaf) |
|
1060 |
return (numerrors < vd->vdev_children ? 0 : EIO); |
|
1061 |
||
7903
4c8fa38f91ec
6760985 assertion failure with dump device on pool with non-writeable vdev
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7872
diff
changeset
|
1062 |
if (doread && !vdev_readable(vd)) |
4c8fa38f91ec
6760985 assertion failure with dump device on pool with non-writeable vdev
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7872
diff
changeset
|
1063 |
return (EIO); |
4c8fa38f91ec
6760985 assertion failure with dump device on pool with non-writeable vdev
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7872
diff
changeset
|
1064 |
else if (!doread && !vdev_writeable(vd)) |
6423 | 1065 |
return (EIO); |
1066 |
||
1067 |
dvd = vd->vdev_tsd; |
|
1068 |
ASSERT3P(dvd, !=, NULL); |
|
1069 |
offset += VDEV_LABEL_START_SIZE; |
|
1070 |
||
1071 |
if (ddi_in_panic() || isdump) { |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1072 |
ASSERT(!doread); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1073 |
if (doread) |
6423 | 1074 |
return (EIO); |
1075 |
return (ldi_dump(dvd->vd_lh, addr, lbtodb(offset), |
|
1076 |
lbtodb(size))); |
|
1077 |
} else { |
|
1078 |
return (vdev_disk_physio(dvd->vd_lh, addr, size, offset, |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1079 |
doread ? B_READ : B_WRITE)); |
6423 | 1080 |
} |
1081 |
} |
|
1082 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1083 |
static int |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1084 |
zvol_dumpio(zvol_state_t *zv, void *addr, uint64_t offset, uint64_t size, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1085 |
boolean_t doread, boolean_t isdump) |
6423 | 1086 |
{ |
1087 |
vdev_t *vd; |
|
1088 |
int error; |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1089 |
zvol_extent_t *ze; |
6423 | 1090 |
spa_t *spa = dmu_objset_spa(zv->zv_objset); |
1091 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1092 |
/* Must be sector aligned, and not stradle a block boundary. */ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1093 |
if (P2PHASE(offset, DEV_BSIZE) || P2PHASE(size, DEV_BSIZE) || |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1094 |
P2BOUNDARY(offset, size, zv->zv_volblocksize)) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1095 |
return (EINVAL); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1096 |
} |
6423 | 1097 |
ASSERT(size <= zv->zv_volblocksize); |
1098 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1099 |
/* Locate the extent this belongs to */ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1100 |
ze = list_head(&zv->zv_extents); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1101 |
while (offset >= ze->ze_nblks * zv->zv_volblocksize) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1102 |
offset -= ze->ze_nblks * zv->zv_volblocksize; |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1103 |
ze = list_next(&zv->zv_extents, ze); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1104 |
} |
11806
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1105 |
|
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1106 |
if (!ddi_in_panic()) |
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1107 |
spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); |
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1108 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1109 |
vd = vdev_lookup_top(spa, DVA_GET_VDEV(&ze->ze_dva)); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1110 |
offset += DVA_GET_OFFSET(&ze->ze_dva); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1111 |
error = zvol_dumpio_vdev(vd, addr, offset, size, doread, isdump); |
11806
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1112 |
|
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1113 |
if (!ddi_in_panic()) |
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1114 |
spa_config_exit(spa, SCL_STATE, FTAG); |
ed3bdb1987b3
6923572 cannot dump to zvol when spa_config_lock is held as writer
George Wilson <George.Wilson@Sun.COM>
parents:
11689
diff
changeset
|
1115 |
|
6423 | 1116 |
return (error); |
1117 |
} |
|
1118 |
||
1119 |
int |
|
789 | 1120 |
zvol_strategy(buf_t *bp) |
1121 |
{ |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1122 |
zfs_soft_state_t *zs = NULL; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1123 |
zvol_state_t *zv; |
789 | 1124 |
uint64_t off, volsize; |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1125 |
size_t resid; |
789 | 1126 |
char *addr; |
1141 | 1127 |
objset_t *os; |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1128 |
rl_t *rl; |
789 | 1129 |
int error = 0; |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1130 |
boolean_t doread = bp->b_flags & B_READ; |
12095
6596d5361407
6891449 zvol_strategy() check for zv == NULL too late
Chris Kirby <Chris.Kirby@sun.com>
parents:
11806
diff
changeset
|
1131 |
boolean_t is_dump; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1132 |
boolean_t sync; |
789 | 1133 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1134 |
if (getminor(bp->b_edev) == 0) { |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1135 |
error = EINVAL; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1136 |
} else { |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1137 |
zs = ddi_get_soft_state(zfsdev_state, getminor(bp->b_edev)); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1138 |
if (zs == NULL) |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1139 |
error = ENXIO; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1140 |
else if (zs->zss_type != ZSST_ZVOL) |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1141 |
error = EINVAL; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1142 |
} |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1143 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1144 |
if (error) { |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1145 |
bioerror(bp, error); |
789 | 1146 |
biodone(bp); |
1147 |
return (0); |
|
1148 |
} |
|
1149 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1150 |
zv = zs->zss_data; |
789 | 1151 |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1152 |
if (!(bp->b_flags & B_READ) && (zv->zv_flags & ZVOL_RDONLY)) { |
789 | 1153 |
bioerror(bp, EROFS); |
1154 |
biodone(bp); |
|
1155 |
return (0); |
|
1156 |
} |
|
1157 |
||
1158 |
off = ldbtob(bp->b_blkno); |
|
1159 |
volsize = zv->zv_volsize; |
|
1160 |
||
1141 | 1161 |
os = zv->zv_objset; |
1162 |
ASSERT(os != NULL); |
|
789 | 1163 |
|
1164 |
bp_mapin(bp); |
|
1165 |
addr = bp->b_un.b_addr; |
|
1166 |
resid = bp->b_bcount; |
|
1167 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1168 |
if (resid > 0 && (off < 0 || off >= volsize)) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1169 |
bioerror(bp, EIO); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1170 |
biodone(bp); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1171 |
return (0); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1172 |
} |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1173 |
|
12095
6596d5361407
6891449 zvol_strategy() check for zv == NULL too late
Chris Kirby <Chris.Kirby@sun.com>
parents:
11806
diff
changeset
|
1174 |
is_dump = zv->zv_flags & ZVOL_DUMPIFIED; |
12294
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
1175 |
sync = ((!(bp->b_flags & B_ASYNC) && |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
1176 |
!(zv->zv_flags & ZVOL_WCE)) || |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
1177 |
(zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS)) && |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
1178 |
!doread && !is_dump; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1179 |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
1180 |
/* |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
1181 |
* 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
|
1182 |
* 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
|
1183 |
*/ |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1184 |
rl = zfs_range_lock(&zv->zv_znode, off, resid, |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1185 |
doread ? RL_READER : RL_WRITER); |
6423 | 1186 |
|
789 | 1187 |
while (resid != 0 && off < volsize) { |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1188 |
size_t size = MIN(resid, zvol_maxphys); |
6423 | 1189 |
if (is_dump) { |
1190 |
size = MIN(size, P2END(off, zv->zv_volblocksize) - off); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1191 |
error = zvol_dumpio(zv, addr, off, size, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1192 |
doread, B_FALSE); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1193 |
} else if (doread) { |
9512
64cafcbcc337
6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9401
diff
changeset
|
1194 |
error = dmu_read(os, ZVOL_OBJ, off, size, addr, |
64cafcbcc337
6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9401
diff
changeset
|
1195 |
DMU_READ_PREFETCH); |
789 | 1196 |
} else { |
1141 | 1197 |
dmu_tx_t *tx = dmu_tx_create(os); |
789 | 1198 |
dmu_tx_hold_write(tx, ZVOL_OBJ, off, size); |
1199 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1200 |
if (error) { |
|
1201 |
dmu_tx_abort(tx); |
|
1202 |
} else { |
|
1141 | 1203 |
dmu_write(os, ZVOL_OBJ, off, size, addr, tx); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1204 |
zvol_log_write(zv, tx, off, size, sync); |
789 | 1205 |
dmu_tx_commit(tx); |
1206 |
} |
|
1207 |
} |
|
7294 | 1208 |
if (error) { |
1209 |
/* convert checksum errors into IO errors */ |
|
1210 |
if (error == ECKSUM) |
|
1211 |
error = EIO; |
|
789 | 1212 |
break; |
7294 | 1213 |
} |
789 | 1214 |
off += size; |
1215 |
addr += size; |
|
1216 |
resid -= size; |
|
1217 |
} |
|
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1218 |
zfs_range_unlock(rl); |
789 | 1219 |
|
1220 |
if ((bp->b_resid = resid) == bp->b_bcount) |
|
1221 |
bioerror(bp, off > volsize ? EINVAL : error); |
|
1222 |
||
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1223 |
if (sync) |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1224 |
zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1225 |
biodone(bp); |
1141 | 1226 |
|
789 | 1227 |
return (0); |
1228 |
} |
|
1229 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1230 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1231 |
* Set the buffer count to the zvol maximum transfer. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1232 |
* Using our own routine instead of the default minphys() |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1233 |
* 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
|
1234 |
* (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
|
1235 |
* (every zvol_maxphys - currently 1MB) instead of minphys (currently |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1236 |
* 56K on X86 and 128K on sparc). |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1237 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1238 |
void |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1239 |
zvol_minphys(struct buf *bp) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1240 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1241 |
if (bp->b_bcount > zvol_maxphys) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1242 |
bp->b_bcount = zvol_maxphys; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1243 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1244 |
|
6423 | 1245 |
int |
1246 |
zvol_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblocks) |
|
1247 |
{ |
|
1248 |
minor_t minor = getminor(dev); |
|
1249 |
zvol_state_t *zv; |
|
1250 |
int error = 0; |
|
1251 |
uint64_t size; |
|
1252 |
uint64_t boff; |
|
1253 |
uint64_t resid; |
|
1254 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1255 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
6423 | 1256 |
if (zv == NULL) |
1257 |
return (ENXIO); |
|
1258 |
||
1259 |
boff = ldbtob(blkno); |
|
1260 |
resid = ldbtob(nblocks); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1261 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1262 |
VERIFY3U(boff + resid, <=, zv->zv_volsize); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1263 |
|
6423 | 1264 |
while (resid) { |
1265 |
size = MIN(resid, P2END(boff, zv->zv_volblocksize) - boff); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1266 |
error = zvol_dumpio(zv, addr, boff, size, B_FALSE, B_TRUE); |
6423 | 1267 |
if (error) |
1268 |
break; |
|
1269 |
boff += size; |
|
1270 |
addr += size; |
|
1271 |
resid -= size; |
|
1272 |
} |
|
1273 |
||
1274 |
return (error); |
|
1275 |
} |
|
1276 |
||
789 | 1277 |
/*ARGSUSED*/ |
1278 |
int |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1279 |
zvol_read(dev_t dev, uio_t *uio, cred_t *cr) |
789 | 1280 |
{ |
4107 | 1281 |
minor_t minor = getminor(dev); |
1282 |
zvol_state_t *zv; |
|
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1283 |
uint64_t volsize; |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1284 |
rl_t *rl; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1285 |
int error = 0; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1286 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1287 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
4107 | 1288 |
if (zv == NULL) |
1289 |
return (ENXIO); |
|
1290 |
||
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1291 |
volsize = zv->zv_volsize; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1292 |
if (uio->uio_resid > 0 && |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1293 |
(uio->uio_loffset < 0 || uio->uio_loffset >= volsize)) |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1294 |
return (EIO); |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1295 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1296 |
if (zv->zv_flags & ZVOL_DUMPIFIED) { |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1297 |
error = physio(zvol_strategy, NULL, dev, B_READ, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1298 |
zvol_minphys, uio); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1299 |
return (error); |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1300 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1301 |
|
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1302 |
rl = zfs_range_lock(&zv->zv_znode, uio->uio_loffset, uio->uio_resid, |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1303 |
RL_READER); |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1304 |
while (uio->uio_resid > 0 && uio->uio_loffset < volsize) { |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1305 |
uint64_t bytes = MIN(uio->uio_resid, DMU_MAX_ACCESS >> 1); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1306 |
|
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1307 |
/* don't read past the end */ |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1308 |
if (bytes > volsize - uio->uio_loffset) |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1309 |
bytes = volsize - uio->uio_loffset; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1310 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1311 |
error = dmu_read_uio(zv->zv_objset, ZVOL_OBJ, uio, bytes); |
7294 | 1312 |
if (error) { |
1313 |
/* convert checksum errors into IO errors */ |
|
1314 |
if (error == ECKSUM) |
|
1315 |
error = EIO; |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1316 |
break; |
7294 | 1317 |
} |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1318 |
} |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1319 |
zfs_range_unlock(rl); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1320 |
return (error); |
789 | 1321 |
} |
1322 |
||
1323 |
/*ARGSUSED*/ |
|
1324 |
int |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1325 |
zvol_write(dev_t dev, uio_t *uio, cred_t *cr) |
789 | 1326 |
{ |
4107 | 1327 |
minor_t minor = getminor(dev); |
1328 |
zvol_state_t *zv; |
|
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1329 |
uint64_t volsize; |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1330 |
rl_t *rl; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1331 |
int error = 0; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1332 |
boolean_t sync; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1333 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1334 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
4107 | 1335 |
if (zv == NULL) |
1336 |
return (ENXIO); |
|
1337 |
||
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1338 |
volsize = zv->zv_volsize; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1339 |
if (uio->uio_resid > 0 && |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1340 |
(uio->uio_loffset < 0 || uio->uio_loffset >= volsize)) |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1341 |
return (EIO); |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1342 |
|
6423 | 1343 |
if (zv->zv_flags & ZVOL_DUMPIFIED) { |
1344 |
error = physio(zvol_strategy, NULL, dev, B_WRITE, |
|
1345 |
zvol_minphys, uio); |
|
1346 |
return (error); |
|
1347 |
} |
|
1348 |
||
12294
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
1349 |
sync = !(zv->zv_flags & ZVOL_WCE) || |
2a74b443e6b1
PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents:
12285
diff
changeset
|
1350 |
(zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1351 |
|
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1352 |
rl = zfs_range_lock(&zv->zv_znode, uio->uio_loffset, uio->uio_resid, |
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1353 |
RL_WRITER); |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1354 |
while (uio->uio_resid > 0 && uio->uio_loffset < volsize) { |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1355 |
uint64_t bytes = MIN(uio->uio_resid, DMU_MAX_ACCESS >> 1); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1356 |
uint64_t off = uio->uio_loffset; |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1357 |
dmu_tx_t *tx = dmu_tx_create(zv->zv_objset); |
789 | 1358 |
|
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1359 |
if (bytes > volsize - off) /* don't write past the end */ |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1360 |
bytes = volsize - off; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1361 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1362 |
dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1363 |
error = dmu_tx_assign(tx, TXG_WAIT); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1364 |
if (error) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1365 |
dmu_tx_abort(tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1366 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1367 |
} |
12123
bb40732a982e
6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents:
12095
diff
changeset
|
1368 |
error = dmu_write_uio_dbuf(zv->zv_dbuf, uio, bytes, tx); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1369 |
if (error == 0) |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1370 |
zvol_log_write(zv, tx, off, bytes, sync); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1371 |
dmu_tx_commit(tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1372 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1373 |
if (error) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1374 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1375 |
} |
3755
8708c35cb823
6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents:
3638
diff
changeset
|
1376 |
zfs_range_unlock(rl); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1377 |
if (sync) |
8524
a56dffa8fba9
6770534 zvols do not observe character device semantics
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8227
diff
changeset
|
1378 |
zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1379 |
return (error); |
789 | 1380 |
} |
1381 |
||
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1382 |
int |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1383 |
zvol_getefi(void *arg, int flag, uint64_t vs, uint8_t bs) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1384 |
{ |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1385 |
struct uuid uuid = EFI_RESERVED; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1386 |
efi_gpe_t gpe = { 0 }; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1387 |
uint32_t crc; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1388 |
dk_efi_t efi; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1389 |
int length; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1390 |
char *ptr; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1391 |
|
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1392 |
if (ddi_copyin(arg, &efi, sizeof (dk_efi_t), flag)) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1393 |
return (EFAULT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1394 |
ptr = (char *)(uintptr_t)efi.dki_data_64; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1395 |
length = efi.dki_length; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1396 |
/* |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1397 |
* Some clients may attempt to request a PMBR for the |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1398 |
* zvol. Currently this interface will return EINVAL to |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1399 |
* such requests. These requests could be supported by |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1400 |
* adding a check for lba == 0 and consing up an appropriate |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1401 |
* PMBR. |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1402 |
*/ |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1403 |
if (efi.dki_lba < 1 || efi.dki_lba > 2 || length <= 0) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1404 |
return (EINVAL); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1405 |
|
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1406 |
gpe.efi_gpe_StartingLBA = LE_64(34ULL); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1407 |
gpe.efi_gpe_EndingLBA = LE_64((vs >> bs) - 1); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1408 |
UUID_LE_CONVERT(gpe.efi_gpe_PartitionTypeGUID, uuid); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1409 |
|
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1410 |
if (efi.dki_lba == 1) { |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1411 |
efi_gpt_t gpt = { 0 }; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1412 |
|
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1413 |
gpt.efi_gpt_Signature = LE_64(EFI_SIGNATURE); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1414 |
gpt.efi_gpt_Revision = LE_32(EFI_VERSION_CURRENT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1415 |
gpt.efi_gpt_HeaderSize = LE_32(sizeof (gpt)); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1416 |
gpt.efi_gpt_MyLBA = LE_64(1ULL); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1417 |
gpt.efi_gpt_FirstUsableLBA = LE_64(34ULL); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1418 |
gpt.efi_gpt_LastUsableLBA = LE_64((vs >> bs) - 1); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1419 |
gpt.efi_gpt_PartitionEntryLBA = LE_64(2ULL); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1420 |
gpt.efi_gpt_NumberOfPartitionEntries = LE_32(1); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1421 |
gpt.efi_gpt_SizeOfPartitionEntry = |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1422 |
LE_32(sizeof (efi_gpe_t)); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1423 |
CRC32(crc, &gpe, sizeof (gpe), -1U, crc32_table); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1424 |
gpt.efi_gpt_PartitionEntryArrayCRC32 = LE_32(~crc); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1425 |
CRC32(crc, &gpt, sizeof (gpt), -1U, crc32_table); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1426 |
gpt.efi_gpt_HeaderCRC32 = LE_32(~crc); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1427 |
if (ddi_copyout(&gpt, ptr, MIN(sizeof (gpt), length), |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1428 |
flag)) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1429 |
return (EFAULT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1430 |
ptr += sizeof (gpt); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1431 |
length -= sizeof (gpt); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1432 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1433 |
if (length > 0 && ddi_copyout(&gpe, ptr, MIN(sizeof (gpe), |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1434 |
length), flag)) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1435 |
return (EFAULT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1436 |
return (0); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1437 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1438 |
|
789 | 1439 |
/* |
12314
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1440 |
* BEGIN entry points to allow external callers access to the volume. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1441 |
*/ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1442 |
/* |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1443 |
* Return the volume parameters needed for access from an external caller. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1444 |
* These values are invariant as long as the volume is held open. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1445 |
*/ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1446 |
int |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1447 |
zvol_get_volume_params(minor_t minor, uint64_t *blksize, |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1448 |
uint64_t *max_xfer_len, void **minor_hdl, void **objset_hdl, void **zil_hdl, |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1449 |
void **rl_hdl, void **bonus_hdl) |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1450 |
{ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1451 |
zvol_state_t *zv; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1452 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1453 |
zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1454 |
if (zv == NULL) |
12314
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1455 |
return (ENXIO); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1456 |
if (zv->zv_flags & ZVOL_DUMPIFIED) |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1457 |
return (ENXIO); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1458 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1459 |
ASSERT(blksize && max_xfer_len && minor_hdl && |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1460 |
objset_hdl && zil_hdl && rl_hdl && bonus_hdl); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1461 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1462 |
*blksize = zv->zv_volblocksize; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1463 |
*max_xfer_len = (uint64_t)zvol_maxphys; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1464 |
*minor_hdl = zv; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1465 |
*objset_hdl = zv->zv_objset; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1466 |
*zil_hdl = zv->zv_zilog; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1467 |
*rl_hdl = &zv->zv_znode; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1468 |
*bonus_hdl = zv->zv_dbuf; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1469 |
return (0); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1470 |
} |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1471 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1472 |
/* |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1473 |
* Return the current volume size to an external caller. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1474 |
* The size can change while the volume is open. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1475 |
*/ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1476 |
uint64_t |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1477 |
zvol_get_volume_size(void *minor_hdl) |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1478 |
{ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1479 |
zvol_state_t *zv = minor_hdl; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1480 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1481 |
return (zv->zv_volsize); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1482 |
} |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1483 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1484 |
/* |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1485 |
* Return the current WCE setting to an external caller. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1486 |
* The WCE setting can change while the volume is open. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1487 |
*/ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1488 |
int |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1489 |
zvol_get_volume_wce(void *minor_hdl) |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1490 |
{ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1491 |
zvol_state_t *zv = minor_hdl; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1492 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1493 |
return ((zv->zv_flags & ZVOL_WCE) ? 1 : 0); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1494 |
} |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1495 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1496 |
/* |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1497 |
* Entry point for external callers to zvol_log_write |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1498 |
*/ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1499 |
void |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1500 |
zvol_log_write_minor(void *minor_hdl, dmu_tx_t *tx, offset_t off, ssize_t resid, |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1501 |
boolean_t sync) |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1502 |
{ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1503 |
zvol_state_t *zv = minor_hdl; |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1504 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1505 |
zvol_log_write(zv, tx, off, resid, sync); |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1506 |
} |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1507 |
/* |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1508 |
* END entry points to allow external callers access to the volume. |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1509 |
*/ |
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1510 |
|
0ed71edeac88
6909809 COMSTAR should avoid extra data copy to zvol-based backing store
James Moore <James.Moore@Sun.COM>
parents:
12296
diff
changeset
|
1511 |
/* |
789 | 1512 |
* Dirtbag ioctls to support mkfs(1M) for UFS filesystems. See dkio(7I). |
1513 |
*/ |
|
1514 |
/*ARGSUSED*/ |
|
1515 |
int |
|
1516 |
zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) |
|
1517 |
{ |
|
1518 |
zvol_state_t *zv; |
|
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1519 |
struct dk_cinfo dki; |
789 | 1520 |
struct dk_minfo dkm; |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1521 |
struct dk_callback *dkc; |
789 | 1522 |
int error = 0; |
6423 | 1523 |
rl_t *rl; |
789 | 1524 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1525 |
mutex_enter(&zfsdev_state_lock); |
789 | 1526 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1527 |
zv = zfsdev_get_soft_state(getminor(dev), ZSST_ZVOL); |
789 | 1528 |
|
1529 |
if (zv == NULL) { |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1530 |
mutex_exit(&zfsdev_state_lock); |
789 | 1531 |
return (ENXIO); |
1532 |
} |
|
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1533 |
ASSERT(zv->zv_total_opens > 0); |
789 | 1534 |
|
1535 |
switch (cmd) { |
|
1536 |
||
1537 |
case DKIOCINFO: |
|
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1538 |
bzero(&dki, sizeof (dki)); |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1539 |
(void) strcpy(dki.dki_cname, "zvol"); |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1540 |
(void) strcpy(dki.dki_dname, "zvol"); |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1541 |
dki.dki_ctype = DKC_UNKNOWN; |
11689
ac2c63b73009
6917482 zvol_dumpify() needs to ensure no writes are in flight before doing traverse
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
11656
diff
changeset
|
1542 |
dki.dki_unit = getminor(dev); |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1543 |
dki.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1544 |
mutex_exit(&zfsdev_state_lock); |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1545 |
if (ddi_copyout(&dki, (void *)arg, sizeof (dki), flag)) |
789 | 1546 |
error = EFAULT; |
1547 |
return (error); |
|
1548 |
||
1549 |
case DKIOCGMEDIAINFO: |
|
1550 |
bzero(&dkm, sizeof (dkm)); |
|
1551 |
dkm.dki_lbsize = 1U << zv->zv_min_bs; |
|
1552 |
dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs; |
|
1553 |
dkm.dki_media_type = DK_UNKNOWN; |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1554 |
mutex_exit(&zfsdev_state_lock); |
789 | 1555 |
if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag)) |
1556 |
error = EFAULT; |
|
1557 |
return (error); |
|
1558 |
||
1559 |
case DKIOCGETEFI: |
|
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1560 |
{ |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1561 |
uint64_t vs = zv->zv_volsize; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1562 |
uint8_t bs = zv->zv_min_bs; |
3016 | 1563 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1564 |
mutex_exit(&zfsdev_state_lock); |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1565 |
error = zvol_getefi((void *)arg, flag, vs, bs); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1566 |
return (error); |
3016 | 1567 |
} |
789 | 1568 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1569 |
case DKIOCFLUSHWRITECACHE: |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1570 |
dkc = (struct dk_callback *)arg; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1571 |
mutex_exit(&zfsdev_state_lock); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1572 |
zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ); |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1573 |
if ((flag & FKIOCTL) && dkc != NULL && dkc->dkc_callback) { |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1574 |
(*dkc->dkc_callback)(dkc->dkc_cookie, error); |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1575 |
error = 0; |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1576 |
} |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1577 |
return (error); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1578 |
|
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1579 |
case DKIOCGETWCE: |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1580 |
{ |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1581 |
int wce = (zv->zv_flags & ZVOL_WCE) ? 1 : 0; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1582 |
if (ddi_copyout(&wce, (void *)arg, sizeof (int), |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1583 |
flag)) |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1584 |
error = EFAULT; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1585 |
break; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1586 |
} |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1587 |
case DKIOCSETWCE: |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1588 |
{ |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1589 |
int wce; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1590 |
if (ddi_copyin((void *)arg, &wce, sizeof (int), |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1591 |
flag)) { |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1592 |
error = EFAULT; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1593 |
break; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1594 |
} |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1595 |
if (wce) { |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1596 |
zv->zv_flags |= ZVOL_WCE; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1597 |
mutex_exit(&zfsdev_state_lock); |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1598 |
} else { |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1599 |
zv->zv_flags &= ~ZVOL_WCE; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1600 |
mutex_exit(&zfsdev_state_lock); |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1601 |
zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1602 |
} |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1603 |
return (0); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1604 |
} |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1605 |
|
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1606 |
case DKIOCGGEOM: |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1607 |
case DKIOCGVTOC: |
6423 | 1608 |
/* |
1609 |
* commands using these (like prtvtoc) expect ENOTSUP |
|
1610 |
* since we're emulating an EFI label |
|
1611 |
*/ |
|
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1612 |
error = ENOTSUP; |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1613 |
break; |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1614 |
|
6423 | 1615 |
case DKIOCDUMPINIT: |
1616 |
rl = zfs_range_lock(&zv->zv_znode, 0, zv->zv_volsize, |
|
1617 |
RL_WRITER); |
|
1618 |
error = zvol_dumpify(zv); |
|
1619 |
zfs_range_unlock(rl); |
|
1620 |
break; |
|
1621 |
||
1622 |
case DKIOCDUMPFINI: |
|
9277
3e67eb420d44
6817316 data corruption: failed zvol dumpify erases tmpfs data
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8524
diff
changeset
|
1623 |
if (!(zv->zv_flags & ZVOL_DUMPIFIED)) |
3e67eb420d44
6817316 data corruption: failed zvol dumpify erases tmpfs data
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8524
diff
changeset
|
1624 |
break; |
6423 | 1625 |
rl = zfs_range_lock(&zv->zv_znode, 0, zv->zv_volsize, |
1626 |
RL_WRITER); |
|
1627 |
error = zvol_dump_fini(zv); |
|
1628 |
zfs_range_unlock(rl); |
|
1629 |
break; |
|
1630 |
||
789 | 1631 |
default: |
3016 | 1632 |
error = ENOTTY; |
789 | 1633 |
break; |
1634 |
||
1635 |
} |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1636 |
mutex_exit(&zfsdev_state_lock); |
789 | 1637 |
return (error); |
1638 |
} |
|
1639 |
||
1640 |
int |
|
1641 |
zvol_busy(void) |
|
1642 |
{ |
|
1643 |
return (zvol_minors != 0); |
|
1644 |
} |
|
1645 |
||
1646 |
void |
|
1647 |
zvol_init(void) |
|
1648 |
{ |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1649 |
VERIFY(ddi_soft_state_init(&zfsdev_state, sizeof (zfs_soft_state_t), |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1650 |
1) == 0); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1651 |
mutex_init(&zfsdev_state_lock, NULL, MUTEX_DEFAULT, NULL); |
789 | 1652 |
} |
1653 |
||
1654 |
void |
|
1655 |
zvol_fini(void) |
|
1656 |
{ |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1657 |
mutex_destroy(&zfsdev_state_lock); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1658 |
ddi_soft_state_fini(&zfsdev_state); |
789 | 1659 |
} |
6423 | 1660 |
|
1661 |
static int |
|
1662 |
zvol_dump_init(zvol_state_t *zv, boolean_t resize) |
|
1663 |
{ |
|
1664 |
dmu_tx_t *tx; |
|
1665 |
int error = 0; |
|
1666 |
objset_t *os = zv->zv_objset; |
|
1667 |
nvlist_t *nv = NULL; |
|
11656
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1668 |
uint64_t version = spa_version(dmu_objset_spa(zv->zv_objset)); |
6423 | 1669 |
|
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12314
diff
changeset
|
1670 |
ASSERT(MUTEX_HELD(&zfsdev_state_lock)); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1671 |
error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, 0, |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1672 |
DMU_OBJECT_END); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1673 |
/* wait for dmu_free_long_range to actually free the blocks */ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1674 |
txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0); |
6423 | 1675 |
|
1676 |
tx = dmu_tx_create(os); |
|
1677 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1678 |
dmu_tx_hold_bonus(tx, ZVOL_OBJ); |
6423 | 1679 |
error = dmu_tx_assign(tx, TXG_WAIT); |
1680 |
if (error) { |
|
1681 |
dmu_tx_abort(tx); |
|
1682 |
return (error); |
|
1683 |
} |
|
1684 |
||
1685 |
/* |
|
1686 |
* If we are resizing the dump device then we only need to |
|
1687 |
* update the refreservation to match the newly updated |
|
1688 |
* zvolsize. Otherwise, we save off the original state of the |
|
1689 |
* zvol so that we can restore them if the zvol is ever undumpified. |
|
1690 |
*/ |
|
1691 |
if (resize) { |
|
1692 |
error = zap_update(os, ZVOL_ZAP_OBJ, |
|
1693 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, |
|
1694 |
&zv->zv_volsize, tx); |
|
1695 |
} else { |
|
11619
d3fb7ae6fe56
6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents:
11422
diff
changeset
|
1696 |
uint64_t checksum, compress, refresrv, vbs, dedup; |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1697 |
|
6423 | 1698 |
error = dsl_prop_get_integer(zv->zv_name, |
1699 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), &compress, NULL); |
|
1700 |
error = error ? error : dsl_prop_get_integer(zv->zv_name, |
|
1701 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), &checksum, NULL); |
|
1702 |
error = error ? error : dsl_prop_get_integer(zv->zv_name, |
|
1703 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), &refresrv, NULL); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1704 |
error = error ? error : dsl_prop_get_integer(zv->zv_name, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1705 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &vbs, NULL); |
11656
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1706 |
if (version >= SPA_VERSION_DEDUP) { |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1707 |
error = error ? error : |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1708 |
dsl_prop_get_integer(zv->zv_name, |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1709 |
zfs_prop_to_name(ZFS_PROP_DEDUP), &dedup, NULL); |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1710 |
} |
6423 | 1711 |
|
1712 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
|
1713 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), 8, 1, |
|
1714 |
&compress, tx); |
|
1715 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
|
1716 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), 8, 1, &checksum, tx); |
|
1717 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
|
1718 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, |
|
1719 |
&refresrv, tx); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1720 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1721 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), 8, 1, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1722 |
&vbs, tx); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1723 |
error = error ? error : dmu_object_set_blocksize( |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1724 |
os, ZVOL_OBJ, SPA_MAXBLOCKSIZE, 0, tx); |
11656
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1725 |
if (version >= SPA_VERSION_DEDUP) { |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1726 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1727 |
zfs_prop_to_name(ZFS_PROP_DEDUP), 8, 1, |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1728 |
&dedup, tx); |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1729 |
} |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1730 |
if (error == 0) |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1731 |
zv->zv_volblocksize = SPA_MAXBLOCKSIZE; |
6423 | 1732 |
} |
1733 |
dmu_tx_commit(tx); |
|
1734 |
||
1735 |
/* |
|
1736 |
* We only need update the zvol's property if we are initializing |
|
1737 |
* the dump area for the first time. |
|
1738 |
*/ |
|
1739 |
if (!resize) { |
|
1740 |
VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
1741 |
VERIFY(nvlist_add_uint64(nv, |
|
1742 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 0) == 0); |
|
1743 |
VERIFY(nvlist_add_uint64(nv, |
|
1744 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), |
|
1745 |
ZIO_COMPRESS_OFF) == 0); |
|
1746 |
VERIFY(nvlist_add_uint64(nv, |
|
1747 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), |
|
1748 |
ZIO_CHECKSUM_OFF) == 0); |
|
11656
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1749 |
if (version >= SPA_VERSION_DEDUP) { |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1750 |
VERIFY(nvlist_add_uint64(nv, |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1751 |
zfs_prop_to_name(ZFS_PROP_DEDUP), |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1752 |
ZIO_CHECKSUM_OFF) == 0); |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1753 |
} |
6423 | 1754 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
1755 |
error = zfs_set_prop_nvlist(zv->zv_name, ZPROP_SRC_LOCAL, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
1756 |
nv, NULL); |
6423 | 1757 |
nvlist_free(nv); |
1758 |
||
1759 |
if (error) |
|
1760 |
return (error); |
|
1761 |
} |
|
1762 |
||
1763 |
/* Allocate the space for the dump */ |
|
1764 |
error = zvol_prealloc(zv); |
|
1765 |
return (error); |
|
1766 |
} |
|
1767 |
||
1768 |
static int |
|
1769 |
zvol_dumpify(zvol_state_t *zv) |
|
1770 |
{ |
|
1771 |
int error = 0; |
|
1772 |
uint64_t dumpsize = 0; |
|
1773 |
dmu_tx_t *tx; |
|
1774 |
objset_t *os = zv->zv_objset; |
|
1775 |
||
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1776 |
if (zv->zv_flags & ZVOL_RDONLY) |
6423 | 1777 |
return (EROFS); |
1778 |
||
1779 |
if (zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, |
|
1780 |
8, 1, &dumpsize) != 0 || dumpsize != zv->zv_volsize) { |
|
1781 |
boolean_t resize = (dumpsize > 0) ? B_TRUE : B_FALSE; |
|
1782 |
||
1783 |
if ((error = zvol_dump_init(zv, resize)) != 0) { |
|
1784 |
(void) zvol_dump_fini(zv); |
|
1785 |
return (error); |
|
1786 |
} |
|
1787 |
} |
|
1788 |
||
1789 |
/* |
|
1790 |
* Build up our lba mapping. |
|
1791 |
*/ |
|
1792 |
error = zvol_get_lbas(zv); |
|
1793 |
if (error) { |
|
1794 |
(void) zvol_dump_fini(zv); |
|
1795 |
return (error); |
|
1796 |
} |
|
1797 |
||
1798 |
tx = dmu_tx_create(os); |
|
1799 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
|
1800 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1801 |
if (error) { |
|
1802 |
dmu_tx_abort(tx); |
|
1803 |
(void) zvol_dump_fini(zv); |
|
1804 |
return (error); |
|
1805 |
} |
|
1806 |
||
1807 |
zv->zv_flags |= ZVOL_DUMPIFIED; |
|
1808 |
error = zap_update(os, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, 8, 1, |
|
1809 |
&zv->zv_volsize, tx); |
|
1810 |
dmu_tx_commit(tx); |
|
1811 |
||
1812 |
if (error) { |
|
1813 |
(void) zvol_dump_fini(zv); |
|
1814 |
return (error); |
|
1815 |
} |
|
1816 |
||
1817 |
txg_wait_synced(dmu_objset_pool(os), 0); |
|
1818 |
return (0); |
|
1819 |
} |
|
1820 |
||
1821 |
static int |
|
1822 |
zvol_dump_fini(zvol_state_t *zv) |
|
1823 |
{ |
|
1824 |
dmu_tx_t *tx; |
|
1825 |
objset_t *os = zv->zv_objset; |
|
1826 |
nvlist_t *nv; |
|
1827 |
int error = 0; |
|
11619
d3fb7ae6fe56
6909744 dedup should be set to off when a ZVOL is dumpified
George Wilson <George.Wilson@Sun.COM>
parents:
11422
diff
changeset
|
1828 |
uint64_t checksum, compress, refresrv, vbs, dedup; |
11656
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1829 |
uint64_t version = spa_version(dmu_objset_spa(zv->zv_objset)); |
6423 | 1830 |
|
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1831 |
/* |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1832 |
* Attempt to restore the zvol back to its pre-dumpified state. |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1833 |
* This is a best-effort attempt as it's possible that not all |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1834 |
* of these properties were initialized during the dumpify process |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1835 |
* (i.e. error during zvol_dump_init). |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1836 |
*/ |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1837 |
|
6423 | 1838 |
tx = dmu_tx_create(os); |
1839 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
|
1840 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1841 |
if (error) { |
|
1842 |
dmu_tx_abort(tx); |
|
1843 |
return (error); |
|
1844 |
} |
|
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1845 |
(void) zap_remove(os, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, tx); |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1846 |
dmu_tx_commit(tx); |
6423 | 1847 |
|
1848 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
|
1849 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), 8, 1, &checksum); |
|
1850 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
|
1851 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), 8, 1, &compress); |
|
1852 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
|
1853 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, &refresrv); |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1854 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1855 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), 8, 1, &vbs); |
6423 | 1856 |
|
1857 |
VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
1858 |
(void) nvlist_add_uint64(nv, |
|
1859 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), checksum); |
|
1860 |
(void) nvlist_add_uint64(nv, |
|
1861 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), compress); |
|
1862 |
(void) nvlist_add_uint64(nv, |
|
1863 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), refresrv); |
|
11656
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1864 |
if (version >= SPA_VERSION_DEDUP && |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1865 |
zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1866 |
zfs_prop_to_name(ZFS_PROP_DEDUP), 8, 1, &dedup) == 0) { |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1867 |
(void) nvlist_add_uint64(nv, |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1868 |
zfs_prop_to_name(ZFS_PROP_DEDUP), dedup); |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1869 |
} |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
1870 |
(void) zfs_set_prop_nvlist(zv->zv_name, ZPROP_SRC_LOCAL, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
1871 |
nv, NULL); |
6423 | 1872 |
nvlist_free(nv); |
1873 |
||
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1874 |
zvol_free_extents(zv); |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1875 |
zv->zv_flags &= ~ZVOL_DUMPIFIED; |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1876 |
(void) dmu_free_long_range(os, ZVOL_OBJ, 0, DMU_OBJECT_END); |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1877 |
/* wait for dmu_free_long_range to actually free the blocks */ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1878 |
txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1879 |
tx = dmu_tx_create(os); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1880 |
dmu_tx_hold_bonus(tx, ZVOL_OBJ); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1881 |
error = dmu_tx_assign(tx, TXG_WAIT); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1882 |
if (error) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1883 |
dmu_tx_abort(tx); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1884 |
return (error); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1885 |
} |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
1886 |
if (dmu_object_set_blocksize(os, ZVOL_OBJ, vbs, 0, tx) == 0) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
1887 |
zv->zv_volblocksize = vbs; |
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
1888 |
dmu_tx_commit(tx); |
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1889 |
|
6423 | 1890 |
return (0); |
1891 |
} |