Allow sleepable allocations in enclosure daemon threads.
There were at least two places where M_NOWAIT was used without NULL check. This change should fix NULL-dereference panic there and possibly improve operation in other ways under memory pressure. MFC after: 2 weeks
This commit is contained in:
parent
a7b81566bc
commit
ed246e8260
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=299373
@ -291,11 +291,8 @@ safte_process_config(enc_softc_t *enc, struct enc_fsm_state *state,
|
|||||||
cfg->DoorLock + cfg->Ntherm + cfg->Nspkrs + cfg->Ntstats + 1;
|
cfg->DoorLock + cfg->Ntherm + cfg->Nspkrs + cfg->Ntstats + 1;
|
||||||
ENC_FREE_AND_NULL(enc->enc_cache.elm_map);
|
ENC_FREE_AND_NULL(enc->enc_cache.elm_map);
|
||||||
enc->enc_cache.elm_map =
|
enc->enc_cache.elm_map =
|
||||||
ENC_MALLOCZ(enc->enc_cache.nelms * sizeof(enc_element_t));
|
malloc(enc->enc_cache.nelms * sizeof(enc_element_t),
|
||||||
if (enc->enc_cache.elm_map == NULL) {
|
M_SCSIENC, M_WAITOK|M_ZERO);
|
||||||
enc->enc_cache.nelms = 0;
|
|
||||||
return (ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
/*
|
/*
|
||||||
|
@ -715,13 +715,15 @@ ses_cache_clone(enc_softc_t *enc, enc_cache_t *src, enc_cache_t *dst)
|
|||||||
* The element map is independent even though it starts out
|
* The element map is independent even though it starts out
|
||||||
* pointing to the same constant page data.
|
* pointing to the same constant page data.
|
||||||
*/
|
*/
|
||||||
dst->elm_map = ENC_MALLOCZ(dst->nelms * sizeof(enc_element_t));
|
dst->elm_map = malloc(dst->nelms * sizeof(enc_element_t),
|
||||||
|
M_SCSIENC, M_WAITOK);
|
||||||
memcpy(dst->elm_map, src->elm_map, dst->nelms * sizeof(enc_element_t));
|
memcpy(dst->elm_map, src->elm_map, dst->nelms * sizeof(enc_element_t));
|
||||||
for (dst_elm = dst->elm_map, src_elm = src->elm_map,
|
for (dst_elm = dst->elm_map, src_elm = src->elm_map,
|
||||||
last_elm = &src->elm_map[src->nelms];
|
last_elm = &src->elm_map[src->nelms];
|
||||||
src_elm != last_elm; src_elm++, dst_elm++) {
|
src_elm != last_elm; src_elm++, dst_elm++) {
|
||||||
|
|
||||||
dst_elm->elm_private = ENC_MALLOCZ(sizeof(ses_element_t));
|
dst_elm->elm_private = malloc(sizeof(ses_element_t),
|
||||||
|
M_SCSIENC, M_WAITOK);
|
||||||
memcpy(dst_elm->elm_private, src_elm->elm_private,
|
memcpy(dst_elm->elm_private, src_elm->elm_private,
|
||||||
sizeof(ses_element_t));
|
sizeof(ses_element_t));
|
||||||
}
|
}
|
||||||
@ -1066,11 +1068,7 @@ ses_set_physpath(enc_softc_t *enc, enc_element_t *elm,
|
|||||||
cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
|
cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
|
||||||
cdai.buftype = CDAI_TYPE_SCSI_DEVID;
|
cdai.buftype = CDAI_TYPE_SCSI_DEVID;
|
||||||
cdai.bufsiz = CAM_SCSI_DEVID_MAXLEN;
|
cdai.bufsiz = CAM_SCSI_DEVID_MAXLEN;
|
||||||
cdai.buf = devid = ENC_MALLOCZ(cdai.bufsiz);
|
cdai.buf = devid = malloc(cdai.bufsiz, M_SCSIENC, M_WAITOK|M_ZERO);
|
||||||
if (devid == NULL) {
|
|
||||||
ret = ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
cam_periph_lock(enc->periph);
|
cam_periph_lock(enc->periph);
|
||||||
xpt_action((union ccb *)&cdai);
|
xpt_action((union ccb *)&cdai);
|
||||||
if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
|
if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
|
||||||
@ -1370,12 +1368,8 @@ ses_process_config(enc_softc_t *enc, struct enc_fsm_state *state,
|
|||||||
* Now waltz through all the subenclosures summing the number of
|
* Now waltz through all the subenclosures summing the number of
|
||||||
* types available in each.
|
* types available in each.
|
||||||
*/
|
*/
|
||||||
subencs = ENC_MALLOCZ(ses_cfg_page_get_num_subenc(cfg_page)
|
subencs = malloc(ses_cfg_page_get_num_subenc(cfg_page)
|
||||||
* sizeof(*subencs));
|
* sizeof(*subencs), M_SCSIENC, M_WAITOK|M_ZERO);
|
||||||
if (subencs == NULL) {
|
|
||||||
err = ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Sub-enclosure data is const after construction (i.e. when
|
* Sub-enclosure data is const after construction (i.e. when
|
||||||
* accessed via our cache object.
|
* accessed via our cache object.
|
||||||
@ -1413,11 +1407,8 @@ ses_process_config(enc_softc_t *enc, struct enc_fsm_state *state,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Process the type headers. */
|
/* Process the type headers. */
|
||||||
ses_types = ENC_MALLOCZ(ntype * sizeof(*ses_types));
|
ses_types = malloc(ntype * sizeof(*ses_types),
|
||||||
if (ses_types == NULL) {
|
M_SCSIENC, M_WAITOK|M_ZERO);
|
||||||
err = ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Type data is const after construction (i.e. when accessed via
|
* Type data is const after construction (i.e. when accessed via
|
||||||
* our cache object.
|
* our cache object.
|
||||||
@ -1454,11 +1445,8 @@ ses_process_config(enc_softc_t *enc, struct enc_fsm_state *state,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create the object map. */
|
/* Create the object map. */
|
||||||
enc_cache->elm_map = ENC_MALLOCZ(nelm * sizeof(enc_element_t));
|
enc_cache->elm_map = malloc(nelm * sizeof(enc_element_t),
|
||||||
if (enc_cache->elm_map == NULL) {
|
M_SCSIENC, M_WAITOK|M_ZERO);
|
||||||
err = ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
enc_cache->nelms = nelm;
|
enc_cache->nelms = nelm;
|
||||||
|
|
||||||
ses_iter_init(enc, enc_cache, &iter);
|
ses_iter_init(enc, enc_cache, &iter);
|
||||||
@ -1472,11 +1460,8 @@ ses_process_config(enc_softc_t *enc, struct enc_fsm_state *state,
|
|||||||
element->subenclosure = thdr->etype_subenc;
|
element->subenclosure = thdr->etype_subenc;
|
||||||
element->enctype = thdr->etype_elm_type;
|
element->enctype = thdr->etype_elm_type;
|
||||||
element->overall_status_elem = iter.type_element_index == 0;
|
element->overall_status_elem = iter.type_element_index == 0;
|
||||||
element->elm_private = ENC_MALLOCZ(sizeof(ses_element_t));
|
element->elm_private = malloc(sizeof(ses_element_t),
|
||||||
if (element->elm_private == NULL) {
|
M_SCSIENC, M_WAITOK|M_ZERO);
|
||||||
err = ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ENC_DLOG(enc, "%s: creating elmpriv %d(%d,%d) subenc %d "
|
ENC_DLOG(enc, "%s: creating elmpriv %d(%d,%d) subenc %d "
|
||||||
"type 0x%x\n", __func__, iter.global_element_index,
|
"type 0x%x\n", __func__, iter.global_element_index,
|
||||||
iter.type_index, iter.type_element_index,
|
iter.type_index, iter.type_element_index,
|
||||||
|
Loading…
Reference in New Issue
Block a user