Whamcloud - gitweb
ext2obd/ext2obd.c, obdfs/namei.c: fixed inline flag to be o_obdflag, not o_flag
[fs/lustre-release.git] / lustre / obdfs / super.c
index 0df6a03..6c598a8 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;
@@ -287,19 +286,64 @@ static void obdfs_put_super(struct super_block *sb)
        EXIT;
 }
 
+void inline obdfs_from_inode(struct obdo *oa, struct inode *inode)
+{
+       obdo_from_inode(oa, inode);
+
+       CDEBUG(D_INODE, "oinfo flags 0x%08x\n", OBDFS_INFO(inode)->oi_flags);
+       if (obdfs_has_inline(inode)) {
+               struct obdfs_inode_info *oinfo = OBDFS_INFO(inode);
+
+               CDEBUG(D_INODE, "inode %ld has inline data\n", inode->i_ino);
+               memcpy(oa->o_inline, oinfo->oi_inline, OBD_INLINESZ);
+               oa->o_obdflags |= OBD_FL_INLINEDATA;
+       }
+}
+
+void inline obdfs_to_inode(struct inode *inode, struct obdo *oa)
+{
+       obdo_to_inode(inode, oa);
+       if (obdo_has_inline(oa)) {
+               struct obdfs_inode_info *oinfo = OBDFS_INFO(inode);
+
+               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;
+       struct obdo *oa;
+       int err;
+
        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;
 
-       error = IOPS(inode, getattr)(IID(inode), inode);
-       if (error) {
-               printk("obdfs_read_inode: obd_getattr fails (%d)\n", error);
+       INIT_LIST_HEAD(&OBDFS_INFO(inode)->oi_pages);
+       
+       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, mode: %o\n", inode->i_ino, inode->i_mode);
-       IDEBUG(inode);
+
+       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;
        else if (S_ISDIR(inode->i_mode))
@@ -309,56 +353,83 @@ void obdfs_read_inode(struct inode *inode)
        else
                /* XXX what do we pass here??? */
                init_special_inode(inode, inode->i_mode, 0 /* XXX XXX */ );
+
+       EXIT;
        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);
+       ENTRY;
+       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);
+               EXIT;
                return;
        }
        
-       return;
+       EXIT;
 }
 
 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);
-
-       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 fails\n");
+               return -ENOMEM;
+       }
+
+       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;
 }
 
 
@@ -366,20 +437,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 = {
@@ -388,10 +459,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);
 }
 
@@ -407,7 +486,10 @@ void cleanup_module(void)
         ENTRY;
 
        obdfs_sysctl_clean();
+       obdfs_cleanup_pgrqcache();
        unregister_filesystem(&obdfs_fs_type);
+
+       EXIT;
 }
 
 #endif