Whamcloud - gitweb
LU-4008 mdt: update mdt_getattr comments about EA sizing
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 13ffb22..ccbf2a9 100644 (file)
@@ -262,7 +262,7 @@ static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o
         EXIT;
 }
 
-int mdt_getstatus(struct tgt_session_info *tsi)
+static int mdt_getstatus(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
        struct mdt_device       *mdt = info->mti_mdt;
@@ -306,7 +306,7 @@ out:
        return rc;
 }
 
-int mdt_statfs(struct tgt_session_info *tsi)
+static int mdt_statfs(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request           *req = tgt_ses_req(tsi);
        struct mdt_thread_info          *info = tsi2mdt_info(tsi);
@@ -617,8 +617,8 @@ int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o,
        return rc;
 }
 
-int mdt_attr_get_pfid(struct mdt_thread_info *info,
-                     struct mdt_object *o, struct lu_fid *pfid)
+static int mdt_attr_get_pfid(struct mdt_thread_info *info,
+                            struct mdt_object *o, struct lu_fid *pfid)
 {
        struct lu_buf           *buf = &info->mti_buf;
        struct link_ea_header   *leh;
@@ -1054,14 +1054,13 @@ static int mdt_renew_capa(struct mdt_thread_info *info)
         RETURN(rc);
 }
 
-int mdt_getattr(struct tgt_session_info *tsi)
+static int mdt_getattr(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
         struct mdt_object       *obj = info->mti_object;
         struct req_capsule      *pill = info->mti_pill;
         struct mdt_body         *reqbody;
         struct mdt_body         *repbody;
-        mode_t                   mode;
         int rc, rc2;
         ENTRY;
 
@@ -1079,8 +1078,10 @@ int mdt_getattr(struct tgt_session_info *tsi)
         LASSERT(obj != NULL);
        LASSERT(lu_object_assert_exists(&obj->mot_obj));
 
-       mode = lu_object_attr(&obj->mot_obj);
-
+       /* Unlike intent case where we need to pre-fill out buffers early on
+        * in intent policy for ldlm reasons, here we can have a much better
+        * guess at EA size by just reading it from disk.
+        * Exceptions are readdir and (missing) directory striping */
        /* Readlink */
        if (reqbody->valid & OBD_MD_LINKNAME) {
                /* No easy way to know how long is the symlink, but it cannot
@@ -1099,15 +1100,13 @@ int mdt_getattr(struct tgt_session_info *tsi)
                 * will reallocate */
                rc = DEF_REP_MD_SIZE;
        } else {
-               /* Hopefully no race in EA change for either file or directory?
-                */
+               /* Read the actual EA size from disk */
                rc = mdt_attr_get_eabuf_size(info, obj);
        }
 
        if (rc < 0)
                GOTO(out_shrink, rc);
 
-       /* old clients may not report needed easize, use max value then */
        req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, rc);
 
        rc = req_capsule_server_pack(pill);
@@ -1147,7 +1146,7 @@ out:
        return rc;
 }
 
-int mdt_is_subdir(struct tgt_session_info *tsi)
+static int mdt_is_subdir(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
         struct mdt_object     *o = info->mti_object;
@@ -1176,7 +1175,7 @@ int mdt_is_subdir(struct tgt_session_info *tsi)
        RETURN(rc);
 }
 
-int mdt_swap_layouts(struct tgt_session_info *tsi)
+static int mdt_swap_layouts(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info;
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
@@ -1333,88 +1332,36 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
         struct lu_name         *lname     = NULL;
         struct mdt_lock_handle *lhp       = NULL;
         struct ldlm_lock       *lock;
-        struct ldlm_res_id     *res_id;
-        int                     is_resent;
-        int                     ma_need = 0;
-        int                     rc;
-
-        ENTRY;
-
-        is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
-        LASSERT(ergo(is_resent,
-                     lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
+       bool                    is_resent;
+       bool                    try_layout;
+       int                     ma_need = 0;
+       int                     rc;
+       ENTRY;
 
-        LASSERT(parent != NULL);
+       is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
+       LASSERT(ergo(is_resent,
+                    lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
 
-       lname = &info->mti_name;
-       mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
+       LASSERT(parent != NULL);
 
-       if (!info->mti_cross_ref) {
-               /*
-                * XXX: Check for anonymous name is for getattr by fid
-                * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
-                * that is the name must contain at least one character and
-                * the terminating '\0'.
-                */
-               if (!lu_name_is_valid(lname)) {
-                       reqbody = req_capsule_client_get(info->mti_pill,
-                                                        &RMF_MDT_BODY);
-                       if (unlikely(reqbody == NULL))
-                               RETURN(err_serious(-EFAULT));
-
-                       if (unlikely(!fid_is_sane(&reqbody->fid2)))
-                               RETURN(err_serious(-EINVAL));
-
-                       CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
-                              "ldlm_rep = %p\n",
-                              PFID(mdt_object_fid(parent)),
-                              PFID(&reqbody->fid2), ldlm_rep);
+       if (info->mti_cross_ref) {
+               /* Only getattr on the child. Parent is on another node. */
+               mdt_set_disposition(info, ldlm_rep,
+                                   DISP_LOOKUP_EXECD | DISP_LOOKUP_POS);
+               child = parent;
+               CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
+                      "ldlm_rep = %p\n",
+                      PFID(mdt_object_fid(child)), ldlm_rep);
+
+               if (is_resent) {
+                       /* Do not take lock for resent case. */
+                       lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
+                       LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
+                                lhc->mlh_reg_lh.cookie);
+                       LASSERT(fid_res_name_eq(mdt_object_fid(child),
+                                               &lock->l_resource->lr_name));
+                       LDLM_LOCK_PUT(lock);
                } else {
-                       CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
-                              "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
-                              PNAME(lname), ldlm_rep);
-               }
-       }
-
-        mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
-
-       if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
-               LU_OBJECT_DEBUG(D_INODE, info->mti_env,
-                               &parent->mot_obj,
-                               "Parent doesn't exist!\n");
-               RETURN(-ESTALE);
-       } else if (!info->mti_cross_ref) {
-               LASSERTF(!mdt_object_remote(parent),
-                        "Parent "DFID" is on remote server\n",
-                        PFID(mdt_object_fid(parent)));
-       }
-
-       if (lu_name_is_valid(lname)) {
-                rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
-                if (rc != 0) {
-                        if (rc > 0)
-                                rc = 0;
-                        RETURN(rc);
-                }
-        }
-
-        if (info->mti_cross_ref) {
-                /* Only getattr on the child. Parent is on another node. */
-                mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-                child = parent;
-                CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
-                       "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
-
-                if (is_resent) {
-                        /* Do not take lock for resent case. */
-                        lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
-                        LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
-                                 lhc->mlh_reg_lh.cookie);
-                        LASSERT(fid_res_name_eq(mdt_object_fid(child),
-                                                &lock->l_resource->lr_name));
-                        LDLM_LOCK_PUT(lock);
-                        rc = 0;
-                } else {
                        mdt_lock_handle_init(lhc);
                        mdt_lock_reg_init(lhc, LCK_PR);
 
@@ -1428,27 +1375,74 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
 
                        rc = mdt_object_lock(info, child, lhc, child_bits,
                                             MDT_LOCAL_LOCK);
+                       if (rc < 0)
+                               RETURN(rc);
                }
-                if (rc == 0) {
-                        /* Finally, we can get attr for child. */
-                       if (!mdt_object_exists(child)) {
-                               LU_OBJECT_DEBUG(D_INFO, info->mti_env,
-                                               &child->mot_obj,
-                                            "remote object doesn't exist.\n");
-                                mdt_object_unlock(info, child, lhc, 1);
-                               RETURN(-ENOENT);
-                       }
 
-                        mdt_set_capainfo(info, 0, mdt_object_fid(child),
-                                         BYPASS_CAPA);
-                        rc = mdt_getattr_internal(info, child, 0);
-                        if (unlikely(rc != 0))
-                                mdt_object_unlock(info, child, lhc, 1);
-                }
+               /* Finally, we can get attr for child. */
+               if (!mdt_object_exists(child)) {
+                       LU_OBJECT_DEBUG(D_INFO, info->mti_env,
+                                       &child->mot_obj,
+                                       "remote object doesn't exist.\n");
+                       mdt_object_unlock(info, child, lhc, 1);
+                       RETURN(-ENOENT);
+               }
+
+               mdt_set_capainfo(info, 0, mdt_object_fid(child), BYPASS_CAPA);
+               rc = mdt_getattr_internal(info, child, 0);
+               if (unlikely(rc != 0))
+                       mdt_object_unlock(info, child, lhc, 1);
+
                 RETURN(rc);
         }
 
+       lname = &info->mti_name;
+       mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
+
        if (lu_name_is_valid(lname)) {
+               CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
+                      "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
+                      PNAME(lname), ldlm_rep);
+       } else {
+               reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
+               if (unlikely(reqbody == NULL))
+                       RETURN(err_serious(-EPROTO));
+
+               *child_fid = reqbody->fid2;
+
+               if (unlikely(!fid_is_sane(child_fid)))
+                       RETURN(err_serious(-EINVAL));
+
+               CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
+                      "ldlm_rep = %p\n",
+                      PFID(mdt_object_fid(parent)),
+                      PFID(&reqbody->fid2), ldlm_rep);
+       }
+
+       mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
+
+       if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
+               LU_OBJECT_DEBUG(D_INODE, info->mti_env,
+                               &parent->mot_obj,
+                               "Parent doesn't exist!\n");
+               RETURN(-ESTALE);
+       }
+
+       if (mdt_object_remote(parent)) {
+               CERROR("%s: parent "DFID" is on remote target\n",
+                      mdt_obd_name(info->mti_mdt),
+                      PFID(mdt_object_fid(parent)));
+               RETURN(-EIO);
+       }
+
+       if (lu_name_is_valid(lname)) {
+               rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
+               if (rc != 0) {
+                       if (rc > 0)
+                               rc = 0;
+                       RETURN(rc);
+               }
+
                /* step 1: lock parent only if parent is a directory */
                if (S_ISDIR(lu_object_attr(&parent->mot_obj))) {
                        lhp = &info->mti_lh[MDT_LH_PARENT];
@@ -1464,18 +1458,14 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                 fid_zero(child_fid);
                 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
                                 &info->mti_spec);
+               if (rc == -ENOENT)
+                       mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
 
-                if (rc != 0) {
-                        if (rc == -ENOENT)
-                                mdt_set_disposition(info, ldlm_rep,
-                                                    DISP_LOOKUP_NEG);
-                        GOTO(out_parent, rc);
-                } else
-                        mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-        } else {
-                *child_fid = reqbody->fid2;
-                mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-        }
+               if (rc != 0)
+                       GOTO(out_parent, rc);
+       }
+
+       mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
 
        /*
         *step 3: find the child object by fid & lock it.
@@ -1502,7 +1492,6 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
                         lhc->mlh_reg_lh.cookie);
 
-               res_id = &lock->l_resource->lr_name;
                if (!fid_res_name_eq(mdt_object_fid(child),
                                     &lock->l_resource->lr_name)) {
                        LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
@@ -1519,14 +1508,12 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                        GOTO(relock, 0);
                }
                LDLM_LOCK_PUT(lock);
-               rc = 0;
        } else {
-               bool try_layout = false;
-
 relock:
                 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
                 mdt_lock_handle_init(lhc);
                mdt_lock_reg_init(lhc, LCK_PR);
+               try_layout = false;
 
                if (!mdt_object_exists(child)) {
                        LU_OBJECT_DEBUG(D_INODE, info->mti_env,
@@ -1608,7 +1595,6 @@ relock:
                 mdt_object_unlock(info, child, lhc, 1);
        } else if (lock) {
                /* Debugging code. */
-               res_id = &lock->l_resource->lr_name;
                LDLM_DEBUG(lock, "Returning lock to client");
                LASSERTF(fid_res_name_eq(mdt_object_fid(child),
                                         &lock->l_resource->lr_name),
@@ -1631,7 +1617,7 @@ out_parent:
 }
 
 /* normal handler: should release the child lock */
-int mdt_getattr_name(struct tgt_session_info *tsi)
+static int mdt_getattr_name(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
         struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
@@ -1672,7 +1658,7 @@ out_shrink:
 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                          void *karg, void *uarg);
 
-int mdt_set_info(struct tgt_session_info *tsi)
+static int mdt_set_info(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        char                    *key;
@@ -1730,7 +1716,7 @@ int mdt_set_info(struct tgt_session_info *tsi)
        RETURN(rc);
 }
 
-int mdt_readpage(struct tgt_session_info *tsi)
+static int mdt_readpage(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = mdt_th_info(tsi->tsi_env);
        struct mdt_object       *object = mdt_obj(tsi->tsi_corpus);
@@ -1896,7 +1882,7 @@ static long mdt_reint_opcode(struct ptlrpc_request *req,
        return opc;
 }
 
-int mdt_reint(struct tgt_session_info *tsi)
+static int mdt_reint(struct tgt_session_info *tsi)
 {
        long opc;
        int  rc;
@@ -1960,7 +1946,7 @@ static int mdt_object_sync(struct mdt_thread_info *info)
         RETURN(rc);
 }
 
-int mdt_sync(struct tgt_session_info *tsi)
+static int mdt_sync(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        struct req_capsule      *pill = tsi->tsi_pill;
@@ -2006,7 +1992,7 @@ int mdt_sync(struct tgt_session_info *tsi)
  * Handle quota control requests to consult current usage/limit, but also
  * to configure quota enforcement
  */
-int mdt_quotactl(struct tgt_session_info *tsi)
+static int mdt_quotactl(struct tgt_session_info *tsi)
 {
        struct obd_export       *exp  = tsi->tsi_exp;
        struct req_capsule      *pill = tsi->tsi_pill;
@@ -2158,7 +2144,7 @@ static int mdt_llog_ctxt_unclone(const struct lu_env *env,
 /*
  * sec context handlers
  */
-int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
+static int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
 {
        int rc;
 
@@ -2180,7 +2166,7 @@ int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
 /*
  * quota request handlers
  */
-int mdt_quota_dqacq(struct tgt_session_info *tsi)
+static int mdt_quota_dqacq(struct tgt_session_info *tsi)
 {
        struct mdt_device       *mdt = mdt_exp2dev(tsi->tsi_exp);
        struct lu_device        *qmt = mdt->mdt_qmt_dev;
@@ -2481,9 +2467,10 @@ static int mdt_object_local_lock(struct mdt_thread_info *info,
         RETURN(rc);
 }
 
-int mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
-                            struct mdt_lock_handle *lh, __u64 ibits,
-                            bool nonblock, int locality)
+static int
+mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
+                        struct mdt_lock_handle *lh, __u64 ibits,
+                        bool nonblock, int locality)
 {
        int rc;
        ENTRY;
@@ -2883,7 +2870,7 @@ struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi)
        return mti;
 }
 
-int mdt_tgt_connect(struct tgt_session_info *tsi)
+static int mdt_tgt_connect(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        int                      rc;
@@ -3010,11 +2997,10 @@ static struct mdt_it_flavor {
        }
 };
 
-int mdt_intent_lock_replace(struct mdt_thread_info *info,
-                            struct ldlm_lock **lockp,
-                            struct ldlm_lock *new_lock,
-                            struct mdt_lock_handle *lh,
-                           __u64 flags)
+static int
+mdt_intent_lock_replace(struct mdt_thread_info *info, struct ldlm_lock **lockp,
+                       struct ldlm_lock *new_lock, struct mdt_lock_handle *lh,
+                       __u64 flags)
 {
         struct ptlrpc_request  *req = mdt_info_req(info);
         struct ldlm_lock       *lock = *lockp;
@@ -3208,7 +3194,6 @@ static int mdt_intent_getattr(enum mdt_it_code opcode,
         struct ldlm_lock       *new_lock = NULL;
         __u64                   child_bits;
         struct ldlm_reply      *ldlm_rep;
-        struct ptlrpc_request  *req;
         struct mdt_body        *reqbody;
         struct mdt_body        *repbody;
         int                     rc, rc2;
@@ -3241,7 +3226,6 @@ static int mdt_intent_getattr(enum mdt_it_code opcode,
         if (rc)
                 GOTO(out_shrink, rc);
 
-        req = info->mti_pill->rc_req;
         ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
         mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
 
@@ -3597,10 +3581,8 @@ static void mdt_seq_fini_cli(struct mdt_device *mdt)
        if (ss == NULL)
                return;
 
-       if (ss->ss_server_seq == NULL)
+       if (ss->ss_server_seq != NULL)
                seq_server_set_cli(NULL, ss->ss_server_seq, NULL);
-
-       return;
 }
 
 static int mdt_seq_fini(const struct lu_env *env, struct mdt_device *mdt)
@@ -3817,7 +3799,6 @@ static int mdt_fld_init(const struct lu_env *env,
 static void mdt_stack_pre_fini(const struct lu_env *env,
                           struct mdt_device *m, struct lu_device *top)
 {
-       struct obd_device       *obd;
        struct lustre_cfg_bufs  *bufs;
        struct lustre_cfg       *lcfg;
        struct mdt_thread_info  *info;
@@ -3832,7 +3813,6 @@ static void mdt_stack_pre_fini(const struct lu_env *env,
 
        LASSERT(m->mdt_child_exp);
        LASSERT(m->mdt_child_exp->exp_obd);
-       obd = m->mdt_child_exp->exp_obd;
 
        /* process cleanup, pass mdt obd name to get obd umount flags */
        /* XXX: this is needed because all layers are referenced by
@@ -4413,7 +4393,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
        EXIT;
 }
 
-int mdt_postrecov(const struct lu_env *, struct mdt_device *);
+static int mdt_postrecov(const struct lu_env *, struct mdt_device *);
 
 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
                      struct lu_device_type *ldt, struct lustre_cfg *cfg)
@@ -5773,7 +5753,7 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         RETURN(rc);
 }
 
-int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
+static int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
 {
         struct lu_device *ld = md2lu_dev(mdt->mdt_child);
         int rc;
@@ -5783,7 +5763,7 @@ int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
         RETURN(rc);
 }
 
-int mdt_obd_postrecov(struct obd_device *obd)
+static int mdt_obd_postrecov(struct obd_device *obd)
 {
         struct lu_env env;
         int rc;
@@ -5949,11 +5929,11 @@ static int __init mdt_mod_init(void)
                GOTO(lu_fini, rc);
 
        lprocfs_mdt_init_vars(&lvars);
-       rc = class_register_type(&mdt_obd_device_ops, NULL, NULL,
+       rc = class_register_type(&mdt_obd_device_ops, NULL, true, NULL,
 #ifndef HAVE_ONLY_PROCFS_SEQ
-                               lvars.module_vars,
+                                lvars.module_vars,
 #endif
-                               LUSTRE_MDT_NAME, &mdt_device_type);
+                                LUSTRE_MDT_NAME, &mdt_device_type);
        if (rc)
                GOTO(mds_fini, rc);
 lu_fini: