Avoid zero-sized kmem_alloc() in vdev_compact_children().
The device evacuation code adds a dependency that
vdev_compact_children() be able to properly empty the vdev_child
array by setting it to NULL and zeroing vdev_children. Under Linux,
kmem_alloc() and related functions return a sentinel pointer rather
than NULL for zero-sized allocations.
This is a part of ZoL port of device removal patch:
commit a1d477c24c
Author: Matthew Ahrens <mahrens@delphix.com>
Ported-by: Tim Chase <tim@chase2k.com>
Approved by: re (kib)
MFC after: 1 week
This commit is contained in:
parent
0f31e1e6a8
commit
178777f516
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=339335
@ -505,17 +505,24 @@ vdev_compact_children(vdev_t *pvd)
|
||||
|
||||
ASSERT(spa_config_held(pvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
|
||||
|
||||
if (oldc == 0)
|
||||
return;
|
||||
|
||||
for (int c = newc = 0; c < oldc; c++)
|
||||
if (pvd->vdev_child[c])
|
||||
newc++;
|
||||
|
||||
newchild = kmem_alloc(newc * sizeof (vdev_t *), KM_SLEEP);
|
||||
if (newc > 0) {
|
||||
newchild = kmem_alloc(newc * sizeof (vdev_t *), KM_SLEEP);
|
||||
|
||||
for (int c = newc = 0; c < oldc; c++) {
|
||||
if ((cvd = pvd->vdev_child[c]) != NULL) {
|
||||
newchild[newc] = cvd;
|
||||
cvd->vdev_id = newc++;
|
||||
for (int c = newc = 0; c < oldc; c++) {
|
||||
if ((cvd = pvd->vdev_child[c]) != NULL) {
|
||||
newchild[newc] = cvd;
|
||||
cvd->vdev_id = newc++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newchild = NULL;
|
||||
}
|
||||
|
||||
kmem_free(pvd->vdev_child, oldc * sizeof (vdev_t *));
|
||||
|
Loading…
Reference in New Issue
Block a user