Whamcloud - gitweb
b=16890 a build fix for --disable-quota
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 5a1076e..aec469b 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -400,10 +400,22 @@ static void mdt_pack_size2body(struct mdt_thread_info *info,
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid)
 {
-        struct md_attr          *ma  = &info->mti_attr;
+        struct md_attr *ma = &info->mti_attr;
 
         LASSERT(ma->ma_valid & MA_INODE);
 
+        b->atime      = attr->la_atime;
+        b->mtime      = attr->la_mtime;
+        b->ctime      = attr->la_ctime;
+        b->mode       = attr->la_mode;
+        b->size       = attr->la_size;
+        b->blocks     = attr->la_blocks;
+        b->uid        = attr->la_uid;
+        b->gid        = attr->la_gid;
+        b->flags      = attr->la_flags;
+        b->nlink      = attr->la_nlink;
+        b->rdev       = attr->la_rdev;
+
         /*XXX should pack the reply body according to lu_valid*/
         b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID   |
                     OBD_MD_FLGID   | OBD_MD_FLTYPE  |
@@ -415,23 +427,12 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
         } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
                 /* means no objects are allocated on osts. */
                 LASSERT(!(ma->ma_valid & MA_LOV));
-                LASSERT(attr->la_blocks == 0);
+                /* just ignore blocks occupied by extend attributes on MDS */
+                b->blocks = 0;
                 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
                 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
         }
 
-        b->atime      = attr->la_atime;
-        b->mtime      = attr->la_mtime;
-        b->ctime      = attr->la_ctime;
-        b->mode       = attr->la_mode;
-        b->size       = attr->la_size;
-        b->blocks     = attr->la_blocks;
-        b->uid        = attr->la_uid;
-        b->gid        = attr->la_gid;
-        b->flags      = attr->la_flags;
-        b->nlink      = attr->la_nlink;
-        b->rdev       = attr->la_rdev;
-
         if (fid) {
                 b->fid1 = *fid;
                 b->valid |= OBD_MD_FLID;
@@ -447,6 +448,10 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
 
         if (info)
                 mdt_body_reverse_idmap(info, b);
+
+        if (b->valid & OBD_MD_FLSIZE)
+                CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
+                       PFID(fid), b->size);
 }
 
 static inline int mdt_body_has_lov(const struct lu_attr *la,
@@ -539,9 +544,6 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                         repbody->eadatasize = ma->ma_lmv_size;
                         repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
                 }
-                if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
-                        repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
-                }
         } else if (S_ISLNK(la->la_mode) &&
                    reqbody->valid & OBD_MD_LINKNAME) {
                 buffer->lb_buf = ma->ma_lmm;
@@ -1234,15 +1236,20 @@ static int mdt_sendpage(struct mdt_thread_info *info,
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
                 GOTO(abort_bulk, rc = 0);
 
-        timeout = (int) req->rq_deadline - cfs_time_current_sec();
-        if (timeout < 0)
-                CERROR("Req deadline already passed %lu (now: %lu)\n",
-                       req->rq_deadline, cfs_time_current_sec());
-        *lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(max(timeout, 1)),
-                                    cfs_time_seconds(1), NULL, NULL);
-        rc = l_wait_event(desc->bd_waitq, !ptlrpc_server_bulk_active(desc) ||
-                          exp->exp_failed || exp->exp_abort_active_req, lwi);
-        LASSERT (rc == 0 || rc == -ETIMEDOUT);
+        do {
+                timeout = (int) req->rq_deadline - cfs_time_current_sec();
+                if (timeout < 0)
+                        CERROR("Req deadline already passed %lu (now: %lu)\n",
+                               req->rq_deadline, cfs_time_current_sec());
+                *lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(max(timeout, 1)),
+                                            cfs_time_seconds(1), NULL, NULL);
+                rc = l_wait_event(desc->bd_waitq,
+                                  !ptlrpc_server_bulk_active(desc) ||
+                                  exp->exp_failed ||
+                                  exp->exp_abort_active_req, lwi);
+                LASSERT (rc == 0 || rc == -ETIMEDOUT);
+        } while ((rc == -ETIMEDOUT) &&
+                 (req->rq_deadline > cfs_time_current_sec()));
 
         if (rc == 0) {
                 if (desc->bd_success &&
@@ -1980,7 +1987,6 @@ static struct ldlm_callback_suite cbs = {
 static int mdt_enqueue(struct mdt_thread_info *info)
 {
         struct ptlrpc_request *req;
-        __u64 req_bits;
         int rc;
 
         /*
@@ -1990,17 +1996,6 @@ static int mdt_enqueue(struct mdt_thread_info *info)
         LASSERT(info->mti_dlm_req != NULL);
 
         req = mdt_info_req(info);
-
-        /*
-         * Lock without inodebits makes no sense and will oops later in
-         * ldlm. Let's check it now to see if we have wrong lock from client or
-         * bits get corrupted somewhere in mdt_intent_policy().
-         */
-        req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
-        /* This is disabled because we need to support liblustre flock.
-         * LASSERT(req_bits != 0);
-         */
-
         rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
                                   req, info->mti_dlm_req, &cbs);
         info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
@@ -2570,10 +2565,25 @@ static int mdt_req_handle(struct mdt_thread_info *info,
 
                 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
                 if (dlm_req != NULL) {
-                        if (info->mti_mdt->mdt_opts.mo_compat_resname)
-                                rc = mdt_lock_resname_compat(info->mti_mdt,
-                                                             dlm_req);
-                        info->mti_dlm_req = dlm_req;
+                        if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
+                                        LDLM_IBITS &&
+                                     dlm_req->lock_desc.l_policy_data.\
+                                        l_inodebits.bits == 0)) {
+                                /*
+                                 * Lock without inodebits makes no sense and
+                                 * will oops later in ldlm. If client miss to
+                                 * set such bits, do not trigger ASSERTION.
+                                 *
+                                 * For liblustre flock case, it maybe zero.
+                                 */
+                                rc = -EPROTO;
+                        } else {
+                                if (info->mti_mdt->mdt_opts.mo_compat_resname)
+                                        rc = mdt_lock_resname_compat(
+                                                                info->mti_mdt,
+                                                                dlm_req);
+                                info->mti_dlm_req = dlm_req;
+                        }
                 } else {
                         rc = -EFAULT;
                 }
@@ -2630,7 +2640,7 @@ static int mdt_req_handle(struct mdt_thread_info *info,
         if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
                 target_committed_to_req(req);
 
-        if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
+        if (unlikely(req_is_replay(req) &&
                      lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
                 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
                 LBUG();
@@ -2694,10 +2704,7 @@ static void mdt_thread_info_init(struct ptlrpc_request *req,
 
         info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
         info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
-        info->mti_mos[0] = NULL;
-        info->mti_mos[1] = NULL;
-        info->mti_mos[2] = NULL;
-        info->mti_mos[3] = NULL;
+        info->mti_mos = NULL;
 
         memset(&info->mti_attr, 0, sizeof(info->mti_attr));
         info->mti_body = NULL;
@@ -3413,6 +3420,8 @@ static int mdt_intent_reint(enum mdt_it_code opcode,
                   * checked here.
                   */
                 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
+                        LASSERTF(rc == 0, "Error occurred but lock handle "
+                                 "is still in use\n");
                         rep->lock_policy_res2 = 0;
                         rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
                         RETURN(rc);
@@ -3522,23 +3531,19 @@ static int mdt_intent_policy(struct ldlm_namespace *ns,
                 req_capsule_extend(pill, &RQF_LDLM_INTENT);
                 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
                 if (it != NULL) {
-                        const struct ldlm_request *dlmreq;
-                        __u64 req_bits;
-
                         rc = mdt_intent_opc(it->opc, info, lockp, flags);
                         if (rc == 0)
                                 rc = ELDLM_OK;
 
-                        /*
-                         * Lock without inodebits makes no sense and will oops
+                        /* Lock without inodebits makes no sense and will oops
                          * later in ldlm. Let's check it now to see if we have
-                         * wrong lock from client or bits get corrupted
-                         * somewhere in mdt_intent_opc().
-                         */
-                        dlmreq = info->mti_dlm_req;
-                        req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
-                        LASSERT(req_bits != 0);
-
+                         * ibits corrupted somewhere in mdt_intent_opc().
+                         * The case for client miss to set ibits has been
+                         * processed by others. */
+                        LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
+                                        lr_type == LDLM_IBITS,
+                                     info->mti_dlm_req->lock_desc.\
+                                        l_policy_data.l_inodebits.bits != 0));
                 } else
                         rc = err_serious(-EFAULT);
         } else {
@@ -3551,25 +3556,6 @@ static int mdt_intent_policy(struct ldlm_namespace *ns,
         RETURN(rc);
 }
 
-/*
- * Seq wrappers
- */
-static void mdt_seq_adjust(const struct lu_env *env,
-                          struct mdt_device *m, int lost)
-{
-        struct md_site *ms = mdt_md_site(m);
-        struct lu_seq_range out;
-        ENTRY;
-
-        LASSERT(ms && ms->ms_server_seq);
-        LASSERT(lost >= 0);
-        /* get extra seq from seq_server, moving it's range up */
-        while (lost-- > 0) {
-                seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env);
-        }
-        EXIT;
-}
-
 static int mdt_seq_fini(const struct lu_env *env,
                         struct mdt_device *m)
 {
@@ -4464,6 +4450,9 @@ static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
                         LCONSOLE_INFO("Disabling ACL\n");
                 }
 
+                if (!*p)
+                        break;
+
                 options = ++p;
         }
 }
@@ -5004,7 +4993,6 @@ static int mdt_obd_connect(const struct lu_env *env,
                            void *localdata)
 {
         struct mdt_thread_info *info;
-        struct lsd_client_data *lcd;
         struct obd_export      *lexp;
         struct lustre_handle    conn = { 0 };
         struct mdt_device      *mdt;
@@ -5033,28 +5021,25 @@ static int mdt_obd_connect(const struct lu_env *env,
 
         rc = mdt_connect_internal(lexp, mdt, data);
         if (rc == 0) {
-                OBD_ALLOC_PTR(lcd);
-                if (lcd != NULL) {
-                        struct mdt_thread_info *mti;
-                        mti = lu_context_key_get(&env->le_ctx,
-                                                 &mdt_thread_key);
-                        LASSERT(mti != NULL);
-                        mti->mti_exp = lexp;
-                        memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
-                        lexp->exp_target_data.ted_lcd = lcd;
-                        rc = mdt_client_new(env, mdt);
-                        if (rc == 0)
-                                mdt_export_stats_init(obd, lexp, localdata);
-                } else {
-                        rc = -ENOMEM;
-                }
+                struct mdt_thread_info *mti;
+                struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
+                LASSERT(lcd);
+                mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
+                LASSERT(mti != NULL);
+                mti->mti_exp = lexp;
+                memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
+                rc = mdt_client_new(env, mdt);
+                if (rc == 0)
+                        mdt_export_stats_init(obd, lexp, 0, localdata);
         }
 
 out:
-        if (rc != 0)
+        if (rc != 0) {
                 class_disconnect(lexp);
-        else
+                *exp = NULL;
+        } else {
                 *exp = lexp;
+        }
 
         RETURN(rc);
 }
@@ -5084,7 +5069,7 @@ static int mdt_obd_reconnect(const struct lu_env *env,
 
         rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
         if (rc == 0)
-                mdt_export_stats_init(obd, exp, localdata);
+                mdt_export_stats_init(obd, exp, 1, localdata);
 
         RETURN(rc);
 }
@@ -5201,7 +5186,10 @@ static int mdt_init_export(struct obd_export *exp)
         cfs_spin_lock(&exp->exp_lock);
         exp->exp_connecting = 1;
         cfs_spin_unlock(&exp->exp_lock);
-        rc = ldlm_init_export(exp);
+        rc = lut_client_alloc(exp);
+        if (rc == 0)
+                rc = ldlm_init_export(exp);
+
         if (rc)
                 CERROR("Error %d while initializing export\n", rc);
         RETURN(rc);
@@ -5219,13 +5207,13 @@ static int mdt_destroy_export(struct obd_export *exp)
 
         target_destroy_export(exp);
         ldlm_destroy_export(exp);
+        lut_client_free(exp);
 
         LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
         LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
         if (obd_uuid_equals(&exp->exp_client_uuid, &exp->exp_obd->obd_uuid))
                 RETURN(0);
 
-        lut_client_free(exp);
         RETURN(rc);
 }
 
@@ -5269,7 +5257,8 @@ static int mdt_upcall(const struct lu_env *env, struct md_device *md,
                                      m->mdt_max_mdsize, m->mdt_max_cookiesize);
                         mdt_allow_cli(m, CONFIG_SYNC);
                         if (data)
-                                (*(__u64 *)data) = m->mdt_lut.lut_mount_count;
+                                (*(__u64 *)data) =
+                                      m->mdt_lut.lut_obd->u.obt.obt_mount_count;
                         break;
                 case MD_NO_TRANS:
                         mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
@@ -5476,17 +5465,10 @@ static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
                  * fid, this is error to find remote object here
                  */
                 CERROR("nonlocal object "DFID"\n", PFID(fid));
-        } else if (rc == 0) {
-                rc = -ENOENT;
-                CDEBUG(D_IOCTL, "no such object: "DFID"\n", PFID(fid));
         } else {
                 version = mo_version_get(mti->mti_env, mdt_object_child(obj));
-                if (version < 0) {
-                        rc = (int)version;
-                } else {
-                        *(__u64 *)data->ioc_inlbuf2 = version;
-                        rc = 0;
-                }
+               *(__u64 *)data->ioc_inlbuf2 = version;
+                rc = 0;
         }
         mdt_object_unlock_put(mti, obj, lh, 1);
         RETURN(rc);
@@ -5549,16 +5531,12 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
 {
         struct lu_device *ld = md2lu_dev(mdt->mdt_child);
-        struct obd_device *obd = mdt2obd_dev(mdt);
 #ifdef HAVE_QUOTA_SUPPORT
+        struct obd_device *obd = mdt2obd_dev(mdt);
         struct md_device *next = mdt->mdt_child;
 #endif
-        int rc, lost;
+        int rc;
         ENTRY;
-        /* if some clients didn't participate in recovery then we can possibly
-         * lost sequence. Now we should increase sequence for safe value */
-        lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
-        mdt_seq_adjust(env, mdt, lost);
 
         rc = ld->ld_ops->ldo_recovery_complete(env, ld);
 #ifdef HAVE_QUOTA_SUPPORT