Whamcloud - gitweb
Lproc-snmp code drop
[fs/lustre-release.git] / lustre / mds / handler.c
index cb340bc..6bd5e0c 100644 (file)
 #include <linux/init.h>
 #include <linux/obd_class.h>
 #include <linux/random.h>
+#include <linux/locks.h>
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 #include <linux/buffer_head.h>
 #endif
+#include <linux/lprocfs_status.h>
 
 static kmem_cache_t *mds_file_cache;
 
-extern int mds_get_lovtgts(struct obd_device *obd, int tgt_count,
+extern int mds_get_lovtgts(struct mds_obd *obd, int tgt_count,
                            obd_uuid_t *uuidarray);
-extern int mds_get_lovdesc(struct obd_device *obd, struct lov_desc *desc);
+extern int mds_get_lovdesc(struct mds_obd  *obd, struct lov_desc *desc);
 extern int mds_update_last_rcvd(struct mds_obd *mds, void *handle,
                                 struct ptlrpc_request *req);
 static int mds_cleanup(struct obd_device * obddev);
 
+extern lprocfs_vars_t status_var_nm_1[];
+extern lprocfs_vars_t status_class_var[];
+
 inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
 {
         return &req->rq_export->exp_obd->u.mds;
@@ -139,7 +144,7 @@ struct dentry *mds_name2locked_dentry(struct obd_device *obd,
                                       int dir_lock_mode)
 {
         struct dentry *dchild;
-        int flags, rc;
+        int flags = 0, rc;
         __u64 res_id[3] = {0};
         ENTRY;
 
@@ -160,6 +165,7 @@ struct dentry *mds_name2locked_dentry(struct obd_device *obd,
                 RETURN(dchild);
 
         res_id[0] = dchild->d_inode->i_ino;
+        res_id[1] = dchild->d_inode->i_generation;
         rc = ldlm_match_or_enqueue(NULL, NULL, obd->obd_namespace, NULL,
                                    res_id, LDLM_PLAIN, NULL, 0, lock_mode,
                                    &flags, ldlm_completion_ast,
@@ -179,7 +185,7 @@ struct dentry *mds_fid2locked_dentry(struct obd_device *obd, struct ll_fid *fid,
 {
         struct mds_obd *mds = &obd->u.mds;
         struct dentry *de = mds_fid2dentry(mds, fid, mnt), *retval = de;
-        int flags, rc;
+        int flags = 0, rc;
         __u64 res_id[3] = {0};
         ENTRY;
 
@@ -187,6 +193,7 @@ struct dentry *mds_fid2locked_dentry(struct obd_device *obd, struct ll_fid *fid,
                 RETURN(de);
 
         res_id[0] = de->d_inode->i_ino;
+        res_id[1] = de->d_inode->i_generation;
         rc = ldlm_match_or_enqueue(NULL, NULL, obd->obd_namespace, NULL,
                                    res_id, LDLM_PLAIN, NULL, 0, lock_mode,
                                    &flags, ldlm_completion_ast,
@@ -385,7 +392,7 @@ static int mds_disconnect(struct lustre_handle *conn)
                 }
         }
         spin_unlock(&med->med_open_lock);
-                                                       
+
         ldlm_cancel_locks_for_export(export);
         mds_client_free(export);
 
@@ -396,6 +403,23 @@ static int mds_disconnect(struct lustre_handle *conn)
         RETURN(rc);
 }
 
+/*
+ * XXX This is NOT guaranteed to flush all transactions to disk (even though
+ *     it is equivalent to calling sync()) because it only _starts_ the flush
+ *     and does not wait for completion.  It's better than nothing though.
+ *     What we really want is a mild form of fsync_dev_lockfs(), but it is
+ *     non-standard, or enabling do_sync_supers in ext3, just for this call.
+ */
+static void mds_fsync_super(struct super_block *sb)
+{
+        lock_kernel();
+        lock_super(sb);
+        if (sb->s_dirt && sb->s_op && sb->s_op->write_super)
+                sb->s_op->write_super(sb);
+        unlock_super(sb);
+        unlock_kernel();
+}
+
 static int mds_getstatus(struct ptlrpc_request *req)
 {
         struct mds_obd *mds = mds_req2mds(req);
@@ -410,7 +434,13 @@ static int mds_getstatus(struct ptlrpc_request *req)
                 RETURN(0);
         }
 
-        /* Anything we need to do here with the client's trans no or so? */
+        /* Flush any outstanding transactions to disk so the client will
+         * get the latest last_committed value and can drop their local
+         * requests if they have any.  This would be fsync_super() if it
+         * was exported.
+         */
+        mds_fsync_super(mds->mds_sb);
+
         body = lustre_msg_buf(req->rq_repmsg, 0);
         memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1));
 
@@ -442,7 +472,7 @@ static int mds_getlovinfo(struct ptlrpc_request *req)
         }
 
         desc = lustre_msg_buf(req->rq_repmsg, 0);
-        rc = mds_get_lovdesc(req->rq_obd, desc);
+        rc = mds_get_lovdesc(mds, desc);
         if (rc) {
                 CERROR("mds_get_lovdesc error %d", rc);
                 req->rq_status = rc;
@@ -458,7 +488,7 @@ static int mds_getlovinfo(struct ptlrpc_request *req)
 
         mds->mds_max_mdsize = sizeof(struct lov_mds_md) +
                 tgt_count * sizeof(struct lov_object_id);
-        rc = mds_get_lovtgts(req->rq_obd, tgt_count,
+        rc = mds_get_lovtgts(mds, tgt_count,
                              lustre_msg_buf(req->rq_repmsg, 1));
         if (rc) {
                 CERROR("get_lovtgts error %d\n", rc);
@@ -590,6 +620,7 @@ static int mds_getattr_name(int offset, struct ptlrpc_request *req)
 
         lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
         res_id[0] = dir->i_ino;
+        res_id[1] = dir->i_generation;
 
         rc = ldlm_lock_match(obd->obd_namespace, res_id, LDLM_PLAIN,
                              NULL, 0, lock_mode, &lockh);
@@ -981,7 +1012,7 @@ int mds_handle(struct ptlrpc_request *req)
         if (req->rq_reqmsg->opc != MDS_CONNECT && req->rq_export == NULL)
                 GOTO(out, rc = -ENOTCONN);
 
-        LASSERT(!strcmp(req->rq_obd->obd_type->typ_name, "mds"));
+        LASSERT(!strcmp(req->rq_obd->obd_type->typ_name, LUSTRE_MDT_NAME));
 
         switch (req->rq_reqmsg->opc) {
         case MDS_CONNECT:
@@ -1166,11 +1197,9 @@ static int mds_recover(struct obd_device *obddev)
         return rc;
 }
 
-#define MDS_NUM_THREADS 8
 /* mount the file system (secretly) */
 static int mds_setup(struct obd_device *obddev, obd_count len, void *buf)
 {
-        int i;
         struct obd_ioctl_data* data = buf;
         struct mds_obd *mds = &obddev->u.mds;
         struct vfsmount *mnt;
@@ -1193,6 +1222,7 @@ static int mds_setup(struct obd_device *obddev, obd_count len, void *buf)
                 GOTO(err_kfree, rc);
         }
 
+        CERROR("%s: mnt is %p\n", data->ioc_inlbuf1, mnt);
         mds->mds_sb = mnt->mnt_root->d_inode->i_sb;
         if (!mds->mds_sb)
                 GOTO(err_put, rc = -ENODEV);
@@ -1205,45 +1235,23 @@ static int mds_setup(struct obd_device *obddev, obd_count len, void *buf)
                 GOTO(err_put, rc);
         }
 
-        mds->mds_service = ptlrpc_init_svc(MDS_NEVENTS, MDS_NBUFS,
-                                           MDS_BUFSIZE, MDS_MAXREQSIZE,
-                                           MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
-                                           "self", mds_handle, "mds");
-        if (!mds->mds_service) {
-                CERROR("failed to start service\n");
-                GOTO(err_fs, rc = -EINVAL);
-        }
-
         obddev->obd_namespace =
                 ldlm_namespace_new("mds_server", LDLM_NAMESPACE_SERVER);
         if (obddev->obd_namespace == NULL) {
                 mds_cleanup(obddev);
-                GOTO(err_svc, rc = -ENOMEM);
+                GOTO(err_fs, rc = -ENOMEM);
         }
 
-        for (i = 0; i < MDS_NUM_THREADS; i++) {
-                char name[32];
-                sprintf(name, "lustre_MDS_%02d", i);
-                rc = ptlrpc_start_thread(obddev, mds->mds_service, name);
-                if (rc) {
-                        CERROR("cannot start MDS thread #%d: rc %d\n", i, rc);
-                        GOTO(err_thread, rc);
-                }
-        }
 
         rc = mds_recover(obddev);
         if (rc)
-                GOTO(err_thread, rc);
+                GOTO(err_fs, rc);
 
         ptlrpc_init_client(LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
                            "mds_ldlm_client", &obddev->obd_ldlm_client);
 
         RETURN(0);
 
-err_thread:
-        ptlrpc_stop_all_threads(mds->mds_service);
-err_svc:
-        ptlrpc_unregister_service(mds->mds_service);
 err_fs:
         mds_fs_cleanup(obddev);
 err_put:
@@ -1265,9 +1273,6 @@ static int mds_cleanup(struct obd_device *obddev)
         struct obd_run_ctxt saved;
         ENTRY;
 
-        ptlrpc_stop_all_threads(mds->mds_service);
-        ptlrpc_unregister_service(mds->mds_service);
-
         sb = mds->mds_sb;
         if (!mds->mds_sb)
                 RETURN(0);
@@ -1415,7 +1420,6 @@ static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
                         }
                 }
 
-
                 if (flags & LDLM_FL_INTENT_ONLY) {
                         LDLM_DEBUG(lock, "INTENT_ONLY, aborting lock");
                         RETURN(ELDLM_LOCK_ABORTED);
@@ -1423,6 +1427,7 @@ static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
                 /* Give the client a lock on the child object, instead of the
                  * parent that it requested. */
                 new_resid[0] = NTOH__u32(mds_rep->ino);
+                new_resid[1] = NTOH__u32(mds_rep->generation);
                 if (new_resid[0] == 0)
                         LBUG();
                 old_res = lock->l_resource->lr_name[0];
@@ -1447,12 +1452,82 @@ static int ldlm_intent_policy(struct ldlm_lock *lock, void *req_cookie,
         RETURN(rc);
 }
 
+int mds_attach(struct obd_device *dev, 
+               obd_count len, void *data)
+{
+        int rc;
+        rc = lprocfs_reg_obd(dev, (lprocfs_vars_t*)status_var_nm_1, (void*)dev);
+        return rc; 
+}
+
+int mds_detach(struct obd_device *dev)
+{
+        int rc;
+        rc = lprocfs_dereg_obd(dev);
+        return rc;
+
+}
+
+#define MDT_NUM_THREADS 8
+static int mdt_setup(struct obd_device *obddev, obd_count len, void *buf)
+{
+        int i;
+        //        struct obd_ioctl_data* data = buf;
+        struct mds_obd *mds = &obddev->u.mds;
+        int rc = 0;
+        ENTRY;
+
+        MOD_INC_USE_COUNT;
+
+        mds->mds_service = ptlrpc_init_svc(MDS_NEVENTS, MDS_NBUFS,
+                                           MDS_BUFSIZE, MDS_MAXREQSIZE,
+                                           MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
+                                           "self", mds_handle, "mds");
+        if (!mds->mds_service) {
+                CERROR("failed to start service\n");
+                GOTO(err_dec, rc = -EINVAL);
+        }
+
+        for (i = 0; i < MDT_NUM_THREADS; i++) {
+                char name[32];
+                sprintf(name, "lustre_MDT_%02d", i);
+                rc = ptlrpc_start_thread(obddev, mds->mds_service, name);
+                if (rc) {
+                        CERROR("cannot start MDT thread #%d: rc %d\n", i, rc);
+                        GOTO(err_thread, rc);
+                }
+        }
+
+        RETURN(0);
+
+err_thread:
+        ptlrpc_stop_all_threads(mds->mds_service);
+        ptlrpc_unregister_service(mds->mds_service);
+err_dec:
+        MOD_DEC_USE_COUNT;
+        RETURN(rc);
+}
+
+
+static int mdt_cleanup(struct obd_device *obddev)
+{
+        struct mds_obd *mds = &obddev->u.mds;
+        ENTRY;
+
+        ptlrpc_stop_all_threads(mds->mds_service);
+        ptlrpc_unregister_service(mds->mds_service);
+
+        MOD_DEC_USE_COUNT;
+        RETURN(0);
+}
 
 extern int mds_iocontrol(long cmd, struct lustre_handle *conn,
                          int len, void *karg, void *uarg);
 
 /* use obd ops to offer management infrastructure */
 static struct obd_ops mds_obd_ops = {
+        o_attach:      mds_attach,
+        o_detach:      mds_detach,
         o_connect:     mds_connect,
         o_disconnect:  mds_disconnect,
         o_setup:       mds_setup,
@@ -1460,25 +1535,41 @@ static struct obd_ops mds_obd_ops = {
         o_iocontrol:   mds_iocontrol
 };
 
+static struct obd_ops mdt_obd_ops = {
+        o_setup:       mdt_setup,
+        o_cleanup:     mdt_cleanup,
+};
+
+
 static int __init mds_init(void)
 {
+     
         mds_file_cache = kmem_cache_create("ll_mds_file_data",
                                            sizeof(struct mds_file_data),
                                            0, 0, NULL, NULL);
         if (mds_file_cache == NULL)
                 return -ENOMEM;
 
-        class_register_type(&mds_obd_ops, LUSTRE_MDS_NAME);
+        class_register_type(&mds_obd_ops, (lprocfs_vars_t*)status_class_var, 
+                            LUSTRE_MDS_NAME);
+        class_register_type(&mdt_obd_ops, 0, LUSTRE_MDT_NAME);
+
         ldlm_register_intent(ldlm_intent_policy);
+        
         return 0;
+        
 }
 
 static void __exit mds_exit(void)
 {
+        
+        
         ldlm_unregister_intent();
         class_unregister_type(LUSTRE_MDS_NAME);
+        class_unregister_type(LUSTRE_MDT_NAME);
         if (kmem_cache_destroy(mds_file_cache))
                 CERROR("couldn't free MDS file cache\n");
+        
 }
 
 MODULE_AUTHOR("Cluster File Systems <info@clusterfs.com>");