Deleted Added
full compact
vdev_disk.c (185029) vdev_disk.c (209962)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/zfs_context.h>
27#include <sys/spa.h>
28#include <sys/refcount.h>
29#include <sys/vdev_disk.h>
30#include <sys/vdev_impl.h>

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

42typedef struct vdev_disk_buf {
43 buf_t vdb_buf;
44 zio_t *vdb_io;
45} vdev_disk_buf_t;
46
47static int
48vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
49{
23 * Use is subject to license terms.
24 */
25
26#include <sys/zfs_context.h>
27#include <sys/spa.h>
28#include <sys/refcount.h>
29#include <sys/vdev_disk.h>
30#include <sys/vdev_impl.h>

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

42typedef struct vdev_disk_buf {
43 buf_t vdb_buf;
44 zio_t *vdb_io;
45} vdev_disk_buf_t;
46
47static int
48vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
49{
50 spa_t *spa = vd->vdev_spa;
50 vdev_disk_t *dvd;
51 struct dk_minfo dkm;
52 int error;
53 dev_t dev;
54 int otyp;
55
56 /*
57 * We must have a pathname, and it must be absolute.

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

90 &dvd->vd_minor) != 0) {
91 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
92 return (EINVAL);
93 }
94 }
95
96 error = EINVAL; /* presume failure */
97
51 vdev_disk_t *dvd;
52 struct dk_minfo dkm;
53 int error;
54 dev_t dev;
55 int otyp;
56
57 /*
58 * We must have a pathname, and it must be absolute.

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

91 &dvd->vd_minor) != 0) {
92 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
93 return (EINVAL);
94 }
95 }
96
97 error = EINVAL; /* presume failure */
98
98 if (vd->vdev_path != NULL && !spa_is_root(vd->vdev_spa)) {
99 if (vd->vdev_path != NULL && !spa_is_root(spa)) {
99 ddi_devid_t devid;
100
101 if (vd->vdev_wholedisk == -1ULL) {
102 size_t len = strlen(vd->vdev_path) + 3;
103 char *buf = kmem_alloc(len, KM_SLEEP);
104 ldi_handle_t lh;
105
106 (void) snprintf(buf, len, "%ss0", vd->vdev_path);
107
100 ddi_devid_t devid;
101
102 if (vd->vdev_wholedisk == -1ULL) {
103 size_t len = strlen(vd->vdev_path) + 3;
104 char *buf = kmem_alloc(len, KM_SLEEP);
105 ldi_handle_t lh;
106
107 (void) snprintf(buf, len, "%ss0", vd->vdev_path);
108
108 if (ldi_open_by_name(buf, spa_mode, kcred,
109 if (ldi_open_by_name(buf, spa_mode(spa), kcred,
109 &lh, zfs_li) == 0) {
110 spa_strfree(vd->vdev_path);
111 vd->vdev_path = buf;
112 vd->vdev_wholedisk = 1ULL;
110 &lh, zfs_li) == 0) {
111 spa_strfree(vd->vdev_path);
112 vd->vdev_path = buf;
113 vd->vdev_wholedisk = 1ULL;
113 (void) ldi_close(lh, spa_mode, kcred);
114 (void) ldi_close(lh, spa_mode(spa), kcred);
114 } else {
115 kmem_free(buf, len);
116 }
117 }
118
115 } else {
116 kmem_free(buf, len);
117 }
118 }
119
119 error = ldi_open_by_name(vd->vdev_path, spa_mode, kcred,
120 error = ldi_open_by_name(vd->vdev_path, spa_mode(spa), kcred,
120 &dvd->vd_lh, zfs_li);
121
122 /*
123 * Compare the devid to the stored value.
124 */
125 if (error == 0 && vd->vdev_devid != NULL &&
126 ldi_get_devid(dvd->vd_lh, &devid) == 0) {
127 if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
128 error = EINVAL;
121 &dvd->vd_lh, zfs_li);
122
123 /*
124 * Compare the devid to the stored value.
125 */
126 if (error == 0 && vd->vdev_devid != NULL &&
127 ldi_get_devid(dvd->vd_lh, &devid) == 0) {
128 if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
129 error = EINVAL;
129 (void) ldi_close(dvd->vd_lh, spa_mode, kcred);
130 (void) ldi_close(dvd->vd_lh, spa_mode(spa),
131 kcred);
130 dvd->vd_lh = NULL;
131 }
132 ddi_devid_free(devid);
133 }
134
135 /*
136 * If we succeeded in opening the device, but 'vdev_wholedisk'
137 * is not yet set, then this must be a slice.
138 */
139 if (error == 0 && vd->vdev_wholedisk == -1ULL)
140 vd->vdev_wholedisk = 0;
141 }
142
143 /*
144 * If we were unable to open by path, or the devid check fails, open by
145 * devid instead.
146 */
147 if (error != 0 && vd->vdev_devid != NULL)
148 error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,
132 dvd->vd_lh = NULL;
133 }
134 ddi_devid_free(devid);
135 }
136
137 /*
138 * If we succeeded in opening the device, but 'vdev_wholedisk'
139 * is not yet set, then this must be a slice.
140 */
141 if (error == 0 && vd->vdev_wholedisk == -1ULL)
142 vd->vdev_wholedisk = 0;
143 }
144
145 /*
146 * If we were unable to open by path, or the devid check fails, open by
147 * devid instead.
148 */
149 if (error != 0 && vd->vdev_devid != NULL)
150 error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,
149 spa_mode, kcred, &dvd->vd_lh, zfs_li);
151 spa_mode(spa), kcred, &dvd->vd_lh, zfs_li);
150
151 /*
152 * If all else fails, then try opening by physical path (if available)
153 * or the logical path (if we failed due to the devid check). While not
154 * as reliable as the devid, this will give us something, and the higher
155 * level vdev validation will prevent us from opening the wrong device.
156 */
157 if (error) {
158 if (vd->vdev_physpath != NULL &&
152
153 /*
154 * If all else fails, then try opening by physical path (if available)
155 * or the logical path (if we failed due to the devid check). While not
156 * as reliable as the devid, this will give us something, and the higher
157 * level vdev validation will prevent us from opening the wrong device.
158 */
159 if (error) {
160 if (vd->vdev_physpath != NULL &&
159 (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != ENODEV)
160 error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode,
161 (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != NODEV)
162 error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa),
161 kcred, &dvd->vd_lh, zfs_li);
162
163 /*
164 * Note that we don't support the legacy auto-wholedisk support
165 * as above. This hasn't been used in a very long time and we
166 * don't need to propagate its oddities to this edge condition.
167 */
163 kcred, &dvd->vd_lh, zfs_li);
164
165 /*
166 * Note that we don't support the legacy auto-wholedisk support
167 * as above. This hasn't been used in a very long time and we
168 * don't need to propagate its oddities to this edge condition.
169 */
168 if (error && vd->vdev_path != NULL &&
169 !spa_is_root(vd->vdev_spa))
170 error = ldi_open_by_name(vd->vdev_path, spa_mode, kcred,
171 &dvd->vd_lh, zfs_li);
170 if (error && vd->vdev_path != NULL && !spa_is_root(spa))
171 error = ldi_open_by_name(vd->vdev_path, spa_mode(spa),
172 kcred, &dvd->vd_lh, zfs_li);
172 }
173
174 if (error) {
175 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
176 return (error);
177 }
178
179 /*

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

248
249 if (dvd->vd_minor != NULL)
250 ddi_devid_str_free(dvd->vd_minor);
251
252 if (dvd->vd_devid != NULL)
253 ddi_devid_free(dvd->vd_devid);
254
255 if (dvd->vd_lh != NULL)
173 }
174
175 if (error) {
176 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
177 return (error);
178 }
179
180 /*

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

249
250 if (dvd->vd_minor != NULL)
251 ddi_devid_str_free(dvd->vd_minor);
252
253 if (dvd->vd_devid != NULL)
254 ddi_devid_free(dvd->vd_devid);
255
256 if (dvd->vd_lh != NULL)
256 (void) ldi_close(dvd->vd_lh, spa_mode, kcred);
257 (void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred);
257
258 kmem_free(dvd, sizeof (vdev_disk_t));
259 vd->vdev_tsd = NULL;
260}
261
262int
263vdev_disk_physio(ldi_handle_t vd_lh, caddr_t data, size_t size,
264 uint64_t offset, int flags)

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

464 char *minor_name;
465
466 /*
467 * Read the device label and build the nvlist.
468 */
469 if (devid != NULL && ddi_devid_str_decode(devid, &tmpdevid,
470 &minor_name) == 0) {
471 error = ldi_open_by_devid(tmpdevid, minor_name,
258
259 kmem_free(dvd, sizeof (vdev_disk_t));
260 vd->vdev_tsd = NULL;
261}
262
263int
264vdev_disk_physio(ldi_handle_t vd_lh, caddr_t data, size_t size,
265 uint64_t offset, int flags)

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

465 char *minor_name;
466
467 /*
468 * Read the device label and build the nvlist.
469 */
470 if (devid != NULL && ddi_devid_str_decode(devid, &tmpdevid,
471 &minor_name) == 0) {
472 error = ldi_open_by_devid(tmpdevid, minor_name,
472 spa_mode, kcred, &vd_lh, zfs_li);
473 FREAD, kcred, &vd_lh, zfs_li);
473 ddi_devid_free(tmpdevid);
474 ddi_devid_str_free(minor_name);
475 }
476
477 if (error && (error = ldi_open_by_name(devpath, FREAD, kcred, &vd_lh,
478 zfs_li)))
479 return (error);
480

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

487 label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP);
488
489 for (l = 0; l < VDEV_LABELS; l++) {
490 uint64_t offset, state, txg = 0;
491
492 /* read vdev label */
493 offset = vdev_label_offset(size, l, 0);
494 if (vdev_disk_physio(vd_lh, (caddr_t)label,
474 ddi_devid_free(tmpdevid);
475 ddi_devid_str_free(minor_name);
476 }
477
478 if (error && (error = ldi_open_by_name(devpath, FREAD, kcred, &vd_lh,
479 zfs_li)))
480 return (error);
481

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

488 label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP);
489
490 for (l = 0; l < VDEV_LABELS; l++) {
491 uint64_t offset, state, txg = 0;
492
493 /* read vdev label */
494 offset = vdev_label_offset(size, l, 0);
495 if (vdev_disk_physio(vd_lh, (caddr_t)label,
495 VDEV_SKIP_SIZE + VDEV_BOOT_HEADER_SIZE +
496 VDEV_PHYS_SIZE, offset, B_READ) != 0)
496 VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, B_READ) != 0)
497 continue;
498
499 if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
500 sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0) {
501 *config = NULL;
502 continue;
503 }
504

--- 22 unchanged lines hidden ---
497 continue;
498
499 if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
500 sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0) {
501 *config = NULL;
502 continue;
503 }
504

--- 22 unchanged lines hidden ---