Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Mar 2018 19:53:56 +0000 (UTC)
From:      Brooks Davis <brooks@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331747 - in stable/11/sys: conf kern sys
Message-ID:  <201803291953.w2TJruZm092415@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: brooks
Date: Thu Mar 29 19:53:56 2018
New Revision: 331747
URL: https://svnweb.freebsd.org/changeset/base/331747

Log:
  MFC r328522:
  
  Create deprecation management functions.
  
  gone_in(majar, msg);	If we're running in FreeBSD major, tell
  			the user this code may be deleted soon.
  			If we're running in FreeBSD major - 1,
  			the the user is deprecated and will
  			be gone in major.
  			Otherwise say nothing.
  
  gone_in_dev(dev, major, msg) Just like gone_in, except use device_printf.
  
  New tunable / sysctl debug.oboslete_panic: 0 - don't panic,
  	1 - panic in major or newer , 2 - panic in major - 1 or newer
  	default: 0
  
  if NO_OBSOLETE_CODE is defined, then both of these turn into compile
  time errors when building for major. Add options NO_OBSOLETE_CODE to
  kernel build system.
  
  This lets us tag code that's going away so users know it will be gone,
  as well as automatically manage things.
  
  Differential Review: https://reviews.freebsd.org/D13818

Modified:
  stable/11/sys/conf/options
  stable/11/sys/kern/subr_bus.c
  stable/11/sys/sys/systm.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/conf/options
==============================================================================
--- stable/11/sys/conf/options	Thu Mar 29 19:48:50 2018	(r331746)
+++ stable/11/sys/conf/options	Thu Mar 29 19:53:56 2018	(r331747)
@@ -176,6 +176,7 @@ NO_ADAPTIVE_MUTEXES	opt_adaptive_mutexes.h
 NO_ADAPTIVE_RWLOCKS
 NO_ADAPTIVE_SX
 NO_EVENTTIMERS		opt_timer.h
+NO_OBSOLETE_CODE	opt_global.h
 NO_SYSCTL_DESCR	opt_global.h
 NSWBUF_MIN	opt_swap.h
 MBUF_PACKET_ZONE_DISABLE	opt_global.h

Modified: stable/11/sys/kern/subr_bus.c
==============================================================================
--- stable/11/sys/kern/subr_bus.c	Thu Mar 29 19:48:50 2018	(r331746)
+++ stable/11/sys/kern/subr_bus.c	Thu Mar 29 19:53:56 2018	(r331747)
@@ -5592,3 +5592,53 @@ devctl2_init(void)
 	make_dev_credf(MAKEDEV_ETERNAL, &devctl2_cdevsw, 0, NULL,
 	    UID_ROOT, GID_WHEEL, 0600, "devctl2");
 }
+
+/*
+ * APIs to manage deprecation and obsolescence.
+ */
+static int obsolete_panic = 0;
+SYSCTL_INT(_debug, OID_AUTO, obsolete_panic, CTLFLAG_RWTUN, &obsolete_panic, 0,
+    "Bus debug level");
+/* 0 - don't panic, 1 - panic if already obsolete, 2 - panic if deprecated */
+static void
+gone_panic(int major, int running, const char *msg)
+{
+
+	switch (obsolete_panic)
+	{
+	case 0:
+		return;
+	case 1:
+		if (running < major)
+			return;
+		/* FALLTHROUGH */
+	default:
+		panic("%s", msg);
+	}
+}
+
+void
+_gone_in(int major, const char *msg)
+{
+
+	gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg);
+	if (P_OSREL_MAJOR(__FreeBSD_version) >= major)
+		printf("Obsolete code will removed soon: %s\n", msg);
+	else if (P_OSREL_MAJOR(__FreeBSD_version) + 1 == major)
+		printf("Deprecated code (to be removed in FreeBSD %d): %s\n",
+		    major, msg);
+}
+
+void
+_gone_in_dev(device_t dev, int major, const char *msg)
+{
+
+	gone_panic(major, P_OSREL_MAJOR(__FreeBSD_version), msg);
+	if (P_OSREL_MAJOR(__FreeBSD_version) >= major)
+		device_printf(dev,
+		    "Obsolete code will removed soon: %s\n", msg);
+	else if (P_OSREL_MAJOR(__FreeBSD_version) + 1 == major)
+		device_printf(dev,
+		    "Deprecated code (to be removed in FreeBSD %d): %s\n",
+		    major, msg);
+}

Modified: stable/11/sys/sys/systm.h
==============================================================================
--- stable/11/sys/sys/systm.h	Thu Mar 29 19:48:50 2018	(r331746)
+++ stable/11/sys/sys/systm.h	Thu Mar 29 19:53:56 2018	(r331747)
@@ -461,6 +461,22 @@ void	intr_prof_stack_use(struct thread *td, struct tra
 
 void counted_warning(unsigned *counter, const char *msg);
 
+/*
+ * APIs to manage deprecation and obsolescence.
+ */
+struct device;
+void _gone_in(int major, const char *msg);
+void _gone_in_dev(struct device *dev, int major, const char *msg);
+#ifdef NO_OBSOLETE_CODE
+#define __gone_ok(m, msg)					 \
+	_Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)),	 \
+	    "Obsolete code" msg);
+#else
+#define	__gone_ok(m, msg)
+#endif
+#define gone_in(major, msg)		__gone_ok(major, msg) _gone_in(major, msg)
+#define gone_in_dev(dev, major, msg)	__gone_ok(major, msg) _gone_in_dev(dev, major, msg)
+
 __NULLABILITY_PRAGMA_POP
 
 #endif /* !_SYS_SYSTM_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803291953.w2TJruZm092415>