Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F167837384
D58526.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D58526.diff
View Options
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -99,6 +99,10 @@
uint32_t *action,
const char **action_string);
static void cam_periph_devctl_notify(union ccb *ccb);
+static char *cam_periph_devctl_sb_init(struct sbuf *sb,
+ struct cam_periph *periph);
+static void cam_periph_devctl_sb_fini(struct sbuf *sb, char *sbmsg,
+ const char *type);
static int nperiph_drivers;
static int initialized = 0;
@@ -2124,32 +2128,65 @@
#define CAM_PERIPH_DEVD_MSG_SIZE 1024
-static void
-cam_periph_devctl_notify(union ccb *ccb)
+/*
+ * Allocate and initialize an sbuf for a devctl notification, populating it
+ * with the device name and serial number. Returns the malloc'd backing
+ * buffer, or NULL on allocation failure. On success, the caller can append
+ * additional fields to sb before calling cam_periph_devctl_sb_fini().
+ */
+static char *
+cam_periph_devctl_sb_init(struct sbuf *sb, struct cam_periph *periph)
{
- struct cam_periph *periph;
struct ccb_getdev *cgd;
- struct sbuf sb;
- char *sbmsg, *type;
+ char *sbmsg;
sbmsg = malloc(CAM_PERIPH_DEVD_MSG_SIZE, M_CAMPERIPH, M_NOWAIT);
if (sbmsg == NULL)
- return;
+ return (NULL);
- sbuf_new(&sb, sbmsg, CAM_PERIPH_DEVD_MSG_SIZE, SBUF_FIXEDLEN);
+ sbuf_new(sb, sbmsg, CAM_PERIPH_DEVD_MSG_SIZE, SBUF_FIXEDLEN);
- periph = xpt_path_periph(ccb->ccb_h.path);
- sbuf_printf(&sb, "device=%s%d ", periph->periph_name,
+ sbuf_printf(sb, "device=%s%d ", periph->periph_name,
periph->unit_number);
- sbuf_cat(&sb, "serial=\"");
+ sbuf_cat(sb, "serial=\"");
if ((cgd = (struct ccb_getdev *)xpt_alloc_ccb_nowait()) != NULL) {
- xpt_gdev_type(cgd, ccb->ccb_h.path);
+ xpt_gdev_type(cgd, periph->path);
if (cgd->ccb_h.status == CAM_REQ_CMP)
- sbuf_bcat(&sb, cgd->serial_num, cgd->serial_num_len);
+ sbuf_bcat(sb, cgd->serial_num, cgd->serial_num_len);
xpt_free_ccb((union ccb *)cgd);
}
- sbuf_cat(&sb, "\" ");
+ sbuf_cat(sb, "\" ");
+
+ return (sbmsg);
+}
+
+/*
+ * Finish and send a devctl notification, then clean up the sbuf and its
+ * backing buffer.
+ */
+static void
+cam_periph_devctl_sb_fini(struct sbuf *sb, char *sbmsg, const char *type)
+{
+
+ if (sbuf_finish(sb) == 0)
+ devctl_notify("CAM", "periph", type, sbuf_data(sb));
+ sbuf_delete(sb);
+ free(sbmsg, M_CAMPERIPH);
+}
+
+static void
+cam_periph_devctl_notify(union ccb *ccb)
+{
+ struct cam_periph *periph;
+ struct sbuf sb;
+ char *sbmsg, *type;
+
+ periph = xpt_path_periph(ccb->ccb_h.path);
+ sbmsg = cam_periph_devctl_sb_init(&sb, periph);
+ if (sbmsg == NULL)
+ return;
+
sbuf_printf(&sb, "cam_status=\"0x%x\" ", ccb->ccb_h.status);
switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
@@ -2213,10 +2250,7 @@
break;
}
- if (sbuf_finish(&sb) == 0)
- devctl_notify("CAM", "periph", type, sbuf_data(&sb));
- sbuf_delete(&sb);
- free(sbmsg, M_CAMPERIPH);
+ cam_periph_devctl_sb_fini(&sb, sbmsg, type);
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 25, 9:48 PM (3 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35717744
Default Alt Text
D58526.diff (2 KB)
Attached To
Mode
D58526: cam: Refactor cam_periph_devctl_notify init/fini bits
Attached
Detach File
Event Timeline
Log In to Comment