Whamcloud - gitweb
LU-4826 lmv: Ensure lmv_intent_lookup cleans up reqp
[fs/lustre-release.git] / lustre / lod / lod_dev.c
index 608f754..1d4849f 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright  2009 Sun Microsystems, Inc. All rights reserved
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  *
  */
 /*
  * Author: Mikhail Pershin <mike.pershin@intel.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <obd_class.h>
+#include <md_object.h>
+#include <lustre_fid.h>
 #include <lustre_param.h>
+#include <lustre_update.h>
 
 #include "lod_internal.h"
 
  * \param lod LOD to be lookup at.
  * \param fid FID of object to find MDT/OST.
  * \param tgt MDT/OST index to return.
- * \param flags indidcate the FID is on MDS or OST.
+ * \param type indidcate the FID is on MDS or OST.
  **/
 int lod_fld_lookup(const struct lu_env *env, struct lod_device *lod,
-                  const struct lu_fid *fid, __u32 *tgt, int flags)
+                  const struct lu_fid *fid, __u32 *tgt, int *type)
 {
-       struct lu_seq_range     range;
+       struct lu_seq_range     range = { 0 };
        struct lu_server_fld    *server_fld;
        int rc = 0;
        ENTRY;
 
        LASSERTF(fid_is_sane(fid), "Invalid FID "DFID"\n", PFID(fid));
+
        if (fid_is_idif(fid)) {
                *tgt = fid_idif_ost_idx(fid);
+               *type = LU_SEQ_RANGE_OST;
                RETURN(rc);
        }
 
-       if (!lod->lod_initialized || !fid_is_norm(fid)) {
+       if (!lod->lod_initialized || (!fid_seq_in_fldb(fid_seq(fid)))) {
                LASSERT(lu_site2seq(lod2lu_dev(lod)->ld_site) != NULL);
+
                *tgt = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
+               *type = LU_SEQ_RANGE_MDT;
                RETURN(rc);
        }
 
        server_fld = lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_server_fld;
-       range.lsr_flags = flags;
+       fld_range_set_type(&range, *type);
        rc = fld_server_lookup(env, server_fld, fid_seq(fid), &range);
-       if (rc) {
-               CERROR("%s: Can't find tgt by seq "LPX64", rc %d\n",
-                      lod2obd(lod)->obd_name, fid_seq(fid), rc);
+       if (rc)
                RETURN(rc);
-       }
 
        *tgt = range.lsr_index;
+       *type = range.lsr_flags;
 
        CDEBUG(D_INFO, "LOD: got tgt %x for sequence: "
               LPX64"\n", *tgt, fid_seq(fid));
@@ -97,7 +99,7 @@ extern struct lu_object_operations lod_lu_obj_ops;
 extern struct dt_object_operations lod_obj_ops;
 
 /* Slab for OSD object allocation */
-cfs_mem_cache_t *lod_object_kmem;
+struct kmem_cache *lod_object_kmem;
 
 static struct lu_kmem_descr lod_caches[] = {
        {
@@ -117,19 +119,20 @@ struct lu_object *lod_object_alloc(const struct lu_env *env,
                                   const struct lu_object_header *hdr,
                                   struct lu_device *dev)
 {
-       struct lu_object  *lu_obj;
-       struct lod_object *lo;
+       struct lod_object       *lod_obj;
+       struct lu_object        *lu_obj;
+       ENTRY;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lo, lod_object_kmem, CFS_ALLOC_IO);
-       if (lo == NULL)
-               return NULL;
+       OBD_SLAB_ALLOC_PTR_GFP(lod_obj, lod_object_kmem, GFP_NOFS);
+       if (lod_obj == NULL)
+               RETURN(ERR_PTR(-ENOMEM));
 
-       lu_obj = lod2lu_obj(lo);
-       dt_object_init(&lo->ldo_obj, NULL, dev);
-       lo->ldo_obj.do_ops = &lod_obj_ops;
+       lu_obj = lod2lu_obj(lod_obj);
+       dt_object_init(&lod_obj->ldo_obj, NULL, dev);
+       lod_obj->ldo_obj.do_ops = &lod_obj_ops;
        lu_obj->lo_ops = &lod_lu_obj_ops;
 
-       return lu_obj;
+       RETURN(lu_obj);
 }
 
 static int lod_cleanup_desc_tgts(const struct lu_env *env,
@@ -165,7 +168,7 @@ static int lod_cleanup_desc_tgts(const struct lu_env *env,
        return rc;
 }
 
-static int lodname2mdt_index(char *lodname, int *index)
+static int lodname2mdt_index(char *lodname, long *index)
 {
        char *ptr, *tmp;
 
@@ -199,6 +202,28 @@ static int lodname2mdt_index(char *lodname, int *index)
        return 0;
 }
 
+/**
+ * Procss config log on LOD
+ * \param env environment info
+ * \param dev lod device
+ * \param lcfg config log
+ *
+ * Add osc config log,
+ * marker  20 (flags=0x01, v2.2.49.56) lustre-OST0001  'add osc'
+ * add_uuid  nid=192.168.122.162@tcp(0x20000c0a87aa2)  0:  1:nidxxx
+ * attach    0:lustre-OST0001-osc-MDT0001  1:osc  2:lustre-MDT0001-mdtlov_UUID
+ * setup     0:lustre-OST0001-osc-MDT0001  1:lustre-OST0001_UUID  2:nid
+ * lov_modify_tgts add 0:lustre-MDT0001-mdtlov  1:lustre-OST0001_UUID  2:1  3:1
+ * marker  20 (flags=0x02, v2.2.49.56) lustre-OST0001  'add osc'
+ *
+ * Add mdc config log
+ * marker  10 (flags=0x01, v2.2.49.56) lustre-MDT0000  'add osp'
+ * add_uuid  nid=192.168.122.162@tcp(0x20000c0a87aa2)  0:  1:nid
+ * attach 0:lustre-MDT0000-osp-MDT0001  1:osp  2:lustre-MDT0001-mdtlov_UUID
+ * setup     0:lustre-MDT0000-osp-MDT0001  1:lustre-MDT0000_UUID  2:nid
+ * modify_mdc_tgts add 0:lustre-MDT0001  1:lustre-MDT0000_UUID  2:0  3:1
+ * marker  10 (flags=0x02, v2.2.49.56) lustre-MDT0000_UUID  'add osp'
+ **/
 static int lod_process_config(const struct lu_env *env,
                              struct lu_device *dev,
                              struct lustre_cfg *lcfg)
@@ -235,10 +260,13 @@ static int lod_process_config(const struct lu_env *env,
                        if (mdt == NULL) {
                                mdt_index = 0;
                        } else {
+                               long long_index;
                                rc = lodname2mdt_index(
-                                       lustre_cfg_string(lcfg, 0), &mdt_index);
+                                       lustre_cfg_string(lcfg, 0),
+                                       &long_index);
                                if (rc != 0)
                                        GOTO(out, rc);
+                               mdt_index = long_index;
                        }
                        rc = lod_add_device(env, lod, arg1, index, gen,
                                            mdt_index, LUSTRE_OSC_NAME, 1);
@@ -254,7 +282,7 @@ static int lod_process_config(const struct lu_env *env,
                } else {
                        rc = lod_del_device(env, lod,
                                            &lod->lod_ost_descs,
-                                           arg1, index, gen);
+                                           arg1, index, gen, true);
                }
 
                break;
@@ -272,9 +300,12 @@ static int lod_process_config(const struct lu_env *env,
                GOTO(out, rc);
        }
        case LCFG_CLEANUP:
+       case LCFG_PRE_CLEANUP: {
                lu_dev_del_linkage(dev->ld_site, dev);
                lod_cleanup_desc_tgts(env, lod, &lod->lod_mdt_descs, lcfg);
                lod_cleanup_desc_tgts(env, lod, &lod->lod_ost_descs, lcfg);
+               if (lcfg->lcfg_command == LCFG_PRE_CLEANUP)
+                       break;
                /*
                 * do cleanup on underlying storage only when
                 * all OSPs are cleaned up, as they use that OSD as well
@@ -289,7 +320,7 @@ static int lod_process_config(const struct lu_env *env,
                if (rc)
                        CERROR("error in disconnect from storage: %d\n", rc);
                break;
-
+       }
        default:
               CERROR("%s: unknown command %u\n", lod2obd(lod)->obd_name,
                      lcfg->lcfg_command);
@@ -373,19 +404,60 @@ static int lod_statfs(const struct lu_env *env,
 static struct thandle *lod_trans_create(const struct lu_env *env,
                                        struct dt_device *dev)
 {
-       return dt_trans_create(env, dt2lod_dev(dev)->lod_child);
+       struct thandle *th;
+
+       th = dt_trans_create(env, dt2lod_dev(dev)->lod_child);
+       if (IS_ERR(th))
+               return th;
+
+       return th;
 }
 
 static int lod_trans_start(const struct lu_env *env, struct dt_device *dev,
                           struct thandle *th)
 {
-       return dt_trans_start(env, dt2lod_dev(dev)->lod_child, th);
+       struct lod_device *lod = dt2lod_dev((struct dt_device *) dev);
+       int rc = 0;
+
+       if (unlikely(th->th_update != NULL)) {
+               struct thandle_update *tu = th->th_update;
+               struct dt_update_request *update;
+
+               list_for_each_entry(update, &tu->tu_remote_update_list,
+                                   dur_list) {
+                       LASSERT(update->dur_dt != NULL);
+                       rc = dt_trans_start(env, update->dur_dt, th);
+                       if (rc != 0)
+                               return rc;
+               }
+       }
+       return dt_trans_start(env, lod->lod_child, th);
 }
 
-static int lod_trans_stop(const struct lu_env *env, struct thandle *th)
+static int lod_trans_stop(const struct lu_env *env, struct dt_device *dt,
+                         struct thandle *th)
 {
-       /* XXX: we don't know next device, will be fixed with DNE */
-       return dt_trans_stop(env, th->th_dev, th);
+       struct thandle_update           *tu = th->th_update;
+       struct dt_update_request        *update;
+       struct dt_update_request        *tmp;
+       int                             rc2 = 0;
+       int                             rc;
+       ENTRY;
+
+       rc = dt_trans_stop(env, th->th_dev, th);
+       if (likely(tu == NULL))
+               RETURN(rc);
+
+       list_for_each_entry_safe(update, tmp,
+                                &tu->tu_remote_update_list,
+                                dur_list) {
+               /* update will be freed inside dt_trans_stop */
+               rc2 = dt_trans_stop(env, update->dur_dt, th);
+               if (unlikely(rc2 != 0 && rc == 0))
+                       rc = rc2;
+       }
+
+       RETURN(rc);
 }
 
 static void lod_conf_get(const struct lu_env *env,
@@ -653,12 +725,12 @@ static struct lu_device *lod_device_fini(const struct lu_env *env,
 
        lod_procfs_fini(lod);
 
-       rc = lod_fini_tgt(lod, &lod->lod_ost_descs);
+       rc = lod_fini_tgt(env, lod, &lod->lod_ost_descs, true);
        if (rc)
                CERROR("%s:can not fini ost descs %d\n",
                        lod2obd(lod)->obd_name, rc);
 
-       rc = lod_fini_tgt(lod, &lod->lod_mdt_descs);
+       rc = lod_fini_tgt(env, lod, &lod->lod_mdt_descs, false);
        if (rc)
                CERROR("%s:can not fini mdt descs %d\n",
                        lod2obd(lod)->obd_name, rc);
@@ -772,25 +844,37 @@ static struct lu_device_type lod_device_type = {
        .ldt_ctx_tags = LCT_MD_THREAD,
 };
 
-static int lod_obd_health_check(const struct lu_env *env,
-               struct obd_device *obd)
+static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp,
+                           __u32 keylen, void *key, __u32 *vallen, void *val,
+                           struct lov_stripe_md *lsm)
 {
-       struct lod_device   *d = lu2lod_dev(obd->obd_lu_dev);
-       struct lod_ost_desc *ost;
-       int                  i, rc = 1;
-       ENTRY;
-
-       LASSERT(d);
-       lod_getref(&d->lod_ost_descs);
-       lod_foreach_ost(d, i) {
-               ost = OST_TGT(d, i);
-               LASSERT(ost && ost->ltd_ost);
-               rc = obd_health_check(env, ost->ltd_exp->exp_obd);
-               /* one healthy device is enough */
-               if (rc == 0)
-                       break;
+       int rc = -EINVAL;
+
+       if (KEY_IS(KEY_OSP_CONNECTED)) {
+               struct obd_device       *obd = exp->exp_obd;
+               struct lod_device       *d;
+               struct lod_ost_desc     *ost;
+               int                     i, rc = 1;
+
+               if (!obd->obd_set_up || obd->obd_stopping)
+                       RETURN(-EAGAIN);
+
+               d = lu2lod_dev(obd->obd_lu_dev);
+               lod_getref(&d->lod_ost_descs);
+               lod_foreach_ost(d, i) {
+                       ost = OST_TGT(d, i);
+                       LASSERT(ost && ost->ltd_ost);
+
+                       rc = obd_get_info(env, ost->ltd_exp, keylen, key,
+                                         vallen, val, lsm);
+                       /* one healthy device is enough */
+                       if (rc == 0)
+                               break;
+               }
+               lod_putref(d, &d->lod_ost_descs);
+               RETURN(rc);
        }
-       lod_putref(d, &d->lod_ost_descs);
+
        RETURN(rc);
 }
 
@@ -798,7 +882,7 @@ static struct obd_ops lod_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_connect      = lod_obd_connect,
        .o_disconnect   = lod_obd_disconnect,
-       .o_health_check = lod_obd_health_check,
+       .o_get_info     = lod_obd_get_info,
        .o_pool_new     = lod_pool_new,
        .o_pool_rem     = lod_pool_remove,
        .o_pool_add     = lod_pool_add,
@@ -817,8 +901,11 @@ static int __init lod_mod_init(void)
 
        lprocfs_lod_init_vars(&lvars);
 
-       rc = class_register_type(&lod_obd_device_ops, NULL, lvars.module_vars,
-                                LUSTRE_LOD_NAME, &lod_device_type);
+       rc = class_register_type(&lod_obd_device_ops, NULL, NULL,
+#ifndef HAVE_ONLY_PROCFS_SEQ
+                               lvars.module_vars,
+#endif
+                               LUSTRE_LOD_NAME, &lod_device_type);
        if (rc) {
                lu_kmem_fini(lod_caches);
                return rc;