Akaros side of the VFS/9ns connection
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 18 Jan 2014 00:18:48 +0000 (16:18 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sat, 18 Jan 2014 00:18:48 +0000 (16:18 -0800)
Manages slash, dot, and what we do for cleaning up 9ns namespaces.

But the inferno code isn't using the updated fd2chan and friends.  Among
other problems...

kern/include/env.h
kern/src/ns/sysfile.c
kern/src/process.c
kern/src/vfs.c

index 4b4003c..0b23c98 100644 (file)
@@ -87,11 +87,10 @@ struct proc {
        struct namespace                        *ns;
        struct fs_struct                        fs_env;
        struct files_struct                     open_files;
-       struct pgrp                             *pgrp;
-       struct fgrp                             *fgrp;
-       struct fgrp                             *closingfgrp;
-       struct chan                             *slash;
-       struct chan                             *dot;
+       struct pgrp                                     *pgrp;
+       struct fgrp                                     *fgrp;
+       struct chan                                     *slash;
+       struct chan                                     *dot;
 
 
        /* UCQ hashlocks */
index 249edf4..4fe87c3 100644 (file)
@@ -1250,8 +1250,8 @@ int plan9setup(struct proc *new_proc, struct proc *parent)
                new_proc->slash = namec("#r", Atodir, 0, 0);
                switch_back(new_proc, old_current);
                /* Want the name to be "/" instead of "#r" */
-               pathclose(new_proc->slash->path);
-               new_proc->slash->path = newpath("/");
+               cnameclose(new_proc->slash->name);
+               new_proc->slash->name = newcname("/");
                new_proc->dot = cclone(new_proc->slash);
                poperror();
                return 0;
index 418ea83..ec5158d 100644 (file)
@@ -356,8 +356,8 @@ error_t proc_alloc(struct proc **pp, struct proc *parent)
 
        atomic_inc(&num_envs);
        frontend_proc_init(p);
-       //plan9setup(p, parent);
-       //devalarm_init(p);
+       plan9setup(p, parent);
+       devalarm_init(p);
        TAILQ_INIT(&p->abortable_sleepers);
        spinlock_init_irqsave(&p->abort_list_lock);
        printd("[%08x] new process %08x\n", current ? current->pid : 0, p->pid);
@@ -417,7 +417,12 @@ static void __proc_free(struct kref *kref)
        assert(kref_refcnt(&p->p_kref) == 0);
        assert(TAILQ_EMPTY(&p->alarmset.list));
 
-       /* close plan9 dot and slash and free fgrp fd and fgrp */
+       cclose(p->dot);
+       cclose(p->slash);
+       p->dot = p->slash = 0; /* catch bugs */
+       /* can safely free the fgrp, now that no one is accessing it */
+       kfree(p->fgrp->fd);
+       kfree(p->fgrp);
        kref_put(&p->fs_env.root->d_kref);
        kref_put(&p->fs_env.pwd->d_kref);
        /* now we'll finally decref files for the file-backed vmrs */
@@ -832,7 +837,7 @@ void proc_destroy(struct proc *p)
         *
         * Also note that any mmap'd files will still be mmapped.  You can close the
         * file after mmapping, with no effect. */
-       //close_9ns_files(p, FALSE);
+       close_9ns_files(p, FALSE);
        close_all_files(&p->open_files, FALSE);
        /* Tell the ksched about our death, and which cores we freed up */
        __sched_proc_destroy(p, pc_arr, nr_cores_revoked);
@@ -2199,12 +2204,12 @@ void print_proc_info(pid_t pid)
        struct files_struct *files = &p->open_files;
        spin_lock(&files->lock);
        for (int i = 0; i < files->max_files; i++)
-               if (files->fd_array[i].fd_file) {
+               if (files->fd[i].fd_file) {
                        printk("\tFD: %02d, File: %p, File name: %s\n", i,
-                              files->fd_array[i].fd_file,
-                              file_name(files->fd_array[i].fd_file));
+                              files->fd[i].fd_file, file_name(files->fd[i].fd_file));
                }
        spin_unlock(&files->lock);
+       print_9ns_files(p);
        printk("Children: (PID (struct proc *))\n");
        TAILQ_FOREACH(child, &p->children, sibling_link)
                printk("\t%d (%p)\n", child->pid, child);
@@ -2249,3 +2254,16 @@ void check_my_owner(void)
                spin_unlock(&pid_hash_lock);
        }
 }
+
+/* Use this via kfunc */
+void print_9ns(void)
+{
+       void print_proc_9ns(void *item)
+       {
+               struct proc *p = (struct proc*)item;
+               print_9ns_files(p);
+       }
+       spin_lock(&pid_hash_lock);
+       hash_for_each(pid_hash, print_proc_9ns);
+       spin_unlock(&pid_hash_lock);
+}
index 38928d7..4151bd3 100644 (file)
@@ -2076,7 +2076,7 @@ struct file *put_file_from_fd(struct files_struct *open_files, int file_desc)
                        assert(file_desc < open_files->max_files);
                        file = open_files->fd[file_desc].fd_file;
                        open_files->fd[file_desc].fd_file = 0;
-                       assert(file);
+                       assert(file);   /* 9ns shouldn't call this put */
                        kref_put(&file->f_kref);
                        CLR_BITMASK_BIT(open_files->open_fds->fds_bits, file_desc);
                }
@@ -2196,8 +2196,9 @@ void clone_files(struct files_struct *src, struct files_struct *dst)
                        assert(i < dst->max_files && dst->fd[i].fd_file == 0);
                        SET_BITMASK_BIT(dst->open_fds->fds_bits, i);
                        dst->fd[i].fd_file = file;
-                       assert(file);
-                       kref_get(&file->f_kref, 1);
+                       /* no file means 9ns is using it, they clone separately */
+                       if (file)
+                               kref_get(&file->f_kref, 1);
                        if (i >= dst->next_fd)
                                dst->next_fd = i + 1;
                }