backout 6266921: causes 6346181, zone crosstalk
authordduvall
Sun, 06 Nov 2005 10:46:57 -0800
changeset 850 504be1e0fe28
parent 849 8d799fd81a9b
child 851 bbbf4a61e3b8
backout 6266921: causes 6346181, zone crosstalk
usr/src/uts/common/io/log.c
usr/src/uts/common/os/logsubr.c
usr/src/uts/common/sys/log.h
--- a/usr/src/uts/common/io/log.c	Fri Nov 04 22:44:23 2005 -0800
+++ b/usr/src/uts/common/io/log.c	Sun Nov 06 10:46:57 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -87,10 +87,11 @@
 }
 
 /*
- * log_open can be called for either /dev/log or dev/conslog.
- * In both cases a new minor device is created. Up to 16 /dev/log devices
- * may be created per zone. Up to LOG_NUMCONS global /dev/conslog
- * devices may be created. Most of the allocation details are handled in
+ * 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.
  */
 /* ARGSUSED */
@@ -104,7 +105,7 @@
 		return (ENXIO);
 
 	switch (minor = getminor(*devp)) {
-	case LOG_CONSMIN:		/* clone open of /dev/conslog */
+	case LOG_CONSMIN:		/* normal open of /dev/conslog */
 		if (flag & FREAD)
 			return (EINVAL);	/* write-only device */
 		if (q->q_ptr)
@@ -142,8 +143,6 @@
 	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;
 
@@ -182,8 +181,8 @@
 	case M_IOCTL:
 		iocp = (struct iocblk *)mp->b_rptr;
 
-		if (lp->log_major != LOG_LOGMIN) {
-			/* write-only device */
+		if (lp->log_minor <= LOG_LOGMIN) {
+			/* not a cloned dev_t */
 			miocnak(q, mp, 0, EINVAL);
 			return (0);
 		}
--- a/usr/src/uts/common/os/logsubr.c	Fri Nov 04 22:44:23 2005 -0800
+++ b/usr/src/uts/common/os/logsubr.c	Sun Nov 06 10:46:57 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -59,8 +59,7 @@
 static stdata_t log_fakestr;
 static id_space_t *log_minorspace;
 static log_t log_backlog;
-static struct kmem_cache *log_cons_cache;	/* log_t cache */
-static vmem_t *log_cons_minor_arena; 		/* Arena for device minors */
+static log_t log_conslog;
 
 static queue_t *log_recentq;
 static queue_t *log_freeq;
@@ -83,8 +82,6 @@
 	"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
@@ -237,15 +234,11 @@
 	log_backlog.log_zoneid = GLOBAL_ZONEID;
 	log_backlog.log_minor = LOG_BACKLOG;
 
-	/* Allocate integer space for conslog's minor numbers */
-	log_cons_minor_arena = vmem_create("log_cons_minor", (void *)1,
-	    LOG_NUMCONS, 1, NULL, NULL, NULL, 0,
-	    VM_SLEEP | VMC_IDENTIFIER);
-
-	/* 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);
+	/*
+	 * Initialize conslog structure.
+	 */
+	log_conslog.log_zoneid = GLOBAL_ZONEID;
+	log_conslog.log_minor = LOG_CONSMIN;
 
 	/*
 	 * Let the logging begin.
@@ -265,10 +258,10 @@
 }
 
 /*
- * 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, with minor numbers
- * supplied from a vmem arena.
+ * 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).
  */
 log_t *
 log_alloc(minor_t type)
@@ -277,45 +270,26 @@
 	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);
+	}
 
-		/*
-		 * Return a write-only /dev/conslog device.
-		 * No point allocating log_t until there's a free minor number.
-		 */
-		minor = (minor_t)(uintptr_t)
-		    vmem_alloc(log_cons_minor_arena, 1, VM_SLEEP);
-		lp = kmem_cache_alloc(log_cons_cache, KM_SLEEP);
-		lp->log_minor = minor;
-		return (lp);
-	} else {
-		ASSERT(type == LOG_LOGMIN);
+	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;
-		}
-		if (i > LOG_LOGMAXIDX)
-			lp = NULL;
-		lp->log_major = LOG_LOGMIN;
-		return (lp);
+	/* 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;
 	}
-}
-
-void
-log_free(log_t *lp)
-{
-	/* Return minor number to the pool */
-	vmem_free(log_cons_minor_arena, (void *)(uintptr_t)lp->log_minor, 1);
-	/* Return log to the cache */
-	kmem_cache_free(log_cons_cache, lp);
+	if (i > LOG_LOGMAXIDX)
+		lp = NULL;
+	return (lp);
 }
 
 /*
@@ -421,6 +395,7 @@
 		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))
@@ -737,24 +712,3 @@
 		}
 	} 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;
-	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);
-}
--- a/usr/src/uts/common/sys/log.h	Fri Nov 04 22:44:23 2005 -0800
+++ b/usr/src/uts/common/sys/log.h	Sun Nov 06 10:46:57 2005 -0800
@@ -20,7 +20,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -41,13 +41,12 @@
 #endif
 
 #define	LOG_CONSMIN	0		/* /dev/conslog minor */
-#define	LOG_LOGMIN	5		/* /dev/log minor */
+#define	LOG_LOGMIN	5		/* /dev/log clone-open minor */
 #define	LOG_BACKLOG	LOG_LOGMIN	/* console backlog queue */
 
 #define	LOG_LOGMINIDX	0		/* index of smallest /dev/log clone */
 #define	LOG_LOGMAXIDX	15		/* up to 16 /dev/log clones */
 #define	LOG_NUMCLONES	(LOG_LOGMAXIDX - LOG_LOGMINIDX + 1)
-#define	LOG_NUMCONS	1024		/* up to 1024 /dev/conslog clones */
 
 #define	LOG_MID		44		/* module ID */
 #define	LOG_MINPS	0		/* min packet size */
@@ -71,11 +70,9 @@
 	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;	/* major number of associated device */
 	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) */
@@ -115,7 +112,6 @@
 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 */