Monitor function to show inodes
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 19 Aug 2010 19:45:10 +0000 (12:45 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:52 +0000 (17:35 -0700)
Also fixes refcounting for the root inode.

kern/src/monitor.c
kern/src/vfs.c

index 5c23668..2600664 100644 (file)
@@ -764,21 +764,33 @@ int mon_fs(int argc, char *NTS *NT COUNT(argc) argv, trapframe_t *tf)
 {
        /* this assumes one mounted FS at the NS root */
        struct super_block *sb = default_ns.root->mnt_root->d_inode->i_sb;
-       struct file *i;
+       struct file *file;
+       struct inode *inode;
+       struct dentry *dentry;
        if (argc < 2) {
                printk("Usage: fs OPTION\n");
                printk("\topen: show all open files\n");
+               printk("\tinodes: show all inodes\n");
                printk("\tls DIR: print the dir tree starting with DIR\n");
                printk("\tpid: proc PID's fs crap placeholder\n");
                return 1;
        }
        if (!strcmp(argv[1], "open")) {
                printk("Open Files:\n----------------------------\n");
-               TAILQ_FOREACH(i, &sb->s_files, f_list)
-                       printk("File: %08p, %s, Refs: %d, Drefs: %d, Irefs: %d\n", i,
-                              file_name(i), kref_refcnt(&i->f_kref),
-                                  kref_refcnt(&i->f_dentry->d_kref),
-                                  kref_refcnt(&i->f_dentry->d_inode->i_kref));
+               TAILQ_FOREACH(file, &sb->s_files, f_list)
+                       printk("File: %08p, %s, Refs: %d, Drefs: %d, Irefs: %d\n", file,
+                              file_name(file), kref_refcnt(&file->f_kref),
+                                  kref_refcnt(&file->f_dentry->d_kref),
+                                  kref_refcnt(&file->f_dentry->d_inode->i_kref));
+       } else if (!strcmp(argv[1], "inodes")) {
+               printk("Mounted FS Inodes:\n----------------------------\n");
+               TAILQ_FOREACH(inode, &sb->s_inodes, i_sb_list) {
+                       printk("Inode: %08p, Refs: %d, Nlinks: %d, Size(B): %d\n", inode,
+                              kref_refcnt(&inode->i_kref), inode->i_nlink, inode->i_size);
+                       TAILQ_FOREACH(dentry, &inode->i_dentry, d_alias)
+                               printk("\t%s: Dentry: %08p, Refs: %d\n", dentry->d_name.name,
+                                      dentry, kref_refcnt(&dentry->d_kref));
+               }
        } else if (!strcmp(argv[1], "ls")) {
                if (argc != 3) {
                        printk("Give me a dir.\n");
index 3ac619c..33e8396 100644 (file)
@@ -485,8 +485,6 @@ void init_sb(struct super_block *sb, struct vfsmount *vmnt,
        struct inode *inode = get_inode(d_root);
        if (!inode)
                panic("This FS sucks!");
-       d_root->d_inode = inode;                                /* storing the inode's kref here */
-       TAILQ_INSERT_TAIL(&inode->i_dentry, d_root, d_alias);   /* weak ref */
        inode->i_ino = root_ino;
        /* TODO: add the inode to the appropriate list (off i_list) */
        /* TODO: do we need to read in the inode?  can we do this on demand? */
@@ -505,6 +503,7 @@ void init_sb(struct super_block *sb, struct vfsmount *vmnt,
         * when's the earliest we should?  what about concurrent accesses to the
         * same dentry?  should be locking the dentry... */
        dcache_put(d_root); // TODO: should set a d_flag too
+       kref_put(&inode->i_kref);               /* give up the ref from get_inode() */
 }
 
 /* Dentry Functions */
@@ -1479,8 +1478,8 @@ static void print_dir(struct dentry *dentry, char *buf, int depth)
                                        print_dir(child_d, buf, depth + 1);
                                        break;
                                case (FS_I_FILE):
-                                       printk("%s%s size(B): %d\n", buf, next.d_name,
-                                              child_d->d_inode->i_size);
+                                       printk("%s%s size(B): %d nlink: %d\n", buf, next.d_name,
+                                              child_d->d_inode->i_size, child_d->d_inode->i_nlink);
                                        break;
                                case (FS_I_SYMLINK):
                                        printk("%s%s -> %s\n", buf, next.d_name,