Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 6f2f035..2e35988 100644 (file)
@@ -923,6 +923,7 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                 LDLM_LOCK_PUT(lock);
                 rc = 0;
         } else {
+                struct md_attr *ma = &info->mti_attr;
 relock:
                 mdt_lock_handle_init(lhc);
                 mdt_lock_reg_init(lhc, LCK_PR);
@@ -932,6 +933,23 @@ relock:
                                         &child->mot_obj.mo_lu,
                                         "Object doesn't exist!\n");
                 }
+
+                ma->ma_valid = 0;
+                ma->ma_need = MA_INODE;
+                rc = mo_attr_get(info->mti_env, next, ma);
+                if (unlikely(rc != 0))
+                        GOTO(out_child, rc);
+
+                /* If the file has not been changed for some time, we return
+                 * not only a LOOKUP lock, but also an UPDATE lock and this
+                 * might save us RPC on later STAT. For directories, it also
+                 * let negative dentry starts working for this dir. */
+                if (ma->ma_valid & MA_INODE &&
+                    ma->ma_attr.la_valid & LA_CTIME &&
+                    info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
+                    ma->ma_attr.la_ctime < cfs_time_current_sec())
+                        child_bits |= MDS_INODELOCK_UPDATE;
+
                 rc = mdt_object_lock(info, child, lhc, child_bits,
                                      MDT_CROSS_LOCK);
 
@@ -1190,7 +1208,7 @@ static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
         ma->ma_attr.la_valid = LA_MODE;
         ma->ma_valid = MA_INODE;
 
-        kmap(page);
+        cfs_kmap(page);
         dp = page_address(page);
         offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
 
@@ -1233,7 +1251,7 @@ static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
         }
         EXIT;
 out:
-        kunmap(page);
+        cfs_kunmap(page);
         return rc;
 }
 
@@ -1320,7 +1338,7 @@ static int mdt_writepage(struct mdt_thread_info *info)
 cleanup_lwi:
         OBD_FREE_PTR(lwi);
 cleanup_page:
-        __cfs_free_page(page);
+        cfs_free_page(page);
 desc_cleanup:
         ptlrpc_free_bulk(desc);
         RETURN(rc);
@@ -1381,7 +1399,7 @@ free_rdpg:
 
         for (i = 0; i < rdpg->rp_npages; i++)
                 if (rdpg->rp_pages[i] != NULL)
-                        __cfs_free_page(rdpg->rp_pages[i]);
+                        cfs_free_page(rdpg->rp_pages[i]);
         OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
 
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
@@ -2205,9 +2223,35 @@ static void mdt_thread_info_fini(struct mdt_thread_info *info)
         info->mti_env = NULL;
 }
 
-/* mds/handler.c */
-extern int mds_filter_recovery_request(struct ptlrpc_request *req,
-                                       struct obd_device *obd, int *process);
+static int mdt_filter_recovery_request(struct ptlrpc_request *req,
+                                       struct obd_device *obd, int *process)
+{
+        switch (lustre_msg_get_opc(req->rq_reqmsg)) {
+        case MDS_CONNECT: /* This will never get here, but for completeness. */
+        case OST_CONNECT: /* This will never get here, but for completeness. */
+        case MDS_DISCONNECT:
+        case OST_DISCONNECT:
+               *process = 1;
+               RETURN(0);
+
+        case MDS_CLOSE:
+        case MDS_DONE_WRITING:
+        case MDS_SYNC: /* used in unmounting */
+        case OBD_PING:
+        case MDS_REINT:
+        case SEQ_QUERY:
+        case FLD_QUERY:
+        case LDLM_ENQUEUE:
+                *process = target_queue_recovery_request(req, obd);
+                RETURN(0);
+
+        default:
+                DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
+                *process = -EAGAIN;
+                RETURN(0);
+        }
+}
+
 /*
  * Handle recovery. Return:
  *        +1: continue request processing;
@@ -2285,7 +2329,7 @@ static int mdt_recovery(struct mdt_thread_info *info)
                 int rc;
                 int should_process;
                 DEBUG_REQ(D_INFO, req, "Got new replay");
-                rc = mds_filter_recovery_request(req, obd, &should_process);
+                rc = mdt_filter_recovery_request(req, obd, &should_process);
                 if (rc != 0 || !should_process)
                         RETURN(rc);
                 else if (should_process < 0) {
@@ -2312,8 +2356,84 @@ static int mdt_reply(struct ptlrpc_request *req, int rc,
         RETURN(0);
 }
 
-/* mds/handler.c */
-extern int mds_msg_check_version(struct lustre_msg *msg);
+static int mdt_msg_check_version(struct lustre_msg *msg)
+{
+        int rc;
+
+        switch (lustre_msg_get_opc(msg)) {
+        case MDS_CONNECT:
+        case MDS_DISCONNECT:
+        case OBD_PING:
+        case SEC_CTX_INIT:
+        case SEC_CTX_INIT_CONT:
+        case SEC_CTX_FINI:
+                rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
+                if (rc)
+                        CERROR("bad opc %u version %08x, expecting %08x\n",
+                               lustre_msg_get_opc(msg),
+                               lustre_msg_get_version(msg),
+                               LUSTRE_OBD_VERSION);
+                break;
+        case MDS_GETSTATUS:
+        case MDS_GETATTR:
+        case MDS_GETATTR_NAME:
+        case MDS_STATFS:
+        case MDS_READPAGE:
+        case MDS_WRITEPAGE:
+        case MDS_IS_SUBDIR:
+        case MDS_REINT:
+        case MDS_CLOSE:
+        case MDS_DONE_WRITING:
+        case MDS_PIN:
+        case MDS_SYNC:
+        case MDS_GETXATTR:
+        case MDS_SETXATTR:
+        case MDS_SET_INFO:
+        case MDS_QUOTACHECK:
+        case MDS_QUOTACTL:
+        case QUOTA_DQACQ:
+        case QUOTA_DQREL:
+        case SEQ_QUERY:
+        case FLD_QUERY:
+                rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
+                if (rc)
+                        CERROR("bad opc %u version %08x, expecting %08x\n",
+                               lustre_msg_get_opc(msg),
+                               lustre_msg_get_version(msg),
+                               LUSTRE_MDS_VERSION);
+                break;
+        case LDLM_ENQUEUE:
+        case LDLM_CONVERT:
+        case LDLM_BL_CALLBACK:
+        case LDLM_CP_CALLBACK:
+                rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
+                if (rc)
+                        CERROR("bad opc %u version %08x, expecting %08x\n",
+                               lustre_msg_get_opc(msg),
+                               lustre_msg_get_version(msg),
+                               LUSTRE_DLM_VERSION);
+                break;
+        case OBD_LOG_CANCEL:
+        case LLOG_ORIGIN_HANDLE_CREATE:
+        case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
+        case LLOG_ORIGIN_HANDLE_READ_HEADER:
+        case LLOG_ORIGIN_HANDLE_CLOSE:
+        case LLOG_ORIGIN_HANDLE_DESTROY:
+        case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
+        case LLOG_CATINFO:
+                rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
+                if (rc)
+                        CERROR("bad opc %u version %08x, expecting %08x\n",
+                               lustre_msg_get_opc(msg),
+                               lustre_msg_get_version(msg),
+                               LUSTRE_LOG_VERSION);
+                break;
+        default:
+                CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
+                rc = -ENOTSUPP;
+        }
+        return rc;
+}
 
 static int mdt_handle0(struct ptlrpc_request *req,
                        struct mdt_thread_info *info,
@@ -2331,7 +2451,7 @@ static int mdt_handle0(struct ptlrpc_request *req,
         LASSERT(current->journal_info == NULL);
 
         msg = req->rq_reqmsg;
-        rc = mds_msg_check_version(msg);
+        rc = mdt_msg_check_version(msg);
         if (likely(rc == 0)) {
                 rc = mdt_recovery(info);
                 if (likely(rc == +1)) {
@@ -3489,7 +3609,6 @@ err_mdt_svc:
 static void mdt_stack_fini(const struct lu_env *env,
                            struct mdt_device *m, struct lu_device *top)
 {
-        struct lu_device        *d = top, *n;
         struct obd_device       *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
         struct lustre_cfg_bufs  *bufs;
         struct lustre_cfg       *lcfg;
@@ -3518,46 +3637,7 @@ static void mdt_stack_fini(const struct lu_env *env,
         top->ld_ops->ldo_process_config(env, top, lcfg);
         lustre_cfg_free(lcfg);
 
-        lu_site_purge(env, top->ld_site, ~0);
-        while (d != NULL) {
-                struct lu_device_type *ldt = d->ld_type;
-
-                /* each fini() returns next device in stack of layers
-                 * so we can avoid the recursion */
-                n = ldt->ldt_ops->ldto_device_fini(env, d);
-                lu_device_put(d);
-
-                /* switch to the next device in the layer */
-                d = n;
-        }
-        /* purge again. */
-        lu_site_purge(env, top->ld_site, ~0);
-
-        if (!list_empty(&top->ld_site->ls_lru) || top->ld_site->ls_total != 0) {
-                /*
-                 * Uh-oh, objects still exist.
-                 */
-                static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR);
-
-                lu_site_print(env, top->ld_site, &cookie, lu_cdebug_printer);
-        }
-
-        d = top;
-        while (d != NULL) {
-                struct obd_type *type;
-                struct lu_device_type *ldt = d->ld_type;
-
-                /* each free() returns next device in stack of layers
-                 * so we can avoid the recursion */
-                n = ldt->ldt_ops->ldto_device_free(env, d);
-                type = ldt->ldt_obd_type;
-                type->typ_refcnt--;
-                class_put_type(type);
-
-                /* switch to the next device in the layer */
-                d = n;
-        }
+        lu_stack_fini(env, top);
         m->mdt_child = NULL;
         m->mdt_bottom = NULL;
 }
@@ -3698,7 +3778,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
         m->mdt_identity_cache = NULL;
 
         if (m->mdt_namespace != NULL) {
-                ldlm_namespace_free(m->mdt_namespace, d->ld_obd->obd_force);
+                ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
                 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
         }
 
@@ -3712,7 +3792,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
         sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
 
         next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
-        del_timer(&m->mdt_ck_timer);
+        cfs_timer_disarm(&m->mdt_ck_timer);
         mdt_ck_thread_stop(m);
 
         /* finish the stack */
@@ -3911,9 +3991,8 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
                 GOTO(err_free_ns, rc);
         }
 
-        m->mdt_ck_timer.function = mdt_ck_timer_callback;
-        m->mdt_ck_timer.data = (unsigned long)m;
-        init_timer(&m->mdt_ck_timer);
+        cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
+
         rc = mdt_ck_thread_start(m);
         if (rc)
                 GOTO(err_free_ns, rc);
@@ -3951,12 +4030,12 @@ err_fs_cleanup:
         target_recovery_fini(obd);
         mdt_fs_cleanup(env, m);
 err_capa:
-        del_timer(&m->mdt_ck_timer);
+        cfs_timer_disarm(&m->mdt_ck_timer);
         mdt_ck_thread_stop(m);
 err_free_ns:
         upcall_cache_cleanup(m->mdt_identity_cache);
         m->mdt_identity_cache = NULL;
-        ldlm_namespace_free(m->mdt_namespace, 0);
+        ldlm_namespace_free(m->mdt_namespace, NULL, 0);
         obd->obd_namespace = m->mdt_namespace = NULL;
 err_fini_seq:
         mdt_seq_fini(env, m);
@@ -4204,7 +4283,8 @@ static int mdt_connect_internal(struct obd_export *exp,
 static int mdt_obd_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_connect_data *data,
+                           void *localdata)
 {
         struct mdt_thread_info *info;
         struct mdt_client_data *mcd;
@@ -4362,7 +4442,7 @@ static int mdt_init_export(struct obd_export *exp)
         struct mdt_export_data *med = &exp->exp_mdt_data;
         ENTRY;
 
-        INIT_LIST_HEAD(&med->med_open_head);
+        CFS_INIT_LIST_HEAD(&med->med_open_head);
         spin_lock_init(&med->med_open_lock);
         sema_init(&med->med_idmap_sem, 1);
         med->med_idmap = NULL;