Whamcloud - gitweb
Add module refcounts for filesystem interface modules.
authoradilger <adilger>
Mon, 22 Jul 2002 17:22:12 +0000 (17:22 +0000)
committeradilger <adilger>
Mon, 22 Jul 2002 17:22:12 +0000 (17:22 +0000)
Minor cleanups in MDS LOV handling (i.e. endianness, code duplication)

lustre/include/linux/lustre_idl.h
lustre/include/linux/lustre_mds.h
lustre/mdc/mdc_request.c
lustre/mds/handler.c
lustre/mds/mds_ext2.c
lustre/mds/mds_ext3.c
lustre/mds/mds_extN.c
lustre/mds/mds_fs.c
lustre/mds/mds_lov.c

index 7b3628e..097faf7 100644 (file)
@@ -294,7 +294,7 @@ struct ost_body {
 #define MDS_DISCONNECT 8
 #define MDS_GETSTATUS  9
 #define MDS_STATFS     10
-#define MDS_LOVINFO    11
+#define MDS_GETLOVINFO 11
 
 #define REINT_SETATTR  1
 #define REINT_CREATE   2
index da851e3..3ede83d 100644 (file)
@@ -189,6 +189,7 @@ extern int mds_client_add(struct mds_obd *mds, struct mds_client_data *mcd,
 
 /* mds/mds_fs.c */
 struct mds_fs_operations {
+        struct module *fs_owner;
         void   *(* fs_start)(struct inode *inode, int op);
         int     (* fs_commit)(struct inode *inode, void *handle);
         int     (* fs_setattr)(struct dentry *dentry, void *handle,
index be73b40..e0b8a97 100644 (file)
@@ -138,7 +138,7 @@ int mdc_getlovinfo(struct obd_device *obd, struct lustre_handle *mdc_connh,
 
         mdc_con2cl(mdc_connh, &cl, &connection, &rconn);
         req = ptlrpc_prep_req2(cl, connection, rconn,
-                               MDS_LOVINFO, 1, size, NULL);
+                               MDS_GETLOVINFO, 1, size, NULL);
         if (!req)
                 GOTO(out, rc = -ENOMEM);
 
@@ -347,7 +347,7 @@ int mdc_enqueue(struct lustre_handle *conn, int lock_type,
                 req->rq_replen = lustre_msg_size(3, repsize);
         } else if (it->it_op == IT_GETATTR || it->it_op == IT_RENAME ||
                    it->it_op == IT_OPEN || it->it_op == IT_SETATTR ||
-                   it->it_op == IT_LOOKUP) {
+                   it->it_op == IT_LOOKUP || it->it_op == IT_READLINK) {
                 size[2] = sizeof(struct mds_body);
                 size[3] = de->d_name.len + 1;
 
index 56c6226..5e205ee 100644 (file)
@@ -23,7 +23,8 @@
 #include <linux/module.h>
 #include <linux/lustre_mds.h>
 #include <linux/lustre_dlm.h>
-extern int mds_get_lovtgts(struct obd_device *obd, uuid_t *uuidarray);
+extern int mds_get_lovtgts(struct obd_device *obd, int tgt_count,
+                           uuid_t *uuidarray);
 extern int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc);
 extern int mds_update_last_rcvd(struct mds_obd *mds, void *handle,
                                 struct ptlrpc_request *req);
@@ -304,11 +305,12 @@ static int mds_getstatus(struct ptlrpc_request *req)
         RETURN(0);
 }
 
-static int mds_lovinfo(struct ptlrpc_request *req)
+static int mds_getlovinfo(struct ptlrpc_request *req)
 {
         struct mds_obd *mds = mds_req2mds(req);
         struct mds_status_req *streq;
         struct lov_desc *desc; 
+        int tgt_count;
         int rc, size[2] = {sizeof(*desc)};
         ENTRY;
 
@@ -327,21 +329,22 @@ static int mds_lovinfo(struct ptlrpc_request *req)
         desc = lustre_msg_buf(req->rq_repmsg, 0); 
         rc = mds_get_lovdesc(req->rq_obd, desc);
         if (rc != 0 ) { 
-                CERROR("get_lovdesc error %d", rc);
+                CERROR("mds_get_lovdesc error %d", rc);
                 req->rq_status = rc;
                 RETURN(0);
         }
 
-        if (desc->ld_tgt_count * sizeof(uuid_t) > streq->repbuf) { 
+        tgt_count = NTOH__u32(desc->ld_tgt_count);
+        if (tgt_count * sizeof(uuid_t) > streq->repbuf) {
                 CERROR("too many targets, enlarge client buffers\n");
                 req->rq_status = -ENOSPC;
                 RETURN(0);
         }
 
-        mds->mds_max_mdsize = sizeof(desc) + 
-                desc->ld_tgt_count * sizeof(uuid_t);
-        rc = mds_get_lovtgts(req->rq_obd, lustre_msg_buf(req->rq_repmsg, 1));
-        if (rc) { 
+        mds->mds_max_mdsize = sizeof(desc) + tgt_count * sizeof(uuid_t);
+        rc = mds_get_lovtgts(req->rq_obd, tgt_count,
+                             lustre_msg_buf(req->rq_repmsg, 1));
+        if (rc) {
                 CERROR("get_lovtgts error %d", rc);
                 req->rq_status = rc;
                 RETURN(0);
@@ -820,9 +823,9 @@ int mds_handle(struct ptlrpc_request *req)
                 rc = mds_getstatus(req);
                 break;
 
-        case MDS_LOVINFO:
-                CDEBUG(D_INODE, "lovinfo\n");
-                rc = mds_lovinfo(req);
+        case MDS_GETLOVINFO:
+                CDEBUG(D_INODE, "getlovinfo\n");
+                rc = mds_getlovinfo(req);
                 break;
 
         case MDS_GETATTR:
index b760102..d467998 100644 (file)
@@ -108,16 +108,17 @@ static int mds_ext2_journal_data(struct file *filp)
 }
 
 static struct mds_fs_operations mds_ext2_fs_ops = {
-        fs_start:       mds_ext2_start,
-        fs_commit:      mds_ext2_stop,
-        fs_setattr:     mds_ext2_setattr,
-        fs_set_objid:   mds_ext2_set_objid,
-        fs_get_objid:   mds_ext2_get_objid,
-        fs_readpage:    mds_ext2_readpage,
-        fs_delete_inode:mds_ext2_delete_inode,
-        cl_delete_inode:clear_inode,
-        fs_journal_data:mds_ext2_journal_data,
-        fs_set_last_rcvd:mds_ext2_set_last_rcvd,
+        fs_owner:               THIS_MODULE,
+        fs_start:               mds_ext2_start,
+        fs_commit:              mds_ext2_stop,
+        fs_setattr:             mds_ext2_setattr,
+        fs_set_objid:           mds_ext2_set_objid,
+        fs_get_objid:           mds_ext2_get_objid,
+        fs_readpage:            mds_ext2_readpage,
+        fs_delete_inode:        mds_ext2_delete_inode,
+        cl_delete_inode:        clear_inode,
+        fs_journal_data:        mds_ext2_journal_data,
+        fs_set_last_rcvd:       mds_ext2_set_last_rcvd,
 };
 
 static int __init mds_ext2_init(void)
index 3ee8489..ee9857d 100644 (file)
@@ -253,16 +253,17 @@ static int mds_ext3_journal_data(struct file *filp)
 }
 
 static struct mds_fs_operations mds_ext3_fs_ops = {
-        fs_start:       mds_ext3_start,
-        fs_commit:      mds_ext3_commit,
-        fs_setattr:     mds_ext3_setattr,
-        fs_set_objid:   mds_ext3_set_objid,
-        fs_get_objid:   mds_ext3_get_objid,
-        fs_readpage:    mds_ext3_readpage,
-        fs_delete_inode:mds_ext3_delete_inode,
-        cl_delete_inode:clear_inode,
-        fs_journal_data:mds_ext3_journal_data,
-        fs_set_last_rcvd:mds_ext3_set_last_rcvd,
+        fs_owner:               THIS_MODULE,
+        fs_start:               mds_ext3_start,
+        fs_commit:              mds_ext3_commit,
+        fs_setattr:             mds_ext3_setattr,
+        fs_set_objid:           mds_ext3_set_objid,
+        fs_get_objid:           mds_ext3_get_objid,
+        fs_readpage:            mds_ext3_readpage,
+        fs_delete_inode:        mds_ext3_delete_inode,
+        cl_delete_inode:        clear_inode,
+        fs_journal_data:        mds_ext3_journal_data,
+        fs_set_last_rcvd:       mds_ext3_set_last_rcvd,
 };
 
 static int __init mds_ext3_init(void)
index 25d3990..c3c50c5 100644 (file)
@@ -289,6 +289,7 @@ static int mds_extN_statfs(struct super_block *sb, struct statfs *sfs)
 }
 
 static struct mds_fs_operations mds_extN_fs_ops = {
+        fs_owner:               THIS_MODULE,
         fs_start:               mds_extN_start,
         fs_commit:              mds_extN_commit,
         fs_setattr:             mds_extN_setattr,
index 8f31965..171adf5 100644 (file)
@@ -391,19 +391,19 @@ void mds_unregister_fs_type(const char *name)
         /* unlock mds_fs_types list */
 }
 
-int mds_fs_setup(struct mds_obd *mds, struct vfsmount *mnt)
+struct mds_fs_operations *mds_fs_get_ops(char *fstype)
 {
         struct mds_fs_operations *fs_ops;
-        int rc;
 
-        if (!(fs_ops = mds_search_fs_type(mds->mds_fstype))) {
+        if (!(fs_ops = mds_search_fs_type(fstype))) {
                 char name[32];
+                int rc;
 
-                snprintf(name, sizeof(name) - 1, "mds_%s", mds->mds_fstype);
+                snprintf(name, sizeof(name) - 1, "mds_%s", fstype);
                 name[sizeof(name) - 1] = '\0';
 
                 if ((rc = request_module(name))) {
-                        fs_ops = mds_search_fs_type(mds->mds_fstype);
+                        fs_ops = mds_search_fs_type(fstype);
                         CDEBUG(D_INFO, "Loaded module '%s'\n", name);
                         if (!fs_ops)
                                 rc = -ENOENT;
@@ -411,11 +411,27 @@ int mds_fs_setup(struct mds_obd *mds, struct vfsmount *mnt)
 
                 if (rc) {
                         CERROR("Can't find MDS fs interface '%s'\n", name);
-                        RETURN(rc);
+                        RETURN(ERR_PTR(rc));
                 }
         }
+        __MOD_INC_USE_COUNT(fs_ops->fs_owner);
+
+        return fs_ops;
+}
+
+void mds_fs_put_ops(struct mds_fs_operations *fs_ops)
+{
+        __MOD_DEC_USE_COUNT(fs_ops->fs_owner);
+}
+
+int mds_fs_setup(struct mds_obd *mds, struct vfsmount *mnt)
+{
+        int rc;
+
+        mds->mds_fsops = mds_fs_get_ops(mds->mds_fstype);
+        if (IS_ERR(mds->mds_fsops))
+                RETURN(PTR_ERR(mds->mds_fsops));
 
-        mds->mds_fsops = fs_ops;
         mds->mds_vfsmnt = mnt;
 
         OBD_SET_CTXT_MAGIC(&mds->mds_ctxt);
@@ -438,7 +454,7 @@ int mds_fs_setup(struct mds_obd *mds, struct vfsmount *mnt)
          */
         OBD_ALLOC(mds->mds_sop, sizeof(*mds->mds_sop));
         if (!mds->mds_sop)
-                RETURN(-ENOMEM);
+                GOTO(out_dec, rc = -ENOMEM);
 
         memcpy(mds->mds_sop, mds->mds_sb->s_op, sizeof(*mds->mds_sop));
         mds->mds_fsops->cl_delete_inode = mds->mds_sop->delete_inode;
@@ -448,8 +464,14 @@ int mds_fs_setup(struct mds_obd *mds, struct vfsmount *mnt)
         rc = mds_fs_prep(mds);
 
         if (rc)
-                OBD_FREE(mds->mds_sop, sizeof(*mds->mds_sop));
+                GOTO(out_free, rc);
+
+        return 0;
 
+out_free:
+        OBD_FREE(mds->mds_sop, sizeof(*mds->mds_sop));
+out_dec:
+        mds_fs_put_ops(mds->mds_fsops);
         return rc;
 }
 
@@ -459,6 +481,7 @@ void mds_fs_cleanup(struct mds_obd *mds)
         mds_server_free_data(mds);
 
         OBD_FREE(mds->mds_sop, sizeof(*mds->mds_sop));
+        mds_fs_put_ops(mds->mds_fsops);
 }
 
 EXPORT_SYMBOL(mds_register_fs_type);
index 42fac10..1be342a 100644 (file)
 #include <linux/lustre_idl.h>
 #include <linux/obd_lov.h>
 
-int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc, 
+int mds_configure_lov(struct obd_device *obd, struct lov_desc *desc,
                       uuid_t *uuidarray)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct obd_run_ctxt saved;
         struct file *f;
-        loff_t off = 0;
-        int count;
+        int tgt_count;
         int rc;
         int i;
 
-        count = desc->ld_tgt_count;
-        lov_packdesc(desc); 
+        tgt_count = desc->ld_tgt_count;
+        lov_packdesc(desc);
 
         push_ctxt(&saved, &mds->mds_ctxt);
         f = filp_open("LOVDESC", O_CREAT|O_RDWR, 0644);
-        if (!f || IS_ERR(f)) { 
-                pop_ctxt(&saved); 
+        if (IS_ERR(f)) {
                 CERROR("Cannot open/create LOVDESC file\n");
-                RETURN(-EIO);
+                GOTO(out, rc = PTR_ERR(f));
         }
-        
-        rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &off); 
-        filp_close(f, 0);
-        if (rc != sizeof(*desc)) { 
-                pop_ctxt(&saved); 
+
+        rc = lustre_fwrite(f, (char *)desc, sizeof(*desc), &f->f_pos);
+        if (filp_close(f, 0))
+                CERROR("Error closing LOVDESC file\n");
+        if (rc != sizeof(*desc)) {
                 CERROR("Cannot open/create LOVDESC file\n");
-                RETURN(-EIO);
+                GOTO(out, rc = PTR_ERR(f));
         }
 
-        off = 0;
         f = filp_open("LOVTGTS", O_CREAT|O_RDWR, 0644);
-        if (!f || IS_ERR(f)) { 
-                pop_ctxt(&saved); 
-                CERROR("Cannot open/create LOVDESC file\n");
-                RETURN(-EIO);
+        if (IS_ERR(f)) {
+                CERROR("Cannot open/create LOVTGTS file\n");
+                GOTO(out, rc = PTR_ERR(f));
         }
 
-        for (i=0 ; i < count ; i++) { 
-                rc = lustre_fwrite(f, uuidarray[i], 
-                                   sizeof(uuidarray[i]), &off); 
-                if (rc != sizeof(uuidarray[i])) { 
+        rc = 0;
+        for (i = 0; i < tgt_count ; i++) {
+                rc = lustre_fwrite(f, uuidarray[i],
+                                   sizeof(uuidarray[i]), &f->f_pos);
+                if (rc != sizeof(uuidarray[i])) {
                         CERROR("cannot write LOV UUID %s (%d)\n",
                                uuidarray[i], i);
+                        if (rc >= 0)
+                                rc = -EIO;
                         break;
                 }
-                rc = 0; 
         }
-        filp_close(f, 0);
-        pop_ctxt(&saved); 
+        if (filp_close(f, 0))
+                CERROR("Error closing LOVTGTS file\n");
 
-        RETURN(rc); 
+out:
+        pop_ctxt(&saved);
+        RETURN(rc);
 }
 
 int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
@@ -81,105 +81,93 @@ int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc)
         struct mds_obd *mds = &obd->u.mds;
         struct obd_run_ctxt saved;
         struct file *f;
-        loff_t off = 0;
-        int rc, rc2;
+        int rc;
 
         push_ctxt(&saved, &mds->mds_ctxt);
         f = filp_open("LOVDESC", O_RDONLY, 0644);
-        if (!f || IS_ERR(f)) { 
+        if (!f || IS_ERR(f)) {
                 CERROR("Cannot open LOVDESC file\n");
-                pop_ctxt(&saved); 
+                pop_ctxt(&saved);
                 RETURN(-EIO);
         }
-        
-        rc = lustre_fread(f, (char *)desc, sizeof(*desc), &off); 
-        rc2 = filp_close(f, 0);
-        if (rc2) { 
-                CERROR("Error closing LOVDESC file %d\n", rc); 
-        }
-        if (rc != sizeof(*desc)) { 
+
+        rc = lustre_fread(f, (char *)desc, sizeof(*desc), &f->f_pos);
+        if (filp_close(f, 0))
+                CERROR("Error closing LOVDESC file\n");
+
+        if (rc != sizeof(*desc)) {
                 CERROR("Cannot read LOVDESC file\n");
-                pop_ctxt(&saved); 
+                pop_ctxt(&saved);
                 RETURN(-EIO);
         }
-        pop_ctxt(&saved); 
+        pop_ctxt(&saved);
 
-        RETURN(0); 
+        RETURN(0);
 }
 
-int mds_get_lovtgts(struct obd_device *obd, uuid_t *uuidarray)
+int mds_get_lovtgts(struct obd_device *obd, int tgt_count, uuid_t *uuidarray)
 {
         struct mds_obd *mds = &obd->u.mds;
         struct obd_run_ctxt saved;
-        struct lov_desc desc; 
         struct file *f;
-        loff_t off = 0;
         int rc;
         int rc2;
         int count;
 
-        rc = mds_get_lovdesc(obd, &desc); 
-        if (rc) { 
-                CERROR("cannot get descriptor\n"); 
-                RETURN(-EIO); 
-        }
-
         push_ctxt(&saved, &mds->mds_ctxt);
         f = filp_open("LOVTGTS", O_RDONLY, 0644);
-        if (!f || IS_ERR(f)) { 
+        if (IS_ERR(f)) {
                 CERROR("Cannot open LOVTGTS file\n");
-                pop_ctxt(&saved); 
-                RETURN(-EIO);
+                GOTO(out, rc = PTR_ERR(f));
         }
 
-        lov_unpackdesc(&desc); 
-        count = desc.ld_tgt_count;
-
-        off = 0;
-        rc = lustre_fread(f, (char *)uuidarray, count * sizeof(uuid_t), 
-                          &off); 
+        rc = lustre_fread(f, (char *)uuidarray, tgt_count * sizeof(uuid_t),
+                          &f->f_pos);
         rc2 = filp_close(f, 0);
-        if (rc2) { 
-                CERROR("Error closing LOVTGTS file %d\n", rc); 
-        }
-        if (rc != count * sizeof(uuid_t)) { 
-                CERROR("Error reading LOVTGTS file\n");
-                pop_ctxt(&saved); 
-                RETURN(-EIO);
+        if (rc2)
+                CERROR("Error closing LOVTGTS file: rc = %d\n", rc2);
+
+        if (rc != count * sizeof(uuid_t)) {
+                CERROR("Error reading LOVTGTS file: rc = %d\n", rc);
+                if (rc >= 0)
+                        rc = -EIO;
+                GOTO(out, rc);
         }
-        pop_ctxt(&saved); 
+        EXIT;
+out:
+        pop_ctxt(&saved);
 
-        RETURN(0); 
+        RETURN(rc);
 }
 
-int mds_iocontrol(long cmd, struct lustre_handle *conn, 
+int mds_iocontrol(long cmd, struct lustre_handle *conn,
                           int len, void *karg, void *uarg)
 {
         struct obd_device *obd = class_conn2obd(conn);
         struct obd_ioctl_data *data = karg;
-        struct lov_desc *desc; 
-        int count; 
-        int rc; 
+        struct lov_desc *desc;
+        int count;
+        int rc;
 
 
-        switch (cmd) { 
+        switch (cmd) {
         case OBD_IOC_LOV_CONFIG:
                 desc = (struct lov_desc *)data->ioc_inlbuf1;
-                if (sizeof(*desc) > data->ioc_inllen1) { 
+                if (sizeof(*desc) > data->ioc_inllen1) {
                         CERROR("descriptor size wrong\n");
-                        RETURN(-EINVAL); 
+                        RETURN(-EINVAL);
                 }
 
                 count = desc->ld_tgt_count;
-                if (sizeof(uuid_t) * count != data->ioc_inllen2) { 
+                if (sizeof(uuid_t) * count != data->ioc_inllen2) {
                         CERROR("UUID array size wrong\n");
-                        RETURN(-EINVAL); 
+                        RETURN(-EINVAL);
                 }
                 rc = mds_configure_lov(obd, desc, (uuid_t *)data->ioc_inlbuf2);
 
-                RETURN(rc); 
+                RETURN(rc);
         default:
-                RETURN(-EINVAL); 
+                RETURN(-EINVAL);
         }
 
         RETURN(0);