Index: sys/cam/cam_xpt.c =================================================================== --- sys/cam/cam_xpt.c +++ sys/cam/cam_xpt.c @@ -241,6 +241,7 @@ static void xpt_run_devq(struct cam_devq *devq); static timeout_t xpt_release_devq_timeout; static void xpt_release_simq_timeout(void *arg) __unused; +static int _xpt_path_string(struct cam_path *path, struct sbuf *sb); static void xpt_acquire_bus(struct cam_eb *bus); static void xpt_release_bus(struct cam_eb *bus); static uint32_t xpt_freeze_devq_device(struct cam_ed *dev, u_int count); @@ -3697,33 +3698,14 @@ void xpt_print_path(struct cam_path *path) { + struct sbuf sb; + char buffer[64]; - if (path == NULL) - printf("(nopath): "); - else { - if (path->periph != NULL) - printf("(%s%d:", path->periph->periph_name, - path->periph->unit_number); - else - printf("(noperiph:"); - - if (path->bus != NULL) - printf("%s%d:%d:", path->bus->sim->sim_name, - path->bus->sim->unit_number, - path->bus->sim->bus_id); - else - printf("nobus:"); - - if (path->target != NULL) - printf("%d:", path->target->target_id); - else - printf("X:"); - - if (path->device != NULL) - printf("%jx): ", (uintmax_t)path->device->lun_id); - else - printf("X): "); - } + sbuf_new(&sb, buffer, 64, SBUF_FIXEDLEN); + _xpt_path_string(path, &sb); + sbuf_finish(&sb); + printf("%s", sbuf_data(&sb)); + sbuf_delete(&sb); } void @@ -3745,49 +3727,66 @@ xpt_print(struct cam_path *path, const char *fmt, ...) { va_list ap; - xpt_print_path(path); + struct sbuf sb; + char buffer[128]; + + sbuf_new(&sb, buffer, 128, SBUF_FIXEDLEN); + + _xpt_path_string(path, &sb); va_start(ap, fmt); - vprintf(fmt, ap); + sbuf_vprintf(&sb, fmt, ap); va_end(ap); + + sbuf_finish(&sb); + printf("%s", sbuf_data(&sb)); + sbuf_delete(&sb); } int xpt_path_string(struct cam_path *path, char *str, size_t str_len) { struct sbuf sb; + int len; sbuf_new(&sb, str, str_len, 0); + len = _xpt_path_string(path, &sb); + sbuf_finish(&sb); + return (len); +} + +static int +_xpt_path_string(struct cam_path *path, struct sbuf *sb) +{ if (path == NULL) - sbuf_printf(&sb, "(nopath): "); + sbuf_printf(sb, "(nopath): "); else { if (path->periph != NULL) - sbuf_printf(&sb, "(%s%d:", path->periph->periph_name, + sbuf_printf(sb, "(%s%d:", path->periph->periph_name, path->periph->unit_number); else - sbuf_printf(&sb, "(noperiph:"); + sbuf_printf(sb, "(noperiph:"); if (path->bus != NULL) - sbuf_printf(&sb, "%s%d:%d:", path->bus->sim->sim_name, + sbuf_printf(sb, "%s%d:%d:", path->bus->sim->sim_name, path->bus->sim->unit_number, path->bus->sim->bus_id); else - sbuf_printf(&sb, "nobus:"); + sbuf_printf(sb, "nobus:"); if (path->target != NULL) - sbuf_printf(&sb, "%d:", path->target->target_id); + sbuf_printf(sb, "%d:", path->target->target_id); else - sbuf_printf(&sb, "X:"); + sbuf_printf(sb, "X:"); if (path->device != NULL) - sbuf_printf(&sb, "%jx): ", + sbuf_printf(sb, "%jx): ", (uintmax_t)path->device->lun_id); else - sbuf_printf(&sb, "X): "); + sbuf_printf(sb, "X): "); } - sbuf_finish(&sb); - return(sbuf_len(&sb)); + return(sbuf_len(sb)); } path_id_t