From 2e55034471413fb668d0d910b2c083610b386127 Mon Sep 17 00:00:00 2001 From: LOLi Date: Wed, 17 Oct 2018 20:21:07 +0200 Subject: zpool: allow sharing of spare device among pools ZFS allows, by default, sharing of spare devices among different pools; this commit simply restores this functionality for disk devices and adds an additional tests case to the ZFS Test Suite to prevent future regression. Reviewed-by: Tony Hutter Reviewed-by: Brian Behlendorf Signed-off-by: loli10K Closes #7999 --- cmd/zpool/zpool_vdev.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cmd/zpool/zpool_vdev.c') diff --git a/cmd/zpool/zpool_vdev.c b/cmd/zpool/zpool_vdev.c index 37f1ca1d9..2d9c1d028 100644 --- a/cmd/zpool/zpool_vdev.c +++ b/cmd/zpool/zpool_vdev.c @@ -419,11 +419,16 @@ check_disk(const char *path, blkid_cache cache, int force, char slice_path[MAXPATHLEN]; int err = 0; int fd, i; + int flags = O_RDONLY|O_DIRECT; if (!iswholedisk) return (check_slice(path, cache, force, isspare)); - if ((fd = open(path, O_RDONLY|O_DIRECT|O_EXCL)) < 0) { + /* only spares can be shared, other devices require exclusive access */ + if (!isspare) + flags |= O_EXCL; + + if ((fd = open(path, flags)) < 0) { char *value = blkid_get_tag_value(cache, "TYPE", path); (void) fprintf(stderr, gettext("%s is in use and contains " "a %s filesystem.\n"), path, value ? value : "unknown"); @@ -547,7 +552,7 @@ is_spare(nvlist_t *config, const char *path) uint_t i, nspares; boolean_t inuse; - if ((fd = open(path, O_RDONLY)) < 0) + if ((fd = open(path, O_RDONLY|O_DIRECT)) < 0) return (B_FALSE); if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) != 0 || -- cgit v1.2.3