diff options
author | Sara Hartse <[email protected]> | 2018-05-31 10:36:37 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-05-31 10:36:37 -0700 |
commit | 74d42600d8d391dab5c57e87e81f97e0ca07b7b2 (patch) | |
tree | 8a32fc9cfbcc8a61e5fc0f6e00757dd2adb73b6d /module | |
parent | d1f06ec5bccae26639b7bb6bd3925f9998848f86 (diff) |
zpool reopen should detect expanded devices
Update bdev_capacity to have wholedisk vdevs query the
size of the underlying block device (correcting for the size
of the efi parition and partition alignment) and therefore detect
expanded space.
Correct vdev_get_stats_ex so that the expandsize is aligned
to metaslab size and new space is only reported if it is large
enough for a new metaslab.
Reviewed by: Don Brady <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed by: George Wilson <[email protected]>
Reviewed-by: Matthew Ahrens <[email protected]>
Reviewed by: John Wren Kennedy <[email protected]>
Signed-off-by: sara hartse <[email protected]>
External-issue: LX-165
Closes #7546
Issue #7582
Diffstat (limited to 'module')
-rw-r--r-- | module/zfs/vdev.c | 3 | ||||
-rw-r--r-- | module/zfs/vdev_disk.c | 46 |
2 files changed, 36 insertions, 13 deletions
diff --git a/module/zfs/vdev.c b/module/zfs/vdev.c index 388be3617..5b67e5f5f 100644 --- a/module/zfs/vdev.c +++ b/module/zfs/vdev.c @@ -21,7 +21,7 @@ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2011, 2015 by Delphix. All rights reserved. + * Copyright (c) 2011, 2018 by Delphix. All rights reserved. * Copyright 2017 Nexenta Systems, Inc. * Copyright (c) 2014 Integros [integros.com] * Copyright 2016 Toomas Soome <[email protected]> @@ -3493,7 +3493,6 @@ vdev_get_stats_ex(vdev_t *vd, vdev_stat_t *vs, vdev_stat_ex_t *vsx) vd->vdev_max_asize - vd->vdev_asize, 1ULL << tvd->vdev_ms_shift); } - vs->vs_esize = vd->vdev_max_asize - vd->vdev_asize; if (vd->vdev_aux == NULL && vd == vd->vdev_top && vdev_is_concrete(vd)) { vs->vs_fragmentation = vd->vdev_mg->mg_fragmentation; diff --git a/module/zfs/vdev_disk.c b/module/zfs/vdev_disk.c index 5cdfd960c..11744c1c1 100644 --- a/module/zfs/vdev_disk.c +++ b/module/zfs/vdev_disk.c @@ -23,7 +23,7 @@ * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Rewritten for Linux by Brian Behlendorf <[email protected]>. * LLNL-CODE-403049. - * Copyright (c) 2012, 2016 by Delphix. All rights reserved. + * Copyright (c) 2012, 2018 by Delphix. All rights reserved. */ #include <sys/zfs_context.h> @@ -34,10 +34,14 @@ #include <sys/fs/zfs.h> #include <sys/zio.h> #include <linux/mod_compat.h> +#include <linux/msdos_fs.h> char *zfs_vdev_scheduler = VDEV_SCHEDULER; static void *zfs_vdev_holder = VDEV_HOLDER; +/* size of the "reserved" partition, in blocks */ +#define EFI_MIN_RESV_SIZE (16 * 1024) + /* * Virtual device vector for disks. */ @@ -81,17 +85,39 @@ vdev_bdev_mode(int smode) } #endif /* HAVE_OPEN_BDEV_EXCLUSIVE */ +/* The capacity (in bytes) of a bdev that is available to be used by a vdev */ static uint64_t -bdev_capacity(struct block_device *bdev) +bdev_capacity(struct block_device *bdev, boolean_t wholedisk) { struct hd_struct *part = bdev->bd_part; + uint64_t sectors = get_capacity(bdev->bd_disk); + /* If there are no paritions, return the entire device capacity */ + if (part == NULL) + return (sectors << SECTOR_BITS); - /* The partition capacity referenced by the block device */ - if (part) - return (part->nr_sects << 9); - - /* Otherwise assume the full device capacity */ - return (get_capacity(bdev->bd_disk) << 9); + /* + * If there are partitions, decide if we are using a `wholedisk` + * layout (composed of part1 and part9) or just a single partition. + */ + if (wholedisk) { + /* Verify the expected device layout */ + ASSERT3P(bdev, !=, bdev->bd_contains); + /* + * Sectors used by the EFI partition (part9) as well as + * partion alignment. + */ + uint64_t used = EFI_MIN_RESV_SIZE + NEW_START_BLOCK + + PARTITION_END_ALIGNMENT; + + /* Space available to the vdev, i.e. the size of part1 */ + if (sectors <= used) + return (0); + uint64_t available = sectors - used; + return (available << SECTOR_BITS); + } else { + /* The partition capacity referenced by the block device */ + return (part->nr_sects << SECTOR_BITS); + } } static void @@ -330,9 +356,7 @@ skip_open: v->vdev_nonrot = blk_queue_nonrot(bdev_get_queue(vd->vd_bdev)); /* Physical volume size in bytes */ - *psize = bdev_capacity(vd->vd_bdev); - - /* TODO: report possible expansion size */ + *psize = bdev_capacity(vd->vd_bdev, v->vdev_wholedisk); *max_psize = *psize; /* Based on the minimum sector size set the block size */ |