Ksched interface cleanup, smp_idle() cleanup
[akaros.git] / kern / src / vfs.c
index eff652d..2ff72da 100644 (file)
@@ -99,7 +99,9 @@ void vfs_init(void)
        /* build list of all FS's in the system.  put yours here.  if this is ever
         * done on the fly, we'll need to lock. */
        TAILQ_INSERT_TAIL(&file_systems, &kfs_fs_type, list);
+#ifdef __CONFIG_EXT2FS__
        TAILQ_INSERT_TAIL(&file_systems, &ext2_fs_type, list);
+#endif
        TAILQ_FOREACH(fs, &file_systems, list)
                printk("Supports the %s Filesystem\n", fs->name);
 
@@ -150,6 +152,9 @@ static struct dentry *do_lookup(struct dentry *parent, char *name)
        /* not in the dcache at all, need to consult the FS */
        result = parent->d_inode->i_op->lookup(parent->d_inode, query, 0);
        if (!result) {
+               /* Note the USED flag will get turned off when this gets added to the
+                * LRU in dentry_release().  There's a slight race here that we'll panic
+                * on, but I want to catch it (in dcache_put()) for now. */
                query->d_flags |= DENTRY_NEGATIVE;
                dcache_put(parent->d_sb, query);
                kref_put(&query->d_kref);
@@ -675,14 +680,15 @@ void dentry_release(struct kref *kref)
        /* While locked, we need to double check the kref, in case someone already
         * reup'd it.  Re-up? you're crazy!  Reee-up, you're outta yo mind! */
        if (!kref_refcnt(&dentry->d_kref)) {
-               /* and make sure it wasn't USED, then UNUSED again */
-               /* TODO: think about issues with this */
+               /* Note this is where negative dentries get set UNUSED */
                if (dentry->d_flags & DENTRY_USED) {
                        dentry->d_flags &= ~DENTRY_USED;
                        spin_lock(&dentry->d_sb->s_lru_lock);
                        TAILQ_INSERT_TAIL(&dentry->d_sb->s_lru_d, dentry, d_lru);
                        spin_unlock(&dentry->d_sb->s_lru_lock);
                } else {
+                       /* and make sure it wasn't USED, then UNUSED again */
+                       /* TODO: think about issues with this */
                        warn("This should be rare.  Tell brho this happened.");
                }
        }
@@ -800,6 +806,7 @@ void dcache_put(struct super_block *sb, struct dentry *key_val)
        old = hashtable_remove(sb->s_dcache, key_val);
        if (old) {
                assert(old->d_flags & DENTRY_NEGATIVE);
+               /* This is possible, but rare for now (about to be put on the LRU) */
                assert(!(old->d_flags & DENTRY_USED));
                assert(!kref_refcnt(&old->d_kref));
                spin_lock(&sb->s_lru_lock);
@@ -909,7 +916,7 @@ struct inode *get_inode(struct dentry *dentry)
 }
 
 /* Helper: loads/ reads in the inode numbered ino and attaches it to dentry */
-void load_inode(struct dentry *dentry, unsigned int ino)
+void load_inode(struct dentry *dentry, unsigned long ino)
 {
        struct inode *inode;
 
@@ -1068,7 +1075,7 @@ void stat_inode(struct inode *inode, struct kstat *kstat)
 /* Inode Cache management.  In general, search on the ino, get a refcnt'd value
  * back.  Remove does not give you a reference back - it should only be called
  * in inode_release(). */
-struct inode *icache_get(struct super_block *sb, unsigned int ino)
+struct inode *icache_get(struct super_block *sb, unsigned long ino)
 {
        /* This is the same style as in pid2proc, it's the "safely create a strong
         * reference from a weak one, so long as other strong ones exist" pattern */
@@ -1090,7 +1097,7 @@ void icache_put(struct super_block *sb, struct inode *inode)
        spin_unlock(&sb->s_icache_lock);
 }
 
-struct inode *icache_remove(struct super_block *sb, unsigned int ino)
+struct inode *icache_remove(struct super_block *sb, unsigned long ino)
 {
        struct inode *inode;
        /* Presumably these hashtable removals could be easier since callers
@@ -1715,7 +1722,7 @@ struct file *get_file_from_fd(struct files_struct *open_files, int file_desc)
                        /* while max_files and max_fdset might not line up, we should never
                         * have a valid fdset higher than files */
                        assert(file_desc < open_files->max_files);
-                       retval = open_files->fd[file_desc];
+                       retval = open_files->fd[file_desc].fd_file;
                        assert(retval);
                        kref_get(&retval->f_kref, 1);
                }
@@ -1738,8 +1745,8 @@ struct file *put_file_from_fd(struct files_struct *open_files, int file_desc)
                        /* while max_files and max_fdset might not line up, we should never
                         * have a valid fdset higher than files */
                        assert(file_desc < open_files->max_files);
-                       file = open_files->fd[file_desc];
-                       open_files->fd[file_desc] = 0;
+                       file = open_files->fd[file_desc].fd_file;
+                       open_files->fd[file_desc].fd_file = 0;
                        assert(file);
                        kref_put(&file->f_kref);
                        CLR_BITMASK_BIT(open_files->open_fds->fds_bits, file_desc);
@@ -1762,9 +1769,11 @@ int insert_file(struct files_struct *open_files, struct file *file, int low_fd)
                        continue;
                slot = i;
                SET_BITMASK_BIT(open_files->open_fds->fds_bits, slot);
-               assert(slot < open_files->max_files && open_files->fd[slot] == 0);
+               assert(slot < open_files->max_files &&
+                      open_files->fd[slot].fd_file == 0);
                kref_get(&file->f_kref, 1);
-               open_files->fd[slot] = file;
+               open_files->fd[slot].fd_file = file;
+               open_files->fd[slot].fd_flags = 0;
                if (slot >= open_files->next_fd)
                        open_files->next_fd = slot + 1;
                break;
@@ -1786,11 +1795,11 @@ void close_all_files(struct files_struct *open_files, bool cloexec)
                        /* while max_files and max_fdset might not line up, we should never
                         * have a valid fdset higher than files */
                        assert(i < open_files->max_files);
-                       file = open_files->fd[i];
-                       if (cloexec && !(file->f_flags & O_CLOEXEC))
+                       file = open_files->fd[i].fd_file;
+                       if (cloexec && !(open_files->fd[i].fd_flags & O_CLOEXEC))
                                continue;
                        /* Actually close the file */
-                       open_files->fd[i] = 0;
+                       open_files->fd[i].fd_file = 0;
                        assert(file);
                        kref_put(&file->f_kref);
                        CLR_BITMASK_BIT(open_files->open_fds->fds_bits, i);
@@ -1810,10 +1819,10 @@ void clone_files(struct files_struct *src, struct files_struct *dst)
                        /* while max_files and max_fdset might not line up, we should never
                         * have a valid fdset higher than files */
                        assert(i < src->max_files);
-                       file = src->fd[i];
-                       assert(i < dst->max_files && dst->fd[i] == 0);
+                       file = src->fd[i].fd_file;
+                       assert(i < dst->max_files && dst->fd[i].fd_file == 0);
                        SET_BITMASK_BIT(dst->open_fds->fds_bits, i);
-                       dst->fd[i] = file;
+                       dst->fd[i].fd_file = file;
                        assert(file);
                        kref_get(&file->f_kref, 1);
                        if (i >= dst->next_fd)