Whamcloud - gitweb
use special macro for print time_t, cleanup in includes.
[fs/lustre-release.git] / lustre / mds / handler.c
index 4e16577..9c33a98 100644 (file)
@@ -289,7 +289,8 @@ static int mds_connect_internal(struct obd_export *exp,
         return 0;
 }
 
-static int mds_reconnect(struct obd_export *exp, struct obd_device *obd,
+static int mds_reconnect(const struct lu_env *env,
+                         struct obd_export *exp, struct obd_device *obd,
                          struct obd_uuid *cluuid,
                          struct obd_connect_data *data)
 {
@@ -312,7 +313,8 @@ static int mds_reconnect(struct obd_export *exp, struct obd_device *obd,
  */
 static int mds_connect(const struct lu_env *env,
                        struct lustre_handle *conn, struct obd_device *obd,
-                       struct obd_uuid *cluuid, struct obd_connect_data *data)
+                       struct obd_uuid *cluuid, struct obd_connect_data *data,
+                       void *localdata)
 {
         struct obd_export *exp;
         struct mds_export_data *med;
@@ -340,6 +342,8 @@ static int mds_connect(const struct lu_env *env,
         LASSERT(exp);
         med = &exp->exp_mds_data;
 
+        exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_NULL;
+
         rc = mds_connect_internal(exp, data);
         if (rc)
                 GOTO(out, rc);
@@ -351,7 +355,7 @@ static int mds_connect(const struct lu_env *env,
         memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
         med->med_mcd = mcd;
 
-        rc = mds_client_add(obd, exp, -1);
+        rc = mds_client_add(obd, exp, -1, localdata);
         GOTO(out, rc);
 
 out:
@@ -372,9 +376,9 @@ int mds_init_export(struct obd_export *exp)
 {
         struct mds_export_data *med = &exp->exp_mds_data;
 
-        INIT_LIST_HEAD(&med->med_open_head);
+        CFS_INIT_LIST_HEAD(&med->med_open_head);
         spin_lock_init(&med->med_open_lock);
-        
+
         spin_lock(&exp->exp_lock);
         exp->exp_connecting = 1;
         spin_unlock(&exp->exp_lock);
@@ -1066,7 +1070,7 @@ out_ucred:
 }
 
 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
-                          __u64 max_age)
+                          __u64 max_age, __u32 flags)
 {
         int rc;
 
@@ -1100,7 +1104,7 @@ static int mds_statfs(struct ptlrpc_request *req)
         /* We call this so that we can cache a bit - 1 jiffie worth */
         rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
                                                 size[REPLY_REC_OFF]),
-                            cfs_time_current_64() - HZ);
+                            cfs_time_current_64() - HZ, 0);
         if (rc) {
                 CERROR("mds_obd_statfs failed: rc %d\n", rc);
                 GOTO(out, rc);
@@ -1131,30 +1135,22 @@ static int mds_sync(struct ptlrpc_request *req, int offset)
         if (rc)
                 GOTO(out, rc);
 
-        if (body->fid1.id == 0) {
-                /* a fid of zero is taken to mean "sync whole filesystem" */
-                rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
-                GOTO(out, rc);
-        } else {
+        rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
+        if (rc == 0 && body->fid1.id != 0) {
                 struct dentry *de;
 
                 de = mds_fid2dentry(mds, &body->fid1, NULL);
                 if (IS_ERR(de))
                         GOTO(out, rc = PTR_ERR(de));
 
-                /* The file parameter isn't used for anything */
-                if (de->d_inode->i_fop && de->d_inode->i_fop->fsync)
-                        rc = de->d_inode->i_fop->fsync(NULL, de, 1);
-                if (rc == 0) {
-                        body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
-                                              sizeof(*body));
-                        mds_pack_inode2fid(&body->fid1, de->d_inode);
-                        mds_pack_inode2body(body, de->d_inode);
-                }
+                body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
+                                      sizeof(*body));
+                mds_pack_inode2fid(&body->fid1, de->d_inode);
+                mds_pack_inode2body(body, de->d_inode);
 
                 l_dput(de);
-                GOTO(out, rc);
         }
+        GOTO(out, rc);
 out:
         req->rq_status = rc;
         return 0;
@@ -1630,6 +1626,7 @@ int mds_handle(struct ptlrpc_request *req)
                 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
                                              sizeof(*opcp));
                 __u32  opc;
+                int op = 0;
                 int size[4] = { sizeof(struct ptlrpc_body),
                                 sizeof(struct mds_body),
                                 mds->mds_max_mdsize,
@@ -1650,6 +1647,33 @@ int mds_handle(struct ptlrpc_request *req)
                           (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
                            reint_names[opc] == NULL) ? reint_names[opc] :
                                                        "unknown opcode");
+                switch (opc) {
+                case REINT_CREATE:
+                        op = PTLRPC_LAST_CNTR + MDS_REINT_CREATE;
+                        break;
+                case REINT_LINK:
+                        op = PTLRPC_LAST_CNTR + MDS_REINT_LINK;
+                        break;
+                case REINT_OPEN:
+                        op = PTLRPC_LAST_CNTR + MDS_REINT_OPEN;
+                        break;
+                case REINT_SETATTR:
+                        op = PTLRPC_LAST_CNTR + MDS_REINT_SETATTR;
+                        break;
+                case REINT_RENAME:
+                        op = PTLRPC_LAST_CNTR + MDS_REINT_RENAME;
+                        break;
+                case REINT_UNLINK:
+                        op = PTLRPC_LAST_CNTR + MDS_REINT_UNLINK;
+                        break;
+                default:
+                        op = 0;
+                        break;
+                }
+
+                if (op && req->rq_rqbd->rqbd_service->srv_stats)
+                        lprocfs_counter_incr(
+                                req->rq_rqbd->rqbd_service->srv_stats, op);
 
                 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_NET))
                         RETURN(0);
@@ -1675,6 +1699,7 @@ int mds_handle(struct ptlrpc_request *req)
                 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_NET))
                         RETURN(0);
                 rc = mds_close(req, REQ_REC_OFF);
+                fail = OBD_FAIL_MDS_CLOSE_NET_REP;
                 break;
 
         case MDS_DONE_WRITING:
@@ -1895,13 +1920,9 @@ static void fsoptions_to_mds_flags(struct mds_obd *mds, char *options)
 }
 static int mds_lov_presetup (struct mds_obd *mds, struct lustre_cfg *lcfg)
 {
-        int rc;
+        int rc = 0;
         ENTRY;
 
-        rc = llog_start_commit_thread();
-        if (rc < 0)
-                RETURN(rc);
-
         if (lcfg->lcfg_bufcount >= 4 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
                 class_uuid_t uuid;
 
@@ -1957,7 +1978,7 @@ static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
 
         /* We mounted in lustre_fill_super.
            lcfg bufs 1, 2, 4 (device, fstype, mount opts) are ignored.*/
-                
+
         lsi = s2lsi(lmi->lmi_sb);
         fsoptions_to_mds_flags(mds, lsi->lsi_ldd->ldd_mount_opts);
         fsoptions_to_mds_flags(mds, lsi->lsi_lmd->lmd_opts);
@@ -1991,8 +2012,15 @@ static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
             lprocfs_alloc_obd_stats(obd, LPROC_MDS_LAST) == 0) {
                 /* Init private stats here */
                 mds_stats_counter_init(obd->obd_stats);
-                obd->obd_proc_exports = proc_mkdir("exports",
-                                                   obd->obd_proc_entry);
+                obd->obd_proc_exports_entry = lprocfs_register("exports",
+                                                         obd->obd_proc_entry,
+                                                         NULL, NULL);
+                if (IS_ERR(obd->obd_proc_exports_entry)) {
+                        rc = PTR_ERR(obd->obd_proc_exports_entry);
+                        CERROR("error %d setting up lprocfs for %s\n",
+                               rc, "exports");
+                        obd->obd_proc_exports_entry = NULL;
+                }
         }
 
         rc = mds_fs_setup(obd, mnt);
@@ -2002,6 +2030,11 @@ static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                 GOTO(err_ns, rc);
         }
 
+        if (obd->obd_proc_exports_entry)
+                lprocfs_add_simple(obd->obd_proc_exports_entry,
+                                   "clear", lprocfs_nid_stats_clear_read,
+                                   lprocfs_nid_stats_clear_write, obd);
+
         rc = mds_lov_presetup(mds, lcfg);
         if (rc < 0)
                 GOTO(err_fs, rc);
@@ -2079,8 +2112,8 @@ err_fs:
         mds->mds_group_hash = NULL;
 #endif
 err_ns:
-        lprocfs_obd_cleanup(obd);
         lprocfs_free_obd_stats(obd);
+        lprocfs_obd_cleanup(obd);
         ldlm_namespace_free(obd->obd_namespace, 0);
         obd->obd_namespace = NULL;
 err_ops:
@@ -2129,12 +2162,12 @@ static int mds_postsetup(struct obd_device *obd)
         int rc = 0;
         ENTRY;
 
-        rc = llog_setup(obd, NULL, LLOG_CONFIG_ORIG_CTXT, obd, 0, NULL,
+        rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd, 0, NULL,
                         &llog_lvfs_ops);
         if (rc)
                 RETURN(rc);
 
-        rc = llog_setup(obd, NULL, LLOG_LOVEA_ORIG_CTXT, obd, 0, NULL,
+        rc = llog_setup(obd, &obd->obd_olg, LLOG_LOVEA_ORIG_CTXT, obd, 0, NULL,
                         &llog_lvfs_ops);
         if (rc)
                 RETURN(rc);
@@ -2174,7 +2207,8 @@ int mds_postrecov(struct obd_device *obd)
                 RETURN(0);
 
         LASSERT(!obd->obd_recovering);
-        LASSERT(llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT) != NULL);
+        LASSERT(!llog_ctxt_null(obd, LLOG_MDS_OST_ORIG_CTXT));
+
         /* clean PENDING dir */
         if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
                 rc = mds_cleanup_pending(obd);
@@ -2253,8 +2287,10 @@ static int mds_cleanup(struct obd_device *obd)
                    we just need to drop our ref */
                 class_export_put(mds->mds_osc_exp);
 
-        lprocfs_obd_cleanup(obd);
+        lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
+        lprocfs_free_per_client_stats(obd);
         lprocfs_free_obd_stats(obd);
+        lprocfs_obd_cleanup(obd);
 
         lquota_cleanup(mds_quota_interface_ref, obd);
 
@@ -2558,12 +2594,12 @@ static int mdt_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                 mds_max_threads = mds_min_threads = mds_num_threads;
         } else {
                 /* Base min threads on memory and cpus */
-                mds_min_threads = num_possible_cpus() * num_physpages >> 
+                mds_min_threads = num_possible_cpus() * num_physpages >>
                         (27 - CFS_PAGE_SHIFT);
                 if (mds_min_threads < MDS_THREADS_MIN)
                         mds_min_threads = MDS_THREADS_MIN;
                 /* Largest auto threads start value */
-                if (mds_min_threads > 32) 
+                if (mds_min_threads > 32)
                         mds_min_threads = 32;
                 mds_max_threads = min(MDS_THREADS_MAX, mds_min_threads * 4);
         }
@@ -2573,7 +2609,7 @@ static int mdt_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                                 MDS_MAXREPSIZE, MDS_REQUEST_PORTAL,
                                 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
                                 mds_handle, LUSTRE_MDS_NAME,
-                                obd->obd_proc_entry, NULL, 
+                                obd->obd_proc_entry, NULL,
                                 mds_min_threads, mds_max_threads, "ll_mdt", 0);
 
         if (!mds->mds_service) {
@@ -2607,7 +2643,7 @@ static int mdt_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                                 MDS_MAXREPSIZE, MDS_READPAGE_PORTAL,
                                 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
                                 mds_handle, "mds_readpage",
-                                obd->obd_proc_entry, NULL, 
+                                obd->obd_proc_entry, NULL,
                                 MDS_THREADS_MIN_READPAGE, mds_max_threads,
                                 "ll_mdt_rdpg", 0);
         if (!mds->mds_readpage_service) {
@@ -2621,7 +2657,7 @@ static int mdt_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                 GOTO(err_thread3, rc);
 
         ping_evictor_start();
-        
+
         RETURN(0);
 
 err_thread3: