author | Eric Taylor <Eric.Taylor@Sun.COM> |
Thu, 18 Feb 2010 10:41:35 -0700 | |
changeset 11689 | ac2c63b73009 |
parent 11656 | bbf9f275fc66 |
child 11806 | ed3bdb1987b3 |
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 |
/* |
|
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11022
diff
changeset
|
22 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* ZFS volume emulation driver. |
|
28 |
* |
|
29 |
* Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes. |
|
30 |
* Volumes are accessed through the symbolic links named: |
|
31 |
* |
|
32 |
* /dev/zvol/dsk/<pool_name>/<dataset_name> |
|
33 |
* /dev/zvol/rdsk/<pool_name>/<dataset_name> |
|
34 |
* |
|
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
|
35 |
* These links are created by the /dev filesystem (sdev_zvolops.c). |
789 | 36 |
* Volumes are persistent through reboot. No user command needs to be |
37 |
* run before opening and using a device. |
|
38 |
*/ |
|
39 |
||
40 |
#include <sys/types.h> |
|
41 |
#include <sys/param.h> |
|
42 |
#include <sys/errno.h> |
|
43 |
#include <sys/uio.h> |
|
44 |
#include <sys/buf.h> |
|
45 |
#include <sys/modctl.h> |
|
46 |
#include <sys/open.h> |
|
47 |
#include <sys/kmem.h> |
|
48 |
#include <sys/conf.h> |
|
49 |
#include <sys/cmn_err.h> |
|
50 |
#include <sys/stat.h> |
|
51 |
#include <sys/zap.h> |
|
52 |
#include <sys/spa.h> |
|
53 |
#include <sys/zio.h> |
|
6423 | 54 |
#include <sys/dmu_traverse.h> |
55 |
#include <sys/dnode.h> |
|
56 |
#include <sys/dsl_dataset.h> |
|
789 | 57 |
#include <sys/dsl_prop.h> |
58 |
#include <sys/dkio.h> |
|
59 |
#include <sys/efi_partition.h> |
|
60 |
#include <sys/byteorder.h> |
|
61 |
#include <sys/pathname.h> |
|
62 |
#include <sys/ddi.h> |
|
63 |
#include <sys/sunddi.h> |
|
64 |
#include <sys/crc32.h> |
|
65 |
#include <sys/dirent.h> |
|
66 |
#include <sys/policy.h> |
|
67 |
#include <sys/fs/zfs.h> |
|
68 |
#include <sys/zfs_ioctl.h> |
|
69 |
#include <sys/mkdev.h> |
|
1141 | 70 |
#include <sys/zil.h> |
2237 | 71 |
#include <sys/refcount.h> |
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
|
72 |
#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
|
73 |
#include <sys/zfs_rlock.h> |
6423 | 74 |
#include <sys/vdev_disk.h> |
75 |
#include <sys/vdev_impl.h> |
|
76 |
#include <sys/zvol.h> |
|
77 |
#include <sys/dumphdr.h> |
|
8227 | 78 |
#include <sys/zil_impl.h> |
789 | 79 |
|
80 |
#include "zfs_namecheck.h" |
|
81 |
||
6423 | 82 |
static void *zvol_state; |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
83 |
static char *zvol_tag = "zvol_tag"; |
789 | 84 |
|
6423 | 85 |
#define ZVOL_DUMPSIZE "dumpsize" |
789 | 86 |
|
87 |
/* |
|
88 |
* This lock protects the zvol_state structure from being modified |
|
89 |
* while it's being used, e.g. an open that comes in before a create |
|
90 |
* finishes. It also protects temporary opens of the dataset so that, |
|
91 |
* e.g., an open doesn't get a spurious EBUSY. |
|
92 |
*/ |
|
93 |
static kmutex_t zvol_state_lock; |
|
94 |
static uint32_t zvol_minors; |
|
95 |
||
6423 | 96 |
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
|
97 |
list_node_t ze_node; |
6423 | 98 |
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
|
99 |
uint64_t ze_nblks; /* number of blocks in extent */ |
6423 | 100 |
} zvol_extent_t; |
101 |
||
102 |
/* |
|
789 | 103 |
* The in-core state of each volume. |
104 |
*/ |
|
105 |
typedef struct zvol_state { |
|
106 |
char zv_name[MAXPATHLEN]; /* pool/dd name */ |
|
107 |
uint64_t zv_volsize; /* amount of space we advertise */ |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
108 |
uint64_t zv_volblocksize; /* volume block size */ |
789 | 109 |
minor_t zv_minor; /* minor number */ |
110 |
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
|
111 |
uint8_t zv_flags; /* readonly, dumpified, etc. */ |
789 | 112 |
objset_t *zv_objset; /* objset handle */ |
113 |
uint32_t zv_open_count[OTYPCNT]; /* open counts */ |
|
114 |
uint32_t zv_total_opens; /* total open count */ |
|
1141 | 115 |
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
|
116 |
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
|
117 |
znode_t zv_znode; /* for range locking */ |
789 | 118 |
} zvol_state_t; |
119 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
120 |
/* |
6423 | 121 |
* zvol specific flags |
122 |
*/ |
|
123 |
#define ZVOL_RDONLY 0x1 |
|
124 |
#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
|
125 |
#define ZVOL_EXCL 0x4 |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
126 |
#define ZVOL_WCE 0x8 |
6423 | 127 |
|
128 |
/* |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
129 |
* zvol maximum transfer in one DMU tx. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
130 |
*/ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
131 |
int zvol_maxphys = DMU_MAX_ACCESS/2; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
132 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
static int zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio); |
6423 | 137 |
static int zvol_dumpify(zvol_state_t *zv); |
138 |
static int zvol_dump_fini(zvol_state_t *zv); |
|
139 |
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
|
140 |
|
789 | 141 |
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
|
142 |
zvol_size_changed(uint64_t volsize, major_t maj, minor_t min) |
789 | 143 |
{ |
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 |
dev_t dev = makedevice(maj, min); |
789 | 145 |
|
146 |
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
|
147 |
"Size", volsize) == DDI_SUCCESS); |
789 | 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 |
"Nblocks", lbtodb(volsize)) == DDI_SUCCESS); |
6423 | 150 |
|
151 |
/* Notify specfs to invalidate the cached size */ |
|
152 |
spec_size_invalidate(dev, VBLK); |
|
153 |
spec_size_invalidate(dev, VCHR); |
|
789 | 154 |
} |
155 |
||
156 |
int |
|
2676 | 157 |
zvol_check_volsize(uint64_t volsize, uint64_t blocksize) |
789 | 158 |
{ |
2676 | 159 |
if (volsize == 0) |
789 | 160 |
return (EINVAL); |
161 |
||
2676 | 162 |
if (volsize % blocksize != 0) |
1133
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
163 |
return (EINVAL); |
335d069294d1
6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents:
849
diff
changeset
|
164 |
|
789 | 165 |
#ifdef _ILP32 |
2676 | 166 |
if (volsize - 1 > SPEC_MAXOFFSET_T) |
789 | 167 |
return (EOVERFLOW); |
168 |
#endif |
|
169 |
return (0); |
|
170 |
} |
|
171 |
||
172 |
int |
|
2676 | 173 |
zvol_check_volblocksize(uint64_t volblocksize) |
789 | 174 |
{ |
2676 | 175 |
if (volblocksize < SPA_MINBLOCKSIZE || |
176 |
volblocksize > SPA_MAXBLOCKSIZE || |
|
177 |
!ISP2(volblocksize)) |
|
789 | 178 |
return (EDOM); |
179 |
||
180 |
return (0); |
|
181 |
} |
|
182 |
||
183 |
int |
|
2885 | 184 |
zvol_get_stats(objset_t *os, nvlist_t *nv) |
789 | 185 |
{ |
186 |
int error; |
|
187 |
dmu_object_info_t doi; |
|
2885 | 188 |
uint64_t val; |
789 | 189 |
|
2885 | 190 |
error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val); |
789 | 191 |
if (error) |
192 |
return (error); |
|
193 |
||
2885 | 194 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLSIZE, val); |
195 |
||
789 | 196 |
error = dmu_object_info(os, ZVOL_OBJ, &doi); |
197 |
||
2885 | 198 |
if (error == 0) { |
199 |
dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLBLOCKSIZE, |
|
200 |
doi.doi_data_block_size); |
|
201 |
} |
|
789 | 202 |
|
203 |
return (error); |
|
204 |
} |
|
205 |
||
206 |
/* |
|
207 |
* Find a free minor number. |
|
208 |
*/ |
|
209 |
static minor_t |
|
210 |
zvol_minor_alloc(void) |
|
211 |
{ |
|
212 |
minor_t minor; |
|
213 |
||
214 |
ASSERT(MUTEX_HELD(&zvol_state_lock)); |
|
215 |
||
216 |
for (minor = 1; minor <= ZVOL_MAX_MINOR; minor++) |
|
217 |
if (ddi_get_soft_state(zvol_state, minor) == NULL) |
|
218 |
return (minor); |
|
219 |
||
220 |
return (0); |
|
221 |
} |
|
222 |
||
223 |
static zvol_state_t * |
|
2676 | 224 |
zvol_minor_lookup(const char *name) |
789 | 225 |
{ |
226 |
minor_t minor; |
|
227 |
zvol_state_t *zv; |
|
228 |
||
229 |
ASSERT(MUTEX_HELD(&zvol_state_lock)); |
|
230 |
||
231 |
for (minor = 1; minor <= ZVOL_MAX_MINOR; minor++) { |
|
232 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
233 |
if (zv == NULL) |
|
234 |
continue; |
|
235 |
if (strcmp(zv->zv_name, name) == 0) |
|
236 |
break; |
|
237 |
} |
|
238 |
||
239 |
return (zv); |
|
240 |
} |
|
241 |
||
6423 | 242 |
/* extent mapping arg */ |
243 |
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
|
244 |
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
|
245 |
uint64_t ma_blks; |
6423 | 246 |
}; |
247 |
||
248 |
/*ARGSUSED*/ |
|
249 |
static int |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
250 |
zvol_map_block(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
251 |
const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg) |
6423 | 252 |
{ |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
253 |
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
|
254 |
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
|
255 |
int bs = ma->ma_zv->zv_volblocksize; |
6423 | 256 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
257 |
if (bp == NULL || zb->zb_object != ZVOL_OBJ || zb->zb_level != 0) |
6423 | 258 |
return (0); |
259 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
|
6423 | 263 |
/* 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
|
264 |
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
|
265 |
return (EFRAGS); |
6423 | 266 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
267 |
/* |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
268 |
* 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
|
269 |
*/ |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
ze->ze_nblks++; |
6423 | 276 |
return (0); |
277 |
} |
|
278 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
279 |
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
|
280 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
281 |
/* 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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
288 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
289 |
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
|
290 |
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
|
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 |
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
|
293 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
298 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
299 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
{ |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
|
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
|
311 |
/* 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
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
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
|
316 |
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
|
317 |
return (err ? err : EIO); |
6423 | 318 |
} |
319 |
||
320 |
return (0); |
|
321 |
} |
|
322 |
||
4543 | 323 |
/* ARGSUSED */ |
789 | 324 |
void |
4543 | 325 |
zvol_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx) |
789 | 326 |
{ |
5331 | 327 |
zfs_creat_t *zct = arg; |
328 |
nvlist_t *nvprops = zct->zct_props; |
|
789 | 329 |
int error; |
2676 | 330 |
uint64_t volblocksize, volsize; |
789 | 331 |
|
4543 | 332 |
VERIFY(nvlist_lookup_uint64(nvprops, |
2676 | 333 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) == 0); |
4543 | 334 |
if (nvlist_lookup_uint64(nvprops, |
2676 | 335 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &volblocksize) != 0) |
336 |
volblocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE); |
|
337 |
||
338 |
/* |
|
6423 | 339 |
* These properties must be removed from the list so the generic |
2676 | 340 |
* property setting step won't apply to them. |
341 |
*/ |
|
4543 | 342 |
VERIFY(nvlist_remove_all(nvprops, |
2676 | 343 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE)) == 0); |
4543 | 344 |
(void) nvlist_remove_all(nvprops, |
2676 | 345 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE)); |
346 |
||
347 |
error = dmu_object_claim(os, ZVOL_OBJ, DMU_OT_ZVOL, volblocksize, |
|
789 | 348 |
DMU_OT_NONE, 0, tx); |
349 |
ASSERT(error == 0); |
|
350 |
||
351 |
error = zap_create_claim(os, ZVOL_ZAP_OBJ, DMU_OT_ZVOL_PROP, |
|
352 |
DMU_OT_NONE, 0, tx); |
|
353 |
ASSERT(error == 0); |
|
354 |
||
2676 | 355 |
error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize, tx); |
789 | 356 |
ASSERT(error == 0); |
357 |
} |
|
358 |
||
359 |
/* |
|
1141 | 360 |
* Replay a TX_WRITE ZIL transaction that didn't get committed |
361 |
* after a system failure |
|
362 |
*/ |
|
363 |
static int |
|
364 |
zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap) |
|
365 |
{ |
|
366 |
objset_t *os = zv->zv_objset; |
|
367 |
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
|
368 |
uint64_t offset, length; |
1141 | 369 |
dmu_tx_t *tx; |
370 |
int error; |
|
371 |
||
372 |
if (byteswap) |
|
373 |
byteswap_uint64_array(lr, sizeof (*lr)); |
|
374 |
||
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
375 |
offset = lr->lr_offset; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
376 |
length = lr->lr_length; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
377 |
|
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
378 |
/* 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
|
379 |
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
|
380 |
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
|
381 |
if (length < blocksize) { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
382 |
offset -= offset % blocksize; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
383 |
length = blocksize; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
384 |
} |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
385 |
} |
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
|
386 |
|
1141 | 387 |
tx = dmu_tx_create(os); |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
388 |
dmu_tx_hold_write(tx, ZVOL_OBJ, offset, length); |
8227 | 389 |
error = dmu_tx_assign(tx, TXG_WAIT); |
1141 | 390 |
if (error) { |
391 |
dmu_tx_abort(tx); |
|
392 |
} else { |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
393 |
dmu_write(os, ZVOL_OBJ, offset, length, data, tx); |
1141 | 394 |
dmu_tx_commit(tx); |
395 |
} |
|
396 |
||
397 |
return (error); |
|
398 |
} |
|
399 |
||
400 |
/* ARGSUSED */ |
|
401 |
static int |
|
402 |
zvol_replay_err(zvol_state_t *zv, lr_t *lr, boolean_t byteswap) |
|
403 |
{ |
|
404 |
return (ENOTSUP); |
|
405 |
} |
|
406 |
||
407 |
/* |
|
408 |
* Callback vectors for replaying records. |
|
409 |
* Only TX_WRITE is needed for zvol. |
|
410 |
*/ |
|
411 |
zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE] = { |
|
412 |
zvol_replay_err, /* 0 no such transaction type */ |
|
413 |
zvol_replay_err, /* TX_CREATE */ |
|
414 |
zvol_replay_err, /* TX_MKDIR */ |
|
415 |
zvol_replay_err, /* TX_MKXATTR */ |
|
416 |
zvol_replay_err, /* TX_SYMLINK */ |
|
417 |
zvol_replay_err, /* TX_REMOVE */ |
|
418 |
zvol_replay_err, /* TX_RMDIR */ |
|
419 |
zvol_replay_err, /* TX_LINK */ |
|
420 |
zvol_replay_err, /* TX_RENAME */ |
|
421 |
zvol_replay_write, /* TX_WRITE */ |
|
422 |
zvol_replay_err, /* TX_TRUNCATE */ |
|
423 |
zvol_replay_err, /* TX_SETATTR */ |
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
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
|
428 |
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
|
429 |
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
|
430 |
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
|
431 |
zvol_replay_err, /* TX_WRITE2 */ |
1141 | 432 |
}; |
433 |
||
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
|
434 |
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
|
435 |
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
|
436 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
437 |
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
|
438 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
439 |
mutex_enter(&zvol_state_lock); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
440 |
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
|
441 |
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
|
442 |
*minor = 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
|
443 |
mutex_exit(&zvol_state_lock); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
444 |
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
|
445 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
446 |
|
1141 | 447 |
/* |
6423 | 448 |
* Create a minor node (plus a whole lot more) for the specified volume. |
789 | 449 |
*/ |
450 |
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
|
451 |
zvol_create_minor(const char *name) |
789 | 452 |
{ |
453 |
zvol_state_t *zv; |
|
454 |
objset_t *os; |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
455 |
dmu_object_info_t doi; |
789 | 456 |
minor_t minor = 0; |
457 |
char chrbuf[30], blkbuf[30]; |
|
458 |
int error; |
|
459 |
||
460 |
mutex_enter(&zvol_state_lock); |
|
461 |
||
11422
42768837421d
PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents:
11022
diff
changeset
|
462 |
if (zvol_minor_lookup(name) != NULL) { |
789 | 463 |
mutex_exit(&zvol_state_lock); |
464 |
return (EEXIST); |
|
465 |
} |
|
466 |
||
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
467 |
/* 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
|
468 |
error = dmu_objset_own(name, DMU_OST_ZVOL, B_TRUE, zvol_tag, &os); |
789 | 469 |
|
470 |
if (error) { |
|
471 |
mutex_exit(&zvol_state_lock); |
|
472 |
return (error); |
|
473 |
} |
|
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 |
if ((minor = zvol_minor_alloc()) == 0) { |
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
476 |
dmu_objset_disown(os, zvol_tag); |
789 | 477 |
mutex_exit(&zvol_state_lock); |
478 |
return (ENXIO); |
|
479 |
} |
|
480 |
||
481 |
if (ddi_soft_state_zalloc(zvol_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
|
482 |
dmu_objset_disown(os, zvol_tag); |
789 | 483 |
mutex_exit(&zvol_state_lock); |
484 |
return (EAGAIN); |
|
485 |
} |
|
2676 | 486 |
(void) ddi_prop_update_string(minor, zfs_dip, ZVOL_PROP_NAME, |
487 |
(char *)name); |
|
789 | 488 |
|
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
|
489 |
(void) snprintf(chrbuf, sizeof (chrbuf), "%u,raw", minor); |
789 | 490 |
|
491 |
if (ddi_create_minor_node(zfs_dip, chrbuf, S_IFCHR, |
|
492 |
minor, DDI_PSEUDO, 0) == DDI_FAILURE) { |
|
493 |
ddi_soft_state_free(zvol_state, minor); |
|
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
494 |
dmu_objset_disown(os, zvol_tag); |
789 | 495 |
mutex_exit(&zvol_state_lock); |
496 |
return (EAGAIN); |
|
497 |
} |
|
498 |
||
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) snprintf(blkbuf, sizeof (blkbuf), "%u", minor); |
789 | 500 |
|
501 |
if (ddi_create_minor_node(zfs_dip, blkbuf, S_IFBLK, |
|
502 |
minor, DDI_PSEUDO, 0) == DDI_FAILURE) { |
|
503 |
ddi_remove_minor_node(zfs_dip, chrbuf); |
|
504 |
ddi_soft_state_free(zvol_state, minor); |
|
10298
a0d52501437c
6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
10272
diff
changeset
|
505 |
dmu_objset_disown(os, zvol_tag); |
789 | 506 |
mutex_exit(&zvol_state_lock); |
507 |
return (EAGAIN); |
|
508 |
} |
|
509 |
||
510 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
511 |
||
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
|
512 |
(void) strlcpy(zv->zv_name, name, MAXPATHLEN); |
789 | 513 |
zv->zv_min_bs = DEV_BSHIFT; |
514 |
zv->zv_minor = minor; |
|
515 |
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
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
offsetof(zvol_extent_t, ze_node)); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
523 |
/* get and cache the blocksize */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
524 |
error = dmu_object_info(os, ZVOL_OBJ, &doi); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
525 |
ASSERT(error == 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
526 |
zv->zv_volblocksize = doi.doi_data_block_size; |
1141 | 527 |
|
8227 | 528 |
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
|
529 |
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
|
530 |
zv->zv_objset = NULL; |
789 | 531 |
|
532 |
zvol_minors++; |
|
533 |
||
534 |
mutex_exit(&zvol_state_lock); |
|
535 |
||
536 |
return (0); |
|
537 |
} |
|
538 |
||
539 |
/* |
|
540 |
* Remove minor node for the specified volume. |
|
541 |
*/ |
|
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
|
542 |
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
|
543 |
zvol_remove_zv(zvol_state_t *zv) |
789 | 544 |
{ |
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
|
545 |
char nmbuf[20]; |
789 | 546 |
|
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
|
547 |
ASSERT(MUTEX_HELD(&zvol_state_lock)); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
548 |
if (zv->zv_total_opens != 0) |
789 | 549 |
return (EBUSY); |
550 |
||
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
|
551 |
(void) snprintf(nmbuf, sizeof (nmbuf), "%u,raw", 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
|
552 |
ddi_remove_minor_node(zfs_dip, nmbuf); |
789 | 553 |
|
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
|
554 |
(void) snprintf(nmbuf, sizeof (nmbuf), "%u", 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
|
555 |
ddi_remove_minor_node(zfs_dip, nmbuf); |
789 | 556 |
|
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
|
557 |
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
|
558 |
mutex_destroy(&zv->zv_znode.z_range_lock); |
789 | 559 |
|
560 |
ddi_soft_state_free(zvol_state, zv->zv_minor); |
|
561 |
||
562 |
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
|
563 |
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
|
564 |
} |
789 | 565 |
|
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 |
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
|
567 |
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
|
568 |
{ |
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 |
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
|
570 |
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
|
571 |
|
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 |
mutex_enter(&zvol_state_lock); |
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 |
if ((zv = zvol_minor_lookup(name)) == 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
|
574 |
mutex_exit(&zvol_state_lock); |
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 |
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
|
576 |
} |
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 |
rc = zvol_remove_zv(zv); |
789 | 578 |
mutex_exit(&zvol_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
|
579 |
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
|
580 |
} |
789 | 581 |
|
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
|
582 |
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
|
583 |
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
|
584 |
{ |
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 |
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
|
586 |
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
|
587 |
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
|
588 |
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
|
589 |
|
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 |
/* 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
|
591 |
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
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
596 |
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
|
597 |
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
|
598 |
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
|
599 |
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
|
600 |
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
|
601 |
} |
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_objset = 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
|
603 |
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
|
604 |
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
|
605 |
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
|
606 |
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
|
607 |
|
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 |
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
|
609 |
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
|
610 |
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
|
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 |
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
|
613 |
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
|
614 |
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
|
615 |
} |
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 |
|
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 |
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
|
618 |
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
|
619 |
{ |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
620 |
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
|
621 |
zv->zv_zilog = 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
|
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 |
||
671 |
ASSERT(MUTEX_HELD(&zvol_state_lock)); |
|
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, "/"); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
701 |
mutex_enter(&zvol_state_lock); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
702 |
for (minor = 1; minor <= ZVOL_MAX_MINOR; 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
|
703 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
704 |
zv = ddi_get_soft_state(zvol_state, 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
|
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 |
|
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
712 |
mutex_exit(&zvol_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 |
|
725 |
mutex_enter(&zvol_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) { |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
728 |
mutex_exit(&zvol_state_lock); |
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 |
|
789 | 791 |
mutex_exit(&zvol_state_lock); |
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 |
minor_t minor = getminor(*devp); |
|
801 |
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
|
802 |
int err = 0; |
789 | 803 |
|
804 |
if (minor == 0) /* This is the control device */ |
|
805 |
return (0); |
|
806 |
||
807 |
mutex_enter(&zvol_state_lock); |
|
808 |
||
809 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
810 |
if (zv == NULL) { |
|
811 |
mutex_exit(&zvol_state_lock); |
|
812 |
return (ENXIO); |
|
813 |
} |
|
814 |
||
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 |
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
|
816 |
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
|
817 |
if (err) { |
789 | 818 |
mutex_exit(&zvol_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
|
819 |
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
|
820 |
} |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
821 |
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
|
822 |
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
|
823 |
goto out; |
789 | 824 |
} |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
825 |
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
|
826 |
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
|
827 |
goto out; |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
828 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
829 |
if (flag & FEXCL) { |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
830 |
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
|
831 |
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
|
832 |
goto out; |
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
833 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
834 |
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
|
835 |
} |
789 | 836 |
|
837 |
if (zv->zv_open_count[otyp] == 0 || otyp == OTYP_LYR) { |
|
838 |
zv->zv_open_count[otyp]++; |
|
839 |
zv->zv_total_opens++; |
|
840 |
} |
|
841 |
mutex_exit(&zvol_state_lock); |
|
842 |
||
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
|
843 |
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
|
844 |
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
|
845 |
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
|
846 |
zvol_last_close(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
|
847 |
mutex_exit(&zvol_state_lock); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
848 |
return (err); |
789 | 849 |
} |
850 |
||
851 |
/*ARGSUSED*/ |
|
852 |
int |
|
853 |
zvol_close(dev_t dev, int flag, int otyp, cred_t *cr) |
|
854 |
{ |
|
855 |
minor_t minor = getminor(dev); |
|
856 |
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
|
857 |
int error = 0; |
789 | 858 |
|
859 |
if (minor == 0) /* This is the control device */ |
|
860 |
return (0); |
|
861 |
||
862 |
mutex_enter(&zvol_state_lock); |
|
863 |
||
864 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
865 |
if (zv == NULL) { |
|
866 |
mutex_exit(&zvol_state_lock); |
|
867 |
return (ENXIO); |
|
868 |
} |
|
869 |
||
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
870 |
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
|
871 |
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
|
872 |
zv->zv_flags &= ~ZVOL_EXCL; |
789 | 873 |
} |
874 |
||
875 |
/* |
|
876 |
* If the open count is zero, this is a spurious close. |
|
877 |
* That indicates a bug in the kernel / DDI framework. |
|
878 |
*/ |
|
879 |
ASSERT(zv->zv_open_count[otyp] != 0); |
|
880 |
ASSERT(zv->zv_total_opens != 0); |
|
881 |
||
882 |
/* |
|
883 |
* You may get multiple opens, but only one close. |
|
884 |
*/ |
|
885 |
zv->zv_open_count[otyp]--; |
|
886 |
zv->zv_total_opens--; |
|
887 |
||
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
|
888 |
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
|
889 |
zvol_last_close(zv); |
789 | 890 |
|
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
|
891 |
mutex_exit(&zvol_state_lock); |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10310
diff
changeset
|
892 |
return (error); |
789 | 893 |
} |
894 |
||
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
895 |
static void |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
896 |
zvol_get_done(zgd_t *zgd, int error) |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
897 |
{ |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
898 |
if (zgd->zgd_db) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
899 |
dmu_buf_rele(zgd->zgd_db, zgd); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
900 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
901 |
zfs_range_unlock(zgd->zgd_rl); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
902 |
|
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
903 |
if (error == 0 && zgd->zgd_bp) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
904 |
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
|
905 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
906 |
kmem_free(zgd, sizeof (zgd_t)); |
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 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
909 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
910 |
* Get data to generate a TX_WRITE intent log record. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
911 |
*/ |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
912 |
static int |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
913 |
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
|
914 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
915 |
zvol_state_t *zv = arg; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
916 |
objset_t *os = zv->zv_objset; |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
917 |
uint64_t object = ZVOL_OBJ; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
918 |
uint64_t offset = lr->lr_offset; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
919 |
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
|
920 |
blkptr_t *bp = &lr->lr_blkptr; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
921 |
dmu_buf_t *db; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
922 |
zgd_t *zgd; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
923 |
int error; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
924 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
925 |
ASSERT(zio != NULL); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
926 |
ASSERT(size != 0); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
927 |
|
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
928 |
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
|
929 |
zgd->zgd_zilog = zv->zv_zilog; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
930 |
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
|
931 |
|
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
|
932 |
/* |
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
|
933 |
* 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
|
934 |
* 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
|
935 |
* 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
|
936 |
* 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
|
937 |
* 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
|
938 |
*/ |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
939 |
if (buf != NULL) { /* immediate write */ |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
940 |
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
|
941 |
DMU_READ_NO_PREFETCH); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
942 |
} else { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
943 |
size = zv->zv_volblocksize; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
944 |
offset = P2ALIGN(offset, size); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
945 |
error = dmu_buf_hold(os, object, offset, zgd, &db); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
946 |
if (error == 0) { |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
947 |
zgd->zgd_db = db; |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
948 |
zgd->zgd_bp = bp; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
949 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
950 |
ASSERT(db->db_offset == offset); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
951 |
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
|
952 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
953 |
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
|
954 |
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
|
955 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
956 |
if (error == 0) |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
957 |
return (0); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
958 |
} |
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
|
959 |
} |
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
|
960 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
961 |
zvol_get_done(zgd, error); |
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
962 |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
963 |
return (error); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
964 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
965 |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
966 |
/* |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
967 |
* zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions. |
1141 | 968 |
* |
969 |
* 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
|
970 |
* Otherwise we will later flush the data out via dmu_sync(). |
1141 | 971 |
*/ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
972 |
ssize_t zvol_immediate_write_sz = 32768; |
1141 | 973 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
974 |
static void |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
975 |
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
|
976 |
boolean_t sync) |
1141 | 977 |
{ |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
978 |
uint32_t blocksize = zv->zv_volblocksize; |
8227 | 979 |
zilog_t *zilog = zv->zv_zilog; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
980 |
boolean_t slogging; |
10310
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
981 |
ssize_t immediate_write_sz; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
982 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
983 |
if (zil_disable) |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
984 |
return; |
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
985 |
|
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
986 |
if (zil_replaying(zilog, tx)) |
8227 | 987 |
return; |
988 |
||
10310
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
989 |
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
|
990 |
? 0 : zvol_immediate_write_sz; |
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
991 |
|
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
992 |
slogging = spa_has_slogs(zilog->zl_spa) && |
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
993 |
(zilog->zl_logbias == ZFS_LOGBIAS_LATENCY); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
994 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
995 |
while (resid) { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
996 |
itx_t *itx; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
997 |
lr_write_t *lr; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
998 |
ssize_t len; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
999 |
itx_wr_state_t write_state; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1000 |
|
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1001 |
/* |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1002 |
* 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
|
1003 |
* upto DMU_MAX_ACCESS/2 (5MB) writes. |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1004 |
*/ |
10310
ba87b3315737
PSARC 2009/423 ZFS logbias property
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
10298
diff
changeset
|
1005 |
if (blocksize > immediate_write_sz && !slogging && |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1006 |
resid >= blocksize && off % blocksize == 0) { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1007 |
write_state = WR_INDIRECT; /* uses dmu_sync */ |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1008 |
len = blocksize; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1009 |
} else if (sync) { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1010 |
write_state = WR_COPIED; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1011 |
len = MIN(ZIL_MAX_LOG_DATA, resid); |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1012 |
} else { |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1013 |
write_state = WR_NEED_COPY; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1014 |
len = MIN(ZIL_MAX_LOG_DATA, resid); |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1015 |
} |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1016 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1017 |
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
|
1018 |
(write_state == WR_COPIED ? len : 0)); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1019 |
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
|
1020 |
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
|
1021 |
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
|
1022 |
zil_itx_destroy(itx); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1023 |
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
|
1024 |
lr = (lr_write_t *)&itx->itx_lr; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1025 |
write_state = WR_NEED_COPY; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1026 |
} |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1027 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1028 |
itx->itx_wr_state = write_state; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1029 |
if (write_state == WR_NEED_COPY) |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1030 |
itx->itx_sod += len; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1031 |
lr->lr_foid = ZVOL_OBJ; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1032 |
lr->lr_offset = off; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1033 |
lr->lr_length = len; |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
1034 |
lr->lr_blkoff = 0; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1035 |
BP_ZERO(&lr->lr_blkptr); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1036 |
|
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1037 |
itx->itx_private = zv; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1038 |
itx->itx_sync = sync; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1039 |
|
8227 | 1040 |
(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
|
1041 |
|
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1042 |
off += len; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1043 |
resid -= len; |
1141 | 1044 |
} |
1045 |
} |
|
1046 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1047 |
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
|
1048 |
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
|
1049 |
boolean_t doread, boolean_t isdump) |
6423 | 1050 |
{ |
1051 |
vdev_disk_t *dvd; |
|
1052 |
int c; |
|
1053 |
int numerrors = 0; |
|
1054 |
||
1055 |
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
|
1056 |
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
|
1057 |
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
|
1058 |
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
|
1059 |
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
|
1060 |
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
|
1061 |
if (err != 0) { |
6423 | 1062 |
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
|
1063 |
} else if (doread) { |
6423 | 1064 |
break; |
1065 |
} |
|
1066 |
} |
|
1067 |
||
1068 |
if (!vd->vdev_ops->vdev_op_leaf) |
|
1069 |
return (numerrors < vd->vdev_children ? 0 : EIO); |
|
1070 |
||
7903
4c8fa38f91ec
6760985 assertion failure with dump device on pool with non-writeable vdev
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7872
diff
changeset
|
1071 |
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
|
1072 |
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
|
1073 |
else if (!doread && !vdev_writeable(vd)) |
6423 | 1074 |
return (EIO); |
1075 |
||
1076 |
dvd = vd->vdev_tsd; |
|
1077 |
ASSERT3P(dvd, !=, NULL); |
|
1078 |
offset += VDEV_LABEL_START_SIZE; |
|
1079 |
||
1080 |
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
|
1081 |
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
|
1082 |
if (doread) |
6423 | 1083 |
return (EIO); |
1084 |
return (ldi_dump(dvd->vd_lh, addr, lbtodb(offset), |
|
1085 |
lbtodb(size))); |
|
1086 |
} else { |
|
1087 |
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
|
1088 |
doread ? B_READ : B_WRITE)); |
6423 | 1089 |
} |
1090 |
} |
|
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 |
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
|
1093 |
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
|
1094 |
boolean_t doread, boolean_t isdump) |
6423 | 1095 |
{ |
1096 |
vdev_t *vd; |
|
1097 |
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
|
1098 |
zvol_extent_t *ze; |
6423 | 1099 |
spa_t *spa = dmu_objset_spa(zv->zv_objset); |
1100 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1101 |
/* 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
|
1102 |
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
|
1103 |
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
|
1104 |
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
|
1105 |
} |
6423 | 1106 |
ASSERT(size <= zv->zv_volblocksize); |
1107 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1108 |
/* 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
|
1109 |
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
|
1110 |
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
|
1111 |
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
|
1112 |
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
|
1113 |
} |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7638
diff
changeset
|
1114 |
spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); |
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1115 |
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
|
1116 |
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
|
1117 |
error = zvol_dumpio_vdev(vd, addr, offset, size, doread, isdump); |
7754
b80e4842ad54
6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
7638
diff
changeset
|
1118 |
spa_config_exit(spa, SCL_STATE, FTAG); |
6423 | 1119 |
return (error); |
1120 |
} |
|
1121 |
||
1122 |
int |
|
789 | 1123 |
zvol_strategy(buf_t *bp) |
1124 |
{ |
|
1125 |
zvol_state_t *zv = ddi_get_soft_state(zvol_state, getminor(bp->b_edev)); |
|
1126 |
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
|
1127 |
size_t resid; |
789 | 1128 |
char *addr; |
1141 | 1129 |
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
|
1130 |
rl_t *rl; |
789 | 1131 |
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
|
1132 |
boolean_t doread = bp->b_flags & 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
|
1133 |
boolean_t is_dump = zv->zv_flags & ZVOL_DUMPIFIED; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1134 |
boolean_t sync; |
789 | 1135 |
|
1136 |
if (zv == NULL) { |
|
1137 |
bioerror(bp, ENXIO); |
|
1138 |
biodone(bp); |
|
1139 |
return (0); |
|
1140 |
} |
|
1141 |
||
1142 |
if (getminor(bp->b_edev) == 0) { |
|
1143 |
bioerror(bp, EINVAL); |
|
1144 |
biodone(bp); |
|
1145 |
return (0); |
|
1146 |
} |
|
1147 |
||
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
|
1148 |
if (!(bp->b_flags & B_READ) && (zv->zv_flags & ZVOL_RDONLY)) { |
789 | 1149 |
bioerror(bp, EROFS); |
1150 |
biodone(bp); |
|
1151 |
return (0); |
|
1152 |
} |
|
1153 |
||
1154 |
off = ldbtob(bp->b_blkno); |
|
1155 |
volsize = zv->zv_volsize; |
|
1156 |
||
1141 | 1157 |
os = zv->zv_objset; |
1158 |
ASSERT(os != NULL); |
|
789 | 1159 |
|
1160 |
bp_mapin(bp); |
|
1161 |
addr = bp->b_un.b_addr; |
|
1162 |
resid = bp->b_bcount; |
|
1163 |
||
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1164 |
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
|
1165 |
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
|
1166 |
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
|
1167 |
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
|
1168 |
} |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1169 |
|
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1170 |
sync = !(bp->b_flags & B_ASYNC) && !doread && !is_dump && |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1171 |
!(zv->zv_flags & ZVOL_WCE) && !zil_disable; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1172 |
|
1861
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
1173 |
/* |
7929434f26fb
6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents:
1669
diff
changeset
|
1174 |
* 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
|
1175 |
* 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
|
1176 |
*/ |
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
|
1177 |
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
|
1178 |
doread ? RL_READER : RL_WRITER); |
6423 | 1179 |
|
789 | 1180 |
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
|
1181 |
size_t size = MIN(resid, zvol_maxphys); |
6423 | 1182 |
if (is_dump) { |
1183 |
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
|
1184 |
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
|
1185 |
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
|
1186 |
} 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
|
1187 |
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
|
1188 |
DMU_READ_PREFETCH); |
789 | 1189 |
} else { |
1141 | 1190 |
dmu_tx_t *tx = dmu_tx_create(os); |
789 | 1191 |
dmu_tx_hold_write(tx, ZVOL_OBJ, off, size); |
1192 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1193 |
if (error) { |
|
1194 |
dmu_tx_abort(tx); |
|
1195 |
} else { |
|
1141 | 1196 |
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
|
1197 |
zvol_log_write(zv, tx, off, size, sync); |
789 | 1198 |
dmu_tx_commit(tx); |
1199 |
} |
|
1200 |
} |
|
7294 | 1201 |
if (error) { |
1202 |
/* convert checksum errors into IO errors */ |
|
1203 |
if (error == ECKSUM) |
|
1204 |
error = EIO; |
|
789 | 1205 |
break; |
7294 | 1206 |
} |
789 | 1207 |
off += size; |
1208 |
addr += size; |
|
1209 |
resid -= size; |
|
1210 |
} |
|
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
|
1211 |
zfs_range_unlock(rl); |
789 | 1212 |
|
1213 |
if ((bp->b_resid = resid) == bp->b_bcount) |
|
1214 |
bioerror(bp, off > volsize ? EINVAL : error); |
|
1215 |
||
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1216 |
if (sync) |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1217 |
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
|
1218 |
biodone(bp); |
1141 | 1219 |
|
789 | 1220 |
return (0); |
1221 |
} |
|
1222 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1223 |
/* |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1224 |
* Set the buffer count to the zvol maximum transfer. |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1225 |
* Using our own routine instead of the default minphys() |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1226 |
* 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
|
1227 |
* (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
|
1228 |
* (every zvol_maxphys - currently 1MB) instead of minphys (currently |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1229 |
* 56K on X86 and 128K on sparc). |
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 |
void |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1232 |
zvol_minphys(struct buf *bp) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1233 |
{ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1234 |
if (bp->b_bcount > zvol_maxphys) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1235 |
bp->b_bcount = zvol_maxphys; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1236 |
} |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
3016
diff
changeset
|
1237 |
|
6423 | 1238 |
int |
1239 |
zvol_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblocks) |
|
1240 |
{ |
|
1241 |
minor_t minor = getminor(dev); |
|
1242 |
zvol_state_t *zv; |
|
1243 |
int error = 0; |
|
1244 |
uint64_t size; |
|
1245 |
uint64_t boff; |
|
1246 |
uint64_t resid; |
|
1247 |
||
1248 |
if (minor == 0) /* This is the control device */ |
|
1249 |
return (ENXIO); |
|
1250 |
||
1251 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
1252 |
if (zv == NULL) |
|
1253 |
return (ENXIO); |
|
1254 |
||
1255 |
boff = ldbtob(blkno); |
|
1256 |
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
|
1257 |
|
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1258 |
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
|
1259 |
|
6423 | 1260 |
while (resid) { |
1261 |
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
|
1262 |
error = zvol_dumpio(zv, addr, boff, size, B_FALSE, B_TRUE); |
6423 | 1263 |
if (error) |
1264 |
break; |
|
1265 |
boff += size; |
|
1266 |
addr += size; |
|
1267 |
resid -= size; |
|
1268 |
} |
|
1269 |
||
1270 |
return (error); |
|
1271 |
} |
|
1272 |
||
789 | 1273 |
/*ARGSUSED*/ |
1274 |
int |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1275 |
zvol_read(dev_t dev, uio_t *uio, cred_t *cr) |
789 | 1276 |
{ |
4107 | 1277 |
minor_t minor = getminor(dev); |
1278 |
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
|
1279 |
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
|
1280 |
rl_t *rl; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1281 |
int error = 0; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1282 |
|
4107 | 1283 |
if (minor == 0) /* This is the control device */ |
1284 |
return (ENXIO); |
|
1285 |
||
1286 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
1287 |
if (zv == NULL) |
|
1288 |
return (ENXIO); |
|
1289 |
||
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1290 |
volsize = zv->zv_volsize; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1291 |
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
|
1292 |
(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
|
1293 |
return (EIO); |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1294 |
|
7837
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1295 |
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
|
1296 |
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
|
1297 |
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
|
1298 |
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
|
1299 |
} |
001de5627df3
6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7754
diff
changeset
|
1300 |
|
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
|
1301 |
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
|
1302 |
RL_READER); |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1303 |
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
|
1304 |
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
|
1305 |
|
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1306 |
/* 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
|
1307 |
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
|
1308 |
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 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1310 |
error = dmu_read_uio(zv->zv_objset, ZVOL_OBJ, uio, bytes); |
7294 | 1311 |
if (error) { |
1312 |
/* convert checksum errors into IO errors */ |
|
1313 |
if (error == ECKSUM) |
|
1314 |
error = EIO; |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1315 |
break; |
7294 | 1316 |
} |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1317 |
} |
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
|
1318 |
zfs_range_unlock(rl); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1319 |
return (error); |
789 | 1320 |
} |
1321 |
||
1322 |
/*ARGSUSED*/ |
|
1323 |
int |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1324 |
zvol_write(dev_t dev, uio_t *uio, cred_t *cr) |
789 | 1325 |
{ |
4107 | 1326 |
minor_t minor = getminor(dev); |
1327 |
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
|
1328 |
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
|
1329 |
rl_t *rl; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1330 |
int error = 0; |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1331 |
boolean_t sync; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1332 |
|
4107 | 1333 |
if (minor == 0) /* This is the control device */ |
1334 |
return (ENXIO); |
|
1335 |
||
1336 |
zv = ddi_get_soft_state(zvol_state, minor); |
|
1337 |
if (zv == NULL) |
|
1338 |
return (ENXIO); |
|
1339 |
||
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1340 |
volsize = zv->zv_volsize; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1341 |
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
|
1342 |
(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
|
1343 |
return (EIO); |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1344 |
|
6423 | 1345 |
if (zv->zv_flags & ZVOL_DUMPIFIED) { |
1346 |
error = physio(zvol_strategy, NULL, dev, B_WRITE, |
|
1347 |
zvol_minphys, uio); |
|
1348 |
return (error); |
|
1349 |
} |
|
1350 |
||
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1351 |
sync = !(zv->zv_flags & ZVOL_WCE) && !zil_disable; |
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1352 |
|
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
|
1353 |
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
|
1354 |
RL_WRITER); |
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1355 |
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
|
1356 |
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
|
1357 |
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
|
1358 |
dmu_tx_t *tx = dmu_tx_create(zv->zv_objset); |
789 | 1359 |
|
7013
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1360 |
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
|
1361 |
bytes = volsize - off; |
540c400de3b4
6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents:
6992
diff
changeset
|
1362 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1363 |
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
|
1364 |
error = dmu_tx_assign(tx, TXG_WAIT); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1365 |
if (error) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1366 |
dmu_tx_abort(tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1367 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1368 |
} |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1369 |
error = dmu_write_uio(zv->zv_objset, ZVOL_OBJ, uio, bytes, tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1370 |
if (error == 0) |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1371 |
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
|
1372 |
dmu_tx_commit(tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1373 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1374 |
if (error) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1375 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1376 |
} |
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
|
1377 |
zfs_range_unlock(rl); |
9401
afae664f76f6
6773224 zvol_log_write() is inefficient
Neil Perrin <Neil.Perrin@Sun.COM>
parents:
9303
diff
changeset
|
1378 |
if (sync) |
8524
a56dffa8fba9
6770534 zvols do not observe character device semantics
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8227
diff
changeset
|
1379 |
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
|
1380 |
return (error); |
789 | 1381 |
} |
1382 |
||
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1383 |
int |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1384 |
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
|
1385 |
{ |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1386 |
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
|
1387 |
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
|
1388 |
uint32_t crc; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1389 |
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
|
1390 |
int length; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1391 |
char *ptr; |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1392 |
|
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1393 |
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
|
1394 |
return (EFAULT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1395 |
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
|
1396 |
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
|
1397 |
/* |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1398 |
* 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
|
1399 |
* 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
|
1400 |
* 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
|
1401 |
* 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
|
1402 |
* PMBR. |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1403 |
*/ |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1404 |
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
|
1405 |
return (EINVAL); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1406 |
|
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_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
|
1408 |
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
|
1409 |
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
|
1410 |
|
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1411 |
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
|
1412 |
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
|
1413 |
|
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_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
|
1415 |
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
|
1416 |
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
|
1417 |
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
|
1418 |
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
|
1419 |
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
|
1420 |
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
|
1421 |
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
|
1422 |
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
|
1423 |
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
|
1424 |
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
|
1425 |
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
|
1426 |
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
|
1427 |
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
|
1428 |
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
|
1429 |
flag)) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1430 |
return (EFAULT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1431 |
ptr += sizeof (gpt); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1432 |
length -= sizeof (gpt); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1433 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1434 |
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
|
1435 |
length), flag)) |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1436 |
return (EFAULT); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1437 |
return (0); |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1438 |
} |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1439 |
|
789 | 1440 |
/* |
1441 |
* Dirtbag ioctls to support mkfs(1M) for UFS filesystems. See dkio(7I). |
|
1442 |
*/ |
|
1443 |
/*ARGSUSED*/ |
|
1444 |
int |
|
1445 |
zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp) |
|
1446 |
{ |
|
1447 |
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
|
1448 |
struct dk_cinfo dki; |
789 | 1449 |
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
|
1450 |
struct dk_callback *dkc; |
789 | 1451 |
int error = 0; |
6423 | 1452 |
rl_t *rl; |
789 | 1453 |
|
1454 |
mutex_enter(&zvol_state_lock); |
|
1455 |
||
1456 |
zv = ddi_get_soft_state(zvol_state, getminor(dev)); |
|
1457 |
||
1458 |
if (zv == NULL) { |
|
1459 |
mutex_exit(&zvol_state_lock); |
|
1460 |
return (ENXIO); |
|
1461 |
} |
|
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1462 |
ASSERT(zv->zv_total_opens > 0); |
789 | 1463 |
|
1464 |
switch (cmd) { |
|
1465 |
||
1466 |
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
|
1467 |
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
|
1468 |
(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
|
1469 |
(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
|
1470 |
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
|
1471 |
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
|
1472 |
dki.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs); |
789 | 1473 |
mutex_exit(&zvol_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
|
1474 |
if (ddi_copyout(&dki, (void *)arg, sizeof (dki), flag)) |
789 | 1475 |
error = EFAULT; |
1476 |
return (error); |
|
1477 |
||
1478 |
case DKIOCGMEDIAINFO: |
|
1479 |
bzero(&dkm, sizeof (dkm)); |
|
1480 |
dkm.dki_lbsize = 1U << zv->zv_min_bs; |
|
1481 |
dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs; |
|
1482 |
dkm.dki_media_type = DK_UNKNOWN; |
|
1483 |
mutex_exit(&zvol_state_lock); |
|
1484 |
if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag)) |
|
1485 |
error = EFAULT; |
|
1486 |
return (error); |
|
1487 |
||
1488 |
case DKIOCGETEFI: |
|
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1489 |
{ |
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1490 |
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
|
1491 |
uint8_t bs = zv->zv_min_bs; |
3016 | 1492 |
|
1493 |
mutex_exit(&zvol_state_lock); |
|
7405
22b4aeef8023
6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
7294
diff
changeset
|
1494 |
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
|
1495 |
return (error); |
3016 | 1496 |
} |
789 | 1497 |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1498 |
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
|
1499 |
dkc = (struct dk_callback *)arg; |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1500 |
mutex_exit(&zvol_state_lock); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1501 |
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
|
1502 |
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
|
1503 |
(*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
|
1504 |
error = 0; |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3755
diff
changeset
|
1505 |
} |
9303
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1506 |
return (error); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1507 |
|
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1508 |
case DKIOCGETWCE: |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1509 |
{ |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1510 |
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
|
1511 |
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
|
1512 |
flag)) |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1513 |
error = EFAULT; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1514 |
break; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1515 |
} |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1516 |
case DKIOCSETWCE: |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1517 |
{ |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1518 |
int wce; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1519 |
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
|
1520 |
flag)) { |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1521 |
error = EFAULT; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1522 |
break; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1523 |
} |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1524 |
if (wce) { |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1525 |
zv->zv_flags |= ZVOL_WCE; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1526 |
mutex_exit(&zvol_state_lock); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1527 |
} else { |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1528 |
zv->zv_flags &= ~ZVOL_WCE; |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1529 |
mutex_exit(&zvol_state_lock); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1530 |
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
|
1531 |
} |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1532 |
return (0); |
587ef5ac9176
6794730 need zvol support for DKIOCSETWCE and friends
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
9277
diff
changeset
|
1533 |
} |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
1534 |
|
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1535 |
case DKIOCGGEOM: |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1536 |
case DKIOCGVTOC: |
6423 | 1537 |
/* |
1538 |
* commands using these (like prtvtoc) expect ENOTSUP |
|
1539 |
* since we're emulating an EFI label |
|
1540 |
*/ |
|
3245
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1541 |
error = ENOTSUP; |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1542 |
break; |
0c86ad4b2673
6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents:
3080
diff
changeset
|
1543 |
|
6423 | 1544 |
case DKIOCDUMPINIT: |
1545 |
rl = zfs_range_lock(&zv->zv_znode, 0, zv->zv_volsize, |
|
1546 |
RL_WRITER); |
|
1547 |
error = zvol_dumpify(zv); |
|
1548 |
zfs_range_unlock(rl); |
|
1549 |
break; |
|
1550 |
||
1551 |
case DKIOCDUMPFINI: |
|
9277
3e67eb420d44
6817316 data corruption: failed zvol dumpify erases tmpfs data
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8524
diff
changeset
|
1552 |
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
|
1553 |
break; |
6423 | 1554 |
rl = zfs_range_lock(&zv->zv_znode, 0, zv->zv_volsize, |
1555 |
RL_WRITER); |
|
1556 |
error = zvol_dump_fini(zv); |
|
1557 |
zfs_range_unlock(rl); |
|
1558 |
break; |
|
1559 |
||
789 | 1560 |
default: |
3016 | 1561 |
error = ENOTTY; |
789 | 1562 |
break; |
1563 |
||
1564 |
} |
|
1565 |
mutex_exit(&zvol_state_lock); |
|
1566 |
return (error); |
|
1567 |
} |
|
1568 |
||
1569 |
int |
|
1570 |
zvol_busy(void) |
|
1571 |
{ |
|
1572 |
return (zvol_minors != 0); |
|
1573 |
} |
|
1574 |
||
1575 |
void |
|
1576 |
zvol_init(void) |
|
1577 |
{ |
|
1578 |
VERIFY(ddi_soft_state_init(&zvol_state, sizeof (zvol_state_t), 1) == 0); |
|
1579 |
mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL); |
|
1580 |
} |
|
1581 |
||
1582 |
void |
|
1583 |
zvol_fini(void) |
|
1584 |
{ |
|
1585 |
mutex_destroy(&zvol_state_lock); |
|
1586 |
ddi_soft_state_fini(&zvol_state); |
|
1587 |
} |
|
6423 | 1588 |
|
1589 |
static int |
|
1590 |
zvol_dump_init(zvol_state_t *zv, boolean_t resize) |
|
1591 |
{ |
|
1592 |
dmu_tx_t *tx; |
|
1593 |
int error = 0; |
|
1594 |
objset_t *os = zv->zv_objset; |
|
1595 |
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
|
1596 |
uint64_t version = spa_version(dmu_objset_spa(zv->zv_objset)); |
6423 | 1597 |
|
1598 |
ASSERT(MUTEX_HELD(&zvol_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
|
1599 |
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
|
1600 |
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
|
1601 |
/* 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
|
1602 |
txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0); |
6423 | 1603 |
|
1604 |
tx = dmu_tx_create(os); |
|
1605 |
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
|
1606 |
dmu_tx_hold_bonus(tx, ZVOL_OBJ); |
6423 | 1607 |
error = dmu_tx_assign(tx, TXG_WAIT); |
1608 |
if (error) { |
|
1609 |
dmu_tx_abort(tx); |
|
1610 |
return (error); |
|
1611 |
} |
|
1612 |
||
1613 |
/* |
|
1614 |
* If we are resizing the dump device then we only need to |
|
1615 |
* update the refreservation to match the newly updated |
|
1616 |
* zvolsize. Otherwise, we save off the original state of the |
|
1617 |
* zvol so that we can restore them if the zvol is ever undumpified. |
|
1618 |
*/ |
|
1619 |
if (resize) { |
|
1620 |
error = zap_update(os, ZVOL_ZAP_OBJ, |
|
1621 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, |
|
1622 |
&zv->zv_volsize, tx); |
|
1623 |
} 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
|
1624 |
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
|
1625 |
|
6423 | 1626 |
error = dsl_prop_get_integer(zv->zv_name, |
1627 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), &compress, NULL); |
|
1628 |
error = error ? error : dsl_prop_get_integer(zv->zv_name, |
|
1629 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), &checksum, NULL); |
|
1630 |
error = error ? error : dsl_prop_get_integer(zv->zv_name, |
|
1631 |
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
|
1632 |
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
|
1633 |
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
|
1634 |
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
|
1635 |
error = error ? error : |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1636 |
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
|
1637 |
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
|
1638 |
} |
6423 | 1639 |
|
1640 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
|
1641 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), 8, 1, |
|
1642 |
&compress, tx); |
|
1643 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
|
1644 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), 8, 1, &checksum, tx); |
|
1645 |
error = error ? error : zap_update(os, ZVOL_ZAP_OBJ, |
|
1646 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1, |
|
1647 |
&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
|
1648 |
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
|
1649 |
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
|
1650 |
&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
|
1651 |
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
|
1652 |
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
|
1653 |
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
|
1654 |
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
|
1655 |
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
|
1656 |
&dedup, tx); |
bbf9f275fc66
6926242 disabling dedup on zvols needs to check pool version
George Wilson <George.Wilson@Sun.COM>
parents:
11619
diff
changeset
|
1657 |
} |
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
|
1658 |
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
|
1659 |
zv->zv_volblocksize = SPA_MAXBLOCKSIZE; |
6423 | 1660 |
} |
1661 |
dmu_tx_commit(tx); |
|
1662 |
||
1663 |
/* |
|
1664 |
* We only need update the zvol's property if we are initializing |
|
1665 |
* the dump area for the first time. |
|
1666 |
*/ |
|
1667 |
if (!resize) { |
|
1668 |
VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
1669 |
VERIFY(nvlist_add_uint64(nv, |
|
1670 |
zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 0) == 0); |
|
1671 |
VERIFY(nvlist_add_uint64(nv, |
|
1672 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), |
|
1673 |
ZIO_COMPRESS_OFF) == 0); |
|
1674 |
VERIFY(nvlist_add_uint64(nv, |
|
1675 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), |
|
1676 |
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
|
1677 |
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
|
1678 |
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
|
1679 |
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
|
1680 |
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
|
1681 |
} |
6423 | 1682 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
1683 |
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
|
1684 |
nv, NULL); |
6423 | 1685 |
nvlist_free(nv); |
1686 |
||
1687 |
if (error) |
|
1688 |
return (error); |
|
1689 |
} |
|
1690 |
||
1691 |
/* Allocate the space for the dump */ |
|
1692 |
error = zvol_prealloc(zv); |
|
1693 |
return (error); |
|
1694 |
} |
|
1695 |
||
1696 |
static int |
|
1697 |
zvol_dumpify(zvol_state_t *zv) |
|
1698 |
{ |
|
1699 |
int error = 0; |
|
1700 |
uint64_t dumpsize = 0; |
|
1701 |
dmu_tx_t *tx; |
|
1702 |
objset_t *os = zv->zv_objset; |
|
1703 |
||
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
|
1704 |
if (zv->zv_flags & ZVOL_RDONLY) |
6423 | 1705 |
return (EROFS); |
1706 |
||
1707 |
if (zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, |
|
1708 |
8, 1, &dumpsize) != 0 || dumpsize != zv->zv_volsize) { |
|
1709 |
boolean_t resize = (dumpsize > 0) ? B_TRUE : B_FALSE; |
|
1710 |
||
1711 |
if ((error = zvol_dump_init(zv, resize)) != 0) { |
|
1712 |
(void) zvol_dump_fini(zv); |
|
1713 |
return (error); |
|
1714 |
} |
|
1715 |
} |
|
1716 |
||
1717 |
/* |
|
1718 |
* Build up our lba mapping. |
|
1719 |
*/ |
|
1720 |
error = zvol_get_lbas(zv); |
|
1721 |
if (error) { |
|
1722 |
(void) zvol_dump_fini(zv); |
|
1723 |
return (error); |
|
1724 |
} |
|
1725 |
||
1726 |
tx = dmu_tx_create(os); |
|
1727 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
|
1728 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1729 |
if (error) { |
|
1730 |
dmu_tx_abort(tx); |
|
1731 |
(void) zvol_dump_fini(zv); |
|
1732 |
return (error); |
|
1733 |
} |
|
1734 |
||
1735 |
zv->zv_flags |= ZVOL_DUMPIFIED; |
|
1736 |
error = zap_update(os, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, 8, 1, |
|
1737 |
&zv->zv_volsize, tx); |
|
1738 |
dmu_tx_commit(tx); |
|
1739 |
||
1740 |
if (error) { |
|
1741 |
(void) zvol_dump_fini(zv); |
|
1742 |
return (error); |
|
1743 |
} |
|
1744 |
||
1745 |
txg_wait_synced(dmu_objset_pool(os), 0); |
|
1746 |
return (0); |
|
1747 |
} |
|
1748 |
||
1749 |
static int |
|
1750 |
zvol_dump_fini(zvol_state_t *zv) |
|
1751 |
{ |
|
1752 |
dmu_tx_t *tx; |
|
1753 |
objset_t *os = zv->zv_objset; |
|
1754 |
nvlist_t *nv; |
|
1755 |
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
|
1756 |
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
|
1757 |
uint64_t version = spa_version(dmu_objset_spa(zv->zv_objset)); |
6423 | 1758 |
|
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1759 |
/* |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1760 |
* 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
|
1761 |
* 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
|
1762 |
* 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
|
1763 |
* (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
|
1764 |
*/ |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1765 |
|
6423 | 1766 |
tx = dmu_tx_create(os); |
1767 |
dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL); |
|
1768 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1769 |
if (error) { |
|
1770 |
dmu_tx_abort(tx); |
|
1771 |
return (error); |
|
1772 |
} |
|
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1773 |
(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
|
1774 |
dmu_tx_commit(tx); |
6423 | 1775 |
|
1776 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
|
1777 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), 8, 1, &checksum); |
|
1778 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
|
1779 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), 8, 1, &compress); |
|
1780 |
(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, |
|
1781 |
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
|
1782 |
(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
|
1783 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), 8, 1, &vbs); |
6423 | 1784 |
|
1785 |
VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
1786 |
(void) nvlist_add_uint64(nv, |
|
1787 |
zfs_prop_to_name(ZFS_PROP_CHECKSUM), checksum); |
|
1788 |
(void) nvlist_add_uint64(nv, |
|
1789 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), compress); |
|
1790 |
(void) nvlist_add_uint64(nv, |
|
1791 |
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
|
1792 |
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
|
1793 |
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
|
1794 |
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
|
1795 |
(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
|
1796 |
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
|
1797 |
} |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
10922
diff
changeset
|
1798 |
(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
|
1799 |
nv, NULL); |
6423 | 1800 |
nvlist_free(nv); |
1801 |
||
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1802 |
zvol_free_extents(zv); |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1803 |
zv->zv_flags &= ~ZVOL_DUMPIFIED; |
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1804 |
(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
|
1805 |
/* 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
|
1806 |
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
|
1807 |
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
|
1808 |
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
|
1809 |
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
|
1810 |
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
|
1811 |
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
|
1812 |
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
|
1813 |
} |
10922
e2081f502306
PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents:
10800
diff
changeset
|
1814 |
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
|
1815 |
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
|
1816 |
dmu_tx_commit(tx); |
7080
13a30a37ddc0
6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents:
7013
diff
changeset
|
1817 |
|
6423 | 1818 |
return (0); |
1819 |
} |