Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Aug 2020 16:06:17 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r364702 - in stable/12/sys: compat/linux i386/linux
Message-ID:  <202008241606.07OG6HKO061940@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Mon Aug 24 16:06:17 2020
New Revision: 364702
URL: https://svnweb.freebsd.org/changeset/base/364702

Log:
  MFC r354413:
  
  Make linux(4) create /dev/shm.  Linux applications often expect
  a tmpfs to be mounted there, and because they like to verify it's
  actually a mountpoint, a symlink won't do.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  stable/12/sys/compat/linux/linux.c
  stable/12/sys/compat/linux/linux.h
  stable/12/sys/compat/linux/linux_common.c
  stable/12/sys/i386/linux/linux_sysvec.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/compat/linux/linux.c
==============================================================================
--- stable/12/sys/compat/linux/linux.c	Mon Aug 24 16:06:11 2020	(r364701)
+++ stable/12/sys/compat/linux/linux.c	Mon Aug 24 16:06:17 2020	(r364702)
@@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/systm.h>
+#include <sys/conf.h>
 #include <sys/ctype.h>
 #include <sys/jail.h>
 #include <sys/lock.h>
@@ -129,6 +130,12 @@ static int linux_to_bsd_sigtbl[LINUX_SIGTBLSZ] = {
 	SIGSYS		/* LINUX_SIGSYS */
 };
 
+static struct cdev *dev_shm_cdev;
+static struct cdevsw dev_shm_cdevsw = {
+     .d_version = D_VERSION,
+     .d_name    = "dev_shm",
+};
+
 /*
  * Map Linux RT signals to the FreeBSD RT signals.
  */
@@ -523,4 +530,24 @@ linux_to_bsd_sockaddr(const struct l_sockaddr *osa, st
 out:
 	free(kosa, M_SONAME);
 	return (error);
+}
+
+void
+linux_dev_shm_create(void)
+{
+	int error;
+
+	error = make_dev_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK, &dev_shm_cdev,
+	    &dev_shm_cdevsw, NULL, UID_ROOT, GID_WHEEL, 0, "shm/.mountpoint");
+	if (error != 0) {
+		printf("%s: failed to create device node, error %d\n",
+		    __func__, error);
+	}
+}
+
+void
+linux_dev_shm_destroy(void)
+{
+
+	destroy_dev(dev_shm_cdev);
 }

Modified: stable/12/sys/compat/linux/linux.h
==============================================================================
--- stable/12/sys/compat/linux/linux.h	Mon Aug 24 16:06:11 2020	(r364701)
+++ stable/12/sys/compat/linux/linux.h	Mon Aug 24 16:06:17 2020	(r364702)
@@ -143,4 +143,7 @@ int bsd_to_linux_signal(int sig);
 extern LIST_HEAD(futex_list, futex) futex_list;
 extern struct mtx futex_mtx;
 
+void linux_dev_shm_create(void);
+void linux_dev_shm_destroy(void);
+
 #endif /* _LINUX_MI_H_ */

Modified: stable/12/sys/compat/linux/linux_common.c
==============================================================================
--- stable/12/sys/compat/linux/linux_common.c	Mon Aug 24 16:06:11 2020	(r364701)
+++ stable/12/sys/compat/linux/linux_common.c	Mon Aug 24 16:06:17 2020	(r364702)
@@ -68,6 +68,7 @@ linux_common_modevent(module_t mod, int type, void *da
 
 	switch(type) {
 	case MOD_LOAD:
+		linux_dev_shm_create();
 		linux_osd_jail_register();
 		linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,
 		    linux_proc_exit, NULL, 1000);
@@ -81,6 +82,7 @@ linux_common_modevent(module_t mod, int type, void *da
 		mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF);
 		break;
 	case MOD_UNLOAD:
+		linux_dev_shm_destroy();
 		linux_osd_jail_deregister();
 		SET_FOREACH(ldhp, linux_device_handler_set)
 			linux_device_unregister_handler(*ldhp);

Modified: stable/12/sys/i386/linux/linux_sysvec.c
==============================================================================
--- stable/12/sys/i386/linux/linux_sysvec.c	Mon Aug 24 16:06:11 2020	(r364701)
+++ stable/12/sys/i386/linux/linux_sysvec.c	Mon Aug 24 16:06:17 2020	(r364702)
@@ -1057,6 +1057,7 @@ linux_elf_modevent(module_t mod, int type, void *data)
 			linux_get_machine(&linux_kplatform);
 			linux_szplatform = roundup(strlen(linux_kplatform) + 1,
 			    sizeof(char *));
+			linux_dev_shm_create();
 			linux_osd_jail_register();
 			stclohz = (stathz ? stathz : hz);
 			if (bootverbose)
@@ -1082,6 +1083,7 @@ linux_elf_modevent(module_t mod, int type, void *data)
 			EVENTHANDLER_DEREGISTER(process_exit, linux_exit_tag);
 			EVENTHANDLER_DEREGISTER(process_exec, linux_exec_tag);
 			EVENTHANDLER_DEREGISTER(thread_dtor, linux_thread_dtor_tag);
+			linux_dev_shm_destroy();
 			linux_osd_jail_deregister();
 			if (bootverbose)
 				printf("Linux ELF exec handler removed\n");



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