Whamcloud - gitweb
LU-819 utils: Fix lfs getstripe -M
[fs/lustre-release.git] / lustre / lmv / lmv_obd.c
index e0d896d..d897826 100644 (file)
@@ -1110,10 +1110,11 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
         lprocfs_obd_setup(obd, lvars.obd_vars);
 #ifdef LPROCFS
         {
-                rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd_status",
+                rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
                                         0444, &lmv_proc_target_fops, obd);
                 if (rc)
-                        CWARN("Error adding target_obd_stats file (%d)\n", rc);
+                        CWARN("%s: error adding LMV target_obd file: rc = %d\n",
+                               obd->obd_name, rc);
        }
 #endif
         rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
@@ -1140,7 +1141,6 @@ static int lmv_cleanup(struct obd_device *obd)
         ENTRY;
 
         fld_client_fini(&lmv->lmv_fld);
-        lprocfs_obd_cleanup(obd);
         lmv_object_cleanup(obd);
         OBD_FREE(lmv->datas, lmv->datas_size);
         OBD_FREE(lmv->tgts, lmv->tgts_size);
@@ -2074,7 +2074,6 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
         struct obd_device       *obd = exp->exp_obd;
         struct lmv_obd          *lmv = &obd->u.lmv;
         struct lmv_tgt_desc     *src_tgt;
-        struct lmv_tgt_desc     *tgt_tgt;
         int                      rc;
         int                      sidx;
         int                      loop = 0;
@@ -2134,7 +2133,6 @@ repeat:
         op_data->op_cap = cfs_curproc_cap_pack();
 
         src_tgt = lmv_get_target(lmv, mds1);
-        tgt_tgt = lmv_get_target(lmv, mds2);
 
         /*
          * LOOKUP lock on src child (fid3) should also be cancelled for
@@ -2535,6 +2533,8 @@ repeat:
                 first->ldp_hash_end = hash_end;
                 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
                 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
+#else
+                SET_BUT_UNUSED(tmp);
 #endif
                 cfs_kunmap(pages[i]);
         }
@@ -2631,7 +2631,8 @@ repeat:
 
 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
 {
-        int        rc = 0;
+        struct lmv_obd *lmv = &obd->u.lmv;
+        int rc = 0;
 
         switch (stage) {
         case OBD_CLEANUP_EARLY:
@@ -2639,6 +2640,8 @@ static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
                  * stack. */
                 break;
         case OBD_CLEANUP_EXPORTS:
+                fld_client_proc_fini(&lmv->lmv_fld);
+                lprocfs_obd_cleanup(obd);
                 rc = obd_llog_finish(obd, 0);
                 if (rc != 0)
                         CERROR("failed to cleanup llogging subsystems\n");
@@ -2885,7 +2888,7 @@ static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
 }
 
 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
-                      __u32 *bits)
+                      __u64 *bits)
 {
         struct obd_device       *obd = exp->exp_obd;
         struct lmv_obd          *lmv = &obd->u.lmv;
@@ -3043,7 +3046,7 @@ int lmv_intent_getattr_async(struct obd_export *exp,
         struct obd_device       *obd = exp->exp_obd;
         struct lmv_obd          *lmv = &obd->u.lmv;
         struct lmv_object       *obj;
-        struct lmv_tgt_desc     *tgt;
+        struct lmv_tgt_desc     *tgt = NULL;
         int                      rc;
         int                      sidx;
         ENTRY;
@@ -3052,36 +3055,21 @@ int lmv_intent_getattr_async(struct obd_export *exp,
         if (rc)
                 RETURN(rc);
 
-        if (!fid_is_sane(&op_data->op_fid2)) {
+        if (op_data->op_namelen) {
                 obj = lmv_object_find(obd, &op_data->op_fid1);
-                if (obj && op_data->op_namelen) {
-                        sidx = raw_name2idx(obj->lo_hashtype,
-                                            obj->lo_objcount,
+                if (obj) {
+                        sidx = raw_name2idx(obj->lo_hashtype, obj->lo_objcount,
                                             (char *)op_data->op_name,
                                             op_data->op_namelen);
                         op_data->op_fid1 = obj->lo_stripes[sidx].ls_fid;
-                        tgt = lmv_get_target(lmv,
-                                             obj->lo_stripes[sidx].ls_mds);
-                        CDEBUG(D_INODE,
-                               "Choose slave dir ("DFID") -> mds #%d\n",
-                               PFID(&op_data->op_fid1), tgt->ltd_idx);
-                } else {
-                        tgt = lmv_find_target(lmv, &op_data->op_fid1);
-                }
-                if (obj)
+                        tgt = lmv_get_target(lmv, obj->lo_stripes[sidx].ls_mds);
                         lmv_object_put(obj);
-        } else {
-                op_data->op_fid1 = op_data->op_fid2;
-                tgt = lmv_find_target(lmv, &op_data->op_fid2);
-                op_data->op_bias = MDS_CROSS_REF;
-                /*
-                 * Unfortunately, we have to lie to MDC/MDS to retrieve
-                 * attributes llite needs.
-                */
-                if (minfo->mi_it.it_op & IT_LOOKUP)
-                        minfo->mi_it.it_op = IT_GETATTR;
+                }
         }
 
+        if (tgt == NULL)
+                tgt = lmv_find_target(lmv, &op_data->op_fid1);
+
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
 
@@ -3090,7 +3078,7 @@ int lmv_intent_getattr_async(struct obd_export *exp,
 }
 
 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
-                        struct lu_fid *fid)
+                        struct lu_fid *fid, __u64 *bits)
 {
         struct obd_device       *obd = exp->exp_obd;
         struct lmv_obd          *lmv = &obd->u.lmv;
@@ -3106,10 +3094,87 @@ int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
         if (IS_ERR(tgt))
                 RETURN(PTR_ERR(tgt));
 
-        rc = md_revalidate_lock(tgt->ltd_exp, it, fid);
+        rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
+        RETURN(rc);
+}
+
+/**
+ * For lmv, only need to send request to master MDT, and the master MDT will
+ * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
+ * we directly fetch data from the slave MDTs.
+ */
+int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
+                 struct obd_quotactl *oqctl)
+{
+        struct obd_device   *obd = class_exp2obd(exp);
+        struct lmv_obd      *lmv = &obd->u.lmv;
+        struct lmv_tgt_desc *tgt = &lmv->tgts[0];
+        int                  rc = 0, i;
+        __u64                curspace, curinodes;
+        ENTRY;
+
+        if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
+                CERROR("master lmv inactive\n");
+                RETURN(-EIO);
+        }
+
+        if (oqctl->qc_cmd != Q_GETOQUOTA) {
+                rc = obd_quotactl(tgt->ltd_exp, oqctl);
+                RETURN(rc);
+        }
+
+        curspace = curinodes = 0;
+        for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
+                int err;
+                tgt = &lmv->tgts[i];
+
+                if (tgt->ltd_exp == NULL)
+                        continue;
+                if (!tgt->ltd_active) {
+                        CDEBUG(D_HA, "mdt %d is inactive.\n", i);
+                        continue;
+                }
+
+                err = obd_quotactl(tgt->ltd_exp, oqctl);
+                if (err) {
+                        CERROR("getquota on mdt %d failed. %d\n", i, err);
+                        if (!rc)
+                                rc = err;
+                } else {
+                        curspace += oqctl->qc_dqblk.dqb_curspace;
+                        curinodes += oqctl->qc_dqblk.dqb_curinodes;
+                }
+        }
+        oqctl->qc_dqblk.dqb_curspace = curspace;
+        oqctl->qc_dqblk.dqb_curinodes = curinodes;
+
         RETURN(rc);
 }
 
+int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
+                   struct obd_quotactl *oqctl)
+{
+        struct obd_device   *obd = class_exp2obd(exp);
+        struct lmv_obd      *lmv = &obd->u.lmv;
+        struct lmv_tgt_desc *tgt;
+        int                  i, rc = 0;
+        ENTRY;
+
+        for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
+                int err;
+
+                if (!tgt->ltd_active) {
+                        CERROR("lmv idx %d inactive\n", i);
+                        RETURN(-EIO);
+                }
+
+                err = obd_quotacheck(tgt->ltd_exp, oqctl);
+                if (err && !rc)
+                        rc = err;
+        }
+
+        RETURN(rc);
+}
 
 struct obd_ops lmv_obd_ops = {
         .o_owner                = THIS_MODULE,
@@ -3127,7 +3192,9 @@ struct obd_ops lmv_obd_ops = {
         .o_notify               = lmv_notify,
         .o_get_uuid             = lmv_get_uuid,
         .o_iocontrol            = lmv_iocontrol,
-        .o_fid_delete           = lmv_fid_delete
+        .o_fid_delete           = lmv_fid_delete,
+        .o_quotacheck           = lmv_quotacheck,
+        .o_quotactl             = lmv_quotactl
 };
 
 struct md_ops lmv_md_ops = {
@@ -3164,9 +3231,6 @@ struct md_ops lmv_md_ops = {
         .m_revalidate_lock      = lmv_revalidate_lock
 };
 
-static quota_interface_t *quota_interface;
-extern quota_interface_t lmv_quota_interface;
-
 int __init lmv_init(void)
 {
         struct lprocfs_static_vars lvars;
@@ -3182,17 +3246,10 @@ int __init lmv_init(void)
 
         lprocfs_lmv_init_vars(&lvars);
 
-        cfs_request_module("lquota");
-        quota_interface = PORTAL_SYMBOL_GET(lmv_quota_interface);
-        init_obd_quota_ops(quota_interface, &lmv_obd_ops);
-
         rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
                                  lvars.module_vars, LUSTRE_LMV_NAME, NULL);
-        if (rc) {
-                if (quota_interface)
-                        PORTAL_SYMBOL_PUT(lmv_quota_interface);
+        if (rc)
                 cfs_mem_cache_destroy(lmv_object_cache);
-        }
 
         return rc;
 }
@@ -3200,9 +3257,6 @@ int __init lmv_init(void)
 #ifdef __KERNEL__
 static void lmv_exit(void)
 {
-        if (quota_interface)
-                PORTAL_SYMBOL_PUT(lmv_quota_interface);
-
         class_unregister_type(LUSTRE_LMV_NAME);
 
         LASSERTF(cfs_atomic_read(&lmv_object_count) == 0,