Skip to content

Commit

Permalink
TA3149 (snap_rebuild) free the clone_zv once rebuilding is done. (ope…
Browse files Browse the repository at this point in the history
…nzfs#124)

Signed-off-by: Pawan <pawanprakash101@gmail.com>
  • Loading branch information
pawanpraka1 authored and vishnuitta committed Oct 1, 2018
1 parent f760c32 commit 166c582
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
12 changes: 2 additions & 10 deletions lib/libzpool/zrepl_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ uzfs_mark_offline_and_free_zinfo(zvol_info_t *zinfo)
" zero on zvol:%s", zinfo->name);
sleep(5);
}
(void) uzfs_zvol_release_internal_clone(
zinfo->main_zv, &zinfo->snap_zv, &zinfo->clone_zv);

LOG_INFO("Freeing zvol %s", zinfo->name);
(void) uzfs_zinfo_free(zinfo);
Expand Down Expand Up @@ -302,8 +304,6 @@ uzfs_zinfo_destroy(const char *name, spa_t *spa)
zvol_info_t *zinfo = NULL;
zvol_info_t *zt = NULL;
int namelen = ((name) ? strlen(name) : 0);
zvol_state_t *clone_zv = NULL;
zvol_state_t *snap_zv = NULL;
zvol_state_t *main_zv;
int destroyed = 0;

Expand All @@ -319,11 +319,7 @@ uzfs_zinfo_destroy(const char *name, spa_t *spa)

mutex_exit(&zvol_list_mutex);
main_zv = zinfo->main_zv;
clone_zv = zinfo->clone_zv;
snap_zv = zinfo->snap_zv;
uzfs_mark_offline_and_free_zinfo(zinfo);
(void) uzfs_zvol_release_internal_clone(
main_zv, &snap_zv, &clone_zv);
uzfs_close_dataset(main_zv);
destroyed++;
mutex_enter(&zvol_list_mutex);
Expand All @@ -340,11 +336,7 @@ uzfs_zinfo_destroy(const char *name, spa_t *spa)

mutex_exit(&zvol_list_mutex);
main_zv = zinfo->main_zv;
clone_zv = zinfo->clone_zv;
snap_zv = zinfo->snap_zv;
uzfs_mark_offline_and_free_zinfo(zinfo);
(void) uzfs_zvol_release_internal_clone(
main_zv, &snap_zv, &clone_zv);
uzfs_close_dataset(main_zv);
destroyed++;
goto end;
Expand Down
55 changes: 43 additions & 12 deletions lib/libzrepl/data_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ zio_cmd_alloc(zvol_io_hdr_t *hdr, int fd)
return (zio_cmd);
}

static inline void quiesce_wait(zvol_info_t *zinfo, uint8_t delete_clone)
{
while (1) {
if (zinfo->quiesce_done ||
!taskq_check_active_ios(
zinfo->uzfs_zvol_taskq)) {
zinfo->quiesce_done = 1;
zinfo->quiesce_requested = 0;
if (delete_clone)
uzfs_zvol_destroy_internal_clone(zinfo->main_zv,
&zinfo->snap_zv, &zinfo->clone_zv);

return;
}
else
sleep(1);
}
}

/*
* Free zio command along with buffer.
*/
Expand Down Expand Up @@ -355,7 +374,10 @@ uzfs_zvol_worker(void *arg)
break;

case ZVOL_OPCODE_SYNC:
uzfs_flush_data(zinfo->main_zv);
if (ZVOL_IS_HEALTHY(zinfo->main_zv) ||
ZVOL_IS_REBUILDING_AFS(zinfo->main_zv)) {
uzfs_flush_data(zinfo->main_zv);
}
if (!ZVOL_IS_HEALTHY(zinfo->main_zv))
uzfs_flush_data(zinfo->clone_zv);
atomic_inc_64(&zinfo->sync_req_received_cnt);
Expand Down Expand Up @@ -702,17 +724,7 @@ uzfs_zvol_rebuild_dw_replica(void *arg)
* Wait for all outstanding IOs to be flushed
* to disk before making further progress
*/
while (1) {
if (zinfo->quiesce_done ||
!taskq_check_active_ios(
zinfo->uzfs_zvol_taskq)) {
zinfo->quiesce_done = 1;
zinfo->quiesce_requested = 0;
break;
}
else
sleep(1);
}
quiesce_wait(zinfo, 0);

if (start_rebuild_from_clone == 1) {
start_rebuild_from_clone = 2;
Expand Down Expand Up @@ -763,6 +775,9 @@ uzfs_zvol_rebuild_dw_replica(void *arg)
LOG_ERR("uzfs_zvol_rebuild_dw_replica thread exiting, "
"rebuilding failed zvol: %s", zinfo->name);
}

uint8_t wquiesce = 0;

(zinfo->main_zv->rebuild_info.rebuild_done_cnt) += 1;
if (zinfo->main_zv->rebuild_info.rebuild_cnt ==
zinfo->main_zv->rebuild_info.rebuild_done_cnt) {
Expand All @@ -776,10 +791,24 @@ uzfs_zvol_rebuild_dw_replica(void *arg)
uzfs_zvol_set_status(zinfo->main_zv,
ZVOL_STATUS_HEALTHY);
uzfs_update_ionum_interval(zinfo, 0);
/*
* Lets ask io_receiver thread to flush
* all outstanding IOs in taskq
*/
zinfo->quiesce_done = 0;
zinfo->quiesce_requested = 1;
wquiesce = 1;
}
}
mutex_exit(&zinfo->main_zv->rebuild_mtx);

/*
* Wait for all outstanding IOs to be flushed
* to disk before making further progress
*/
if (wquiesce)
quiesce_wait(zinfo, 1);

kmem_free(arg, sizeof (rebuild_thread_arg_t));
if (zio_cmd != NULL)
zio_cmd_free(&zio_cmd);
Expand Down Expand Up @@ -1887,6 +1916,7 @@ uzfs_zvol_io_receiver(void *arg)
zio_cmd_free(&zio_cmd);
break;
}

/* Take refcount for uzfs_zvol_worker to work on it */
uzfs_zinfo_take_refcnt(zinfo);
zio_cmd->zinfo = zinfo;
Expand Down Expand Up @@ -1936,6 +1966,7 @@ uzfs_zvol_io_receiver(void *arg)
zinfo->is_io_receiver_created = B_FALSE;
(void) uzfs_zvol_release_internal_clone(zinfo->main_zv,
&zinfo->snap_zv, &zinfo->clone_zv);

zinfo->quiesce_requested = 0;
zinfo->quiesce_done = 1;
uzfs_zinfo_drop_refcnt(zinfo);
Expand Down

0 comments on commit 166c582

Please sign in to comment.