X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdfs%2Fsuper.c;h=f2c91e7460f05b272ae7189214ca2ee7880523d2;hb=a679032a54782f700fce08e452e2603c6c15228a;hp=c40122b35a27cfdf6cd8b31e7bb19724719f295e;hpb=1e7d496794cc655eabb30c1edb1a269aec6309dc;p=fs%2Flustre-release.git diff --git a/lustre/obdfs/super.c b/lustre/obdfs/super.c index c40122b..f2c91e7 100644 --- a/lustre/obdfs/super.c +++ b/lustre/obdfs/super.c @@ -30,12 +30,10 @@ #include #include -#include /* XXX for development/debugging only */ -#include +#include /* 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 *); @@ -57,64 +55,202 @@ 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; - int error = 0; + struct obdfs_sb_info *sbi = (struct obdfs_sb_info *)(&sb->u.generic_sbp); + struct obd_device *obddev; + 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; + } - sbi->osi_obd = &obd_dev[obd_minor]; + obddev = &obd_dev[MINOR(devno)]; + + 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; - error = sbi->osi_ops->o_connect(obd_minor, &sbi->osi_conn_info); - if ( error ) { - printk("OBDFS: cannot connect to 0x%x.\n", obd_minor); - goto error; + sbi->osi_conn.oc_dev = obddev; + err = sbi->osi_ops->o_connect(&sbi->osi_conn); + if ( err ) { + printk("OBDFS: cannot connect to %s\n", device); + goto ERR; } + INIT_LIST_HEAD(&sbi->osi_list); + sbi->osi_super = sb; + 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 ERR; + } + + 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 ERR; + } + + 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 ERR; + } + 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; + /* XXX how to get "sb->s_flags |= MS_RDONLY" here for snapshots? */ + /* 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; - error = ENOENT; + err = -ENOENT; unlock_super(sb); - goto error; + goto ERR; } - - printk("obdfs_read_super: rootinode is %ld dev %d\n", - root->i_ino, root->i_dev); + + 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; - error: +ERR: EXIT; MOD_DEC_USE_COUNT; if (sbi) { @@ -127,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; @@ -137,132 +274,207 @@ 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; - sbi->osi_ops->o_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; -} +} /* obdfs_put_super */ -extern struct inode_operations obdfs_inode_ops; +void inline obdfs_from_inode(struct obdo *oa, struct inode *inode) +{ + struct obdfs_inode_info *oinfo = OBDFS_INFO(inode); + + CDEBUG(D_INODE, "inode %ld (%p)\n", inode->i_ino, inode); + obdo_from_inode(oa, inode); + if (obdfs_has_inline(inode)) { + CDEBUG(D_INODE, "inode has inline data\n"); + memcpy(oa->o_inline, oinfo->oi_inline, OBD_INLINESZ); + oa->o_obdflags |= OBD_FL_INLINEDATA; + oa->o_valid |= OBD_MD_FLINLINE; + } + if (obdfs_has_obdmd(inode)) { + CDEBUG(D_INODE, "inode %ld has obdmd data\n"); + oa->o_obdflags |= OBD_FL_OBDMDEXISTS; + } +} /* obdfs_from_inode */ + +void inline obdfs_to_inode(struct inode *inode, struct obdo *oa) +{ + struct obdfs_inode_info *oinfo = OBDFS_INFO(inode); + + CDEBUG(D_INODE, "inode %ld (%p)\n", inode->i_ino, inode); + obdo_to_inode(inode, oa); + if (obdo_has_inline(oa)) { + CDEBUG(D_INODE, "obdo has inline data\n"); + memcpy(oinfo->oi_inline, oa->o_inline, OBD_INLINESZ); + oinfo->oi_flags |= OBD_FL_INLINEDATA; + } + if (obdo_has_obdmd(oa)) { + CDEBUG(D_INODE, "obdo has obdmd data\n"); + oinfo->oi_flags |= OBD_FL_OBDMDEXISTS; + } +} /* obdfs_to_inode */ /* all filling in of inodes postponed until lookup */ -static void obdfs_read_inode(struct inode *inode) +void obdfs_read_inode(struct inode *inode) { - struct iattr attr; - int error; - struct obdfs_sb_info *sbi = inode->i_sb->u.generic_sbp; + 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 = sbi->osi_ops->o_getattr(sbi->osi_conn_info.conn_id, - inode->i_ino, &attr); - if (error) { - printk("obdfs_read_inode: ibd_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; } - inode_setattr(inode, &attr); - inode->i_op = &obdfs_inode_ops; - return; -} + ODEBUG(oa); + obdfs_to_inode(inode, oa); + INIT_LIST_HEAD(&OBDFS_LIST(inode)); -static void inode_to_iattr(struct inode *inode, struct iattr *tmp) -{ - 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; -} + 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)) + inode->i_op = &obdfs_dir_inode_operations; + else if (S_ISLNK(inode->i_mode)) + inode->i_op = &obdfs_symlink_inode_operations; + else + init_special_inode(inode, inode->i_mode, + ((long *)OBDFS_INFO(inode)->oi_inline)[0]); + + EXIT; + return; +} /* obdfs_read_inode */ static void obdfs_write_inode(struct inode *inode) { - struct obdfs_sb_info *sbi; - struct iattr attr; - int error; + struct obdo *oa; + int err; - inode_to_iattr(inode, &attr); - sbi = inode->i_sb->u.generic_sbp; - error = sbi->osi_ops->o_setattr(sbi->osi_conn_info.conn_id, - inode->i_ino, &attr); - if (error) { - printk("obdfs_write_inode: ibd_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_FLOBDMD; + 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) { - struct obdfs_sb_info *sbi; - int error; + struct obdo *oa; + int err; ENTRY; - sbi = inode->i_sb->u.generic_sbp; - error = sbi->osi_ops->o_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(); + oa->o_valid = ~OBD_MD_FLOBDMD; + 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 obdfs_sb_info * sbi; - int error; + struct obdo *oa; + int err; ENTRY; + oa = obdo_alloc(); + if ( !oa ) { + printk("obdfs_notify_change: obdo_alloc failed\n"); + return -ENOMEM; + } - sbi = inode->i_sb->u.generic_sbp; - error = sbi->osi_ops->o_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; + 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 { - inode_setattr(inode, iattr); + /* 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; } - EXIT; - return error; -} + + obdo_free(oa); + return err; +} /* obdfs_notify_change */ 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 = sbi->osi_ops->o_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