usr/src/uts/common/fs/zfs/zvol.c
author Eric Taylor <Eric.Taylor@Sun.COM>
Mon, 12 Jan 2009 11:10:12 -0700
changeset 8524 a56dffa8fba9
parent 8227 f7d7be9b1f56
child 9277 3e67eb420d44
permissions -rw-r--r--
6770534 zvols do not observe character device semantics
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1357
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1357
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
8524
a56dffa8fba9 6770534 zvols do not observe character device semantics
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8227
diff changeset
    22
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
 * ZFS volume emulation driver.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
 * Makes a DMU object look like a volume of arbitrary size, up to 2^64 bytes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
 * Volumes are accessed through the symbolic links named:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
 * /dev/zvol/dsk/<pool_name>/<dataset_name>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
 * /dev/zvol/rdsk/<pool_name>/<dataset_name>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 * These links are created by the ZFS-specific devfsadm link generator.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 * Volumes are persistent through reboot.  No user command needs to be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 * run before opening and using a device.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/uio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/buf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/modctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/open.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/conf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#include <sys/zio.h>
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    54
#include <sys/dmu_traverse.h>
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    55
#include <sys/dnode.h>
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    56
#include <sys/dsl_dataset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
#include <sys/dsl_prop.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
#include <sys/dkio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
#include <sys/efi_partition.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
#include <sys/byteorder.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
#include <sys/pathname.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
#include <sys/ddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
#include <sys/sunddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
#include <sys/crc32.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
#include <sys/dirent.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
#include <sys/zfs_ioctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
#include <sys/mkdev.h>
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
    70
#include <sys/zil.h>
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
    71
#include <sys/refcount.h>
3755
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
    72
#include <sys/zfs_znode.h>
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
    73
#include <sys/zfs_rlock.h>
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    74
#include <sys/vdev_disk.h>
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    75
#include <sys/vdev_impl.h>
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    76
#include <sys/zvol.h>
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    77
#include <sys/dumphdr.h>
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
    78
#include <sys/zil_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
#include "zfs_namecheck.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    82
static void *zvol_state;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    84
#define	ZVOL_DUMPSIZE		"dumpsize"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
 * This lock protects the zvol_state structure from being modified
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
 * while it's being used, e.g. an open that comes in before a create
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
 * finishes.  It also protects temporary opens of the dataset so that,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
 * e.g., an open doesn't get a spurious EBUSY.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
static kmutex_t zvol_state_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
static uint32_t zvol_minors;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    95
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
    96
	list_node_t	ze_node;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    97
	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
    98
	uint64_t	ze_nblks;	/* number of blocks in extent */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
    99
} zvol_extent_t;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   100
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   101
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
 * The in-core state of each volume.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
typedef struct zvol_state {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	char		zv_name[MAXPATHLEN]; /* pool/dd name */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	uint64_t	zv_volsize;	/* amount of space we advertise */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   107
	uint64_t	zv_volblocksize; /* volume block size */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	minor_t		zv_minor;	/* minor number */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	uint8_t		zv_min_bs;	/* minimum addressable block shift */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   110
	uint8_t		zv_flags;	/* readonly; dumpified */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	objset_t	*zv_objset;	/* objset handle */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	uint32_t	zv_mode;	/* DS_MODE_* flags at open time */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	uint32_t	zv_open_count[OTYPCNT];	/* open counts */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	uint32_t	zv_total_opens;	/* total open count */
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   115
	zilog_t		*zv_zilog;	/* ZIL handle */
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   116
	list_t		zv_extents;	/* List of extents for dump */
3755
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
   117
	znode_t		zv_znode;	/* for range locking */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
} zvol_state_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   120
/*
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   121
 * zvol specific flags
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   122
 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   123
#define	ZVOL_RDONLY	0x1
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   124
#define	ZVOL_DUMPIFIED	0x2
7405
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   125
#define	ZVOL_EXCL	0x4
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   126
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   127
/*
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   128
 * zvol maximum transfer in one DMU tx.
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   129
 */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   130
int zvol_maxphys = DMU_MAX_ACCESS/2;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   131
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   132
extern int zfs_set_prop_nvlist(const char *, nvlist_t *);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   133
static int zvol_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   134
static int zvol_dumpify(zvol_state_t *zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   135
static int zvol_dump_fini(zvol_state_t *zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   136
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
   137
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
static void
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4543
diff changeset
   139
zvol_size_changed(zvol_state_t *zv, major_t maj)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4543
diff changeset
   141
	dev_t dev = makedevice(maj, zv->zv_minor);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	VERIFY(ddi_prop_update_int64(dev, zfs_dip,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	    "Size", zv->zv_volsize) == DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	VERIFY(ddi_prop_update_int64(dev, zfs_dip,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
	    "Nblocks", lbtodb(zv->zv_volsize)) == DDI_SUCCESS);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   147
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   148
	/* Notify specfs to invalidate the cached size */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   149
	spec_size_invalidate(dev, VBLK);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   150
	spec_size_invalidate(dev, VCHR);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   154
zvol_check_volsize(uint64_t volsize, uint64_t blocksize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   156
	if (volsize == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   159
	if (volsize % blocksize != 0)
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 849
diff changeset
   160
		return (EINVAL);
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 849
diff changeset
   161
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
#ifdef _ILP32
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   163
	if (volsize - 1 > SPEC_MAXOFFSET_T)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
		return (EOVERFLOW);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   170
zvol_check_volblocksize(uint64_t volblocksize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   172
	if (volblocksize < SPA_MINBLOCKSIZE ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   173
	    volblocksize > SPA_MAXBLOCKSIZE ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   174
	    !ISP2(volblocksize))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
		return (EDOM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
zvol_readonly_changed_cb(void *arg, uint64_t newval)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
	zvol_state_t *zv = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   185
	if (newval)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   186
		zv->zv_flags |= ZVOL_RDONLY;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   187
	else
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   188
		zv->zv_flags &= ~ZVOL_RDONLY;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
int
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   192
zvol_get_stats(objset_t *os, nvlist_t *nv)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
	dmu_object_info_t doi;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   196
	uint64_t val;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   199
	error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   203
	dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLSIZE, val);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   204
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
	error = dmu_object_info(os, ZVOL_OBJ, &doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   207
	if (error == 0) {
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   208
		dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_VOLBLOCKSIZE,
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   209
		    doi.doi_data_block_size);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2676
diff changeset
   210
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
 * Find a free minor number.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
static minor_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
zvol_minor_alloc(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	minor_t minor;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	ASSERT(MUTEX_HELD(&zvol_state_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	for (minor = 1; minor <= ZVOL_MAX_MINOR; minor++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
		if (ddi_get_soft_state(zvol_state, minor) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
			return (minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
static zvol_state_t *
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   233
zvol_minor_lookup(const char *name)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
	minor_t minor;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
	ASSERT(MUTEX_HELD(&zvol_state_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
	for (minor = 1; minor <= ZVOL_MAX_MINOR; minor++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
		zv = ddi_get_soft_state(zvol_state, minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
		if (zv == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
		if (strcmp(zv->zv_name, name) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
	return (zv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   251
/* extent mapping arg */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   252
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
   253
	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
   254
	uint64_t	ma_blks;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   255
};
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   256
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   257
/*ARGSUSED*/
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   258
static int
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   259
zvol_map_block(spa_t *spa, blkptr_t *bp, const zbookmark_t *zb,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   260
    const dnode_phys_t *dnp, void *arg)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   261
{
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   262
	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
   263
	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
   264
	int bs = ma->ma_zv->zv_volblocksize;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   265
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   266
	if (bp == NULL || zb->zb_object != ZVOL_OBJ || zb->zb_level != 0)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   267
		return (0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   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
	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
   270
	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
   271
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   272
	/* 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
   273
	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
   274
		return (EFRAGS);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   275
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   276
	/*
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   277
	 * 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
   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
	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
   280
	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
   281
	    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
   282
	    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
   283
	    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
   284
		ze->ze_nblks++;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   285
		return (0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   286
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   287
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   288
	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
   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
	/* 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
   291
	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
   292
	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
   293
	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
   294
	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
   295
	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
   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
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   298
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
   299
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
   300
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   301
	zvol_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
   302
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   303
	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
   304
		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
   305
		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
   306
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   307
}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   308
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   309
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
   310
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
   311
{
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   312
	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
   313
	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
   314
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   315
	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
   316
	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
   317
	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
   318
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   319
	err = traverse_dataset(dmu_objset_ds(zv->zv_objset), 0,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   320
	    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
   321
	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
   322
		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
   323
		return (err ? err : EIO);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   324
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   325
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   326
	return (0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   327
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   328
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4391
diff changeset
   329
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4391
diff changeset
   331
zvol_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4935
diff changeset
   333
	zfs_creat_t *zct = arg;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4935
diff changeset
   334
	nvlist_t *nvprops = zct->zct_props;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	int error;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   336
	uint64_t volblocksize, volsize;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4391
diff changeset
   338
	VERIFY(nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   339
	    zfs_prop_to_name(ZFS_PROP_VOLSIZE), &volsize) == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4391
diff changeset
   340
	if (nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   341
	    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &volblocksize) != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   342
		volblocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   343
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   344
	/*
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   345
	 * These properties must be removed from the list so the generic
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   346
	 * property setting step won't apply to them.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   347
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4391
diff changeset
   348
	VERIFY(nvlist_remove_all(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   349
	    zfs_prop_to_name(ZFS_PROP_VOLSIZE)) == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4391
diff changeset
   350
	(void) nvlist_remove_all(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   351
	    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   352
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   353
	error = dmu_object_claim(os, ZVOL_OBJ, DMU_OT_ZVOL, volblocksize,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
	    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
	error = zap_create_claim(os, ZVOL_ZAP_OBJ, DMU_OT_ZVOL_PROP,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   361
	error = zap_update(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
/*
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   366
 * Replay a TX_WRITE ZIL transaction that didn't get committed
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   367
 * after a system failure
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   368
 */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   369
static int
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   370
zvol_replay_write(zvol_state_t *zv, lr_write_t *lr, boolean_t byteswap)
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   371
{
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   372
	objset_t *os = zv->zv_objset;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   373
	char *data = (char *)(lr + 1);	/* data follows lr_write_t */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   374
	uint64_t off = lr->lr_offset;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   375
	uint64_t len = lr->lr_length;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   376
	dmu_tx_t *tx;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   377
	int error;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   378
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   379
	if (byteswap)
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   380
		byteswap_uint64_array(lr, sizeof (*lr));
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   381
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   382
	tx = dmu_tx_create(os);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   383
	dmu_tx_hold_write(tx, ZVOL_OBJ, off, len);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   384
	error = dmu_tx_assign(tx, TXG_WAIT);
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   385
	if (error) {
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   386
		dmu_tx_abort(tx);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   387
	} else {
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   388
		dmu_write(os, ZVOL_OBJ, off, len, data, tx);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   389
		dmu_tx_commit(tx);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   390
	}
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   391
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   392
	return (error);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   393
}
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   394
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   395
/* ARGSUSED */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   396
static int
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   397
zvol_replay_err(zvol_state_t *zv, lr_t *lr, boolean_t byteswap)
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   398
{
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   399
	return (ENOTSUP);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   400
}
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   401
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   402
/*
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   403
 * Callback vectors for replaying records.
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   404
 * Only TX_WRITE is needed for zvol.
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   405
 */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   406
zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE] = {
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   407
	zvol_replay_err,	/* 0 no such transaction type */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   408
	zvol_replay_err,	/* TX_CREATE */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   409
	zvol_replay_err,	/* TX_MKDIR */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   410
	zvol_replay_err,	/* TX_MKXATTR */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   411
	zvol_replay_err,	/* TX_SYMLINK */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   412
	zvol_replay_err,	/* TX_REMOVE */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   413
	zvol_replay_err,	/* TX_RMDIR */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   414
	zvol_replay_err,	/* TX_LINK */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   415
	zvol_replay_err,	/* TX_RENAME */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   416
	zvol_replay_write,	/* TX_WRITE */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   417
	zvol_replay_err,	/* TX_TRUNCATE */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   418
	zvol_replay_err,	/* TX_SETATTR */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   419
	zvol_replay_err,	/* TX_ACL */
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   420
};
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   421
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   422
/*
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   423
 * Create a minor node (plus a whole lot more) for the specified volume.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
int
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4543
diff changeset
   426
zvol_create_minor(const char *name, major_t maj)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	objset_t *os;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   430
	dmu_object_info_t doi;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
	uint64_t volsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
	minor_t minor = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
	struct pathname linkpath;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6423
diff changeset
   434
	int ds_mode = DS_MODE_OWNER;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
	vnode_t *vp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	char *devpath;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   437
	size_t devpathlen = strlen(ZVOL_FULL_DEV_DIR) + strlen(name) + 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
	char chrbuf[30], blkbuf[30];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	mutex_enter(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	if ((zv = zvol_minor_lookup(name)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
	if (strchr(name, '@') != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
		ds_mode |= DS_MODE_READONLY;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
	error = dmu_objset_open(name, DMU_OST_ZVOL, ds_mode, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	error = zap_lookup(os, ZVOL_ZAP_OBJ, "size", 8, 1, &volsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
	 * If there's an existing /dev/zvol symlink, try to use the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
	 * same minor number we used last time.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
	devpath = kmem_alloc(devpathlen, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   472
	(void) sprintf(devpath, "%s%s", ZVOL_FULL_DEV_DIR, name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	error = lookupname(devpath, UIO_SYSSPACE, NO_FOLLOW, NULL, &vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
	kmem_free(devpath, devpathlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
	if (error == 0 && vp->v_type != VLNK)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
		error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
		pn_alloc(&linkpath);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
		error = pn_getsymlink(vp, &linkpath, kcred);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
		if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
			char *ms = strstr(linkpath.pn_path, ZVOL_PSEUDO_DEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
			if (ms != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
				ms += strlen(ZVOL_PSEUDO_DEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
				minor = stoi(&ms);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
		pn_free(&linkpath);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	if (vp != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
		VN_RELE(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
	 * If we found a minor but it's already in use, we must pick a new one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	if (minor != 0 && ddi_get_soft_state(zvol_state, minor) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
		minor = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	if (minor == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
		minor = zvol_minor_alloc();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
	if (minor == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	if (ddi_soft_state_zalloc(zvol_state, minor) != DDI_SUCCESS) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
		return (EAGAIN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   518
	(void) ddi_prop_update_string(minor, zfs_dip, ZVOL_PROP_NAME,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   519
	    (char *)name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
	(void) sprintf(chrbuf, "%uc,raw", minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
	if (ddi_create_minor_node(zfs_dip, chrbuf, S_IFCHR,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
	    minor, DDI_PSEUDO, 0) == DDI_FAILURE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
		ddi_soft_state_free(zvol_state, minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
		return (EAGAIN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	(void) sprintf(blkbuf, "%uc", minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
	if (ddi_create_minor_node(zfs_dip, blkbuf, S_IFBLK,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	    minor, DDI_PSEUDO, 0) == DDI_FAILURE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
		ddi_remove_minor_node(zfs_dip, chrbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
		ddi_soft_state_free(zvol_state, minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
		return (EAGAIN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
	zv = ddi_get_soft_state(zvol_state, minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
	(void) strcpy(zv->zv_name, name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
	zv->zv_min_bs = DEV_BSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
	zv->zv_minor = minor;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	zv->zv_volsize = volsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
	zv->zv_objset = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	zv->zv_mode = ds_mode;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   550
	zv->zv_zilog = zil_open(os, zvol_get_data);
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
   551
	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
   552
	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
   553
	    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
   554
	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
   555
	    offsetof(zvol_extent_t, ze_node));
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   556
	/* get and cache the blocksize */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   557
	error = dmu_object_info(os, ZVOL_OBJ, &doi);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   558
	ASSERT(error == 0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   559
	zv->zv_volblocksize = doi.doi_data_block_size;
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   560
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   561
	zil_replay(os, zv, zvol_replay_vector);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4543
diff changeset
   562
	zvol_size_changed(zv, maj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1357
diff changeset
   564
	/* XXX this should handle the possible i/o error */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	VERIFY(dsl_prop_register(dmu_objset_ds(zv->zv_objset),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
	    "readonly", zvol_readonly_changed_cb, zv) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
	zvol_minors++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
	mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
 * Remove minor node for the specified volume.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   579
zvol_remove_minor(const char *name)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
	char namebuf[30];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
	mutex_enter(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   586
	if ((zv = zvol_minor_lookup(name)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
	if (zv->zv_total_opens != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	(void) sprintf(namebuf, "%uc,raw", zv->zv_minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
	ddi_remove_minor_node(zfs_dip, namebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
	(void) sprintf(namebuf, "%uc", zv->zv_minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
	ddi_remove_minor_node(zfs_dip, namebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
	VERIFY(dsl_prop_unregister(dmu_objset_ds(zv->zv_objset),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
	    "readonly", zvol_readonly_changed_cb, zv) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   605
	zil_close(zv->zv_zilog);
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   606
	zv->zv_zilog = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
	dmu_objset_close(zv->zv_objset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
	zv->zv_objset = NULL;
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
   609
	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
   610
	mutex_destroy(&zv->zv_znode.z_range_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
	ddi_soft_state_free(zvol_state, zv->zv_minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
	zvol_minors--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
	mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   621
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   622
zvol_prealloc(zvol_state_t *zv)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   623
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   624
	objset_t *os = zv->zv_objset;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   625
	dmu_tx_t *tx;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   626
	uint64_t refd, avail, usedobjs, availobjs;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   627
	uint64_t resid = zv->zv_volsize;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   628
	uint64_t off = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   629
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   630
	/* Check the space usage before attempting to allocate the space */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   631
	dmu_objset_space(os, &refd, &avail, &usedobjs, &availobjs);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   632
	if (avail < zv->zv_volsize)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   633
		return (ENOSPC);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   634
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   635
	/* Free old extents if they exist */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   636
	zvol_free_extents(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   637
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   638
	while (resid != 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   639
		int error;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   640
		uint64_t bytes = MIN(resid, SPA_MAXBLOCKSIZE);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   641
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   642
		tx = dmu_tx_create(os);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   643
		dmu_tx_hold_write(tx, ZVOL_OBJ, off, bytes);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   644
		error = dmu_tx_assign(tx, TXG_WAIT);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   645
		if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   646
			dmu_tx_abort(tx);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6730
diff changeset
   647
			(void) dmu_free_long_range(os, ZVOL_OBJ, 0, off);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   648
			return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   649
		}
7872
40a9434212f6 6646775 Speed up the dumpifying process for zvols
Tim Haley <Tim.Haley@Sun.COM>
parents: 7837
diff changeset
   650
		dmu_prealloc(os, ZVOL_OBJ, off, bytes, tx);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   651
		dmu_tx_commit(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   652
		off += bytes;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   653
		resid -= bytes;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   654
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   655
	txg_wait_synced(dmu_objset_pool(os), 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   656
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   657
	return (0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   658
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   659
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   660
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   661
zvol_update_volsize(zvol_state_t *zv, major_t maj, uint64_t volsize)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   662
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   663
	dmu_tx_t *tx;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   664
	int error;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   665
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   666
	ASSERT(MUTEX_HELD(&zvol_state_lock));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   667
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   668
	tx = dmu_tx_create(zv->zv_objset);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   669
	dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   670
	error = dmu_tx_assign(tx, TXG_WAIT);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   671
	if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   672
		dmu_tx_abort(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   673
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   674
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   675
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   676
	error = zap_update(zv->zv_objset, ZVOL_ZAP_OBJ, "size", 8, 1,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   677
	    &volsize, tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   678
	dmu_tx_commit(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   679
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   680
	if (error == 0)
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6730
diff changeset
   681
		error = dmu_free_long_range(zv->zv_objset,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6730
diff changeset
   682
		    ZVOL_OBJ, volsize, DMU_OBJECT_END);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   683
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   684
	/*
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   685
	 * If we are using a faked-up state (zv_minor == 0) then don't
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   686
	 * try to update the in-core zvol state.
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   687
	 */
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   688
	if (error == 0 && zv->zv_minor) {
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   689
		zv->zv_volsize = volsize;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   690
		zvol_size_changed(zv, maj);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   691
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   692
	return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   693
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   694
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
int
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4543
diff changeset
   696
zvol_set_volsize(const char *name, major_t maj, uint64_t volsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
	int error;
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 849
diff changeset
   700
	dmu_object_info_t doi;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   701
	uint64_t old_volsize = 0ULL;
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   702
	zvol_state_t state = { 0 };
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
	mutex_enter(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   706
	if ((zv = zvol_minor_lookup(name)) == NULL) {
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   707
		/*
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   708
		 * If we are doing a "zfs clone -o volsize=", then the
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   709
		 * minor node won't exist yet.
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   710
		 */
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   711
		error = dmu_objset_open(name, DMU_OST_ZVOL, DS_MODE_OWNER,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   712
		    &state.zv_objset);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   713
		if (error != 0)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   714
			goto out;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   715
		zv = &state;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   717
	old_volsize = zv->zv_volsize;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 849
diff changeset
   719
	if ((error = dmu_object_info(zv->zv_objset, ZVOL_OBJ, &doi)) != 0 ||
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   720
	    (error = zvol_check_volsize(volsize,
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   721
	    doi.doi_data_block_size)) != 0)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   722
		goto out;
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 849
diff changeset
   723
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   724
	if (zv->zv_flags & ZVOL_RDONLY || (zv->zv_mode & DS_MODE_READONLY)) {
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   725
		error = EROFS;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   726
		goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   729
	error = zvol_update_volsize(zv, maj, volsize);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   731
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   732
	 * Reinitialize the dump area to the new size. If we
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   733
	 * failed to resize the dump area then restore the it back to
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   734
	 * it's original size.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   735
	 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   736
	if (error == 0 && zv->zv_flags & ZVOL_DUMPIFIED) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   737
		if ((error = zvol_dumpify(zv)) != 0 ||
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   738
		    (error = dumpvp_resize()) != 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   739
			(void) zvol_update_volsize(zv, maj, old_volsize);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   740
			error = zvol_dumpify(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   741
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   744
out:
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   745
	if (state.zv_objset)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   746
		dmu_objset_close(state.zv_objset);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7080
diff changeset
   747
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
	mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   754
zvol_set_volblocksize(const char *name, uint64_t volblocksize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
	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
   759
	boolean_t needlock;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   761
	/*
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   762
	 * The lock may already be held if we are being called from
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   763
	 * zvol_dump_init().
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   764
	 */
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   765
	needlock = !MUTEX_HELD(&zvol_state_lock);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   766
	if (needlock)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   767
		mutex_enter(&zvol_state_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   769
	if ((zv = zvol_minor_lookup(name)) == 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
   770
		if (needlock)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   771
			mutex_exit(&zvol_state_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   774
	if (zv->zv_flags & ZVOL_RDONLY || (zv->zv_mode & DS_MODE_READONLY)) {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   775
		if (needlock)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   776
			mutex_exit(&zvol_state_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
		return (EROFS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	tx = dmu_tx_create(zv->zv_objset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
	dmu_tx_hold_bonus(tx, ZVOL_OBJ);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
		dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
		error = dmu_object_set_blocksize(zv->zv_objset, ZVOL_OBJ,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2638
diff changeset
   787
		    volblocksize, 0, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
		if (error == ENOTSUP)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
			error = EBUSY;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
		dmu_tx_commit(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
   791
		if (error == 0)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   792
			zv->zv_volblocksize = volblocksize;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   795
	if (needlock)
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
   796
		mutex_exit(&zvol_state_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
zvol_open(dev_t *devp, int flag, int otyp, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
	minor_t minor = getminor(*devp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
	if (minor == 0)			/* This is the control device */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
	mutex_enter(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
	zv = ddi_get_soft_state(zvol_state, minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	if (zv == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	ASSERT(zv->zv_objset != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
	if ((flag & FWRITE) &&
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   822
	    (zv->zv_flags & ZVOL_RDONLY || (zv->zv_mode & DS_MODE_READONLY))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
		return (EROFS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
	}
7405
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   826
	if (zv->zv_flags & ZVOL_EXCL) {
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   827
		mutex_exit(&zvol_state_lock);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   828
		return (EBUSY);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   829
	}
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   830
	if (flag & FEXCL) {
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   831
		if (zv->zv_total_opens != 0) {
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   832
			mutex_exit(&zvol_state_lock);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   833
			return (EBUSY);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   834
		}
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   835
		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
   836
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
	if (zv->zv_open_count[otyp] == 0 || otyp == OTYP_LYR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
		zv->zv_open_count[otyp]++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
		zv->zv_total_opens++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
	mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
zvol_close(dev_t dev, int flag, int otyp, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
	minor_t minor = getminor(dev);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
	zvol_state_t *zv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
	if (minor == 0)		/* This is the control device */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
	mutex_enter(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
	zv = ddi_get_soft_state(zvol_state, minor);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
	if (zv == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
7405
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
   866
	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
   867
		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
   868
		zv->zv_flags &= ~ZVOL_EXCL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	 * If the open count is zero, this is a spurious close.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	 * That indicates a bug in the kernel / DDI framework.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
	ASSERT(zv->zv_open_count[otyp] != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	ASSERT(zv->zv_total_opens != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
	 * You may get multiple opens, but only one close.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
	zv->zv_open_count[otyp]--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
	zv->zv_total_opens--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
	mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   889
static void
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   890
zvol_get_done(dmu_buf_t *db, void *vzgd)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   891
{
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   892
	zgd_t *zgd = (zgd_t *)vzgd;
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
   893
	rl_t *rl = zgd->zgd_rl;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   894
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   895
	dmu_buf_rele(db, vzgd);
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
   896
	zfs_range_unlock(rl);
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   897
	zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   898
	kmem_free(zgd, sizeof (zgd_t));
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   899
}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   900
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   901
/*
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   902
 * Get data to generate a TX_WRITE intent log record.
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   903
 */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   904
static int
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   905
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
   906
{
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   907
	zvol_state_t *zv = arg;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   908
	objset_t *os = zv->zv_objset;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   909
	dmu_buf_t *db;
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
   910
	rl_t *rl;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   911
	zgd_t *zgd;
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
   912
	uint64_t boff; 			/* block starting offset */
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
   913
	int dlen = lr->lr_length;	/* length of user data */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   914
	int error;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   915
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   916
	ASSERT(zio);
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
   917
	ASSERT(dlen != 0);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   918
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
   919
	/*
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
   920
	 * 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
   921
	 * 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
   922
	 * 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
   923
	 * 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
   924
	 * 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
   925
	 */
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
   926
	if (buf != NULL) /* immediate write */
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
   927
		return (dmu_read(os, ZVOL_OBJ, lr->lr_offset, dlen, buf));
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   928
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   929
	zgd = (zgd_t *)kmem_alloc(sizeof (zgd_t), KM_SLEEP);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   930
	zgd->zgd_zilog = zv->zv_zilog;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   931
	zgd->zgd_bp = &lr->lr_blkptr;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   932
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
   933
	/*
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
   934
	 * Lock the range of the block to ensure that when the data is
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
   935
	 * written out and its checksum is being calculated that no other
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
   936
	 * thread can change the block.
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
   937
	 */
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
   938
	boff = P2ALIGN_TYPED(lr->lr_offset, zv->zv_volblocksize, uint64_t);
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
   939
	rl = zfs_range_lock(&zv->zv_znode, boff, zv->zv_volblocksize,
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
   940
	    RL_READER);
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
   941
	zgd->zgd_rl = rl;
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
   942
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   943
	VERIFY(0 == dmu_buf_hold(os, ZVOL_OBJ, lr->lr_offset, zgd, &db));
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   944
	error = dmu_sync(zio, db, &lr->lr_blkptr,
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   945
	    lr->lr_common.lrc_txg, zvol_get_done, zgd);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   946
	if (error == 0)
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   947
		zil_add_block(zv->zv_zilog, &lr->lr_blkptr);
3063
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
	 * If we get EINPROGRESS, then we need to wait for a
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   950
	 * write IO initiated by dmu_sync() to complete before
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   951
	 * we can release this dbuf.  We will finish everything
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   952
	 * up in the zvol_get_done() callback.
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
	if (error == EINPROGRESS)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   955
		return (0);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   956
	dmu_buf_rele(db, zgd);
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
   957
	zfs_range_unlock(rl);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   958
	kmem_free(zgd, sizeof (zgd_t));
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   959
	return (error);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   960
}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   961
1861
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
   962
/*
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
   963
 * zvol_log_write() handles synchronous writes using TX_WRITE ZIL transactions.
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   964
 *
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   965
 * 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
   966
 * Otherwise we will later flush the data out via dmu_sync().
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   967
 */
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
   968
ssize_t zvol_immediate_write_sz = 32768;
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   969
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   970
static void
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   971
zvol_log_write(zvol_state_t *zv, dmu_tx_t *tx, offset_t off, ssize_t len)
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   972
{
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   973
	uint32_t blocksize = zv->zv_volblocksize;
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   974
	zilog_t *zilog = zv->zv_zilog;
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
   975
	lr_write_t *lr;
1861
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
   976
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   977
	if (zilog->zl_replay) {
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   978
		dsl_dataset_dirty(dmu_objset_ds(zilog->zl_os), tx);
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   979
		zilog->zl_replayed_seq[dmu_tx_get_txg(tx) & TXG_MASK] =
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   980
		    zilog->zl_replaying_seq;
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   981
		return;
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   982
	}
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   983
1861
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
   984
	while (len) {
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   985
		ssize_t nbytes = MIN(len, blocksize - P2PHASE(off, blocksize));
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   986
		itx_t *itx = zil_itx_create(TX_WRITE, sizeof (*lr));
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   987
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   988
		itx->itx_wr_state =
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   989
		    len > zvol_immediate_write_sz ?  WR_INDIRECT : WR_NEED_COPY;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   990
		itx->itx_private = zv;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   991
		lr = (lr_write_t *)&itx->itx_lr;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   992
		lr->lr_foid = ZVOL_OBJ;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   993
		lr->lr_offset = off;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   994
		lr->lr_length = nbytes;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   995
		lr->lr_blkoff = off - P2ALIGN_TYPED(off, blocksize, uint64_t);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   996
		BP_ZERO(&lr->lr_blkptr);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   997
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7903
diff changeset
   998
		(void) zil_itx_assign(zilog, itx, tx);
1861
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
   999
		len -= nbytes;
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
  1000
		off += nbytes;
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1001
	}
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1002
}
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1003
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1004
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
  1005
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
  1006
    boolean_t doread, boolean_t isdump)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1007
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1008
	vdev_disk_t *dvd;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1009
	int c;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1010
	int numerrors = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1011
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1012
	for (c = 0; c < vd->vdev_children; c++) {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1013
		ASSERT(vd->vdev_ops == &vdev_mirror_ops);
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1014
		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
  1015
		    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
  1016
		if (err != 0) {
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1017
			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
  1018
		} else if (doread) {
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1019
			break;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1020
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1021
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1022
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1023
	if (!vd->vdev_ops->vdev_op_leaf)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1024
		return (numerrors < vd->vdev_children ? 0 : EIO);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1025
7903
4c8fa38f91ec 6760985 assertion failure with dump device on pool with non-writeable vdev
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7872
diff changeset
  1026
	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
  1027
		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
  1028
	else if (!doread && !vdev_writeable(vd))
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1029
		return (EIO);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1030
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1031
	dvd = vd->vdev_tsd;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1032
	ASSERT3P(dvd, !=, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1033
	offset += VDEV_LABEL_START_SIZE;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1034
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1035
	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
  1036
		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
  1037
		if (doread)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1038
			return (EIO);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1039
		return (ldi_dump(dvd->vd_lh, addr, lbtodb(offset),
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1040
		    lbtodb(size)));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1041
	} else {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1042
		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
  1043
		    doread ? B_READ : B_WRITE));
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1044
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1045
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1046
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1047
static int
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1048
zvol_dumpio(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
  1049
    boolean_t doread, boolean_t isdump)
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1050
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1051
	vdev_t *vd;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1052
	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
  1053
	zvol_extent_t *ze;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1054
	spa_t *spa = dmu_objset_spa(zv->zv_objset);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1055
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1056
	/* 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
  1057
	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
  1058
	    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
  1059
		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
  1060
	}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1061
	ASSERT(size <= zv->zv_volblocksize);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1062
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1063
	/* 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
  1064
	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
  1065
	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
  1066
		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
  1067
		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
  1068
	}
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  1069
	spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1070
	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
  1071
	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
  1072
	error = zvol_dumpio_vdev(vd, addr, offset, size, doread, isdump);
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7638
diff changeset
  1073
	spa_config_exit(spa, SCL_STATE, FTAG);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1074
	return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1075
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1076
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1077
int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
zvol_strategy(buf_t *bp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	zvol_state_t *zv = ddi_get_soft_state(zvol_state, getminor(bp->b_edev));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
	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
  1082
	size_t resid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
	char *addr;
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1084
	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
  1085
	rl_t *rl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
	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
  1087
	boolean_t doread = bp->b_flags & B_READ;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1088
	boolean_t is_dump = zv->zv_flags & ZVOL_DUMPIFIED;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	if (zv == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
		bioerror(bp, ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
		biodone(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
	if (getminor(bp->b_edev) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
		bioerror(bp, EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
		biodone(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1102
	if (!(bp->b_flags & B_READ) &&
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1103
	    (zv->zv_flags & ZVOL_RDONLY ||
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1104
	    zv->zv_mode & DS_MODE_READONLY)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
		bioerror(bp, EROFS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
		biodone(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
	off = ldbtob(bp->b_blkno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
	volsize = zv->zv_volsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1113
	os = zv->zv_objset;
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1114
	ASSERT(os != NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
	bp_mapin(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
	addr = bp->b_un.b_addr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
	resid = bp->b_bcount;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1120
	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
  1121
		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
  1122
		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
  1123
		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
  1124
	}
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1125
1861
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
  1126
	/*
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
  1127
	 * 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
  1128
	 * 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
  1129
	 */
3755
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
  1130
	rl = 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
  1131
	    doread ? RL_READER : RL_WRITER);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1132
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	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
  1134
		size_t size = MIN(resid, zvol_maxphys);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1135
		if (is_dump) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1136
			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
  1137
			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
  1138
			    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
  1139
		} else if (doread) {
1861
7929434f26fb 6413125 zvol_strategy() race can lead to on-disk corruption.
perrin
parents: 1669
diff changeset
  1140
			error = dmu_read(os, ZVOL_OBJ, off, size, addr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
		} else {
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1142
			dmu_tx_t *tx = dmu_tx_create(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
			dmu_tx_hold_write(tx, ZVOL_OBJ, off, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
			error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
			if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
				dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
			} else {
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1148
				dmu_write(os, ZVOL_OBJ, off, size, addr, tx);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1149
				zvol_log_write(zv, tx, off, size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
				dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
		}
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1153
		if (error) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1154
			/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1155
			if (error == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1156
				error = EIO;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
			break;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1158
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
		off += size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
		addr += size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
		resid -= size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
	}
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
  1163
	zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
	if ((bp->b_resid = resid) == bp->b_bcount)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
		bioerror(bp, off > volsize ? EINVAL : error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1168
	if (!(bp->b_flags & B_ASYNC) && !doread && !zil_disable && !is_dump)
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1169
		zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1170
	biodone(bp);
1141
ca4bb9237a10 6354547 sticky log buf size
perrin
parents: 1133
diff changeset
  1171
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1175
/*
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1176
 * Set the buffer count to the zvol maximum transfer.
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1177
 * Using our own routine instead of the default minphys()
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1178
 * 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
  1179
 * (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
  1180
 * (every zvol_maxphys - currently 1MB) instead of minphys (currently
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1181
 * 56K on X86 and 128K on sparc).
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1182
 */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1183
void
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1184
zvol_minphys(struct buf *bp)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1185
{
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1186
	if (bp->b_bcount > zvol_maxphys)
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1187
		bp->b_bcount = zvol_maxphys;
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1188
}
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 3016
diff changeset
  1189
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1190
int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1191
zvol_dump(dev_t dev, caddr_t addr, daddr_t blkno, int nblocks)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1192
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1193
	minor_t minor = getminor(dev);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1194
	zvol_state_t *zv;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1195
	int error = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1196
	uint64_t size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1197
	uint64_t boff;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1198
	uint64_t resid;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1199
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1200
	if (minor == 0)			/* This is the control device */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1201
		return (ENXIO);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1202
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1203
	zv = ddi_get_soft_state(zvol_state, minor);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1204
	if (zv == NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1205
		return (ENXIO);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1206
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1207
	boff = ldbtob(blkno);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1208
	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
  1209
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1210
	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
  1211
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1212
	while (resid) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1213
		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
  1214
		error = zvol_dumpio(zv, addr, boff, size, B_FALSE, B_TRUE);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1215
		if (error)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1216
			break;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1217
		boff += size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1218
		addr += size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1219
		resid -= size;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1220
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1221
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1222
	return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1223
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1224
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
int
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1227
zvol_read(dev_t dev, uio_t *uio, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
{
4107
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1229
	minor_t minor = getminor(dev);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1230
	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
  1231
	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
  1232
	rl_t *rl;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1233
	int error = 0;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1234
4107
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1235
	if (minor == 0)			/* This is the control device */
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1236
		return (ENXIO);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1237
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1238
	zv = ddi_get_soft_state(zvol_state, minor);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1239
	if (zv == NULL)
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1240
		return (ENXIO);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1241
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1242
	volsize = zv->zv_volsize;
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1243
	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
  1244
	    (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
  1245
		return (EIO);
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1246
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1247
	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
  1248
		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
  1249
		    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
  1250
		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
  1251
	}
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1252
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
  1253
	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
  1254
	    RL_READER);
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1255
	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
  1256
		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
  1257
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1258
		/* 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
  1259
		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
  1260
			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
  1261
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1262
		error =  dmu_read_uio(zv->zv_objset, ZVOL_OBJ, uio, bytes);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1263
		if (error) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1264
			/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1265
			if (error == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1266
				error = EIO;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1267
			break;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  1268
		}
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  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);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1271
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1273
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
int
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1276
zvol_write(dev_t dev, uio_t *uio, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
{
4107
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1278
	minor_t minor = getminor(dev);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1279
	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
  1280
	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
  1281
	rl_t *rl;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1282
	int error = 0;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1283
4107
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1284
	if (minor == 0)			/* This is the control device */
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1285
		return (ENXIO);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1286
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1287
	zv = ddi_get_soft_state(zvol_state, minor);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1288
	if (zv == NULL)
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1289
		return (ENXIO);
5b13dedb1ea7 6549112 writes to /dev/zfs panic system
gw25295
parents: 3897
diff changeset
  1290
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1291
	volsize = zv->zv_volsize;
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1292
	if (uio->uio_resid > 0 &&
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1293
	    (uio->uio_loffset < 0 || uio->uio_loffset >= volsize))
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1294
		return (EIO);
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1295
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1296
	if (zv->zv_flags & ZVOL_DUMPIFIED) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1297
		error = physio(zvol_strategy, NULL, dev, B_WRITE,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1298
		    zvol_minphys, uio);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1299
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1300
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1301
3755
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
  1302
	rl = zfs_range_lock(&zv->zv_znode, uio->uio_loffset, uio->uio_resid,
8708c35cb823 6525008 panic: dr->dt.dl.dr_override_state != DR_IN_DMU_SYNC, file: ../../common/fs/zfs/dbuf.c, line: 676
perrin
parents: 3638
diff changeset
  1303
	    RL_WRITER);
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1304
	while (uio->uio_resid > 0 && uio->uio_loffset < volsize) {
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1305
		uint64_t bytes = MIN(uio->uio_resid, DMU_MAX_ACCESS >> 1);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1306
		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
  1307
		dmu_tx_t *tx = dmu_tx_create(zv->zv_objset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
7013
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1309
		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
  1310
			bytes = volsize - off;
540c400de3b4 6596419 zvol character (raw) devices allow read/write past the end of the device
gw25295
parents: 6992
diff changeset
  1311
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1312
		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
  1313
		error = dmu_tx_assign(tx, TXG_WAIT);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1314
		if (error) {
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1315
			dmu_tx_abort(tx);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1316
			break;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1317
		}
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1318
		error = dmu_write_uio(zv->zv_objset, ZVOL_OBJ, uio, bytes, tx);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1319
		if (error == 0)
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1320
			zvol_log_write(zv, tx, off, bytes);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1321
		dmu_tx_commit(tx);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1322
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1323
		if (error)
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1324
			break;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1325
	}
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
  1326
	zfs_range_unlock(rl);
8524
a56dffa8fba9 6770534 zvols do not observe character device semantics
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8227
diff changeset
  1327
	if (!zil_disable)
a56dffa8fba9 6770534 zvols do not observe character device semantics
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8227
diff changeset
  1328
		zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1329
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
7405
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1332
int
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1333
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
  1334
{
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1335
	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
  1336
	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
  1337
	uint32_t crc;
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1338
	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
  1339
	int length;
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1340
	char *ptr;
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1341
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1342
	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
  1343
		return (EFAULT);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1344
	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
  1345
	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
  1346
	/*
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1347
	 * 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
  1348
	 * 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
  1349
	 * 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
  1350
	 * 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
  1351
	 * PMBR.
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1352
	 */
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1353
	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
  1354
		return (EINVAL);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1355
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1356
	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
  1357
	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
  1358
	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
  1359
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1360
	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
  1361
		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
  1362
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1363
		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
  1364
		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
  1365
		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
  1366
		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
  1367
		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
  1368
		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
  1369
		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
  1370
		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
  1371
		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
  1372
		    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
  1373
		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
  1374
		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
  1375
		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
  1376
		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
  1377
		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
  1378
		    flag))
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1379
			return (EFAULT);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1380
		ptr += sizeof (gpt);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1381
		length -= sizeof (gpt);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1382
	}
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1383
	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
  1384
	    length), flag))
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1385
		return (EFAULT);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1386
	return (0);
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1387
}
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1388
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
 * Dirtbag ioctls to support mkfs(1M) for UFS filesystems.  See dkio(7I).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
zvol_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
	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
  1397
	struct dk_cinfo dki;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
	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
  1399
	struct dk_callback *dkc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
	int error = 0;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1401
	rl_t *rl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
	mutex_enter(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
	zv = ddi_get_soft_state(zvol_state, getminor(dev));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
	if (zv == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
	switch (cmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
	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
  1415
		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
  1416
		(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
  1417
		(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
  1418
		dki.dki_ctype = DKC_UNKNOWN;
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3755
diff changeset
  1419
		dki.dki_maxtransfer = 1 << (SPA_MAXBLOCKSHIFT - zv->zv_min_bs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
		mutex_exit(&zvol_state_lock);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3755
diff changeset
  1421
		if (ddi_copyout(&dki, (void *)arg, sizeof (dki), flag))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
			error = EFAULT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
	case DKIOCGMEDIAINFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
		bzero(&dkm, sizeof (dkm));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
		dkm.dki_lbsize = 1U << zv->zv_min_bs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
		dkm.dki_capacity = zv->zv_volsize >> zv->zv_min_bs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
		dkm.dki_media_type = DK_UNKNOWN;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
		mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
		if (ddi_copyout(&dkm, (void *)arg, sizeof (dkm), flag))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
			error = EFAULT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
	case DKIOCGETEFI:
7405
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
			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
  1438
			uint8_t bs = zv->zv_min_bs;
3016
e46176752558 6480048 newfs failed to create new ufs in zvol.
maybee
parents: 2885
diff changeset
  1439
e46176752558 6480048 newfs failed to create new ufs in zvol.
maybee
parents: 2885
diff changeset
  1440
			mutex_exit(&zvol_state_lock);
7405
22b4aeef8023 6612759 zvol DKIOCGETEFI should return GPT and GPE when possible
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7294
diff changeset
  1441
			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
  1442
			return (error);
3016
e46176752558 6480048 newfs failed to create new ufs in zvol.
maybee
parents: 2885
diff changeset
  1443
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1445
	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
  1446
		dkc = (struct dk_callback *)arg;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1447
		zil_commit(zv->zv_zilog, UINT64_MAX, ZVOL_OBJ);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3755
diff changeset
  1448
		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
  1449
			(*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
  1450
			error = 0;
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3755
diff changeset
  1451
		}
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1452
		break;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  1453
3245
0c86ad4b2673 6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents: 3080
diff changeset
  1454
	case DKIOCGGEOM:
0c86ad4b2673 6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents: 3080
diff changeset
  1455
	case DKIOCGVTOC:
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1456
		/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1457
		 * commands using these (like prtvtoc) expect ENOTSUP
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1458
		 * since we're emulating an EFI label
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1459
		 */
3245
0c86ad4b2673 6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents: 3080
diff changeset
  1460
		error = ENOTSUP;
0c86ad4b2673 6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents: 3080
diff changeset
  1461
		break;
0c86ad4b2673 6493634 zvol should return ENOTSUP on DKIOCGVTOC ioctl
maybee
parents: 3080
diff changeset
  1462
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1463
	case DKIOCDUMPINIT:
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1464
		rl = zfs_range_lock(&zv->zv_znode, 0, zv->zv_volsize,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1465
		    RL_WRITER);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1466
		error = zvol_dumpify(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1467
		zfs_range_unlock(rl);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1468
		break;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1469
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1470
	case DKIOCDUMPFINI:
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1471
		rl = zfs_range_lock(&zv->zv_znode, 0, zv->zv_volsize,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1472
		    RL_WRITER);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1473
		error = zvol_dump_fini(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1474
		zfs_range_unlock(rl);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1475
		break;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1476
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1477
	default:
3016
e46176752558 6480048 newfs failed to create new ufs in zvol.
maybee
parents: 2885
diff changeset
  1478
		error = ENOTTY;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1481
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1482
	mutex_exit(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
zvol_busy(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
	return (zvol_minors != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
zvol_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
	VERIFY(ddi_soft_state_init(&zvol_state, sizeof (zvol_state_t), 1) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	mutex_init(&zvol_state_lock, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
zvol_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
	mutex_destroy(&zvol_state_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
	ddi_soft_state_fini(&zvol_state);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
}
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1505
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1506
static boolean_t
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1507
zvol_is_swap(zvol_state_t *zv)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1508
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1509
	vnode_t *vp;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1510
	boolean_t ret = B_FALSE;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1511
	char *devpath;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1512
	size_t devpathlen;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1513
	int error;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1514
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1515
	devpathlen = strlen(ZVOL_FULL_DEV_DIR) + strlen(zv->zv_name) + 1;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1516
	devpath = kmem_alloc(devpathlen, KM_SLEEP);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1517
	(void) sprintf(devpath, "%s%s", ZVOL_FULL_DEV_DIR, zv->zv_name);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1518
	error = lookupname(devpath, UIO_SYSSPACE, FOLLOW, NULLVPP, &vp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1519
	kmem_free(devpath, devpathlen);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1520
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1521
	ret = !error && IS_SWAPVP(common_specvp(vp));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1522
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1523
	if (vp != NULL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1524
		VN_RELE(vp);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1525
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1526
	return (ret);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1527
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1528
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1529
static int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1530
zvol_dump_init(zvol_state_t *zv, boolean_t resize)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1531
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1532
	dmu_tx_t *tx;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1533
	int error = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1534
	objset_t *os = zv->zv_objset;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1535
	nvlist_t *nv = NULL;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1536
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1537
	ASSERT(MUTEX_HELD(&zvol_state_lock));
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1538
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1539
	tx = dmu_tx_create(os);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1540
	dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1541
	error = dmu_tx_assign(tx, TXG_WAIT);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1542
	if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1543
		dmu_tx_abort(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1544
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1545
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1546
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1547
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1548
	 * If we are resizing the dump device then we only need to
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1549
	 * update the refreservation to match the newly updated
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1550
	 * zvolsize. Otherwise, we save off the original state of the
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1551
	 * zvol so that we can restore them if the zvol is ever undumpified.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1552
	 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1553
	if (resize) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1554
		error = zap_update(os, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1555
		    zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1556
		    &zv->zv_volsize, tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1557
	} else {
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1558
		uint64_t checksum, compress, refresrv, vbs;
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1559
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1560
		error = dsl_prop_get_integer(zv->zv_name,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1561
		    zfs_prop_to_name(ZFS_PROP_COMPRESSION), &compress, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1562
		error = error ? error : dsl_prop_get_integer(zv->zv_name,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1563
		    zfs_prop_to_name(ZFS_PROP_CHECKSUM), &checksum, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1564
		error = error ? error : dsl_prop_get_integer(zv->zv_name,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1565
		    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
  1566
		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
  1567
		    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), &vbs, NULL);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1568
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1569
		error = error ? error : zap_update(os, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1570
		    zfs_prop_to_name(ZFS_PROP_COMPRESSION), 8, 1,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1571
		    &compress, tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1572
		error = error ? error : zap_update(os, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1573
		    zfs_prop_to_name(ZFS_PROP_CHECKSUM), 8, 1, &checksum, tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1574
		error = error ? error : zap_update(os, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1575
		    zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 8, 1,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1576
		    &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
  1577
		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
  1578
		    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
  1579
		    &vbs, tx);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1580
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1581
	dmu_tx_commit(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1582
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1583
	/* Truncate the file */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1584
	if (!error)
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6730
diff changeset
  1585
		error = dmu_free_long_range(zv->zv_objset,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6730
diff changeset
  1586
		    ZVOL_OBJ, 0, DMU_OBJECT_END);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1587
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1588
	if (error)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1589
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1590
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1591
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1592
	 * We only need update the zvol's property if we are initializing
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1593
	 * the dump area for the first time.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1594
	 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1595
	if (!resize) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1596
		VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1597
		VERIFY(nvlist_add_uint64(nv,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1598
		    zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 0) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1599
		VERIFY(nvlist_add_uint64(nv,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1600
		    zfs_prop_to_name(ZFS_PROP_COMPRESSION),
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1601
		    ZIO_COMPRESS_OFF) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1602
		VERIFY(nvlist_add_uint64(nv,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1603
		    zfs_prop_to_name(ZFS_PROP_CHECKSUM),
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1604
		    ZIO_CHECKSUM_OFF) == 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
  1605
		VERIFY(nvlist_add_uint64(nv,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1606
		    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1607
		    SPA_MAXBLOCKSIZE) == 0);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1608
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1609
		error = zfs_set_prop_nvlist(zv->zv_name, nv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1610
		nvlist_free(nv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1611
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1612
		if (error)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1613
			return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1614
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1615
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1616
	/* Allocate the space for the dump */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1617
	error = zvol_prealloc(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1618
	return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1619
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1620
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1621
static int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1622
zvol_dumpify(zvol_state_t *zv)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1623
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1624
	int error = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1625
	uint64_t dumpsize = 0;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1626
	dmu_tx_t *tx;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1627
	objset_t *os = zv->zv_objset;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1628
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1629
	if (zv->zv_flags & ZVOL_RDONLY || (zv->zv_mode & DS_MODE_READONLY))
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1630
		return (EROFS);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1631
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1632
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1633
	 * We do not support swap devices acting as dump devices.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1634
	 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1635
	if (zvol_is_swap(zv))
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1636
		return (ENOTSUP);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1637
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1638
	if (zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1639
	    8, 1, &dumpsize) != 0 || dumpsize != zv->zv_volsize) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1640
		boolean_t resize = (dumpsize > 0) ? B_TRUE : B_FALSE;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1641
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1642
		if ((error = zvol_dump_init(zv, resize)) != 0) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1643
			(void) zvol_dump_fini(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1644
			return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1645
		}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1646
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1647
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1648
	/*
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1649
	 * Build up our lba mapping.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1650
	 */
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1651
	error = zvol_get_lbas(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1652
	if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1653
		(void) zvol_dump_fini(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1654
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1655
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1656
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1657
	tx = dmu_tx_create(os);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1658
	dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1659
	error = dmu_tx_assign(tx, TXG_WAIT);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1660
	if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1661
		dmu_tx_abort(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1662
		(void) zvol_dump_fini(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1663
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1664
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1665
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1666
	zv->zv_flags |= ZVOL_DUMPIFIED;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1667
	error = zap_update(os, ZVOL_ZAP_OBJ, ZVOL_DUMPSIZE, 8, 1,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1668
	    &zv->zv_volsize, tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1669
	dmu_tx_commit(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1670
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1671
	if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1672
		(void) zvol_dump_fini(zv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1673
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1674
	}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1675
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1676
	txg_wait_synced(dmu_objset_pool(os), 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1677
	return (0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1678
}
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1679
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1680
static int
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1681
zvol_dump_fini(zvol_state_t *zv)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1682
{
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1683
	dmu_tx_t *tx;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1684
	objset_t *os = zv->zv_objset;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1685
	nvlist_t *nv;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1686
	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
  1687
	uint64_t checksum, compress, refresrv, vbs;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1688
7080
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1689
	/*
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1690
	 * 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
  1691
	 * 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
  1692
	 * 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
  1693
	 * (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
  1694
	 */
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1695
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1696
	tx = dmu_tx_create(os);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1697
	dmu_tx_hold_zap(tx, ZVOL_ZAP_OBJ, TRUE, NULL);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1698
	error = dmu_tx_assign(tx, TXG_WAIT);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1699
	if (error) {
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1700
		dmu_tx_abort(tx);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1701
		return (error);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1702
	}
7080
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1703
	(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
  1704
	dmu_tx_commit(tx);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1705
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1706
	(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1707
	    zfs_prop_to_name(ZFS_PROP_CHECKSUM), 8, 1, &checksum);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1708
	(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1709
	    zfs_prop_to_name(ZFS_PROP_COMPRESSION), 8, 1, &compress);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1710
	(void) zap_lookup(zv->zv_objset, ZVOL_ZAP_OBJ,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1711
	    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
  1712
	(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
  1713
	    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), 8, 1, &vbs);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1714
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1715
	VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1716
	(void) nvlist_add_uint64(nv,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1717
	    zfs_prop_to_name(ZFS_PROP_CHECKSUM), checksum);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1718
	(void) nvlist_add_uint64(nv,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1719
	    zfs_prop_to_name(ZFS_PROP_COMPRESSION), compress);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1720
	(void) nvlist_add_uint64(nv,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1721
	    zfs_prop_to_name(ZFS_PROP_REFRESERVATION), 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
  1722
	(void) nvlist_add_uint64(nv,
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7754
diff changeset
  1723
	    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), vbs);
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1724
	(void) zfs_set_prop_nvlist(zv->zv_name, nv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1725
	nvlist_free(nv);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1726
7080
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1727
	zvol_free_extents(zv);
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1728
	zv->zv_flags &= ~ZVOL_DUMPIFIED;
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1729
	(void) dmu_free_long_range(os, ZVOL_OBJ, 0, DMU_OBJECT_END);
13a30a37ddc0 6724533 assertion failed: file: ../../common/fs/zfs/dmu_tx.c, line: 983
maybee
parents: 7013
diff changeset
  1730
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1731
	return (0);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 5688
diff changeset
  1732
}