diff --git a/include/zrepl_mgmt.h b/include/zrepl_mgmt.h index 1901a6abf714..2570ea3cd761 100644 --- a/include/zrepl_mgmt.h +++ b/include/zrepl_mgmt.h @@ -141,6 +141,7 @@ typedef struct zvol_io_cmd_s { zvol_io_hdr_t hdr; void *zv; void *buf; + uint64_t buf_len; metadata_desc_t *metadata_desc; int conn; } zvol_io_cmd_t; diff --git a/lib/libzrepl/data_conn.c b/lib/libzrepl/data_conn.c index 81da8774bb01..d47943d8b755 100644 --- a/lib/libzrepl/data_conn.c +++ b/lib/libzrepl/data_conn.c @@ -62,6 +62,7 @@ zio_cmd_alloc(zvol_io_hdr_t *hdr, int fd) (hdr->opcode == ZVOL_OPCODE_WRITE) || (hdr->opcode == ZVOL_OPCODE_OPEN)) { zio_cmd->buf = kmem_zalloc(sizeof (char) * hdr->len, KM_SLEEP); + zio_cmd->buf_len = hdr->len; } zio_cmd->conn = fd; @@ -81,7 +82,7 @@ zio_cmd_free(zvol_io_cmd_t **cmd) case ZVOL_OPCODE_WRITE: case ZVOL_OPCODE_OPEN: if (zio_cmd->buf != NULL) { - kmem_free(zio_cmd->buf, zio_cmd->hdr.len); + kmem_free(zio_cmd->buf, zio_cmd->buf_len); } break; @@ -260,11 +261,13 @@ uzfs_zvol_worker(void *arg) read_metadata = hdr->flags & ZVOL_OP_FLAG_READ_METADATA; /* - * Why to delay offline activity ? anyway - * we are not going to ACK these IOs + * For rebuild case, do not free zio_cmd */ if (zinfo->state == ZVOL_INFO_STATE_OFFLINE) { - zio_cmd_free(&zio_cmd); + hdr->status = ZVOL_OP_STATUS_FAILED; + hdr->len = 0; + if (!(rebuild_cmd_req && (hdr->opcode == ZVOL_OPCODE_WRITE))) + zio_cmd_free(&zio_cmd); goto drop_refcount; }