zvol.c (246666) | zvol.c (248571) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 9 unchanged lines hidden (view full) --- 18 * 19 * CDDL HEADER END 20 */ 21/* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 * 24 * Copyright (c) 2006-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 25 * All rights reserved. | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 9 unchanged lines hidden (view full) --- 18 * 19 * CDDL HEADER END 20 */ 21/* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 * 24 * Copyright (c) 2006-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 25 * All rights reserved. |
26 * Copyright (c) 2012 by Delphix. All rights reserved. |
|
26 */ 27 28/* Portions Copyright 2010 Robert Milkowski */ 29/* Portions Copyright 2011 Martin Matuska <mm@FreeBSD.org> */ 30 31/* 32 * ZFS volume emulation driver. 33 * --- 105 unchanged lines hidden (view full) --- 139#define ZVOL_WCE 0x8 140 141/* 142 * zvol maximum transfer in one DMU tx. 143 */ 144int zvol_maxphys = DMU_MAX_ACCESS/2; 145 146extern int zfs_set_prop_nvlist(const char *, zprop_source_t, | 27 */ 28 29/* Portions Copyright 2010 Robert Milkowski */ 30/* Portions Copyright 2011 Martin Matuska <mm@FreeBSD.org> */ 31 32/* 33 * ZFS volume emulation driver. 34 * --- 105 unchanged lines hidden (view full) --- 140#define ZVOL_WCE 0x8 141 142/* 143 * zvol maximum transfer in one DMU tx. 144 */ 145int zvol_maxphys = DMU_MAX_ACCESS/2; 146 147extern int zfs_set_prop_nvlist(const char *, zprop_source_t, |
147 nvlist_t *, nvlist_t **); | 148 nvlist_t *, nvlist_t *); |
148static int zvol_remove_zv(zvol_state_t *); 149static int zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio); 150static int zvol_dumpify(zvol_state_t *zv); 151static int zvol_dump_fini(zvol_state_t *zv); 152static int zvol_dump_init(zvol_state_t *zv, boolean_t resize); 153 154static zvol_state_t *zvol_geom_create(const char *name); 155static void zvol_geom_run(zvol_state_t *zv); --- 533 unchanged lines hidden (view full) --- 689 zv->zv_dbuf = NULL; 690 691 /* 692 * Evict cached data 693 */ 694 if (dsl_dataset_is_dirty(dmu_objset_ds(zv->zv_objset)) && 695 !(zv->zv_flags & ZVOL_RDONLY)) 696 txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0); | 149static int zvol_remove_zv(zvol_state_t *); 150static int zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio); 151static int zvol_dumpify(zvol_state_t *zv); 152static int zvol_dump_fini(zvol_state_t *zv); 153static int zvol_dump_init(zvol_state_t *zv, boolean_t resize); 154 155static zvol_state_t *zvol_geom_create(const char *name); 156static void zvol_geom_run(zvol_state_t *zv); --- 533 unchanged lines hidden (view full) --- 690 zv->zv_dbuf = NULL; 691 692 /* 693 * Evict cached data 694 */ 695 if (dsl_dataset_is_dirty(dmu_objset_ds(zv->zv_objset)) && 696 !(zv->zv_flags & ZVOL_RDONLY)) 697 txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0); |
697 (void) dmu_objset_evict_dbufs(zv->zv_objset); | 698 dmu_objset_evict_dbufs(zv->zv_objset); |
698 699 dmu_objset_disown(zv->zv_objset, zvol_tag); 700 zv->zv_objset = NULL; 701} 702 703#ifdef sun 704int 705zvol_prealloc(zvol_state_t *zv) --- 30 unchanged lines hidden (view full) --- 736 resid -= bytes; 737 } 738 txg_wait_synced(dmu_objset_pool(os), 0); 739 740 return (0); 741} 742#endif /* sun */ 743 | 699 700 dmu_objset_disown(zv->zv_objset, zvol_tag); 701 zv->zv_objset = NULL; 702} 703 704#ifdef sun 705int 706zvol_prealloc(zvol_state_t *zv) --- 30 unchanged lines hidden (view full) --- 737 resid -= bytes; 738 } 739 txg_wait_synced(dmu_objset_pool(os), 0); 740 741 return (0); 742} 743#endif /* sun */ 744 |
744int | 745static int |
745zvol_update_volsize(objset_t *os, uint64_t volsize) 746{ 747 dmu_tx_t *tx; 748 int error; 749 750 ASSERT(MUTEX_HELD(&spa_namespace_lock)); 751 752 tx = dmu_tx_create(os); --- 466 unchanged lines hidden (view full) --- 1219 1220 /* Locate the extent this belongs to */ 1221 ze = list_head(&zv->zv_extents); 1222 while (offset >= ze->ze_nblks * zv->zv_volblocksize) { 1223 offset -= ze->ze_nblks * zv->zv_volblocksize; 1224 ze = list_next(&zv->zv_extents, ze); 1225 } 1226 | 746zvol_update_volsize(objset_t *os, uint64_t volsize) 747{ 748 dmu_tx_t *tx; 749 int error; 750 751 ASSERT(MUTEX_HELD(&spa_namespace_lock)); 752 753 tx = dmu_tx_create(os); --- 466 unchanged lines hidden (view full) --- 1220 1221 /* Locate the extent this belongs to */ 1222 ze = list_head(&zv->zv_extents); 1223 while (offset >= ze->ze_nblks * zv->zv_volblocksize) { 1224 offset -= ze->ze_nblks * zv->zv_volblocksize; 1225 ze = list_next(&zv->zv_extents, ze); 1226 } 1227 |
1228 if (ze == NULL) 1229 return (EINVAL); 1230 |
|
1227 if (!ddi_in_panic()) 1228 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); 1229 1230 vd = vdev_lookup_top(spa, DVA_GET_VDEV(&ze->ze_dva)); 1231 offset += DVA_GET_OFFSET(&ze->ze_dva); 1232 error = zvol_dumpio_vdev(vd, addr, offset, size, doread, isdump); 1233 1234 if (!ddi_in_panic()) --- 114 unchanged lines hidden (view full) --- 1349 uint64_t size; 1350 uint64_t boff; 1351 uint64_t resid; 1352 1353 zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); 1354 if (zv == NULL) 1355 return (ENXIO); 1356 | 1231 if (!ddi_in_panic()) 1232 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); 1233 1234 vd = vdev_lookup_top(spa, DVA_GET_VDEV(&ze->ze_dva)); 1235 offset += DVA_GET_OFFSET(&ze->ze_dva); 1236 error = zvol_dumpio_vdev(vd, addr, offset, size, doread, isdump); 1237 1238 if (!ddi_in_panic()) --- 114 unchanged lines hidden (view full) --- 1353 uint64_t size; 1354 uint64_t boff; 1355 uint64_t resid; 1356 1357 zv = zfsdev_get_soft_state(minor, ZSST_ZVOL); 1358 if (zv == NULL) 1359 return (ENXIO); 1360 |
1361 if ((zv->zv_flags & ZVOL_DUMPIFIED) == 0) 1362 return (EINVAL); 1363 |
|
1357 boff = ldbtob(blkno); 1358 resid = ldbtob(nblocks); 1359 1360 VERIFY3U(boff + resid, <=, zv->zv_volsize); 1361 1362 while (resid) { 1363 size = MIN(resid, P2END(boff, zv->zv_volblocksize) - boff); 1364 error = zvol_dumpio(zv, addr, boff, size, B_FALSE, B_TRUE); --- 508 unchanged lines hidden (view full) --- 1873 dmu_tx_t *tx; 1874 objset_t *os = zv->zv_objset; 1875 1876 if (zv->zv_flags & ZVOL_RDONLY) 1877 return (EROFS); 1878 1879 if (zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, 1880 8, 1, &dumpsize) != 0 || dumpsize != zv->zv_volsize) { | 1364 boff = ldbtob(blkno); 1365 resid = ldbtob(nblocks); 1366 1367 VERIFY3U(boff + resid, <=, zv->zv_volsize); 1368 1369 while (resid) { 1370 size = MIN(resid, P2END(boff, zv->zv_volblocksize) - boff); 1371 error = zvol_dumpio(zv, addr, boff, size, B_FALSE, B_TRUE); --- 508 unchanged lines hidden (view full) --- 1880 dmu_tx_t *tx; 1881 objset_t *os = zv->zv_objset; 1882 1883 if (zv->zv_flags & ZVOL_RDONLY) 1884 return (EROFS); 1885 1886 if (zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, 1887 8, 1, &dumpsize) != 0 || dumpsize != zv->zv_volsize) { |
1881 boolean_t resize = (dumpsize > 0) ? B_TRUE : B_FALSE; | 1888 boolean_t resize = (dumpsize > 0); |
1882 1883 if ((error = zvol_dump_init(zv, resize)) != 0) { 1884 (void) zvol_dump_fini(zv); 1885 return (error); 1886 } 1887 } 1888 1889 /* --- 282 unchanged lines hidden (view full) --- 2172{ 2173 uint64_t cookie, obj; 2174 char *sname; 2175 int error, len; 2176 2177 cookie = obj = 0; 2178 sname = kmem_alloc(MAXPATHLEN, KM_SLEEP); 2179 | 1889 1890 if ((error = zvol_dump_init(zv, resize)) != 0) { 1891 (void) zvol_dump_fini(zv); 1892 return (error); 1893 } 1894 } 1895 1896 /* --- 282 unchanged lines hidden (view full) --- 2179{ 2180 uint64_t cookie, obj; 2181 char *sname; 2182 int error, len; 2183 2184 cookie = obj = 0; 2185 sname = kmem_alloc(MAXPATHLEN, KM_SLEEP); 2186 |
2187#if 0 |
|
2180 (void) dmu_objset_find(name, dmu_objset_prefetch, NULL, 2181 DS_FIND_SNAPSHOTS); | 2188 (void) dmu_objset_find(name, dmu_objset_prefetch, NULL, 2189 DS_FIND_SNAPSHOTS); |
2190#endif |
|
2182 2183 for (;;) { 2184 len = snprintf(sname, MAXPATHLEN, "%s@", name); 2185 if (len >= MAXPATHLEN) { 2186 dmu_objset_rele(os, FTAG); 2187 error = ENAMETOOLONG; 2188 break; 2189 } --- 29 unchanged lines hidden (view full) --- 2219 return (0); 2220 2221 if ((error = dmu_objset_hold(name, FTAG, &os)) != 0) { 2222 printf("ZFS WARNING: Unable to put hold on %s (error=%d).\n", 2223 name, error); 2224 return (error); 2225 } 2226 if (dmu_objset_type(os) == DMU_OST_ZVOL) { | 2191 2192 for (;;) { 2193 len = snprintf(sname, MAXPATHLEN, "%s@", name); 2194 if (len >= MAXPATHLEN) { 2195 dmu_objset_rele(os, FTAG); 2196 error = ENAMETOOLONG; 2197 break; 2198 } --- 29 unchanged lines hidden (view full) --- 2228 return (0); 2229 2230 if ((error = dmu_objset_hold(name, FTAG, &os)) != 0) { 2231 printf("ZFS WARNING: Unable to put hold on %s (error=%d).\n", 2232 name, error); 2233 return (error); 2234 } 2235 if (dmu_objset_type(os) == DMU_OST_ZVOL) { |
2236 dsl_dataset_long_hold(os->os_dsl_dataset, FTAG); 2237 dsl_pool_rele(dmu_objset_pool(os), FTAG); |
|
2227 if ((error = zvol_create_minor(name)) == 0) 2228 error = zvol_create_snapshots(os, name); 2229 else { 2230 printf("ZFS WARNING: Unable to create ZVOL %s (error=%d).\n", 2231 name, error); 2232 } | 2238 if ((error = zvol_create_minor(name)) == 0) 2239 error = zvol_create_snapshots(os, name); 2240 else { 2241 printf("ZFS WARNING: Unable to create ZVOL %s (error=%d).\n", 2242 name, error); 2243 } |
2233 dmu_objset_rele(os, FTAG); | 2244 dsl_dataset_long_rele(os->os_dsl_dataset, FTAG); 2245 dsl_dataset_rele(os->os_dsl_dataset, FTAG); |
2234 return (error); 2235 } 2236 if (dmu_objset_type(os) != DMU_OST_ZFS) { 2237 dmu_objset_rele(os, FTAG); 2238 return (0); 2239 } 2240 2241 osname = kmem_alloc(MAXPATHLEN, KM_SLEEP); 2242 if (snprintf(osname, MAXPATHLEN, "%s/", name) >= MAXPATHLEN) { 2243 dmu_objset_rele(os, FTAG); 2244 kmem_free(osname, MAXPATHLEN); 2245 return (ENOENT); 2246 } 2247 p = osname + strlen(osname); 2248 len = MAXPATHLEN - (p - osname); 2249 | 2246 return (error); 2247 } 2248 if (dmu_objset_type(os) != DMU_OST_ZFS) { 2249 dmu_objset_rele(os, FTAG); 2250 return (0); 2251 } 2252 2253 osname = kmem_alloc(MAXPATHLEN, KM_SLEEP); 2254 if (snprintf(osname, MAXPATHLEN, "%s/", name) >= MAXPATHLEN) { 2255 dmu_objset_rele(os, FTAG); 2256 kmem_free(osname, MAXPATHLEN); 2257 return (ENOENT); 2258 } 2259 p = osname + strlen(osname); 2260 len = MAXPATHLEN - (p - osname); 2261 |
2262#if 0 |
|
2250 /* Prefetch the datasets. */ 2251 cookie = 0; 2252 while (dmu_dir_list_next(os, len, p, NULL, &cookie) == 0) { 2253 if (!dataset_name_hidden(osname)) 2254 (void) dmu_objset_prefetch(osname, NULL); 2255 } | 2263 /* Prefetch the datasets. */ 2264 cookie = 0; 2265 while (dmu_dir_list_next(os, len, p, NULL, &cookie) == 0) { 2266 if (!dataset_name_hidden(osname)) 2267 (void) dmu_objset_prefetch(osname, NULL); 2268 } |
2269#endif |
|
2256 2257 cookie = 0; 2258 while (dmu_dir_list_next(os, MAXPATHLEN - (p - osname), p, NULL, 2259 &cookie) == 0) { 2260 dmu_objset_rele(os, FTAG); 2261 (void)zvol_create_minors(osname); 2262 if ((error = dmu_objset_hold(name, FTAG, &os)) != 0) { 2263 printf("ZFS WARNING: Unable to put hold on %s (error=%d).\n", --- 76 unchanged lines hidden --- | 2270 2271 cookie = 0; 2272 while (dmu_dir_list_next(os, MAXPATHLEN - (p - osname), p, NULL, 2273 &cookie) == 0) { 2274 dmu_objset_rele(os, FTAG); 2275 (void)zvol_create_minors(osname); 2276 if ((error = dmu_objset_hold(name, FTAG, &os)) != 0) { 2277 printf("ZFS WARNING: Unable to put hold on %s (error=%d).\n", --- 76 unchanged lines hidden --- |