Author: jhb
Date: Fri Aug 29 18:18:29 2014
New Revision: 270823
URL: http://svnweb.freebsd.org/changeset/base/270823

Log:
  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.
  
  MFC after:    1 week

Modified:
  head/sys/kern/uipc_shm.c

Modified: head/sys/kern/uipc_shm.c
==============================================================================
--- head/sys/kern/uipc_shm.c    Fri Aug 29 18:02:58 2014        (r270822)
+++ head/sys/kern/uipc_shm.c    Fri Aug 29 18:18:29 2014        (r270823)
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
 #include <sys/capsicum.h>
+#include <sys/conf.h>
 #include <sys/fcntl.h>
 #include <sys/file.h>
 #include <sys/filedesc.h>
@@ -101,6 +102,8 @@ 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])
 
@@ -408,6 +411,8 @@ shm_stat(struct file *fp, struct stat *s
        sb->st_uid = shmfd->shm_uid;
        sb->st_gid = shmfd->shm_gid;
        mtx_unlock(&shm_timestamp_lock);
+       sb->st_dev = shm_dev_ino;
+       sb->st_ino = shmfd->shm_ino;
 
        return (0);
 }
@@ -539,6 +544,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;
@@ -555,6 +561,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);
        mtx_init(&shmfd->shm_mtx, "shmrl", NULL, MTX_DEF);
        rangelock_init(&shmfd->shm_rl);
@@ -585,6 +596,8 @@ shm_drop(struct shmfd *shmfd)
                rangelock_destroy(&shmfd->shm_rl);
                mtx_destroy(&shmfd->shm_mtx);
                vm_object_deallocate(shmfd->shm_object);
+               if (shmfd->shm_ino != 0)
+                       free_unr(shm_ino_unr, shmfd->shm_ino);
                free(shmfd, M_SHMFD);
        }
 }
@@ -617,14 +630,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)
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to