Whamcloud - gitweb
Pass inline data from filesystem through obdo to VFS.
[fs/lustre-release.git] / lustre / obdfs / super.c
index f8c5415..6e571f5 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,6 +122,8 @@ 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)
 {
@@ -146,24 +150,28 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
        if ( !device ) {
                printk("No device\n");
                MOD_DEC_USE_COUNT;
+               EXIT;
                return NULL;
        }
 
        if ( (err = obdfs_getdev(device, &devno)) ) {
                printk("Cannot get devno of %s, error %d\n", device, err);
                MOD_DEC_USE_COUNT;
+               EXIT;
                return NULL;
        }
 
        if ( MAJOR(devno) != OBD_PSDEV_MAJOR ) {
                printk("Wrong major number!\n");
                MOD_DEC_USE_COUNT;
+               EXIT;
                return NULL;
        }
                
        if ( MINOR(devno) >= MAX_OBD_DEVICES ) {
                printk("Minor of %s too high (%d)\n", device, MINOR(devno));
                MOD_DEC_USE_COUNT;
+               EXIT;
                return NULL;
        } 
 
@@ -171,7 +179,10 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
 
        if ( ! (obddev->obd_flags & OBD_ATTACHED) || 
             ! (obddev->obd_flags & OBD_SET_UP) ){
+               printk("Device %s not attached or not set up (%d)\n", 
+                      device, MINOR(devno));
                MOD_DEC_USE_COUNT;
+               EXIT;
                return NULL;
        } 
 
@@ -185,7 +196,7 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
                goto error;
        }
 
-       
+       INIT_LIST_HEAD(&sbi->osi_list);
 
        sbi->osi_super = sb;
 
@@ -258,6 +269,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;
@@ -280,32 +292,89 @@ static void obdfs_put_super(struct super_block *sb)
        EXIT;
 }
 
-extern struct inode_operations obdfs_inode_ops;
+inline int obdfs_has_inline(struct inode *inode)
+{
+       struct obdfs_inode_info *oinfo = inode->u.generic_ip;
+       
+       return (oinfo->oi_flags & OBD_FL_INLINEDATA);
+}
+
+void inline obdfs_from_inode(struct obdo *oa, struct inode *inode)
+{
+       struct obdfs_inode_info *oinfo = inode->u.generic_ip;
+
+       obdo_from_inode(oa, inode);
+       if (obdfs_has_inline(inode)) {
+               memcpy(oa->o_inline, oinfo->oi_inline, OBD_INLINESZ);
+               oa->o_flags |= OBD_FL_INLINEDATA;
+       }
+}
+
+void inline obdfs_to_inode(struct inode *inode, struct obdo *oa)
+{
+       struct obdfs_inode_info *oinfo = inode->u.generic_ip;
+
+       obdo_to_inode(inode, oa);
+       if (obdo_has_inline(oa)) {
+               memcpy(oinfo->oi_inline, oa->o_inline, OBD_INLINESZ);
+               oinfo->oi_flags |= OBD_FL_INLINEDATA;
+       }
+}
 
 /* all filling in of inodes postponed until lookup */
 void obdfs_read_inode(struct inode *inode)
 {
-       int error;
-       ENTRY;
+       struct obdo *oa;
+       int err;
 
-       error = IOPS(inode, getattr)(IID(inode), inode);
-       if (error) {
-               printk("obdfs_read_inode: obd_getattr fails (%d)\n", error);
+       ENTRY;
+       oa = obdo_alloc();
+       if (!oa) {
+               printk("obdfs_read_inode: obdo_alloc failed\n");
+               EXIT;
+               return;
+       }
+       oa->o_valid = ~OBD_MD_FLOBDMD;
+       oa->o_id = inode->i_ino;
+       err = IOPS(inode, getattr)(IID(inode), oa);
+       if (err) {
+               printk("obdfs_read_inode: obd_getattr fails (%d)\n", err);
+               obdo_free(oa);
+               EXIT;
                return;
        }
-       CDEBUG(D_INODE, "ino %ld, COWFL %x\n", inode->i_ino, inode->i_flags & 0x0010000);
+
+       ODEBUG(oa);
+       obdfs_to_inode(inode, oa);
+       obdo_free(oa);
        IDEBUG(inode);
-       inode->i_op = &obdfs_inode_ops;
+
+       if (S_ISREG(inode->i_mode))
+               inode->i_op = &obdfs_file_inode_operations;
+       else if (S_ISDIR(inode->i_mode))
+               inode->i_op = &obdfs_dir_inode_operations;
+       else if (S_ISLNK(inode->i_mode))
+               inode->i_op = &obdfs_symlink_inode_operations;
+       else
+               /* XXX what do we pass here??? */
+               init_special_inode(inode, inode->i_mode, 0 /* XXX XXX */ );
        return;
 }
 
 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);
+       oa = obdo_alloc();
+       oa->o_valid = OBD_MD_FLALL;
+       obdfs_from_inode(oa, inode);
+       err = IOPS(inode, setattr)(IID(inode), oa);
+
+       obdo_free(oa);
+
+       if (err) {
+               printk("obdfs_write_inode: obd_setattr fails (%d)\n", err);
                return;
        }
        
@@ -314,38 +383,54 @@ static void obdfs_write_inode(struct inode *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();
+       /* XXX we currently assume "id" is all that's needed for destroy */
+       oa->o_id = inode->i_ino;
+       err = IOPS(inode, destroy)(IID(inode), oa);
+       obdo_free(oa);
+
+       if (err) {
+               printk("obdfs_delete_node: obd_destroy fails (%d)\n", err);
                return;
        }
 
        EXIT;
 }
 
-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);
+       oa = obdo_alloc();
+       if (!oa) {
+               printk("obdfs_notify_change: obdo_alloc fails\n");
+               return -ENOMEM;
+       }
 
-       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->o_id = inode->i_ino;
+       obdo_from_iattr(oa, attr);
+        err = IOPS(inode, setattr)(IID(inode), oa);
+       obdo_free(oa);
+
+       if ( err ) {
+               printk("obdfs_notify_change: obd_setattr fails (%d)\n", err);
+               return err;
        }
+       inode_setattr(inode, attr);
 
        CDEBUG(D_INODE, "inode blocks now %ld\n", inode->i_blocks);
        EXIT;
-        return error;
+        return err;
 }
 
 
@@ -353,20 +438,20 @@ 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 = {
@@ -375,10 +460,21 @@ 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_wreqcache();
+       if (err)
+               return err;
+
+       /* XXX
+       flushd_init();
+       */
+
        return register_filesystem(&obdfs_fs_type);
 }
 
@@ -394,6 +490,7 @@ void cleanup_module(void)
         ENTRY;
 
        obdfs_sysctl_clean();
+       obdfs_cleanup_wreqcache();
        unregister_filesystem(&obdfs_fs_type);
 }