#!/usr/local/bin/perl
use Modern::Perl;
use File::Spec;
my $img1 = File::Spec->rel2abs('img1');
my $img2 = File::Spec->rel2abs('img2');
my $img3 = File::Spec->rel2abs('img3');
my $img4 = File::Spec->rel2abs('img4');
my $pool = "pool_try1";
my @check = (
"zpool status $pool",
"zpool get all $pool | ack '\\bsize|expand'",
);
my @cmd = (
"truncate -s 1G $img1",
"truncate -s 1G $img2",
"truncate -s 2G $img3",
"truncate -s 2G $img4",
"zpool create $pool mirror $img1 $img2",
@check,
"zpool detach $pool $img2",
@check,
"zpool attach $pool $img1 $img3",
@check,
"zpool detach $pool $img1",
qq#perl -E 'sleep 1 while `zpool status $pool` =~ /Wait/'#,
"zpool detach $pool $img1",
"zpool attach $pool $img3 $img4",
@check,
"zpool online -e $pool $img3",
@check,
"zpool destroy $pool",
);
for (0..$#cmd) {
my $cmd = $cmd[$_];
say "" unless $_ == 0;
say "% $cmd";
system($cmd);
}
__END__
% truncate -s 1G /usr/home/bokutin/code/try/zpool_expand/img1
% truncate -s 1G /usr/home/bokutin/code/try/zpool_expand/img2
% truncate -s 2G /usr/home/bokutin/code/try/zpool_expand/img3
% truncate -s 2G /usr/home/bokutin/code/try/zpool_expand/img4
% zpool create pool_try1 mirror /usr/home/bokutin/code/try/zpool_expand/img1 /usr/home/bokutin/code/try/zpool_expand/img2
% zpool status pool_try1
pool: pool_try1
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
pool_try1 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img1 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img2 ONLINE 0 0 0
errors: No known data errors
% zpool get all pool_try1 | ack '\bsize|expand'
pool_try1 size 960M -
pool_try1 autoexpand off default
pool_try1 expandsize - -
% zpool detach pool_try1 /usr/home/bokutin/code/try/zpool_expand/img2
% zpool status pool_try1
pool: pool_try1
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
pool_try1 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img1 ONLINE 0 0 0
errors: No known data errors
% zpool get all pool_try1 | ack '\bsize|expand'
pool_try1 size 960M -
pool_try1 autoexpand off default
pool_try1 expandsize - -
% zpool attach pool_try1 /usr/home/bokutin/code/try/zpool_expand/img1 /usr/home/bokutin/code/try/zpool_expand/img3
% zpool status pool_try1
pool: pool_try1
state: ONLINE
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Tue Dec 17 09:27:47 2019
87.5K scanned at 87.5K/s, 87.5K issued at 87.5K/s, 96.5K total
1.50K resilvered, 90.67% done, no estimated completion time
config:
NAME STATE READ WRITE CKSUM
pool_try1 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img1 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img3 ONLINE 0 0 0
errors: No known data errors
% zpool get all pool_try1 | ack '\bsize|expand'
pool_try1 size 960M -
pool_try1 autoexpand off default
pool_try1 expandsize - -
% zpool detach pool_try1 /usr/home/bokutin/code/try/zpool_expand/img1
cannot detach /usr/home/bokutin/code/try/zpool_expand/img1: no valid replicas
% perl -E 'sleep 1 while `zpool status pool_try1` =~ /Wait/'
% zpool detach pool_try1 /usr/home/bokutin/code/try/zpool_expand/img1
% zpool attach pool_try1 /usr/home/bokutin/code/try/zpool_expand/img3 /usr/home/bokutin/code/try/zpool_expand/img4
% zpool status pool_try1
pool: pool_try1
state: ONLINE
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Tue Dec 17 09:27:49 2019
93.5K scanned at 93.5K/s, 93.5K issued at 93.5K/s, 116K total
2K resilvered, 80.60% done, no estimated completion time
config:
NAME STATE READ WRITE CKSUM
pool_try1 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img3 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img4 ONLINE 0 0 0
errors: No known data errors
% zpool get all pool_try1 | ack '\bsize|expand'
pool_try1 size 960M -
pool_try1 autoexpand off default
pool_try1 expandsize - -
% zpool online -e pool_try1 /usr/home/bokutin/code/try/zpool_expand/img3
% zpool status pool_try1
pool: pool_try1
state: ONLINE
scan: resilvered 93.5K in 0 days 00:00:00 with 0 errors on Tue Dec 17 09:27:49 2019
config:
NAME STATE READ WRITE CKSUM
pool_try1 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img3 ONLINE 0 0 0
/usr/home/bokutin/code/try/zpool_expand/img4 ONLINE 0 0 0
errors: No known data errors
% zpool get all pool_try1 | ack '\bsize|expand'
pool_try1 size 1.94G -
pool_try1 autoexpand off default
pool_try1 expandsize - -
% zpool destroy pool_try1