summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/uts/common/io/log.c27
-rw-r--r--usr/src/uts/common/os/logsubr.c92
-rw-r--r--usr/src/uts/common/sys/log.h7
3 files changed, 88 insertions, 38 deletions
diff --git a/usr/src/uts/common/io/log.c b/usr/src/uts/common/io/log.c
index 8725c97ffb..15e66f0e91 100644
--- a/usr/src/uts/common/io/log.c
+++ b/usr/src/uts/common/io/log.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -87,13 +87,18 @@ log_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
}
/*
- * log_open can be called for one of two devices, /dev/conslog or
- * /dev/log. In the case of /dev/conslog it returns the global
- * console device (i.e., multiple opens return the same device), while
- * for /dev/log a new device is created for each open (up to a limit
- * of 16 per zone). Most of the allocation details are handled in
- * log_alloc.
+ * log_open can be called for either /dev/log or dev/conslog.
+ *
+ * In the /dev/conslog case log_alloc() allocates a new minor device from
+ * its cache.
+ *
+ * In the case of /dev/log, LOG_NUMCLONES devices are pre-allocated at zone
+ * creation. log_alloc() finds the zone's next available minor device.
+ *
+ * On entry devp's minor number indicates which device (log or conslog), on
+ * successful return it is the device instance.
*/
+
/* ARGSUSED */
static int
log_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *cr)
@@ -105,7 +110,7 @@ log_open(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *cr)
return (ENXIO);
switch (minor = getminor(*devp)) {
- case LOG_CONSMIN: /* normal open of /dev/conslog */
+ case LOG_CONSMIN: /* clone open of /dev/conslog */
if (flag & FREAD)
return (EINVAL); /* write-only device */
if (q->q_ptr)
@@ -143,6 +148,8 @@ log_close(queue_t *q, int flag, cred_t *cr)
log_update(lp, NULL, 0, NULL);
freemsg(lp->log_data);
lp->log_data = NULL;
+ if (lp->log_major == LOG_CONSMIN)
+ log_free(lp);
q->q_ptr = NULL;
WR(q)->q_ptr = NULL;
@@ -181,8 +188,8 @@ log_wput(queue_t *q, mblk_t *mp)
case M_IOCTL:
iocp = (struct iocblk *)mp->b_rptr;
- if (lp->log_minor <= LOG_LOGMIN) {
- /* not a cloned dev_t */
+ if (lp->log_major != LOG_LOGMIN) {
+ /* write-only device */
miocnak(q, mp, 0, EINVAL);
return (0);
}
diff --git a/usr/src/uts/common/os/logsubr.c b/usr/src/uts/common/os/logsubr.c
index 00df4a09bb..a8593929a8 100644
--- a/usr/src/uts/common/os/logsubr.c
+++ b/usr/src/uts/common/os/logsubr.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -59,7 +59,7 @@ static int log_seq_no[SL_CONSOLE + 1];
static stdata_t log_fakestr;
static id_space_t *log_minorspace;
static log_t log_backlog;
-static log_t log_conslog;
+static struct kmem_cache *log_cons_cache; /* log_t cache */
static queue_t *log_recentq;
static queue_t *log_freeq;
@@ -82,6 +82,8 @@ static char log_fac[LOG_NFACILITIES + 1][LOG_FACSIZE] = {
"local4", "local5", "local6", "local7",
"unknown"
};
+static int log_cons_constructor(void *, void *, int);
+static void log_cons_destructor(void *, void *);
/*
* Get exclusive access to the logging system; this includes all minor
@@ -234,11 +236,10 @@ log_init(void)
log_backlog.log_zoneid = GLOBAL_ZONEID;
log_backlog.log_minor = LOG_BACKLOG;
- /*
- * Initialize conslog structure.
- */
- log_conslog.log_zoneid = GLOBAL_ZONEID;
- log_conslog.log_minor = LOG_CONSMIN;
+ /* Allocate kmem cache for conslog's log structures */
+ log_cons_cache = kmem_cache_create("log_cons_cache",
+ sizeof (struct log), 0, log_cons_constructor, log_cons_destructor,
+ NULL, NULL, NULL, 0);
/*
* Let the logging begin.
@@ -258,10 +259,9 @@ log_init(void)
}
/*
- * Allocate a log device corresponding to supplied device type. All
- * processes within a given zone that open /dev/conslog share the same
- * device; processes opening /dev/log get distinct devices (if
- * available).
+ * Allocate a log device corresponding to supplied device type.
+ * Both devices are clonable. /dev/log devices are allocated per zone.
+ * /dev/conslog devices are allocated from kmem cache.
*/
log_t *
log_alloc(minor_t type)
@@ -270,26 +270,44 @@ log_alloc(minor_t type)
log_zone_t *lzp;
log_t *lp;
int i;
+ minor_t minor;
if (type == LOG_CONSMIN) {
- /* return the dedicated /dev/conslog device */
- return (&log_conslog);
- }
- ASSERT(type == LOG_LOGMIN);
+ /*
+ * Return a write-only /dev/conslog device.
+ * No point allocating log_t until there's a free minor number.
+ */
+ minor = (minor_t)id_alloc(log_minorspace);
+ lp = kmem_cache_alloc(log_cons_cache, KM_SLEEP);
+ lp->log_minor = minor;
+ return (lp);
+ } else {
+ ASSERT(type == LOG_LOGMIN);
- lzp = zone_getspecific(log_zone_key, zptr);
- ASSERT(lzp != NULL);
+ lzp = zone_getspecific(log_zone_key, zptr);
+ ASSERT(lzp != NULL);
- /* search for an available /dev/log device for the zone */
- for (i = LOG_LOGMINIDX; i <= LOG_LOGMAXIDX; i++) {
- lp = &lzp->lz_clones[i];
- if (lp->log_inuse == 0)
- break;
+ /* search for an available /dev/log device for the zone */
+ for (i = LOG_LOGMINIDX; i <= LOG_LOGMAXIDX; i++) {
+ lp = &lzp->lz_clones[i];
+ if (lp->log_inuse == 0)
+ break;
+ }
+ if (i > LOG_LOGMAXIDX)
+ lp = NULL;
+ else
+ /* Indicate which device type */
+ lp->log_major = LOG_LOGMIN;
+ return (lp);
}
- if (i > LOG_LOGMAXIDX)
- lp = NULL;
- return (lp);
+}
+
+void
+log_free(log_t *lp)
+{
+ id_free(log_minorspace, lp->log_minor);
+ kmem_cache_free(log_cons_cache, lp);
}
/*
@@ -395,7 +413,6 @@ log_update(log_t *target, queue_t *q, short flags, log_filter_t *filter)
lzp = zone_getspecific(log_zone_key, zptr);
}
ASSERT(lzp != NULL);
-
for (i = LOG_LOGMAXIDX; i >= LOG_LOGMINIDX; i--) {
lp = &lzp->lz_clones[i];
if (zoneid == GLOBAL_ZONEID && (lp->log_flags & SL_CONSOLE))
@@ -712,3 +729,26 @@ log_printq(queue_t *qfirst)
}
} while ((qlast = q) != qfirst);
}
+
+/* ARGSUSED */
+static int
+log_cons_constructor(void *buf, void *cdrarg, int kmflags)
+{
+ struct log *lp = buf;
+
+ lp->log_zoneid = GLOBAL_ZONEID;
+ lp->log_major = LOG_CONSMIN; /* Indicate which device type */
+ lp->log_data = NULL;
+ return (0);
+}
+
+/* ARGSUSED */
+static void
+log_cons_destructor(void *buf, void *cdrarg)
+{
+ struct log *lp = buf;
+
+ ASSERT(lp->log_zoneid == GLOBAL_ZONEID);
+ ASSERT(lp->log_major == LOG_CONSMIN);
+ ASSERT(lp->log_data == NULL);
+}
diff --git a/usr/src/uts/common/sys/log.h b/usr/src/uts/common/sys/log.h
index 1ae7b71a2a..2d1fb46b73 100644
--- a/usr/src/uts/common/sys/log.h
+++ b/usr/src/uts/common/sys/log.h
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -41,7 +41,7 @@ extern "C" {
#endif
#define LOG_CONSMIN 0 /* /dev/conslog minor */
-#define LOG_LOGMIN 5 /* /dev/log clone-open minor */
+#define LOG_LOGMIN 5 /* /dev/log minor */
#define LOG_BACKLOG LOG_LOGMIN /* console backlog queue */
#define LOG_LOGMINIDX 0 /* index of smallest /dev/log clone */
@@ -70,9 +70,11 @@ struct log {
short log_inuse; /* is this log device open? */
int log_overflow; /* messages lost due to QFULL */
zoneid_t log_zoneid; /* zone id of log */
+ major_t log_major; /* device type */
minor_t log_minor; /* minor number of associated device */
};
+/* Array of /dev/log minor devices */
typedef struct log_zone {
log_t lz_clones[LOG_NUMCLONES];
uint16_t lz_active; /* active types (OR of all log_flags fields) */
@@ -112,6 +114,7 @@ extern void log_sendmsg(mblk_t *, zoneid_t);
extern void log_flushq(queue_t *);
extern void log_printq(queue_t *);
extern log_t *log_alloc(minor_t);
+extern void log_free(log_t *);
#endif /* _KERNEL */