usr/src/uts/common/fs/zfs/vdev_file.c
author gw25295
Mon, 29 Oct 2007 17:24:59 -0700
changeset 5369 27c1235ef9a4
parent 5331 3047ad28a67b
child 5530 4ed96167d864
permissions -rw-r--r--
6621355 panic in vdev_disk_io_start when trying to write to a faulted device 6622732 Assertion failed: !(zio->io_flags & ZIO_FLAG_WRITE_RETRY), file ../../../uts/com mon/fs/zfs/zio.c 6623221 CIFS breaks ZFS root
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: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
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
/*
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    22
 * Copyright 2007 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
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/vdev_file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 * Virtual device vector for files.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
static int
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    40
vdev_file_open_common(vdev_t *vd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
	vdev_file_t *vf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
	vnode_t *vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
	 * We must have a pathname, and it must be absolute.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
	if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
	vf = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_file_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
	 * We always open the files from the root of the global zone, even if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
	 * we're in a local zone.  If the user has gotten to this point, the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
	 * administrator has already decided that the pool should be available
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
	 * to local zone users, so the underlying devices should be as well.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
	ASSERT(vd->vdev_path != NULL && vd->vdev_path[0] == '/');
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    63
	error = vn_openat(vd->vdev_path + 1, UIO_SYSSPACE,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    64
	    spa_mode | FOFFMAX, 0, &vp, 0, 0, rootdir, -1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
	vf->vf_vnode = vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
#ifdef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
	 * Make sure it's a regular file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	if (vp->v_type != VREG) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
		return (ENODEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    83
	return (0);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    84
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    85
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    86
static int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    87
vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    88
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    89
	vdev_file_t *vf;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    90
	vattr_t vattr;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    91
	int error;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    92
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    93
	if ((error = vdev_file_open_common(vd)) != 0)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    94
		return (error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    95
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    96
	vf = vd->vdev_tsd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
    97
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
	 * Determine the physical size of the file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	vattr.va_mask = AT_SIZE;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   102
	error = VOP_GETATTR(vf->vf_vnode, &vattr, 0, kcred, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
		vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	*psize = vattr.va_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	*ashift = SPA_MINBLOCKSHIFT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
vdev_file_close(vdev_t *vd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	vdev_file_t *vf = vd->vdev_tsd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	if (vf == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	if (vf->vf_vnode != NULL) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   123
		(void) VOP_PUTPAGE(vf->vf_vnode, 0, 0, B_INVAL, kcred, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   124
		(void) VOP_CLOSE(vf->vf_vnode, spa_mode, 1, 0, kcred, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
		VN_RELE(vf->vf_vnode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	kmem_free(vf, sizeof (vdev_file_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	vd->vdev_tsd = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   132
static int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   133
vdev_file_probe_io(vdev_t *vd, caddr_t data, size_t size, uint64_t offset,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   134
    enum uio_rw rw)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   135
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   136
	vdev_file_t *vf = vd->vdev_tsd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   137
	ssize_t resid;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   138
	int error = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   139
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   140
	if (vd == NULL || vf == NULL || vf->vf_vnode == NULL)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   141
		return (EINVAL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   142
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   143
	ASSERT(rw == UIO_READ || rw ==  UIO_WRITE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   144
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   145
	error = vn_rdwr(rw, vf->vf_vnode, data, size, offset, UIO_SYSSPACE,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   146
	    0, RLIM64_INFINITY, kcred, &resid);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   147
	if (error || resid != 0)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   148
		return (EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   149
	return (0);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   150
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   151
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   152
/*
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   153
 * Determine if the underlying device is accessible by reading and writing
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   154
 * to a known location. We must be able to do this during syncing context
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   155
 * and thus we cannot set the vdev state directly.
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   156
 */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   157
static int
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   158
vdev_file_probe(vdev_t *vd)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   159
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   160
	vdev_t *nvd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   161
	char *vl_boot;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   162
	uint64_t offset;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   163
	int l, error = 0, retries = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   164
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   165
	if (vd == NULL)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   166
		return (EINVAL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   167
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   168
	/* Hijack the current vdev */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   169
	nvd = vd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   170
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   171
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   172
	 * Pick a random label to rewrite.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   173
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   174
	l = spa_get_random(VDEV_LABELS);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   175
	ASSERT(l < VDEV_LABELS);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   176
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   177
	offset = vdev_label_offset(vd->vdev_psize, l,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   178
	    offsetof(vdev_label_t, vl_boot_header));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   179
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   180
	vl_boot = kmem_alloc(VDEV_BOOT_HEADER_SIZE, KM_SLEEP);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   181
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   182
	while ((error = vdev_file_probe_io(nvd, vl_boot, VDEV_BOOT_HEADER_SIZE,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   183
	    offset, UIO_READ)) != 0 && retries == 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   184
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   185
		/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   186
		 * If we failed with the vdev that was passed in then
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   187
		 * try allocating a new one and try again.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   188
		 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   189
		nvd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   190
		if (vd->vdev_path)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   191
			nvd->vdev_path = spa_strdup(vd->vdev_path);
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   192
		retries++;
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   193
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   194
		error = vdev_file_open_common(nvd);
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   195
		if (error)
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   196
			break;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   197
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   198
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   199
	if ((spa_mode & FWRITE) && !error) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   200
		error = vdev_file_probe_io(nvd, vl_boot, VDEV_BOOT_HEADER_SIZE,
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   201
		    offset, UIO_WRITE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   202
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   203
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   204
	if (retries) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   205
		vdev_file_close(nvd);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   206
		if (nvd->vdev_path)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   207
			spa_strfree(nvd->vdev_path);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   208
		kmem_free(nvd, sizeof (vdev_t));
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   209
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   210
	kmem_free(vl_boot, VDEV_BOOT_HEADER_SIZE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   211
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   212
	if (!error)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   213
		vd->vdev_is_failing = B_FALSE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   214
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   215
	return (error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   216
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   217
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
vdev_file_io_start(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	vdev_file_t *vf = vd->vdev_tsd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	ssize_t resid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	if (zio->io_type == ZIO_TYPE_IOCTL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
		zio_vdev_io_bypass(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
		/* XXPOLICY */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   230
		if (!vdev_readable(vd)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
			zio->io_error = ENXIO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
			zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
		switch (zio->io_cmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
		case DKIOCFLUSHWRITECACHE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
			zio->io_error = VOP_FSYNC(vf->vf_vnode, FSYNC | FDSYNC,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   239
			    kcred, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
			dprintf("fsync(%s) = %d\n", vdev_description(vd),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
			    zio->io_error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
		default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
			zio->io_error = ENOTSUP;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
		zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   251
	/*
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   252
	 * In the kernel, don't bother double-caching, but in userland,
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   253
	 * we want to test the vdev_cache code.
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   254
	 */
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   255
#ifndef _KERNEL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
	if (zio->io_type == ZIO_TYPE_READ && vdev_cache_read(zio) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
		return;
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   258
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	if ((zio = vdev_queue_io(zio)) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	/* XXPOLICY */
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   264
	if (zio->io_type == ZIO_TYPE_WRITE)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   265
		error = vdev_writeable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   266
	else
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   267
		error = vdev_readable(vd) ? vdev_error_inject(vd, zio) : ENXIO;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   268
	error = (vd->vdev_remove_wanted || vd->vdev_is_failing) ? ENXIO : error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
		zio->io_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
		zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	zio->io_error = vn_rdwr(zio->io_type == ZIO_TYPE_READ ?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	    UIO_READ : UIO_WRITE, vf->vf_vnode, zio->io_data,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	    zio->io_size, zio->io_offset, UIO_SYSSPACE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
	    0, RLIM64_INFINITY, kcred, &resid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
	if (resid != 0 && zio->io_error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
		zio->io_error = ENOSPC;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	zio_next_stage_async(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
vdev_file_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
{
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   289
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   290
	if (zio_injection_enabled && zio->io_error == 0)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   291
		zio->io_error = zio_handle_device_injection(zio->io_vd, EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   292
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   293
	/*
5369
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   294
	 * If an error has been encountered then attempt to probe the device
27c1235ef9a4 6621355 panic in vdev_disk_io_start when trying to write to a faulted device
gw25295
parents: 5331
diff changeset
   295
	 * to determine if it's still accessible.
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   296
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   297
	if (zio->io_error == EIO) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   298
		vdev_t *vd = zio->io_vd;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   299
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   300
		if (vdev_probe(vd) != 0)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   301
			vd->vdev_is_failing = B_TRUE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   302
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   303
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	vdev_queue_io_done(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   306
#ifndef _KERNEL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	if (zio->io_type == ZIO_TYPE_WRITE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
		vdev_cache_write(zio);
3059
7d69dbccfcbb 6472021 vdev knobs can not be turned
ahrens
parents: 1544
diff changeset
   309
#endif
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	zio_next_stage(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
vdev_ops_t vdev_file_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
	vdev_file_open,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
	vdev_file_close,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   317
	vdev_file_probe,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	vdev_default_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	vdev_file_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
	vdev_file_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
	NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
	VDEV_TYPE_FILE,		/* name of this vdev type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
	B_TRUE			/* leaf vdev */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
 * From userland we access disks just like files.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
#ifndef _KERNEL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
vdev_ops_t vdev_disk_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
	vdev_file_open,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
	vdev_file_close,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 3059
diff changeset
   334
	vdev_file_probe,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	vdev_default_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
	vdev_file_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
	vdev_file_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	NULL,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	VDEV_TYPE_DISK,		/* name of this vdev type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
	B_TRUE			/* leaf vdev */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
#endif