MFC r208370, r208371, r208372, r208442, r208443:

MFC r208370:
Fix: vdev_reopen() can lead to failed allocations
OpenSolaris onnv-revision: 7980:589f37f25048, Bug ID: 6764914

MFC r208371:
Fix stack overflow in zfs send.
OpenSolaris onnv-revision: 8012:8ea30813950f, Bug ID: 6765626

MFC r208372:
Reorder some already introduced locking variables.
OpenSolaris onnv revision: 8214:d7abf7c1f1c1, Bug ID: 6747934

MFC r208442:
Fix mutex_exit misorder that can cause a kernel panic.
OpenSolaris onnv revision: 8667:5c308a17eb7c, Bug ID: 6795440

MFC r208443:
Fix kernel panic when calling spa_tryimport() on a corrupted pool.
OpenSolaris onnv revision: 8680:005fe27123ba, Bug ID: 6786321

Approved by:	pav, delphij (mentor)
Obtained from:	OpenSolaris (multiple Bug IDs)
This commit is contained in:
mm 2010-05-24 06:07:55 +00:00
parent 7edcc7de7a
commit f372c76833
9 changed files with 43 additions and 25 deletions

View File

@ -134,6 +134,7 @@ static int
traverse_visitbp(struct traverse_data *td, const dnode_phys_t *dnp,
arc_buf_t *pbuf, blkptr_t *bp, const zbookmark_t *zb)
{
zbookmark_t czb;
int err = 0;
arc_buf_t *buf = NULL;
struct prefetch_data *pd = td->td_pfd;
@ -179,8 +180,6 @@ traverse_visitbp(struct traverse_data *td, const dnode_phys_t *dnp,
/* recursively visitbp() blocks below this */
cbp = buf->b_data;
for (i = 0; i < epb; i++, cbp++) {
zbookmark_t czb;
SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
zb->zb_level - 1,
zb->zb_blkid * epb + i);
@ -203,8 +202,6 @@ traverse_visitbp(struct traverse_data *td, const dnode_phys_t *dnp,
dnp = buf->b_data;
for (i = 0; i < epb && err == 0; i++, dnp++) {
for (j = 0; j < dnp->dn_nblkptr; j++) {
zbookmark_t czb;
SET_BOOKMARK(&czb, zb->zb_objset,
zb->zb_blkid * epb + i,
dnp->dn_nlevels - 1, j);
@ -229,8 +226,6 @@ traverse_visitbp(struct traverse_data *td, const dnode_phys_t *dnp,
traverse_zil(td, &osp->os_zil_header);
for (j = 0; j < osp->os_meta_dnode.dn_nblkptr; j++) {
zbookmark_t czb;
SET_BOOKMARK(&czb, zb->zb_objset, 0,
osp->os_meta_dnode.dn_nlevels - 1, j);
err = traverse_visitbp(td, &osp->os_meta_dnode, buf,

View File

@ -53,10 +53,11 @@ dnode_cons(void *arg, void *unused, int kmflag)
dnode_t *dn = arg;
bzero(dn, sizeof (dnode_t));
cv_init(&dn->dn_notxholds, NULL, CV_DEFAULT, NULL);
rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL);
mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL);
cv_init(&dn->dn_notxholds, NULL, CV_DEFAULT, NULL);
refcount_create(&dn->dn_holds);
refcount_create(&dn->dn_tx_holds);
@ -82,10 +83,10 @@ dnode_dest(void *arg, void *unused)
int i;
dnode_t *dn = arg;
cv_destroy(&dn->dn_notxholds);
rw_destroy(&dn->dn_struct_rwlock);
mutex_destroy(&dn->dn_mtx);
mutex_destroy(&dn->dn_dbufs_mtx);
cv_destroy(&dn->dn_notxholds);
refcount_destroy(&dn->dn_holds);
refcount_destroy(&dn->dn_tx_holds);

View File

@ -781,7 +781,7 @@ top:
/*
* Don't allocate from faulted devices.
*/
if (!vdev_writeable(vd))
if (!vdev_allocatable(vd))
goto next;
/*
* Avoid writing single-copy data to a failing vdev

View File

@ -2082,10 +2082,10 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props,
if (version >= SPA_VERSION_ZPOOL_HISTORY && history_str != NULL)
(void) spa_history_log(spa, history_str, LOG_CMD_POOL_CREATE);
mutex_exit(&spa_namespace_lock);
spa->spa_minref = refcount_count(&spa->spa_refcount);
mutex_exit(&spa_namespace_lock);
return (0);
}
@ -2478,6 +2478,7 @@ spa_tryimport(nvlist_t *tryconfig)
char *poolname;
spa_t *spa;
uint64_t state;
int error;
if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_POOL_NAME, &poolname))
return (NULL);
@ -2497,7 +2498,7 @@ spa_tryimport(nvlist_t *tryconfig)
* Pass TRUE for mosconfig because the user-supplied config
* is actually the one to trust when doing an import.
*/
(void) spa_load(spa, tryconfig, SPA_LOAD_TRYIMPORT, B_TRUE);
error = spa_load(spa, tryconfig, SPA_LOAD_TRYIMPORT, B_TRUE);
/*
* If 'tryconfig' was at least parsable, return the current config.
@ -2516,7 +2517,7 @@ spa_tryimport(nvlist_t *tryconfig)
* copy it out so that external consumers can tell which
* pools are bootable.
*/
if (spa->spa_bootfs) {
if ((!error || error == EEXIST) && spa->spa_bootfs) {
char *tmpname = kmem_alloc(MAXPATHLEN, KM_SLEEP);
/*

View File

@ -23,8 +23,6 @@
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/zfs_context.h>
#include <sys/spa.h>
#include <sys/dmu.h>
@ -61,6 +59,7 @@ space_map_create(space_map_t *sm, uint64_t start, uint64_t size, uint8_t shift,
bzero(sm, sizeof (*sm));
cv_init(&sm->sm_load_cv, NULL, CV_DEFAULT, NULL);
avl_create(&sm->sm_root, space_map_seg_compare,
sizeof (space_seg_t), offsetof(struct space_seg, ss_node));

View File

@ -85,6 +85,7 @@ extern void vdev_clear(spa_t *spa, vdev_t *vd);
extern boolean_t vdev_is_dead(vdev_t *vd);
extern boolean_t vdev_readable(vdev_t *vd);
extern boolean_t vdev_writeable(vdev_t *vd);
extern boolean_t vdev_allocatable(vdev_t *vd);
extern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
extern void vdev_cache_init(vdev_t *vd);

View File

@ -79,6 +79,7 @@ txg_init(dsl_pool_t *dp, uint64_t txg)
rw_init(&tx->tx_suspend, NULL, RW_DEFAULT, NULL);
mutex_init(&tx->tx_sync_lock, NULL, MUTEX_DEFAULT, NULL);
cv_init(&tx->tx_sync_more_cv, NULL, CV_DEFAULT, NULL);
cv_init(&tx->tx_sync_done_cv, NULL, CV_DEFAULT, NULL);
cv_init(&tx->tx_quiesce_more_cv, NULL, CV_DEFAULT, NULL);
@ -99,14 +100,15 @@ txg_fini(dsl_pool_t *dp)
ASSERT(tx->tx_threads == 0);
cv_destroy(&tx->tx_exit_cv);
cv_destroy(&tx->tx_quiesce_done_cv);
cv_destroy(&tx->tx_quiesce_more_cv);
cv_destroy(&tx->tx_sync_done_cv);
cv_destroy(&tx->tx_sync_more_cv);
rw_destroy(&tx->tx_suspend);
mutex_destroy(&tx->tx_sync_lock);
cv_destroy(&tx->tx_sync_more_cv);
cv_destroy(&tx->tx_sync_done_cv);
cv_destroy(&tx->tx_quiesce_more_cv);
cv_destroy(&tx->tx_quiesce_done_cv);
cv_destroy(&tx->tx_exit_cv);
for (c = 0; c < max_ncpus; c++) {
int i;

View File

@ -1860,6 +1860,19 @@ vdev_writeable(vdev_t *vd)
return (!vdev_is_dead(vd) && !vd->vdev_cant_write);
}
boolean_t
vdev_allocatable(vdev_t *vd)
{
/*
* We currently allow allocations from vdevs which maybe in the
* process of reopening (i.e. VDEV_STATE_CLOSED). If the device
* fails to reopen then we'll catch it later when we're holding
* the proper locks.
*/
return (!(vdev_is_dead(vd) && vd->vdev_state != VDEV_STATE_CLOSED) &&
!vd->vdev_cant_write);
}
boolean_t
vdev_accessible(vdev_t *vd, zio_t *zio)
{

View File

@ -2367,9 +2367,10 @@ zfs_ioc_rollback(zfs_cmd_t *zc)
}
if (zfsvfs != NULL) {
char osname[MAXNAMELEN];
char *osname;
int mode;
osname = kmem_alloc(MAXNAMELEN, KM_SLEEP);
error = zfs_suspend_fs(zfsvfs, osname, &mode);
if (error == 0) {
int resume_err;
@ -2381,6 +2382,7 @@ zfs_ioc_rollback(zfs_cmd_t *zc)
} else {
dmu_objset_close(os);
}
kmem_free(osname, MAXNAMELEN);
VFS_RELE(zfsvfs->z_vfs);
} else {
error = dmu_objset_rollback(os);
@ -2552,10 +2554,11 @@ zfs_ioc_recv(zfs_cmd_t *zc)
error = dmu_recv_stream(&drc, fp, &off);
if (error == 0 && zfsvfs) {
char osname[MAXNAMELEN];
char *osname;
int mode;
/* online recv */
osname = kmem_alloc(MAXNAMELEN, KM_SLEEP);
error = zfs_suspend_fs(zfsvfs, osname, &mode);
if (error == 0) {
int resume_err;
@ -2566,6 +2569,7 @@ zfs_ioc_recv(zfs_cmd_t *zc)
} else {
dmu_recv_abort_cleanup(&drc);
}
kmem_free(osname, MAXNAMELEN);
} else if (error == 0) {
error = dmu_recv_end(&drc);
}
@ -2616,16 +2620,18 @@ zfs_ioc_send(zfs_cmd_t *zc)
return (error);
if (zc->zc_value[0] != '\0') {
char buf[MAXPATHLEN];
char *buf;
char *cp;
(void) strncpy(buf, zc->zc_name, sizeof (buf));
buf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
(void) strncpy(buf, zc->zc_name, MAXPATHLEN);
cp = strchr(buf, '@');
if (cp)
*(cp+1) = 0;
(void) strlcat(buf, zc->zc_value, sizeof (buf));
(void) strlcat(buf, zc->zc_value, MAXPATHLEN);
error = dmu_objset_open(buf, DMU_OST_ANY,
DS_MODE_USER | DS_MODE_READONLY, &fromsnap);
kmem_free(buf, MAXPATHLEN);
if (error) {
dmu_objset_close(tosnap);
return (error);