Whamcloud - gitweb
Pass inline data from filesystem through obdo to VFS.
[fs/lustre-release.git] / lustre / obdfs / super.c
index 7d61a06..6e571f5 100644 (file)
@@ -2,6 +2,9 @@
  * OBDFS Super operations
  *
  * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
+ * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
+ * Copryright (C) 1999 Seagate Technology Inc.
+ *
  */
 
 #define EXPORT_SYMTAB
 #include <linux/vmalloc.h>
 #include <asm/segment.h>
 
-#include <../obd/linux/sym_obd.h>
-#include <obdfs.h>
-
-/* DEBUGGING! */
-#undef MOD_INC_USE_COUNT
-#define MOD_INC_USE_COUNT
-#undef MOD_DEC_USE_COUNT
-#define MOD_DEC_USE_COUNT
+#include <linux/obd_support.h>
+#include <linux/obd_class.h>
+#include <linux/obdfs.h>
 
 /* VFS super_block ops */
 static struct super_block *obdfs_read_super(struct super_block *, void *, int);
-static void obdfs_read_inode(struct inode *);
 static int  obdfs_notify_change(struct dentry *dentry, struct iattr *attr);
 static void obdfs_write_inode(struct inode *);
 static void obdfs_delete_inode(struct inode *);
@@ -58,44 +55,189 @@ struct super_operations obdfs_super_operations =
        NULL                    /* remount_fs */
 };
 
-struct obdfs_sb_info obdfs_super_info;
-int obd_minor = 0;
-int obd_root_ino = 2;
+struct list_head obdfs_super_list;
+
+static char *obdfs_read_opt(const char *opt, char *data)
+{
+       char *value;
+       char *retval;
+
+       CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
+       if ( strncmp(opt, data, strlen(opt)) )
+               return NULL;
+
+       if ( (value = strchr(data, '=')) == NULL )
+               return NULL;
+
+       value++;
+       OBD_ALLOC(retval, char *, strlen(value) + 1);
+       if ( !retval ) {
+               printk("OBDFS: Out of memory!\n");
+               return NULL;
+       }
+       
+       memcpy(retval, value, strlen(value)+1);
+       CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
+       return retval;
+}
+
+void obdfs_options(char *options, char **dev, char **vers)
+{
+       char *this_char;
+
+       if (!options)
+               return;
+
+       for (this_char = strtok (options, ",");
+            this_char != NULL;
+            this_char = strtok (NULL, ",")) {
+               CDEBUG(D_SUPER, "this_char %s\n", this_char);
+               if ( (!*dev && (*dev = obdfs_read_opt("device", this_char)))||
+                    (!*vers && (*vers = obdfs_read_opt("version", this_char))) )
+                       continue;
+               
+       }
+}
+
+static int obdfs_getdev(char *devpath, int *dev)
+{
+       struct dentry *dentry;
+       kdev_t devno;
+
+       dentry = lookup_dentry(devpath, NULL, 0);
+       if (IS_ERR(dentry))
+               return PTR_ERR(dentry);
+       
+       if (!S_ISCHR(dentry->d_inode->i_mode))
+               return -ENODEV;
+
+       devno = dentry->d_inode->i_rdev;
+       if ( MAJOR(devno) != OBD_PSDEV_MAJOR ) 
+               return -ENODEV;
+       
+       if ( MINOR(devno) >= MAX_OBD_DEVICES ) 
+               return -ENODEV;
+
+       *dev = devno;
+       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 = NULL;
+       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;
+       int err;
+       unsigned long blocksize;
+       unsigned long blocksize_bits;
+       unsigned long root_ino;
+       int scratch;
+       
 
        ENTRY;
         MOD_INC_USE_COUNT; 
+       
+       memset(sbi, 0, sizeof(*sbi));
+       
+       obdfs_options(data, &device, &version);
+       if ( !device ) {
+               printk("No device\n");
+               MOD_DEC_USE_COUNT;
+               EXIT;
+               return NULL;
+       }
 
-       sbi = &obdfs_super_info;
+       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 ( sbi->osi_super ) {
-               printk("Already mounted\n");
+       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;
+       } 
+
+       obddev = &obd_dev[MINOR(devno)];
 
-        error  = obd_connect(obd_minor, &sbi->osi_conn_info);
+       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;
+       } 
+
+       sbi->osi_obd = obddev;
+       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 ) {
-               printk("OBDFS: cannot connect to 0x%x.\n", obd_minor);
+               printk("OBDFS: cannot connect to %s\n", device);
                goto error;
        }
+
+       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 ) {
+               printk("Getinfo call to drive failed (blocksize)\n");
+               goto error;
+       }
+
+       error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
+                                        strlen("blocksize_bits"), 
+                                        "blocksize_bits", 
+                                        &scratch, (void *)&blocksize_bits);
+       if ( error ) {
+               printk("Getinfo call to drive failed (blocksize_bits)\n");
+               goto error;
+       }
+
+       error = sbi->osi_ops->o_get_info(&sbi->osi_conn,
+                                        strlen("root_ino"), 
+                                        "root_ino", 
+                                        &scratch, (void *)&root_ino);
+       if ( error ) {
+               printk("Getinfo call to drive failed (root_ino)\n");
+               goto error;
+       }
+       
+
+
         lock_super(sb);
-        sb->u.generic_sbp = sbi;
-        sb->s_blocksize = sbi->osi_conn_info.conn_blocksize;
-        sb->s_blocksize_bits = sbi->osi_conn_info.conn_blocksize_bits;
+       
+        sb->s_blocksize = blocksize;
+        sb->s_blocksize_bits = (unsigned char)blocksize_bits;
         sb->s_magic = OBDFS_SUPER_MAGIC;
         sb->s_op = &obdfs_super_operations;
 
        /* make root inode */
-       root = iget(sb, sbi->osi_conn_info.conn_ino);
+       root = iget(sb, root_ino);
         if (!root || is_bad_inode(root)) {
            printk("OBDFS: bad iget for root\n");
            sb->s_dev = 0;
@@ -103,10 +245,13 @@ static struct super_block * obdfs_read_super(struct super_block *sb,
            unlock_super(sb);
            goto error;
        } 
+       
 
-       printk("obdfs_read_super: rootinode is %ld dev %d\n", 
-              root->i_ino, root->i_dev);
-       sb->s_root = d_alloc_root(root, NULL);
+       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), 
+              blocksize, blocksize_bits);
+       sb->s_root = d_alloc_root(root);
        unlock_super(sb);
        EXIT;  
         return sb;
@@ -124,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;
@@ -134,104 +280,157 @@ static void obdfs_put_super(struct super_block *sb)
         sb->s_dev = 0;
        
        /* XXX flush stuff */
-       sbi = sb->u.generic_sbp;
-       sb->u.generic_sbp = NULL;
-       obd_disconnect(sbi->osi_conn_info.conn_id);
-       sbi->osi_super = NULL;
+       sbi = (struct obdfs_sb_info *) &sb->u.generic_sbp;
 
+       OPS(sb,disconnect)(ID(sb));
+
+       memset(sbi, 0, sizeof(* sbi));
        
        printk("OBDFS: Bye bye.\n");
-       memset(sbi, 0, sizeof(* sbi));
 
         MOD_DEC_USE_COUNT;
        EXIT;
 }
 
-/* all filling in of inodes postponed until lookup */
-static void obdfs_read_inode(struct inode *inode)
+inline int obdfs_has_inline(struct inode *inode)
 {
-       struct iattr attr;
-       int error;
-       struct obdfs_sb_info *sbi = inode->i_sb->u.generic_sbp;
-       ENTRY;
+       struct obdfs_inode_info *oinfo = inode->u.generic_ip;
+       
+       return (oinfo->oi_flags & OBD_FL_INLINEDATA);
+}
 
-       error = obd_getattr(sbi->osi_conn_info.conn_id, inode->i_ino, &attr);
-       if (error) {
-               printk("obdfs_read_inode: ibd_getattr fails (%d)\n", error);
-               return;
+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;
        }
+}
 
-       inode_setattr(inode, &attr);
-       inode->i_op = NULL;
-       return;
+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;
+       }
 }
 
-static void inode_to_iattr(struct inode *inode, struct iattr *tmp)
+/* all filling in of inodes postponed until lookup */
+void obdfs_read_inode(struct inode *inode)
 {
-       tmp->ia_mode = inode->i_mode;
-       tmp->ia_uid = inode->i_uid;
-       tmp->ia_gid = inode->i_gid;
-       tmp->ia_size = inode->i_size;
-       tmp->ia_atime = inode->i_atime;
-       tmp->ia_mtime = inode->i_mtime;
-       tmp->ia_ctime = inode->i_ctime;
-       tmp->ia_attr_flags = inode->i_flags;
-
-       tmp->ia_valid = ~0;
+       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;
+       err = IOPS(inode, getattr)(IID(inode), oa);
+       if (err) {
+               printk("obdfs_read_inode: obd_getattr fails (%d)\n", err);
+               obdo_free(oa);
+               EXIT;
+               return;
+       }
+
+       ODEBUG(oa);
+       obdfs_to_inode(inode, oa);
+       obdo_free(oa);
+       IDEBUG(inode);
+
+       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) 
 {
-        struct obdfs_sb_info *sbi;
-       struct iattr attr;
-       int error;
-       ENTRY;
+       struct obdo *oa;
+       int err;
        
-       inode_to_iattr(inode, &attr);
-       sbi = inode->i_sb->u.generic_sbp;
-       error = obd_setattr(sbi->osi_conn_info.conn_id, inode->i_ino, &attr);
-       if (error) {
-               printk("obdfs_write_inode: ibd_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;
        }
-
+       
        return;
 }
 
 static void obdfs_delete_inode(struct inode *inode)
 {
-        struct obdfs_sb_info *sbi;
-       int error;
+       struct obdo *oa;
+       int err;
         ENTRY;
 
-       sbi = inode->i_sb->u.generic_sbp;
-       error = obd_destroy(sbi->osi_conn_info.conn_id , inode->i_ino);
-       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 obdfs_sb_info * sbi;
-       int error;
+       struct obdo *oa;
+       int err;
 
        ENTRY;
+       oa = obdo_alloc();
+       if (!oa) {
+               printk("obdfs_notify_change: obdo_alloc fails\n");
+               return -ENOMEM;
+       }
 
-       sbi = inode->i_sb->u.generic_sbp;
-        error = obd_setattr(sbi->osi_conn_info.conn_id, inode->i_ino, iattr);
-       if ( error ) {
-               printk("obdfs_notify_change: obd_setattr fails (%d)\n", error);
-               return error;
-       } else {
-               inode_setattr(inode, iattr);
+       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;
 }
 
 
@@ -239,22 +438,20 @@ static int obdfs_statfs(struct super_block *sb, struct statfs *buf,
                       int bufsize)
 {
        struct statfs tmp;
-       struct obdfs_sb_info * sbi;
-       int error;
+       int err;
 
        ENTRY;
 
-       sbi = sb->u.generic_sbp;
-       error = obd_statfs(sbi->osi_conn_info.conn_id, &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 = {
@@ -263,9 +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);
 }
 
@@ -281,12 +490,8 @@ void cleanup_module(void)
         ENTRY;
 
        obdfs_sysctl_clean();
+       obdfs_cleanup_wreqcache();
+       unregister_filesystem(&obdfs_fs_type);
 }
-void obdfs_psdev_dec_use_count(void)
-{
-       MOD_DEC_USE_COUNT;
-}
-
-EXPORT_SYMBOL(obdfs_psdev_dec_use_count);
 
 #endif