Deleted Added
full compact
zvol.c (249195) zvol.c (255750)
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

--- 10 unchanged lines hidden (view full) ---

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) 2013 by Delphix. 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

--- 10 unchanged lines hidden (view full) ---

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) 2013 by Delphix. All rights reserved.
27 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
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 *

--- 20 unchanged lines hidden (view full) ---

55#include <sys/bio.h>
56#include <sys/buf.h>
57#include <sys/kmem.h>
58#include <sys/conf.h>
59#include <sys/cmn_err.h>
60#include <sys/stat.h>
61#include <sys/zap.h>
62#include <sys/spa.h>
28 */
29
30/* Portions Copyright 2010 Robert Milkowski */
31/* Portions Copyright 2011 Martin Matuska <mm@FreeBSD.org> */
32
33/*
34 * ZFS volume emulation driver.
35 *

--- 20 unchanged lines hidden (view full) ---

56#include <sys/bio.h>
57#include <sys/buf.h>
58#include <sys/kmem.h>
59#include <sys/conf.h>
60#include <sys/cmn_err.h>
61#include <sys/stat.h>
62#include <sys/zap.h>
63#include <sys/spa.h>
64#include <sys/spa_impl.h>
63#include <sys/zio.h>
64#include <sys/dmu_traverse.h>
65#include <sys/dnode.h>
66#include <sys/dsl_dataset.h>
67#include <sys/dsl_prop.h>
68#include <sys/dkio.h>
69#include <sys/byteorder.h>
70#include <sys/sunddi.h>
71#include <sys/dirent.h>
72#include <sys/policy.h>
73#include <sys/fs/zfs.h>
74#include <sys/zfs_ioctl.h>
75#include <sys/zil.h>
76#include <sys/refcount.h>
77#include <sys/zfs_znode.h>
78#include <sys/zfs_rlock.h>
79#include <sys/vdev_impl.h>
65#include <sys/zio.h>
66#include <sys/dmu_traverse.h>
67#include <sys/dnode.h>
68#include <sys/dsl_dataset.h>
69#include <sys/dsl_prop.h>
70#include <sys/dkio.h>
71#include <sys/byteorder.h>
72#include <sys/sunddi.h>
73#include <sys/dirent.h>
74#include <sys/policy.h>
75#include <sys/fs/zfs.h>
76#include <sys/zfs_ioctl.h>
77#include <sys/zil.h>
78#include <sys/refcount.h>
79#include <sys/zfs_znode.h>
80#include <sys/zfs_rlock.h>
81#include <sys/vdev_impl.h>
82#include <sys/vdev_raidz.h>
80#include <sys/zvol.h>
81#include <sys/zil_impl.h>
82#include <sys/dbuf.h>
83#include <sys/zvol.h>
84#include <sys/zil_impl.h>
85#include <sys/dbuf.h>
86#include <sys/dmu_tx.h>
87#include <sys/zfeature.h>
88#include <sys/zio_checksum.h>
89
83#include <geom/geom.h>
84
85#include "zfs_namecheck.h"
86
87struct g_class zfs_zvol_class = {
88 .name = "ZFS::ZVOL",
89 .version = G_VERSION,
90};

--- 1062 unchanged lines hidden (view full) ---

1153
1154 off += len;
1155 resid -= len;
1156 }
1157}
1158
1159#ifdef sun
1160static int
90#include <geom/geom.h>
91
92#include "zfs_namecheck.h"
93
94struct g_class zfs_zvol_class = {
95 .name = "ZFS::ZVOL",
96 .version = G_VERSION,
97};

--- 1062 unchanged lines hidden (view full) ---

1160
1161 off += len;
1162 resid -= len;
1163 }
1164}
1165
1166#ifdef sun
1167static int
1161zvol_dumpio_vdev(vdev_t *vd, void *addr, uint64_t offset, uint64_t size,
1162 boolean_t doread, boolean_t isdump)
1168zvol_dumpio_vdev(vdev_t *vd, void *addr, uint64_t offset, uint64_t origoffset,
1169 uint64_t size, boolean_t doread, boolean_t isdump)
1163{
1164 vdev_disk_t *dvd;
1165 int c;
1166 int numerrors = 0;
1167
1170{
1171 vdev_disk_t *dvd;
1172 int c;
1173 int numerrors = 0;
1174
1168 for (c = 0; c < vd->vdev_children; c++) {
1169 ASSERT(vd->vdev_ops == &vdev_mirror_ops ||
1170 vd->vdev_ops == &vdev_replacing_ops ||
1171 vd->vdev_ops == &vdev_spare_ops);
1172 int err = zvol_dumpio_vdev(vd->vdev_child[c],
1173 addr, offset, size, doread, isdump);
1174 if (err != 0) {
1175 numerrors++;
1176 } else if (doread) {
1177 break;
1175 if (vd->vdev_ops == &vdev_mirror_ops ||
1176 vd->vdev_ops == &vdev_replacing_ops ||
1177 vd->vdev_ops == &vdev_spare_ops) {
1178 for (c = 0; c < vd->vdev_children; c++) {
1179 int err = zvol_dumpio_vdev(vd->vdev_child[c],
1180 addr, offset, origoffset, size, doread, isdump);
1181 if (err != 0) {
1182 numerrors++;
1183 } else if (doread) {
1184 break;
1185 }
1178 }
1179 }
1180
1186 }
1187 }
1188
1181 if (!vd->vdev_ops->vdev_op_leaf)
1189 if (!vd->vdev_ops->vdev_op_leaf && vd->vdev_ops != &vdev_raidz_ops)
1182 return (numerrors < vd->vdev_children ? 0 : EIO);
1183
1184 if (doread && !vdev_readable(vd))
1185 return (SET_ERROR(EIO));
1186 else if (!doread && !vdev_writeable(vd))
1187 return (SET_ERROR(EIO));
1188
1190 return (numerrors < vd->vdev_children ? 0 : EIO);
1191
1192 if (doread && !vdev_readable(vd))
1193 return (SET_ERROR(EIO));
1194 else if (!doread && !vdev_writeable(vd))
1195 return (SET_ERROR(EIO));
1196
1189 dvd = vd->vdev_tsd;
1190 ASSERT3P(dvd, !=, NULL);
1197 if (vd->vdev_ops == &vdev_raidz_ops) {
1198 return (vdev_raidz_physio(vd,
1199 addr, size, offset, origoffset, doread, isdump));
1200 }
1201
1191 offset += VDEV_LABEL_START_SIZE;
1192
1193 if (ddi_in_panic() || isdump) {
1194 ASSERT(!doread);
1195 if (doread)
1196 return (SET_ERROR(EIO));
1202 offset += VDEV_LABEL_START_SIZE;
1203
1204 if (ddi_in_panic() || isdump) {
1205 ASSERT(!doread);
1206 if (doread)
1207 return (SET_ERROR(EIO));
1208 dvd = vd->vdev_tsd;
1209 ASSERT3P(dvd, !=, NULL);
1197 return (ldi_dump(dvd->vd_lh, addr, lbtodb(offset),
1198 lbtodb(size)));
1199 } else {
1210 return (ldi_dump(dvd->vd_lh, addr, lbtodb(offset),
1211 lbtodb(size)));
1212 } else {
1200 return (vdev_disk_physio(dvd->vd_lh, addr, size, offset,
1201 doread ? B_READ : B_WRITE));
1213 dvd = vd->vdev_tsd;
1214 ASSERT3P(dvd, !=, NULL);
1215 return (vdev_disk_ldi_physio(dvd->vd_lh, addr, size,
1216 offset, doread ? B_READ : B_WRITE));
1202 }
1203}
1204
1205static int
1206zvol_dumpio(zvol_state_t *zv, void *addr, uint64_t offset, uint64_t size,
1207 boolean_t doread, boolean_t isdump)
1208{
1209 vdev_t *vd;

--- 18 unchanged lines hidden (view full) ---

1228 if (ze == NULL)
1229 return (SET_ERROR(EINVAL));
1230
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);
1217 }
1218}
1219
1220static int
1221zvol_dumpio(zvol_state_t *zv, void *addr, uint64_t offset, uint64_t size,
1222 boolean_t doread, boolean_t isdump)
1223{
1224 vdev_t *vd;

--- 18 unchanged lines hidden (view full) ---

1243 if (ze == NULL)
1244 return (SET_ERROR(EINVAL));
1245
1246 if (!ddi_in_panic())
1247 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
1248
1249 vd = vdev_lookup_top(spa, DVA_GET_VDEV(&ze->ze_dva));
1250 offset += DVA_GET_OFFSET(&ze->ze_dva);
1236 error = zvol_dumpio_vdev(vd, addr, offset, size, doread, isdump);
1251 error = zvol_dumpio_vdev(vd, addr, offset, DVA_GET_OFFSET(&ze->ze_dva),
1252 size, doread, isdump);
1237
1238 if (!ddi_in_panic())
1239 spa_config_exit(spa, SCL_STATE, FTAG);
1240
1241 return (error);
1242}
1243#endif /* sun */
1244
1245int
1246zvol_strategy(struct bio *bp)
1247{
1248 zvol_state_t *zv = bp->bio_to->private;
1249 uint64_t off, volsize;
1250 size_t resid;
1251 char *addr;
1252 objset_t *os;
1253 rl_t *rl;
1254 int error = 0;
1255 boolean_t doread = (bp->bio_cmd == BIO_READ);
1253
1254 if (!ddi_in_panic())
1255 spa_config_exit(spa, SCL_STATE, FTAG);
1256
1257 return (error);
1258}
1259#endif /* sun */
1260
1261int
1262zvol_strategy(struct bio *bp)
1263{
1264 zvol_state_t *zv = bp->bio_to->private;
1265 uint64_t off, volsize;
1266 size_t resid;
1267 char *addr;
1268 objset_t *os;
1269 rl_t *rl;
1270 int error = 0;
1271 boolean_t doread = (bp->bio_cmd == BIO_READ);
1272 boolean_t is_dumpified;
1256 boolean_t sync;
1257
1258 if (zv == NULL) {
1259 g_io_deliver(bp, ENXIO);
1260 return (0);
1261 }
1262
1263 if (bp->bio_cmd != BIO_READ && (zv->zv_flags & ZVOL_RDONLY)) {

--- 10 unchanged lines hidden (view full) ---

1274 addr = bp->bio_data;
1275 resid = bp->bio_length;
1276
1277 if (resid > 0 && (off < 0 || off >= volsize)) {
1278 g_io_deliver(bp, EIO);
1279 return (0);
1280 }
1281
1273 boolean_t sync;
1274
1275 if (zv == NULL) {
1276 g_io_deliver(bp, ENXIO);
1277 return (0);
1278 }
1279
1280 if (bp->bio_cmd != BIO_READ && (zv->zv_flags & ZVOL_RDONLY)) {

--- 10 unchanged lines hidden (view full) ---

1291 addr = bp->bio_data;
1292 resid = bp->bio_length;
1293
1294 if (resid > 0 && (off < 0 || off >= volsize)) {
1295 g_io_deliver(bp, EIO);
1296 return (0);
1297 }
1298
1282 sync = !doread && zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS;
1299#ifdef illumos
1300 is_dumpified = zv->zv_flags & ZVOL_DUMPIFIED;
1301#else
1302 is_dumpified = B_FALSE;
1303#endif
1304 sync = !doread && !is_dumpified &&
1305 zv->zv_objset->os_sync == ZFS_SYNC_ALWAYS;
1283
1284 /*
1285 * There must be no buffer changes when doing a dmu_sync() because
1286 * we can't change the data whilst calculating the checksum.
1287 */
1288 rl = zfs_range_lock(&zv->zv_znode, off, resid,
1289 doread ? RL_READER : RL_WRITER);
1290
1291 while (resid != 0 && off < volsize) {
1292 size_t size = MIN(resid, zvol_maxphys);
1306
1307 /*
1308 * There must be no buffer changes when doing a dmu_sync() because
1309 * we can't change the data whilst calculating the checksum.
1310 */
1311 rl = zfs_range_lock(&zv->zv_znode, off, resid,
1312 doread ? RL_READER : RL_WRITER);
1313
1314 while (resid != 0 && off < volsize) {
1315 size_t size = MIN(resid, zvol_maxphys);
1316#ifdef illumos
1317 if (is_dumpified) {
1318 size = MIN(size, P2END(off, zv->zv_volblocksize) - off);
1319 error = zvol_dumpio(zv, addr, off, size,
1320 doread, B_FALSE);
1321 } else if (doread) {
1322#else
1293 if (doread) {
1323 if (doread) {
1324#endif
1294 error = dmu_read(os, ZVOL_OBJ, off, size, addr,
1295 DMU_READ_PREFETCH);
1296 } else {
1297 dmu_tx_t *tx = dmu_tx_create(os);
1298 dmu_tx_hold_write(tx, ZVOL_OBJ, off, size);
1299 error = dmu_tx_assign(tx, TXG_WAIT);
1300 if (error) {
1301 dmu_tx_abort(tx);

--- 517 unchanged lines hidden (view full) ---

1819void
1820zvol_fini(void)
1821{
1822 ddi_soft_state_fini(&zfsdev_state);
1823 ZFS_LOG(1, "ZVOL Deinitialized.");
1824}
1825
1826#ifdef sun
1325 error = dmu_read(os, ZVOL_OBJ, off, size, addr,
1326 DMU_READ_PREFETCH);
1327 } else {
1328 dmu_tx_t *tx = dmu_tx_create(os);
1329 dmu_tx_hold_write(tx, ZVOL_OBJ, off, size);
1330 error = dmu_tx_assign(tx, TXG_WAIT);
1331 if (error) {
1332 dmu_tx_abort(tx);

--- 517 unchanged lines hidden (view full) ---

1850void
1851zvol_fini(void)
1852{
1853 ddi_soft_state_fini(&zfsdev_state);
1854 ZFS_LOG(1, "ZVOL Deinitialized.");
1855}
1856
1857#ifdef sun
1858/*ARGSUSED*/
1827static int
1859static int
1860zfs_mvdev_dump_feature_check(void *arg, dmu_tx_t *tx)
1861{
1862 spa_t *spa = dmu_tx_pool(tx)->dp_spa;
1863
1864 if (spa_feature_is_active(spa,
1865 &spa_feature_table[SPA_FEATURE_MULTI_VDEV_CRASH_DUMP]))
1866 return (1);
1867 return (0);
1868}
1869
1870/*ARGSUSED*/
1871static void
1872zfs_mvdev_dump_activate_feature_sync(void *arg, dmu_tx_t *tx)
1873{
1874 spa_t *spa = dmu_tx_pool(tx)->dp_spa;
1875
1876 spa_feature_incr(spa,
1877 &spa_feature_table[SPA_FEATURE_MULTI_VDEV_CRASH_DUMP], tx);
1878}
1879
1880static int
1828zvol_dump_init(zvol_state_t *zv, boolean_t resize)
1829{
1830 dmu_tx_t *tx;
1881zvol_dump_init(zvol_state_t *zv, boolean_t resize)
1882{
1883 dmu_tx_t *tx;
1831 int error = 0;
1884 int error;
1832 objset_t *os = zv->zv_objset;
1885 objset_t *os = zv->zv_objset;
1886 spa_t *spa = dmu_objset_spa(os);
1887 vdev_t *vd = spa->spa_root_vdev;
1833 nvlist_t *nv = NULL;
1888 nvlist_t *nv = NULL;
1834 uint64_t version = spa_version(dmu_objset_spa(zv->zv_objset));
1889 uint64_t version = spa_version(spa);
1890 enum zio_checksum checksum;
1835
1836 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1891
1892 ASSERT(MUTEX_HELD(&spa_namespace_lock));
1893 ASSERT(vd->vdev_ops == &vdev_root_ops);
1894
1837 error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, 0,
1838 DMU_OBJECT_END);
1839 /* wait for dmu_free_long_range to actually free the blocks */
1840 txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0);
1841
1895 error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, 0,
1896 DMU_OBJECT_END);
1897 /* wait for dmu_free_long_range to actually free the blocks */
1898 txg_wait_synced(dmu_objset_pool(zv->zv_objset), 0);
1899
1900 /*
1901 * If the pool on which the dump device is being initialized has more
1902 * than one child vdev, check that the MULTI_VDEV_CRASH_DUMP feature is
1903 * enabled. If so, bump that feature's counter to indicate that the
1904 * feature is active. We also check the vdev type to handle the
1905 * following case:
1906 * # zpool create test raidz disk1 disk2 disk3
1907 * Now have spa_root_vdev->vdev_children == 1 (the raidz vdev),
1908 * the raidz vdev itself has 3 children.
1909 */
1910 if (vd->vdev_children > 1 || vd->vdev_ops == &vdev_raidz_ops) {
1911 if (!spa_feature_is_enabled(spa,
1912 &spa_feature_table[SPA_FEATURE_MULTI_VDEV_CRASH_DUMP]))
1913 return (SET_ERROR(ENOTSUP));
1914 (void) dsl_sync_task(spa_name(spa),
1915 zfs_mvdev_dump_feature_check,
1916 zfs_mvdev_dump_activate_feature_sync, NULL, 2);
1917 }
1918
1842 tx = dmu_tx_create(os);
1843 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
1844 dmu_tx_hold_bonus(tx, ZVOL_OBJ);
1845 error = dmu_tx_assign(tx, TXG_WAIT);
1846 if (error) {
1847 dmu_tx_abort(tx);
1848 return (error);
1849 }
1850
1851 /*
1919 tx = dmu_tx_create(os);
1920 dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
1921 dmu_tx_hold_bonus(tx, ZVOL_OBJ);
1922 error = dmu_tx_assign(tx, TXG_WAIT);
1923 if (error) {
1924 dmu_tx_abort(tx);
1925 return (error);
1926 }
1927
1928 /*
1929 * If MULTI_VDEV_CRASH_DUMP is active, use the NOPARITY checksum
1930 * function. Otherwise, use the old default -- OFF.
1931 */
1932 checksum = spa_feature_is_active(spa,
1933 &spa_feature_table[SPA_FEATURE_MULTI_VDEV_CRASH_DUMP]) ?
1934 ZIO_CHECKSUM_NOPARITY : ZIO_CHECKSUM_OFF;
1935
1936 /*
1852 * If we are resizing the dump device then we only need to
1853 * update the refreservation to match the newly updated
1854 * zvolsize. Otherwise, we save off the original state of the
1855 * zvol so that we can restore them if the zvol is ever undumpified.
1856 */
1857 if (resize) {
1858 error = zap_update(os, ZVOL_ZAP_OBJ,
1859 zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1,

--- 46 unchanged lines hidden (view full) ---

1906 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1907 VERIFY(nvlist_add_uint64(nv,
1908 zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 0) == 0);
1909 VERIFY(nvlist_add_uint64(nv,
1910 zfs_prop_to_name(ZFS_PROP_COMPRESSION),
1911 ZIO_COMPRESS_OFF) == 0);
1912 VERIFY(nvlist_add_uint64(nv,
1913 zfs_prop_to_name(ZFS_PROP_CHECKSUM),
1937 * If we are resizing the dump device then we only need to
1938 * update the refreservation to match the newly updated
1939 * zvolsize. Otherwise, we save off the original state of the
1940 * zvol so that we can restore them if the zvol is ever undumpified.
1941 */
1942 if (resize) {
1943 error = zap_update(os, ZVOL_ZAP_OBJ,
1944 zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1,

--- 46 unchanged lines hidden (view full) ---

1991 VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1992 VERIFY(nvlist_add_uint64(nv,
1993 zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 0) == 0);
1994 VERIFY(nvlist_add_uint64(nv,
1995 zfs_prop_to_name(ZFS_PROP_COMPRESSION),
1996 ZIO_COMPRESS_OFF) == 0);
1997 VERIFY(nvlist_add_uint64(nv,
1998 zfs_prop_to_name(ZFS_PROP_CHECKSUM),
1914 ZIO_CHECKSUM_OFF) == 0);
1999 checksum) == 0);
1915 if (version >= SPA_VERSION_DEDUP) {
1916 VERIFY(nvlist_add_uint64(nv,
1917 zfs_prop_to_name(ZFS_PROP_DEDUP),
1918 ZIO_CHECKSUM_OFF) == 0);
1919 }
1920
1921 error = zfs_set_prop_nvlist(zv->zv_name, ZPROP_SRC_LOCAL,
1922 nv, NULL);

--- 492 unchanged lines hidden ---
2000 if (version >= SPA_VERSION_DEDUP) {
2001 VERIFY(nvlist_add_uint64(nv,
2002 zfs_prop_to_name(ZFS_PROP_DEDUP),
2003 ZIO_CHECKSUM_OFF) == 0);
2004 }
2005
2006 error = zfs_set_prop_nvlist(zv->zv_name, ZPROP_SRC_LOCAL,
2007 nv, NULL);

--- 492 unchanged lines hidden ---