Whamcloud - gitweb
LU-1399 config: check lustre_cfg_new() return
[fs/lustre-release.git] / lustre / ofd / ofd_dev.c
index 077858a..82bcafc 100644 (file)
@@ -75,6 +75,7 @@
 #include <lustre/lustre_idl.h>
 #include <lustre_dlm.h>
 #include <lustre_quota.h>
+#include <lustre_nodemap.h>
 
 #include "ofd_internal.h"
 
@@ -230,10 +231,8 @@ static void ofd_stack_fini(const struct lu_env *env, struct ofd_device *m,
                strcat(flags, "A");
        lustre_cfg_bufs_set_string(&bufs, 1, flags);
        lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
-       if (!lcfg) {
-               CERROR("Cannot alloc lcfg!\n");
+       if (lcfg == NULL)
                RETURN_EXIT;
-       }
 
        LASSERT(top);
        top->ld_ops->ldo_process_config(env, top, lcfg);
@@ -464,7 +463,7 @@ static int ofd_object_print(const struct lu_env *env, void *cookie,
        return (*p)(env, cookie, LUSTRE_OST_NAME"-object@%p", o);
 }
 
-struct lu_object_operations ofd_obj_ops = {
+static struct lu_object_operations ofd_obj_ops = {
        .loo_object_init        = ofd_object_init,
        .loo_object_free        = ofd_object_free,
        .loo_object_print       = ofd_object_print
@@ -894,7 +893,7 @@ out_free:
  * \retval             0 if successful
  * \retval             negative value on error
  */
-int ofd_set_info_hdl(struct tgt_session_info *tsi)
+static int ofd_set_info_hdl(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        struct ost_body         *body = NULL, *repbody;
@@ -1136,7 +1135,7 @@ unlock_zero_regions(struct ldlm_namespace *ns, struct list_head *locked)
  * \retval             0 if successful
  * \retval             negative value on error
  */
-int ofd_get_info_hdl(struct tgt_session_info *tsi)
+static int ofd_get_info_hdl(struct tgt_session_info *tsi)
 {
        struct obd_export               *exp = tsi->tsi_exp;
        struct ofd_device               *ofd = ofd_exp(exp);
@@ -1635,7 +1634,8 @@ static int ofd_create_hdl(struct tgt_session_info *tsi)
                CDEBUG(D_HA, "ofd_last_id() = "LPU64" -> diff = %d\n",
                        ofd_seq_last_oid(oseq), diff);
                if (-diff > OST_MAX_PRECREATE) {
-                       /* FIXME: should reset precreate_next_id on MDS */
+                       /* Let MDS know that we are so far ahead. */
+                       ostid_set_id(&rep_oa->o_oi, ofd_seq_last_oid(oseq) + 1);
                        rc = 0;
                } else if (diff < 0) {
                        rc = ofd_orphans_destroy(tsi->tsi_env, exp,
@@ -1828,7 +1828,7 @@ static int ofd_destroy_hdl(struct tgt_session_info *tsi)
                dlm = req_capsule_client_get(tsi->tsi_pill, &RMF_DLM_REQ);
                if (dlm == NULL)
                        RETURN(-EFAULT);
-               ldlm_request_cancel(tgt_ses_req(tsi), dlm, 0);
+               ldlm_request_cancel(tgt_ses_req(tsi), dlm, 0, LATF_SKIP);
        }
 
        *fid = body->oa.o_oi.oi_fid;
@@ -2100,6 +2100,9 @@ out:
 static int ofd_quotactl(struct tgt_session_info *tsi)
 {
        struct obd_quotactl     *oqctl, *repoqc;
+       struct lu_nodemap       *nodemap =
+               tsi->tsi_exp->exp_target_data.ted_nodemap;
+       int                      id;
        int                      rc;
 
        ENTRY;
@@ -2118,11 +2121,28 @@ static int ofd_quotactl(struct tgt_session_info *tsi)
                RETURN(0);
 
        *repoqc = *oqctl;
+
+       id = repoqc->qc_id;
+       if (oqctl->qc_type == USRQUOTA)
+               id = nodemap_map_id(nodemap, NODEMAP_UID,
+                                   NODEMAP_CLIENT_TO_FS,
+                                   repoqc->qc_id);
+       else if (oqctl->qc_type == GRPQUOTA)
+               id = nodemap_map_id(nodemap, NODEMAP_GID,
+                                   NODEMAP_CLIENT_TO_FS,
+                                   repoqc->qc_id);
+
+       if (repoqc->qc_id != id)
+               swap(repoqc->qc_id, id);
+
        rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom, repoqc);
 
        ofd_counter_incr(tsi->tsi_exp, LPROC_OFD_STATS_QUOTACTL,
                         tsi->tsi_jobid, 1);
 
+       if (repoqc->qc_id != id)
+               swap(repoqc->qc_id, id);
+
        RETURN(rc);
 }
 
@@ -2136,15 +2156,18 @@ static int ofd_quotactl(struct tgt_session_info *tsi)
  *
  * \retval             amount of time to extend the timeout with
  */
-static inline int prolong_timeout(struct ptlrpc_request *req)
+static inline int prolong_timeout(struct ptlrpc_request *req,
+                                 struct ldlm_lock *lock)
 {
        struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
 
        if (AT_OFF)
                return obd_timeout / 2;
 
-       return max(at_est2timeout(at_get(&svcpt->scp_at_estimate)),
-                  ldlm_timeout);
+       /* We are in the middle of the process - BL AST is sent, CANCEL
+         is ahead. Take half of AT + IO process time. */
+       return at_est2timeout(at_get(&svcpt->scp_at_estimate)) +
+               (ldlm_bl_timeout(lock) >> 1);
 }
 
 /**
@@ -2163,8 +2186,9 @@ static inline int prolong_timeout(struct ptlrpc_request *req)
  */
 static int ofd_prolong_one_lock(struct tgt_session_info *tsi,
                                struct ldlm_lock *lock,
-                               struct ldlm_extent *extent, int timeout)
+                               struct ldlm_extent *extent)
 {
+       int timeout = prolong_timeout(tgt_ses_req(tsi), lock);
 
        if (lock->l_flags & LDLM_FL_DESTROYED) /* lock already cancelled */
                return 0;
@@ -2222,7 +2246,6 @@ static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
                .end = end
        };
        struct ldlm_lock        *lock;
-       int                      timeout = prolong_timeout(tgt_ses_req(tsi));
        int                      lock_count = 0;
 
        ENTRY;
@@ -2240,7 +2263,7 @@ static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
                                /* bingo */
                                LASSERT(lock->l_export == exp);
                                lock_count = ofd_prolong_one_lock(tsi, lock,
-                                                            &extent, timeout);
+                                                                 &extent);
                                LDLM_LOCK_PUT(lock);
                                RETURN(lock_count);
                        }
@@ -2260,7 +2283,7 @@ static int ofd_prolong_extent_locks(struct tgt_session_info *tsi,
                                         &extent))
                        continue;
 
-               lock_count += ofd_prolong_one_lock(tsi, lock, &extent, timeout);
+               lock_count += ofd_prolong_one_lock(tsi, lock, &extent);
        }
        spin_unlock_bh(&exp->exp_bl_list_lock);
 
@@ -2479,13 +2502,13 @@ static void ofd_punch_hpreq_fini(struct ptlrpc_request *req)
        ofd_punch_hpreq_check(req);
 }
 
-struct ptlrpc_hpreq_ops ofd_hpreq_rw = {
+static struct ptlrpc_hpreq_ops ofd_hpreq_rw = {
        .hpreq_lock_match       = ofd_rw_hpreq_lock_match,
        .hpreq_check            = ofd_rw_hpreq_check,
        .hpreq_fini             = ofd_rw_hpreq_fini
 };
 
-struct ptlrpc_hpreq_ops ofd_hpreq_punch = {
+static struct ptlrpc_hpreq_ops ofd_hpreq_punch = {
        .hpreq_lock_match       = ofd_punch_hpreq_lock_match,
        .hpreq_check            = ofd_punch_hpreq_check,
        .hpreq_fini             = ofd_punch_hpreq_fini
@@ -2992,7 +3015,7 @@ static struct lu_device_type ofd_device_type = {
  * \retval             0 if successful
  * \retval             negative value on error
  */
-int __init ofd_init(void)
+static int __init ofd_init(void)
 {
        int                             rc;
 
@@ -3017,7 +3040,7 @@ int __init ofd_init(void)
  * This function is called upon OFD module unloading.
  * It frees all related structures and unregisters OFD device type.
  */
-void __exit ofd_exit(void)
+static void __exit ofd_exit(void)
 {
        ofd_fmd_exit();
        lu_kmem_fini(ofd_caches);