Whamcloud - gitweb
include/obd_support.h: removed printk() of long long values (sometimes does
[fs/lustre-release.git] / lustre / obdfs / super.c
index a58949a..6a30cea 100644 (file)
@@ -55,6 +55,8 @@ struct super_operations obdfs_super_operations =
        NULL                    /* remount_fs */
 };
 
+struct list_head obdfs_super_list;
+
 static char *obdfs_read_opt(const char *opt, char *data)
 {
        char *value;
@@ -120,13 +122,14 @@ static int obdfs_getdev(char *devpath, int *dev)
        return 0;
 }
 
+
+/* XXX allocate a super_entry, and add the super to the obdfs_super_list */
 static struct super_block * obdfs_read_super(struct super_block *sb, 
                                            void *data, int silent)
 {
         struct inode *root = 0; 
        struct obdfs_sb_info *sbi = (struct obdfs_sb_info *)(&sb->u.generic_sbp);
        struct obd_device *obddev;
-        int error = 0;
        char *device = NULL;
        char *version = NULL;
        int devno;
@@ -186,45 +189,39 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
        sbi->osi_ops = sbi->osi_obd->obd_type->typ_ops;
        
        sbi->osi_conn.oc_dev = obddev;
-        error  = sbi->osi_ops->o_connect(&sbi->osi_conn);
-       if ( error ) {
+        err = sbi->osi_ops->o_connect(&sbi->osi_conn);
+       if ( err ) {
                printk("OBDFS: cannot connect to %s\n", device);
-               goto error;
+               goto ERR;
        }
 
-       
+       INIT_LIST_HEAD(&sbi->osi_list);
 
        sbi->osi_super = sb;
 
-       error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
-                                        strlen("blocksize"), 
-                                        "blocksize", 
-                                        &scratch, (void *)&blocksize);
-       if ( error ) {
+       err = sbi->osi_ops->o_get_info(&sbi->osi_conn, strlen("blocksize"),
+                                      "blocksize", &scratch,
+                                      (void *)&blocksize);
+       if ( err ) {
                printk("Getinfo call to drive failed (blocksize)\n");
-               goto error;
+               goto ERR;
        }
 
-       error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
-                                        strlen("blocksize_bits"), 
-                                        "blocksize_bits", 
-                                        &scratch, (void *)&blocksize_bits);
-       if ( error ) {
+       err = sbi->osi_ops->o_get_info(&sbi->osi_conn, strlen("blocksize_bits"),
+                                      "blocksize_bits", &scratch,
+                                      (void *)&blocksize_bits);
+       if ( err ) {
                printk("Getinfo call to drive failed (blocksize_bits)\n");
-               goto error;
+               goto ERR;
        }
 
-       error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
-                                        strlen("root_ino"), 
-                                        "root_ino", 
-                                        &scratch, (void *)&root_ino);
-       if ( error ) {
+       err = sbi->osi_ops->o_get_info(&sbi->osi_conn, strlen("root_ino"), 
+                                      "root_ino", &scratch, (void *)&root_ino);
+       if ( err ) {
                printk("Getinfo call to drive failed (root_ino)\n");
-               goto error;
+               goto ERR;
        }
        
-
-
         lock_super(sb);
        
         sb->s_blocksize = blocksize;
@@ -232,17 +229,18 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
         sb->s_magic = OBDFS_SUPER_MAGIC;
         sb->s_op = &obdfs_super_operations;
 
+       /* XXX how to get "sb->s_flags |= MS_RDONLY" here for snapshots? */
+
        /* make root inode */
        root = iget(sb, root_ino);
         if (!root || is_bad_inode(root)) {
            printk("OBDFS: bad iget for root\n");
            sb->s_dev = 0;
-           error = ENOENT;
+           err = -ENOENT;
            unlock_super(sb);
-           goto error;
+           goto ERR;
        } 
        
-
        printk("obdfs_read_super: sbdev %d, rootino: %ld, dev %s, "
               "minor: %d, blocksize: %ld, blocksize bits %ld\n", 
               sb->s_dev, root->i_ino, device, MINOR(devno), 
@@ -252,7 +250,7 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
        EXIT;  
         return sb;
 
- error:
+ERR:
        EXIT;  
        MOD_DEC_USE_COUNT;
        if (sbi) {
@@ -265,6 +263,7 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
         return NULL;
 }
 
+/* XXX remove the super to the obdfs_super_list */
 static void obdfs_put_super(struct super_block *sb)
 {
         struct obdfs_sb_info *sbi;
@@ -285,95 +284,157 @@ static void obdfs_put_super(struct super_block *sb)
 
         MOD_DEC_USE_COUNT;
        EXIT;
-}
-
-extern struct inode_operations obdfs_inode_ops;
+} /* obdfs_put_super */
 
 /* all filling in of inodes postponed until lookup */
 void obdfs_read_inode(struct inode *inode)
 {
-       int error;
+       struct obdo *oa;
+
        ENTRY;
+       oa = obdo_fromid(IID(inode), inode->i_ino, OBD_MD_FLNOTOBD);
+       if ( IS_ERR(oa) ) {
+               printk("obdfs_read_inode: obdo_fromid failed\n");
+               EXIT;
+               return /* PTR_ERR(oa) */;
+       }
 
-       error = IOPS(inode, getattr)(IID(inode), inode);
-       if (error) {
-               printk("obdfs_read_inode: obd_getattr fails (%d)\n", error);
-               return;
+       ODEBUG(oa);
+       obdfs_to_inode(inode, oa);
+       INIT_LIST_HEAD(&OBDFS_LIST(inode));
+
+       obdo_free(oa);
+       OIDEBUG(inode);
+
+       if (S_ISREG(inode->i_mode)) {
+               inode->i_op = &obdfs_file_inode_operations;
+               EXIT;
+       } else if (S_ISDIR(inode->i_mode)) {
+               inode->i_op = &obdfs_dir_inode_operations;
+               EXIT;
+       } else if (S_ISLNK(inode->i_mode)) {
+               inode->i_op = &obdfs_symlink_inode_operations;
+               EXIT;
+       } else {
+               init_special_inode(inode, inode->i_mode,
+                                  /* XXX need to fill in the ext2 side */
+                                  ((long *)OBDFS_INFO(inode)->oi_inline)[0]);
        }
-       CDEBUG(D_INODE, "ino %ld, COWFL %x\n", inode->i_ino, inode->i_flags & 0x0010000);
-       IDEBUG(inode);
-       inode->i_op = &obdfs_inode_ops;
+
        return;
-}
+} /* obdfs_read_inode */
 
 static void obdfs_write_inode(struct inode *inode) 
 {
-       int error;
+       struct obdo *oa;
+       int err;
        
-       error = IOPS(inode, setattr)(IID(inode), inode);
-       if (error) {
-               printk("obdfs_write_inode: obd_setattr fails (%d)\n", error);
+       ENTRY;
+       oa = obdo_alloc();
+       if ( !oa ) {
+               printk("obdfs_write_inode: obdo_alloc failed\n");
                return;
        }
-       
-       return;
-}
+
+       oa->o_valid = OBD_MD_FLNOTOBD;
+       obdfs_from_inode(oa, inode);
+       err = IOPS(inode, setattr)(IID(inode), oa);
+
+       if ( err ) {
+               printk("obdfs_write_inode: obd_setattr fails (%d)\n", err);
+               EXIT;
+       } else {
+               /* Copy back attributes from oa, as there may have been
+                * changes at the target (e.g. obdo becomes a redirector
+                * in the snapshot layer).
+                */
+               obdfs_to_inode(inode, oa);
+               EXIT;
+       }
+
+       obdo_free(oa);
+} /* obdfs_write_inode */
+
 
 static void obdfs_delete_inode(struct inode *inode)
 {
-       int error;
+       struct obdo *oa;
+       int err;
         ENTRY;
 
-       error = IOPS(inode, destroy)(IID(inode), inode);
-       if (error) {
-               printk("obdfs_delete_node: ibd_destroy fails (%d)\n", error);
+       oa = obdo_alloc();
+       if ( !oa ) {
+               printk("obdfs_delete_inode: obdo_alloc failed\n");
+               return;
+       }
+       oa->o_valid = OBD_MD_FLNOTOBD;
+       obdfs_from_inode(oa, inode);
+
+       err = IOPS(inode, destroy)(IID(inode), oa);
+       obdo_free(oa);
+
+       if (err) {
+               printk("obdfs_delete_node: obd_destroy fails (%d)\n", err);
+               EXIT;
                return;
        }
 
        EXIT;
-}
+} /* obdfs_delete_inode */
+
 
-static int  obdfs_notify_change(struct dentry *de, struct iattr *iattr)
+static int obdfs_notify_change(struct dentry *de, struct iattr *attr)
 {
        struct inode *inode = de->d_inode;
-       struct iattr saved_copy;
-       int error;
+       struct obdo *oa;
+       int err;
 
        ENTRY;
-       inode_to_iattr(inode, &saved_copy);
-
-       inode_setattr(inode, iattr);
-        error = IOPS(inode, setattr)(IID(inode), inode);
-       if ( error ) {
-               inode_setattr(inode, &saved_copy);
-               printk("obdfs_notify_change: obd_setattr fails (%d)\n", error);
-               return error;
+       oa = obdo_alloc();
+       if ( !oa ) {
+               printk("obdfs_notify_change: obdo_alloc failed\n");
+               return -ENOMEM;
        }
 
-       CDEBUG(D_INODE, "inode blocks now %ld\n", inode->i_blocks);
-       EXIT;
-        return error;
-}
+       oa->o_id = inode->i_ino;
+       obdo_from_iattr(oa, attr);
+        err = IOPS(inode, setattr)(IID(inode), oa);
+
+       if ( err ) {
+               printk("obdfs_notify_change: obd_setattr fails (%d)\n", err);
+               EXIT;
+       } else {
+               /* Copy back attributes from oa, as there may have been
+                * changes at the target (e.g. obdo becomes a redirector
+                * in the snapshot layer).
+                */
+               obdfs_to_inode(inode, oa);
+               EXIT;
+       }
+
+       obdo_free(oa);
+        return err;
+} /* obdfs_notify_change */
 
 
 static int obdfs_statfs(struct super_block *sb, struct statfs *buf, 
                       int bufsize)
 {
        struct statfs tmp;
-       int error;
+       int err;
 
        ENTRY;
 
-       error = OPS(sb,statfs)(ID(sb), &tmp);
-       if ( error ) { 
-               printk("obdfs_notify_change: obd_statfs fails (%d)\n", error);
-               return error;
+       err = OPS(sb,statfs)(ID(sb), &tmp);
+       if ( err ) { 
+               printk("obdfs_notify_change: obd_statfs fails (%d)\n", err);
+               return err;
        }
        copy_to_user(buf, &tmp, (bufsize<sizeof(tmp)) ? bufsize : sizeof(tmp));
 
        EXIT;
 
-       return error
+       return err; 
 }
 
 struct file_system_type obdfs_fs_type = {
@@ -382,10 +443,18 @@ struct file_system_type obdfs_fs_type = {
 
 int init_obdfs(void)
 {
+       int err;
+
        printk(KERN_INFO "OBDFS v0.1, braam@stelias.com\n");
 
        obdfs_sysctl_init();
 
+       INIT_LIST_HEAD(&obdfs_super_list);
+       err = obdfs_init_pgrqcache();
+       if (err)
+               return err;
+
+       flushd_init();
        return register_filesystem(&obdfs_fs_type);
 }
 
@@ -401,7 +470,10 @@ void cleanup_module(void)
         ENTRY;
 
        obdfs_sysctl_clean();
+       obdfs_cleanup_pgrqcache();
        unregister_filesystem(&obdfs_fs_type);
+
+       EXIT;
 }
 
 #endif