From 461dddba27c5624bdf8b4ce08866e476a00a4fc2 Mon Sep 17 00:00:00 2001 From: "Kenneth D. Merry" Date: Wed, 26 Mar 2003 04:38:39 +0000 Subject: [PATCH] Clean up dynamically allocated sysctl variables when we run dacleanup() and cdcleanup(). This fixes sysctl problems ("can't re-use a leaf") when someone adds another peripheral at the same unit number. (e.g. rescan da0, it goes away, then rescan again and da0 comes back, but since we haven't cleaned up the sysctl variables from the last da0 instance, we can't register the variables for the new instance under the same name.) Reported by: njl Tested by: njl --- sys/cam/scsi/scsi_cd.c | 6 ++++++ sys/cam/scsi/scsi_da.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index bda6b7b8a666..66b18f0d8ac1 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -455,6 +455,11 @@ cdcleanup(struct cam_periph *periph) xpt_print_path(periph->path); printf("removing device entry\n"); + if (sysctl_ctx_free(&softc->sysctl_ctx) != 0) { + xpt_print_path(periph->path); + printf("can't remove sysctl context\n"); + } + s = splsoftcam(); /* * In the queued, non-active case, the device in question @@ -688,6 +693,7 @@ cdregister(struct cam_periph *periph, void *arg) snprintf(tmpstr, sizeof(tmpstr), "CAM CD unit %d", periph->unit_number); snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number); + sysctl_ctx_init(&softc->sysctl_ctx); softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx, SYSCTL_STATIC_CHILDREN(_kern_cam_cd), OID_AUTO, tmpstr2, CTLFLAG_RD, 0, tmpstr); diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 4007d29ca828..bdb827654e78 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -987,6 +987,13 @@ dacleanup(struct cam_periph *periph) xpt_print_path(periph->path); printf("removing device entry\n"); + /* + * If we can't free the sysctl tree, oh well... + */ + if (sysctl_ctx_free(&softc->sysctl_ctx) != 0) { + xpt_print_path(periph->path); + printf("can't remove sysctl context\n"); + } disk_destroy(&softc->disk); free(softc, M_DEVBUF); } @@ -1142,6 +1149,7 @@ daregister(struct cam_periph *periph, void *arg) snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number); snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number); + sysctl_ctx_init(&softc->sysctl_ctx); softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx, SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2, CTLFLAG_RD, 0, tmpstr);