Deleted Added
full compact
vdev_disk.c (219089) vdev_disk.c (236155)
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

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

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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

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

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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
23 */
24
25#include <sys/zfs_context.h>
26#include <sys/spa_impl.h>
27#include <sys/refcount.h>
28#include <sys/vdev_disk.h>
29#include <sys/vdev_impl.h>
30#include <sys/fs/zfs.h>
31#include <sys/zio.h>
32#include <sys/sunldi.h>
24 */
25
26#include <sys/zfs_context.h>
27#include <sys/spa_impl.h>
28#include <sys/refcount.h>
29#include <sys/vdev_disk.h>
30#include <sys/vdev_impl.h>
31#include <sys/fs/zfs.h>
32#include <sys/zio.h>
33#include <sys/sunldi.h>
34#include <sys/efi_partition.h>
33#include <sys/fm/fs/zfs.h>
34
35/*
36 * Virtual device vector for disks.
37 */
38
39extern ldi_ident_t zfs_li;
40

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

97 }
98 if (vd->vdev_devid_vp) {
99 VN_RELE_ASYNC(vd->vdev_devid_vp,
100 dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool));
101 vd->vdev_devid_vp = NULL;
102 }
103}
104
35#include <sys/fm/fs/zfs.h>
36
37/*
38 * Virtual device vector for disks.
39 */
40
41extern ldi_ident_t zfs_li;
42

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

99 }
100 if (vd->vdev_devid_vp) {
101 VN_RELE_ASYNC(vd->vdev_devid_vp,
102 dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool));
103 vd->vdev_devid_vp = NULL;
104 }
105}
106
107static uint64_t
108vdev_disk_get_space(vdev_t *vd, uint64_t capacity, uint_t blksz)
109{
110 ASSERT(vd->vdev_wholedisk);
111
112 vdev_disk_t *dvd = vd->vdev_tsd;
113 dk_efi_t dk_ioc;
114 efi_gpt_t *efi;
115 uint64_t avail_space = 0;
116 int efisize = EFI_LABEL_SIZE * 2;
117
118 dk_ioc.dki_data = kmem_alloc(efisize, KM_SLEEP);
119 dk_ioc.dki_lba = 1;
120 dk_ioc.dki_length = efisize;
121 dk_ioc.dki_data_64 = (uint64_t)(uintptr_t)dk_ioc.dki_data;
122 efi = dk_ioc.dki_data;
123
124 if (ldi_ioctl(dvd->vd_lh, DKIOCGETEFI, (intptr_t)&dk_ioc,
125 FKIOCTL, kcred, NULL) == 0) {
126 uint64_t efi_altern_lba = LE_64(efi->efi_gpt_AlternateLBA);
127
128 zfs_dbgmsg("vdev %s, capacity %llu, altern lba %llu",
129 vd->vdev_path, capacity, efi_altern_lba);
130 if (capacity > efi_altern_lba)
131 avail_space = (capacity - efi_altern_lba) * blksz;
132 }
133 kmem_free(dk_ioc.dki_data, efisize);
134 return (avail_space);
135}
136
105static int
137static int
106vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)
138vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
139 uint64_t *ashift)
107{
108 spa_t *spa = vd->vdev_spa;
109 vdev_disk_t *dvd;
110 struct dk_minfo_ext dkmext;
111 int error;
112 dev_t dev;
113 int otyp;
114

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

269 * Determine the actual size of the device.
270 */
271 if (ldi_get_size(dvd->vd_lh, psize) != 0) {
272 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
273 return (EINVAL);
274 }
275
276 /*
140{
141 spa_t *spa = vd->vdev_spa;
142 vdev_disk_t *dvd;
143 struct dk_minfo_ext dkmext;
144 int error;
145 dev_t dev;
146 int otyp;
147

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

302 * Determine the actual size of the device.
303 */
304 if (ldi_get_size(dvd->vd_lh, psize) != 0) {
305 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
306 return (EINVAL);
307 }
308
309 /*
277 * If we own the whole disk, try to enable disk write caching.
278 * We ignore errors because it's OK if we can't do it.
279 */
280 if (vd->vdev_wholedisk == 1) {
281 int wce = 1;
282 (void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,
283 FKIOCTL, kcred, NULL);
284 }
285
286 /*
287 * Determine the device's minimum transfer size.
288 * If the ioctl isn't supported, assume DEV_BSIZE.
289 */
290 if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFOEXT, (intptr_t)&dkmext,
291 FKIOCTL, kcred, NULL) != 0)
292 dkmext.dki_pbsize = DEV_BSIZE;
293
294 *ashift = highbit(MAX(dkmext.dki_pbsize, SPA_MINBLOCKSIZE)) - 1;
295
310 * Determine the device's minimum transfer size.
311 * If the ioctl isn't supported, assume DEV_BSIZE.
312 */
313 if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFOEXT, (intptr_t)&dkmext,
314 FKIOCTL, kcred, NULL) != 0)
315 dkmext.dki_pbsize = DEV_BSIZE;
316
317 *ashift = highbit(MAX(dkmext.dki_pbsize, SPA_MINBLOCKSIZE)) - 1;
318
319 if (vd->vdev_wholedisk == 1) {
320 uint64_t capacity = dkmext.dki_capacity - 1;
321 uint64_t blksz = dkmext.dki_lbsize;
322 int wce = 1;
323
324 /*
325 * If we own the whole disk, try to enable disk write caching.
326 * We ignore errors because it's OK if we can't do it.
327 */
328 (void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,
329 FKIOCTL, kcred, NULL);
330
331 *max_psize = *psize + vdev_disk_get_space(vd, capacity, blksz);
332 zfs_dbgmsg("capacity change: vdev %s, psize %llu, "
333 "max_psize %llu", vd->vdev_path, *psize, *max_psize);
334 } else {
335 *max_psize = *psize;
336 }
337
296 /*
297 * Clear the nowritecache bit, so that on a vdev_reopen() we will
298 * try again.
299 */
300 vd->vdev_nowritecache = B_FALSE;
301
302 return (0);
303}

--- 307 unchanged lines hidden ---
338 /*
339 * Clear the nowritecache bit, so that on a vdev_reopen() we will
340 * try again.
341 */
342 vd->vdev_nowritecache = B_FALSE;
343
344 return (0);
345}

--- 307 unchanged lines hidden ---