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