Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Sep 2014 15:45:18 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r271399 - in stable: 10/sys/kern 10/sys/sys 8/sys/kern 8/sys/sys 9/sys/kern 9/sys/sys
Message-ID:  <201409101545.s8AFjI3t032168@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed Sep 10 15:45:18 2014
New Revision: 271399
URL: http://svnweb.freebsd.org/changeset/base/271399

Log:
  MFC 270823,270825,270829:
  Use a unit number allocator to provide suitable st_dev and st_ino values
  for POSIX shared memory descriptors.  The implementation is similar to
  that used for pipes.
  
  Approved by:	re (gjb for 10)

Modified:
  stable/8/sys/kern/uipc_shm.c
  stable/8/sys/sys/mman.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/kern/   (props changed)
  stable/8/sys/sys/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/10/sys/kern/uipc_shm.c
  stable/10/sys/sys/mman.h
  stable/9/sys/kern/uipc_shm.c
  stable/9/sys/sys/mman.h
Directory Properties:
  stable/10/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/sys/   (props changed)

Modified: stable/8/sys/kern/uipc_shm.c
==============================================================================
--- stable/8/sys/kern/uipc_shm.c	Wed Sep 10 15:25:15 2014	(r271398)
+++ stable/8/sys/kern/uipc_shm.c	Wed Sep 10 15:45:18 2014	(r271399)
@@ -56,6 +56,7 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#include <sys/conf.h>
 #include <sys/fcntl.h>
 #include <sys/file.h>
 #include <sys/filedesc.h>
@@ -101,12 +102,14 @@ static LIST_HEAD(, shm_mapping) *shm_dic
 static struct sx shm_dict_lock;
 static struct mtx shm_timestamp_lock;
 static u_long shm_hash;
+static struct unrhdr *shm_ino_unr;
+static dev_t shm_dev_ino;
 
 #define	SHM_HASH(fnv)	(&shm_dictionary[(fnv) & shm_hash])
 
 static int	shm_access(struct shmfd *shmfd, struct ucred *ucred, int flags);
 static struct shmfd *shm_alloc(struct ucred *ucred, mode_t mode);
-static void	shm_dict_init(void *arg);
+static void	shm_init(void *arg);
 static void	shm_drop(struct shmfd *shmfd);
 static struct shmfd *shm_hold(struct shmfd *shmfd);
 static void	shm_insert(char *path, Fnv32_t fnv, struct shmfd *shmfd);
@@ -227,6 +230,8 @@ shm_stat(struct file *fp, struct stat *s
 	sb->st_birthtimespec = shmfd->shm_birthtime;	
 	sb->st_uid = shmfd->shm_uid;
 	sb->st_gid = shmfd->shm_gid;
+	sb->st_dev = shm_dev_ino;
+	sb->st_ino = shmfd->shm_ino;
 
 	return (0);
 }
@@ -350,6 +355,7 @@ static struct shmfd *
 shm_alloc(struct ucred *ucred, mode_t mode)
 {
 	struct shmfd *shmfd;
+	int ino;
 
 	shmfd = malloc(sizeof(*shmfd), M_SHMFD, M_WAITOK | M_ZERO);
 	shmfd->shm_size = 0;
@@ -366,6 +372,11 @@ shm_alloc(struct ucred *ucred, mode_t mo
 	vfs_timestamp(&shmfd->shm_birthtime);
 	shmfd->shm_atime = shmfd->shm_mtime = shmfd->shm_ctime =
 	    shmfd->shm_birthtime;
+	ino = alloc_unr(shm_ino_unr);
+	if (ino == -1)
+		shmfd->shm_ino = 0;
+	else
+		shmfd->shm_ino = ino;
 	refcount_init(&shmfd->shm_refs, 1);
 #ifdef MAC
 	mac_posixshm_init(shmfd);
@@ -392,6 +403,8 @@ shm_drop(struct shmfd *shmfd)
 		mac_posixshm_destroy(shmfd);
 #endif
 		vm_object_deallocate(shmfd->shm_object);
+		if (shmfd->shm_ino != 0)
+			free_unr(shm_ino_unr, shmfd->shm_ino);
 		free(shmfd, M_SHMFD);
 	}
 }
@@ -420,14 +433,18 @@ shm_access(struct shmfd *shmfd, struct u
  * the mappings in a hash table.
  */
 static void
-shm_dict_init(void *arg)
+shm_init(void *arg)
 {
 
 	mtx_init(&shm_timestamp_lock, "shm timestamps", NULL, MTX_DEF);
 	sx_init(&shm_dict_lock, "shm dictionary");
 	shm_dictionary = hashinit(1024, M_SHMFD, &shm_hash);
+	shm_ino_unr = new_unrhdr(1, INT32_MAX, NULL);
+	KASSERT(shm_ino_unr != NULL, ("shm fake inodes not initialized"));
+	shm_dev_ino = devfs_alloc_cdp_inode();
+	KASSERT(shm_dev_ino > 0, ("shm dev inode not initialized"));
 }
-SYSINIT(shm_dict_init, SI_SUB_SYSV_SHM, SI_ORDER_ANY, shm_dict_init, NULL);
+SYSINIT(shm_init, SI_SUB_SYSV_SHM, SI_ORDER_ANY, shm_init, NULL);
 
 static struct shmfd *
 shm_lookup(char *path, Fnv32_t fnv)

Modified: stable/8/sys/sys/mman.h
==============================================================================
--- stable/8/sys/sys/mman.h	Wed Sep 10 15:25:15 2014	(r271398)
+++ stable/8/sys/sys/mman.h	Wed Sep 10 15:45:18 2014	(r271399)
@@ -200,6 +200,7 @@ struct shmfd {
 	struct timespec	shm_mtime;
 	struct timespec	shm_ctime;
 	struct timespec	shm_birthtime;
+	ino_t		shm_ino;
 
 	struct label	*shm_label;		/* MAC label */
 	const char	*shm_path;



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