Changeset View
Changeset View
Standalone View
Standalone View
sys/cam/cam_xpt.c
Show First 20 Lines • Show All 4,687 Lines • ▼ Show 20 Lines | xpt_alloc_ccb_nowait(void) | ||||
new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT); | new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT); | ||||
return (new_ccb); | return (new_ccb); | ||||
} | } | ||||
void | void | ||||
xpt_free_ccb(union ccb *free_ccb) | xpt_free_ccb(union ccb *free_ccb) | ||||
{ | { | ||||
struct cam_periph *periph; | |||||
if (free_ccb->ccb_h.alloc_flags & CAM_CCB_FROM_UMA) { | |||||
imp: Don't we have a flag we can more directly tag the allocation so the free is unambiguous rather… | |||||
Done Inline ActionsWe do have the ccb_h.flags, but it gets overwritten by xpt_setup_ccb(). Also, explicitly setting the len helps in debugging. But yeah, would be nice to have a better mechanism for this. trasz: We do have the ccb_h.flags, but it gets overwritten by xpt_setup_ccb(). Also, explicitly… | |||||
/* | |||||
Not Done Inline ActionsAgain, I'd prefer we have a flag that tells us it was allocated from UMA rather than malloc. This breaks if we're not using small allocations per the sysctl you added in this review iteration. imp: Again, I'd prefer we have a flag that tells us it was allocated from UMA rather than malloc. | |||||
Done Inline ActionsI've noticed some drivers overwrite the flags: dev/ahci/ahci.c: ccb->ccb_h.flags = CAM_DIR_IN How about a separate flag just for the backing storage, like in the updated version? trasz: I've noticed some drivers overwrite the flags:
dev/ahci/ahci.c: ccb->ccb_h. | |||||
* Looks like a CCB allocated from a periph UMA zone. | |||||
*/ | |||||
periph = free_ccb->ccb_h.path->periph; | |||||
uma_zfree(periph->ccb_zone, free_ccb); | |||||
} else { | |||||
free(free_ccb, M_CAMCCB); | free(free_ccb, M_CAMCCB); | ||||
} | } | ||||
} | |||||
/* Private XPT functions */ | /* Private XPT functions */ | ||||
/* | /* | ||||
* Get a CAM control block for the caller. Charge the structure to the device | * Get a CAM control block for the caller. Charge the structure to the device | ||||
* referenced by the path. If we don't have sufficient resources to allocate | * referenced by the path. If we don't have sufficient resources to allocate | ||||
* more ccbs, we return NULL. | * more ccbs, we return NULL. | ||||
*/ | */ | ||||
static union ccb * | static union ccb * | ||||
xpt_get_ccb_nowait(struct cam_periph *periph) | xpt_get_ccb_nowait(struct cam_periph *periph) | ||||
{ | { | ||||
union ccb *new_ccb; | union ccb *new_ccb; | ||||
int alloc_flags; | |||||
if (periph->ccb_zone != NULL) { | |||||
alloc_flags = CAM_CCB_FROM_UMA; | |||||
new_ccb = uma_zalloc(periph->ccb_zone, M_ZERO|M_NOWAIT); | |||||
} else { | |||||
alloc_flags = 0; | |||||
new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT); | new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT); | ||||
} | |||||
if (new_ccb == NULL) | if (new_ccb == NULL) | ||||
return (NULL); | return (NULL); | ||||
new_ccb->ccb_h.alloc_flags = alloc_flags; | |||||
periph->periph_allocated++; | periph->periph_allocated++; | ||||
cam_ccbq_take_opening(&periph->path->device->ccbq); | cam_ccbq_take_opening(&periph->path->device->ccbq); | ||||
return (new_ccb); | return (new_ccb); | ||||
} | } | ||||
static union ccb * | static union ccb * | ||||
xpt_get_ccb(struct cam_periph *periph) | xpt_get_ccb(struct cam_periph *periph) | ||||
{ | { | ||||
union ccb *new_ccb; | union ccb *new_ccb; | ||||
int alloc_flags; | |||||
cam_periph_unlock(periph); | cam_periph_unlock(periph); | ||||
if (periph->ccb_zone != NULL) { | |||||
alloc_flags = CAM_CCB_FROM_UMA; | |||||
new_ccb = uma_zalloc(periph->ccb_zone, M_ZERO|M_WAITOK); | |||||
} else { | |||||
alloc_flags = 0; | |||||
new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK); | new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK); | ||||
} | |||||
new_ccb->ccb_h.alloc_flags = alloc_flags; | |||||
cam_periph_lock(periph); | cam_periph_lock(periph); | ||||
periph->periph_allocated++; | periph->periph_allocated++; | ||||
cam_ccbq_take_opening(&periph->path->device->ccbq); | cam_ccbq_take_opening(&periph->path->device->ccbq); | ||||
return (new_ccb); | return (new_ccb); | ||||
} | } | ||||
union ccb * | union ccb * | ||||
cam_periph_getccb(struct cam_periph *periph, u_int32_t priority) | cam_periph_getccb(struct cam_periph *periph, u_int32_t priority) | ||||
▲ Show 20 Lines • Show All 910 Lines • Show Last 20 Lines |
Don't we have a flag we can more directly tag the allocation so the free is unambiguous rather than guessing?