Skip to content

Commit

Permalink
fix for PR8162
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Kozhukhov <[email protected]>
  • Loading branch information
ikozhukhov committed Mar 20, 2019
1 parent ca6c7a9 commit 3bab909
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 11 additions & 3 deletions module/zfs/spa_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,16 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa,
fnvlist_free(nvl);
return;
}
if (nvl == NULL)
return;

size_t msglen = vsnprintf(NULL, 0, fmt, adx) + 1;
ASSERT(msglen != 0);

msg = kmem_vasprintf(fmt, adx);
msg = kmem_alloc(msglen, KM_SLEEP);
(void) vsprintf(msg, fmt, adx);
fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg);
strfree(msg);
kmem_free(msg, msglen);

fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation);
fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg);
Expand Down Expand Up @@ -564,8 +570,10 @@ spa_history_log_internal(spa_t *spa, const char *operation,
}
}

/* we will free nvl in log_internal() */
nvlist_t *nvl = fnvlist_alloc();
va_start(adx, fmt);
log_internal(fnvlist_alloc(), operation, spa, htx, fmt, adx);
log_internal(nvl, operation, spa, htx, fmt, adx);
va_end(adx);

/* if we didn't get a tx from the caller, commit the one we made */
Expand Down
17 changes: 12 additions & 5 deletions module/zfs/vdev_removal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2101,10 +2101,10 @@ spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare)
nvlist_t **spares, **l2cache, *nv;
uint64_t txg = 0;
uint_t nspares, nl2cache;
int error = 0;
int error = 0, error_log;
boolean_t locked = MUTEX_HELD(&spa_namespace_lock);
sysevent_t *ev = NULL;
char *vd_type = NULL, *vd_path = NULL;
char *vd_type = NULL, *vd_path = NULL, *vd_path_log = NULL;

ASSERT(spa_writeable(spa));

Expand Down Expand Up @@ -2164,7 +2164,7 @@ spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare)
spa->spa_l2cache.sav_sync = B_TRUE;
} else if (vd != NULL && vd->vdev_islog) {
ASSERT(!locked);
vd_type = "log";
vd_type = VDEV_TYPE_LOG;
vd_path = (vd->vdev_path != NULL) ? vd->vdev_path : "-";
error = spa_vdev_remove_log(vd, &txg);
} else if (vd != NULL) {
Expand All @@ -2177,6 +2177,11 @@ spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare)
error = SET_ERROR(ENOENT);
}

if (vd_path != NULL)
vd_path_log = spa_strdup(vd_path);

error_log = error;

if (!locked)
error = spa_vdev_exit(spa, NULL, txg, error);

Expand All @@ -2187,10 +2192,12 @@ spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare)
* Doing that would prevent the txg sync from actually happening,
* causing a deadlock.
*/
if (error == 0 && vd_type != NULL && vd_path != NULL) {
if (error_log == 0 && vd_type != NULL && vd_path_log != NULL) {
spa_history_log_internal(spa, "vdev remove", NULL,
"%s vdev (%s) %s", spa_name(spa), vd_type, vd_path);
"%s vdev (%s) %s", spa_name(spa), vd_type, vd_path_log);
}
if (vd_path_log != NULL)
spa_strfree(vd_path_log);

if (ev != NULL)
spa_event_post(ev);
Expand Down

0 comments on commit 3bab909

Please sign in to comment.