Whamcloud - gitweb
A mostly-fix for "mknod /mnt/lustre/foofo p". It doesn't fail outright
[fs/lustre-release.git] / lustre / llite / super.c
index 1f92883..cc1e655 100644 (file)
@@ -6,12 +6,7 @@
  * This code is issued under the GNU General Public License.
  * See the file COPYING in this distribution
  *
- * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
- * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
- * Copryright (C) 1999 Seagate Technology Inc.
- * Copryright (C) 2001 Mountain View Data, Inc.
  * Copryright (C) 2002 Cluster File Systems, Inc.
- *
  */
 
 #define DEBUG_SUBSYSTEM S_LLITE
@@ -36,7 +31,7 @@ static char *ll_read_opt(const char *opt, char *data)
         char *retval;
         ENTRY;
 
-        CDEBUG(D_INFO, "option: %s, data %s\n", opt, data);
+        CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
         if ( strncmp(opt, data, strlen(opt)) )
                 RETURN(NULL);
         if ( (value = strchr(data, '=')) == NULL )
@@ -67,7 +62,7 @@ static void ll_options(char *options, char **ost, char **mds)
         for (this_char = strtok (options, ",");
              this_char != NULL;
              this_char = strtok (NULL, ",")) {
-                CDEBUG(D_INFO, "this_char %s\n", this_char);
+                CDEBUG(D_SUPER, "this_char %s\n", this_char);
                 if ( (!*ost && (*ost = ll_read_opt("ost", this_char)))||
                      (!*mds && (*mds = ll_read_opt("mds", this_char))) )
                         continue;
@@ -75,16 +70,21 @@ static void ll_options(char *options, char **ost, char **mds)
         EXIT;
 }
 
+#ifndef log2
+#define log2(n) ffz(~(n))
+#endif
+
 static struct super_block * ll_read_super(struct super_block *sb,
                                           void *data, int silent)
 {
         struct inode *root = 0;
+        struct obd_device *obd;
         struct ll_sb_info *sbi;
         char *ost = NULL;
         char *mds = NULL;
-        int devno;
         int err;
         struct ll_fid rootfid;
+        struct statfs sfs;
         __u64 last_committed, last_rcvd;
         __u32 last_xid;
         struct ptlrpc_request *request = NULL;
@@ -113,86 +113,81 @@ static struct super_block * ll_read_super(struct super_block *sb,
                 GOTO(out_free, sb = NULL);
         }
 
-        devno = simple_strtoul(ost, NULL, 0);
-        if (devno >= MAX_OBD_DEVICES) {
-                CERROR("devno of %s too high\n", ost);
+        obd = class_uuid2obd(mds); 
+        if (!obd) {
+                CERROR("MDS %s: not setup or attached\n", mds);
                 GOTO(out_free, sb = NULL);
         }
 
-        sbi->ll_osc_conn.oc_dev = &obd_dev[devno];
-        err = obd_connect(&sbi->ll_osc_conn);
+#if 0
+        err = connmgr_connect(ptlrpc_connmgr, sbi->ll_mds_conn);
         if (err) {
-                CERROR("cannot connect to %s: rc = %d\n", ost, err);
-                GOTO(out_free, sb = NULL);
-        }
-
-        devno = simple_strtoul(mds, NULL, 0);
-        if (devno >= MAX_OBD_DEVICES) {
-                CERROR("devno of %s too high\n", mds);
-                GOTO(out_free, sb = NULL);
+                CERROR("cannot connect to MDS: rc = %d\n", err);
+                GOTO(out_rpc, sb = NULL);
         }
+#endif 
 
-        sbi->ll_mdc_conn.oc_dev = &obd_dev[devno];
-        err = obd_connect(&sbi->ll_mdc_conn);
+        err = obd_connect(&sbi->ll_mdc_conn, obd);
         if (err) {
                 CERROR("cannot connect to %s: rc = %d\n", mds, err);
                 GOTO(out_free, sb = NULL);
         }
+        sbi2mdc(sbi)->mdc_conn->c_level = LUSTRE_CONN_FULL;
 
-#if 0
-        err = connmgr_connect(ptlrpc_connmgr, sbi->ll_mds_conn);
+        obd = class_uuid2obd(ost);
+        if (!obd) {
+                CERROR("OST %s: not setup or attached\n", ost);
+                GOTO(out_mdc, sb = NULL);
+        }
+        err = obd_connect(&sbi->ll_osc_conn, obd);
         if (err) {
-                CERROR("cannot connect to MDS: rc = %d\n", err);
-                GOTO(out_rpc, sb = NULL);
+                CERROR("cannot connect to %s: rc = %d\n", ost, err);
+                GOTO(out_mdc, sb = NULL);
         }
-#endif 
-
-        sbi2mdc(sbi)->mdc_conn->c_level = LUSTRE_CONN_FULL;
 
         /* XXX: need to store the last_* values somewhere */
-        err = mdc_getstatus(&sbi->ll_mdc_conn,
-                            &rootfid, &last_committed, 
-                            &last_rcvd, &last_xid,
-                            &request);
+        err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
+                            &last_rcvd, &last_xid, &request);
         if (err) {
                 CERROR("cannot mds_connect: rc = %d\n", err);
-                GOTO(out_disc, sb = NULL);
+                GOTO(out_request, sb = NULL);
         }
-        CDEBUG(D_SUPER, "rootfid %ld\n", (unsigned long)rootfid.id);
+        CDEBUG(D_SUPER, "rootfid %Ld\n", (unsigned long long)rootfid.id);
         sbi->ll_rootino = rootfid.id;
 
-        sb->s_maxbytes = 1ULL << 36;
-        /* XXX get this with a get_info call (like we have in OBDFS),
-           this info call should return the blocksize of the MDS */
-        sb->s_blocksize = 4096;
-        sb->s_blocksize_bits = 12;
+        memset(&sfs, 0, sizeof(sfs));
+        err = mdc_statfs(&sbi->ll_mdc_conn, &sfs, &request);
+        sb->s_blocksize = sfs.f_bsize;
+        sb->s_blocksize_bits = log2(sfs.f_bsize);
         sb->s_magic = LL_SUPER_MAGIC;
+        sb->s_maxbytes = (1ULL << (32 + 9)) - sfs.f_bsize;
+        ptlrpc_req_finished(request);
+
         sb->s_op = &ll_super_operations;
 
         /* make root inode */
-        err = mdc_getattr(&sbi->ll_mdc_conn,
-                          sbi->ll_rootino, S_IFDIR,
+        err = mdc_getattr(&sbi->ll_mdc_conn, sbi->ll_rootino, S_IFDIR,
                           OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
         if (err) {
                 CERROR("mdc_getattr failed for root: rc = %d\n", err);
-                GOTO(out_mdc, sb = NULL);
+                GOTO(out_request, sb = NULL);
         }
 
         /* initialize committed transaction callback daemon */
-        spin_lock_init(&sbi->ll_commitcbd_lock); 
+        spin_lock_init(&sbi->ll_commitcbd_lock);
         init_waitqueue_head(&sbi->ll_commitcbd_waitq);
         init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
         sbi->ll_commitcbd_flags = 0;
         err = ll_commitcbd_setup(sbi);
         if (err) {
                 CERROR("failed to start commit callback daemon: rc = %d\n",err);
-                GOTO(out_mdc, sb = NULL);
+                GOTO(out_request, sb = NULL);
         }
 
         md.body = lustre_msg_buf(request->rq_repmsg, 0);
-        md.obdo = NULL;
+        md.md = NULL;
         root = iget4(sb, sbi->ll_rootino, NULL, &md);
-                     
+
         if (root) {
                 sb->s_root = d_alloc_root(root);
         } else {
@@ -212,12 +207,11 @@ out_dev:
 
 out_cdb:
         ll_commitcbd_cleanup(sbi);
-out_mdc:
-        obd_disconnect(&sbi->ll_mdc_conn);
-        obd_disconnect(&sbi->ll_osc_conn);
-out_disc:
+out_request:
         ptlrpc_free_req(request);
         obd_disconnect(&sbi->ll_osc_conn);
+out_mdc:
+        obd_disconnect(&sbi->ll_mdc_conn);
 out_free:
         OBD_FREE(sbi, sizeof(*sbi));
 
@@ -241,10 +235,10 @@ static void ll_put_super(struct super_block *sb)
 static void ll_clear_inode(struct inode *inode)
 {
         if (atomic_read(&inode->i_count) == 0) {
-                struct obdo *oa = ll_i2info(inode)->lli_obdo;
-                if (oa) {
-                        obdo_free(oa);
-                        ll_i2info(inode)->lli_obdo = NULL;
+                struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
+                if (md) {
+                        OBD_FREE(md, md->lmd_size); 
+                        ll_i2info(inode)->lli_smd = NULL;
                 }
                 if (ll_i2info(inode)->lli_symlink_name) {
                         OBD_FREE(ll_i2info(inode)->lli_symlink_name,
@@ -258,37 +252,40 @@ static void ll_delete_inode(struct inode *inode)
 {
         if (S_ISREG(inode->i_mode)) { 
                 int err;
-                struct obdo *oa;
-                oa = ll_i2info(inode)->lli_obdo;
-
-                if (!oa)
+                struct obdo oa;
+                struct lov_stripe_md *md = ll_i2info(inode)->lli_smd;
+               if (!md)
                         GOTO(out, -EINVAL);
 
-                if (oa->o_id == 0)
+                oa.o_id = md->lmd_object_id;
+                oa.o_easize = md->lmd_size;
+                if (oa.o_id == 0) { 
+                        CERROR("This really happens\n"); 
                         /* No obdo was ever created */
                         GOTO(out, 0);
+                }
 
-                err = obd_destroy(ll_i2obdconn(inode), oa);
-                CDEBUG(D_INODE, "obd destroy of %Ld error %d\n",
-                       (unsigned long long)oa->o_id, err);
+                err = obd_destroy(ll_i2obdconn(inode), &oa, md);
+                CDEBUG(D_SUPER, "obd destroy of %Ld error %d\n",
+                       md->lmd_object_id, err);
         }
 out:
         clear_inode(inode);
 }
 
-/* like inode_setattr, but doesn't mark the inode dirty */ 
+/* like inode_setattr, but doesn't mark the inode dirty */
 static int ll_attr2inode(struct inode * inode, struct iattr * attr, int trunc)
 {
         unsigned int ia_valid = attr->ia_valid;
         int error = 0;
 
-        if ((ia_valid & ATTR_SIZE) && trunc ) {
+        if ((ia_valid & ATTR_SIZE) && trunc) {
                 error = vmtruncate(inode, attr->ia_size);
                 if (error)
                         goto out;
-        } else if (ia_valid & ATTR_SIZE) { 
+        } else if (ia_valid & ATTR_SIZE)
                 inode->i_size = attr->ia_size;
-        }               
 
         if (ia_valid & ATTR_UID)
                 inode->i_uid = attr->ia_uid;
@@ -320,8 +317,7 @@ int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
         /* change incore inode */
         ll_attr2inode(inode, attr, do_trunc);
 
-        err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr,
-                          &request);
+        err = mdc_setattr(&sbi->ll_mdc_conn, inode, attr, &request);
         if (err)
                 CERROR("mdc_setattr fails (%d)\n", err);
 
@@ -332,95 +328,112 @@ int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
 
 int ll_setattr(struct dentry *de, struct iattr *attr)
 {
+        int rc = inode_change_ok(de->d_inode, attr);
+
+        if (rc)
+                return rc;
+
         return ll_inode_setattr(de->d_inode, attr, 1);
 }
 
-static int ll_statfs(struct super_block *sb, struct statfs *buf)
+static int ll_statfs(struct super_block *sb, struct statfs *sfs)
 {
-        struct statfs tmp;
-        int err;
+        struct ptlrpc_request *request = NULL;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        int rc;
         ENTRY;
 
-        err = obd_statfs(&ll_s2sbi(sb)->ll_osc_conn, &tmp);
-        if (err) {
-                CERROR("obd_statfs fails (%d)\n", err);
-                RETURN(err);
-        }
-        memcpy(buf, &tmp, sizeof(*buf));
-#if 0
-        err = mdc_statfs(&sbi->ll_mds_client, sbi->ll_mds_conn, &tmp,
-                          &request);
-        if (err) {
-                CERROR("obd_statfs fails (%d)\n", err);
-                RETURN(err);
+        memset(sfs, 0, sizeof(*sfs));
+        rc = mdc_statfs(&sbi->ll_mdc_conn, sfs, &request);
+        ptlrpc_req_finished(request);
+        if (rc)
+                CERROR("obd_statfs fails: rc = %d\n", rc);
+        else
+                CDEBUG(D_SUPER, "statfs shows blocks %ld/%ld objects %ld/%ld\n",
+                       sfs->f_bavail, sfs->f_blocks, sfs->f_files,sfs->f_ffree);
+
+        /* temporary until mds_statfs returns statfs info for all OSTs */
+        if (!rc) {
+                struct statfs obd_sfs;
+
+                rc = obd_statfs(&sbi->ll_osc_conn, &obd_sfs);
+                if (rc) {
+                        CERROR("obd_statfs fails: rc = %d\n", rc);
+                        GOTO(out, rc);
+                }
+                CDEBUG(D_SUPER, "obd_statfs returns blocks %ld/%ld, "
+                       "objects %ld/%ld\n",
+                       obd_sfs.f_bavail, obd_sfs.f_blocks,
+                       obd_sfs.f_ffree, obd_sfs.f_files);
+
+                sfs->f_bfree = obd_sfs.f_bfree;
+                sfs->f_bavail = obd_sfs.f_bavail;
+                sfs->f_blocks = obd_sfs.f_blocks;
+                if (obd_sfs.f_ffree < sfs->f_ffree)
+                        sfs->f_ffree = obd_sfs.f_ffree;
         }
-       if (tmp.f_files < buf->f_files)
-                buf->f_files = tmp.f_files;
-       if (tmp.f_ffree < buf->f_ffree)
-                buf->f_ffree = tmp.f_ffree;
-        buf->f_namelen = tmp.f_namelen;
-#endif
-        CDEBUG(D_SUPER, "statfs returns avail %ld\n", tmp.f_bavail);
 
-        RETURN(err);
+out:
+        RETURN(rc);
 }
 
-static void inline ll_to_inode(struct inode *dst, struct ll_inode_md *md)
+inline int ll_stripe_md_size(struct super_block *sb)
+{
+        struct mdc_obd *mdc = sbi2mdc(ll_s2sbi(sb));
+        return mdc->mdc_max_mdsize;
+}
+
+static void ll_to_inode(struct inode *dst, struct ll_inode_md *md)
 {
         struct mds_body *body = md->body;
         struct ll_inode_info *ii = ll_i2info(dst);
 
         /* core attributes first */
-        if ( body->valid & OBD_MD_FLID )
+        if (body->valid & OBD_MD_FLID)
                 dst->i_ino = body->ino;
-        if ( body->valid & OBD_MD_FLATIME ) 
+        if (body->valid & OBD_MD_FLATIME)
                 dst->i_atime = body->atime;
-        if ( body->valid & OBD_MD_FLMTIME ) 
+        if (body->valid & OBD_MD_FLMTIME)
                 dst->i_mtime = body->mtime;
-        if ( body->valid & OBD_MD_FLCTIME ) 
+        if (body->valid & OBD_MD_FLCTIME)
                 dst->i_ctime = body->ctime;
-        if ( body->valid & OBD_MD_FLSIZE ) 
+        if (body->valid & OBD_MD_FLSIZE)
                 dst->i_size = body->size;
-        if ( body->valid & OBD_MD_FLMODE ) 
+        if (body->valid & OBD_MD_FLMODE)
                 dst->i_mode = body->mode;
-        if ( body->valid & OBD_MD_FLUID ) 
+        if (body->valid & OBD_MD_FLUID)
                 dst->i_uid = body->uid;
-        if ( body->valid & OBD_MD_FLGID ) 
+        if (body->valid & OBD_MD_FLGID)
                 dst->i_gid = body->gid;
-        if ( body->valid & OBD_MD_FLFLAGS ) 
+        if (body->valid & OBD_MD_FLFLAGS)
                 dst->i_flags = body->flags;
-        if ( body->valid & OBD_MD_FLNLINK )
+        if (body->valid & OBD_MD_FLNLINK)
                 dst->i_nlink = body->nlink;
-        if ( body->valid & OBD_MD_FLGENER )
+        if (body->valid & OBD_MD_FLGENER)
                 dst->i_generation = body->generation;
-
-        /* this will become more elaborate for striping etc */ 
-        if (md->obdo != NULL && md->obdo->o_valid != 0) {
-                ii->lli_obdo = obdo_alloc();
-                memcpy(ii->lli_obdo, md->obdo, sizeof(*md->obdo));
-        }
-#if 0
-
-        if (obdo_has_inline(oa)) {
-                if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
-                    S_ISFIFO(inode->i_mode)) {
-                        obd_rdev rdev = *((obd_rdev *)oa->o_inline);
-                        CDEBUG(D_INODE,
-                               "copying device %x from obdo to inode\n", rdev);
-                        init_special_inode(inode, inode->i_mode, rdev);
-                } else {
-                        CDEBUG(D_INFO, "copying inline from obdo to inode\n");
-                        memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
+        if (body->valid & OBD_MD_FLRDEV)
+                dst->i_rdev = body->extra;
+        if (md && md->md && md->md->lmd_stripe_count) { 
+                struct lov_stripe_md *smd = md->md;
+                int size = ll_stripe_md_size(dst->i_sb);
+                if (md->md->lmd_size != size) { 
+                        CERROR("Striping metadata size error %ld\n",
+                               dst->i_ino); 
+                        LBUG();
+                }
+                OBD_ALLOC(ii->lli_smd, size);
+                if (!ii->lli_smd){ 
+                        CERROR("No memory for %d\n", size);
+                        LBUG();
                 }
-                oinfo->lli_flags |= OBD_FL_INLINEDATA;
+                memcpy(ii->lli_smd, smd, size);
         }
-#endif 
 } /* ll_to_inode */
 
-static inline void ll_read_inode2(struct inode *inode, void *opaque)
+static void ll_read_inode2(struct inode *inode, void *opaque)
 {
         struct ll_inode_md *md = opaque;
-        
+
         ENTRY;
         ll_to_inode(inode, md);
 
@@ -433,7 +446,7 @@ static inline void ll_read_inode2(struct inode *inode, void *opaque)
                 EXIT;
         } else if (S_ISDIR(inode->i_mode)) {
                 inode->i_op = &ll_dir_inode_operations;
-                inode->i_fop = &ll_dir_operations; 
+                inode->i_fop = &ll_dir_operations;
                 inode->i_mapping->a_ops = &ll_dir_aops;
                 EXIT;
         } else if (S_ISLNK(inode->i_mode)) {
@@ -464,7 +477,7 @@ struct file_system_type lustre_lite_fs_type = {
 
 static int __init init_lustre_lite(void)
 {
-        printk(KERN_INFO "Lustre Lite 0.0.1, braam@clusterfs.com\n");
+        printk(KERN_INFO "Lustre Lite 0.0.1, info@clusterfs.com\n");
         ll_file_data_slab = kmem_cache_create("ll_file_data",
                                               sizeof(struct ll_file_data), 0,
                                                SLAB_HWCACHE_ALIGN, NULL, NULL);
@@ -479,7 +492,7 @@ static void __exit exit_lustre_lite(void)
         kmem_cache_destroy(ll_file_data_slab);
 }
 
-MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
+MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
 MODULE_DESCRIPTION("Lustre Lite Client File System v1.0");
 MODULE_LICENSE("GPL");