Whamcloud - gitweb
LU-3864 lov: return minimal FIEMAP for released files
[fs/lustre-release.git] / lustre / lov / lov_obd.c
index 74cabb9..8aed982 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -388,11 +388,24 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
         CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
                lov, uuid->uuid, ev);
 
-        obd_getref(obd);
-        for (index = 0; index < lov->desc.ld_tgt_count; index++) {
-                tgt = lov->lov_tgts[index];
-                if (!tgt || !tgt->ltd_exp)
-                        continue;
+       obd_getref(obd);
+       for (index = 0; index < lov->desc.ld_tgt_count; index++) {
+               tgt = lov->lov_tgts[index];
+               if (!tgt)
+                       continue;
+               /*
+                * LU-642, initially inactive OSC could miss the obd_connect,
+                * we make up for it here.
+                */
+               if (ev == OBD_NOTIFY_ACTIVATE && tgt->ltd_exp == NULL &&
+                   obd_uuid_equals(uuid, &tgt->ltd_uuid)) {
+                       struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"};
+
+                       obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd,
+                                   &lov_osc_uuid, &lov->lov_ocd, NULL);
+               }
+               if (!tgt->ltd_exp)
+                       continue;
 
                 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
                        index, obd_uuid2str(&tgt->ltd_uuid),
@@ -449,8 +462,15 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                       enum obd_notify_event ev, void *data)
 {
         int rc = 0;
+       struct lov_obd *lov = &obd->u.lov;
         ENTRY;
 
+       down_read(&lov->lov_notify_lock);
+       if (!lov->lov_connects) {
+               up_read(&lov->lov_notify_lock);
+               RETURN(rc);
+       }
+
         if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE ||
             ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) {
                 struct obd_uuid *uuid;
@@ -458,6 +478,7 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                 LASSERT(watched);
 
                 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
+                       up_read(&lov->lov_notify_lock);
                         CERROR("unexpected notification of %s %s!\n",
                                watched->obd_type->typ_name,
                                watched->obd_name);
@@ -470,6 +491,7 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                  */
                 rc = lov_set_osc_active(obd, uuid, ev);
                 if (rc < 0) {
+                       up_read(&lov->lov_notify_lock);
                         CERROR("event(%d) of %s failed: %d\n", ev,
                                obd_uuid2str(uuid), rc);
                         RETURN(rc);
@@ -514,6 +536,7 @@ static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                 obd_putref(obd);
         }
 
+       up_read(&lov->lov_notify_lock);
         RETURN(rc);
 }
 
@@ -666,6 +689,8 @@ int lov_del_target(struct obd_device *obd, __u32 index,
                 RETURN(-EINVAL);
         }
 
+       /* to make sure there's no ongoing lov_notify() now */
+       down_write(&lov->lov_notify_lock);
         obd_getref(obd);
 
         if (!lov->lov_tgts[index]) {
@@ -690,6 +715,7 @@ int lov_del_target(struct obd_device *obd, __u32 index,
         /* we really delete it from obd_putref */
 out:
         obd_putref(obd);
+       up_write(&lov->lov_notify_lock);
 
         RETURN(rc);
 }
@@ -721,16 +747,18 @@ static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
 
 void lov_fix_desc_stripe_size(__u64 *val)
 {
-        if (*val < PTLRPC_MAX_BRW_SIZE) {
-                LCONSOLE_WARN("Increasing default stripe size to min %u\n",
-                              PTLRPC_MAX_BRW_SIZE);
-                *val = PTLRPC_MAX_BRW_SIZE;
-        } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
-                *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
-                LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
-                              "multiple of %u)\n",
-                              *val, LOV_MIN_STRIPE_SIZE);
-        }
+       if (*val < LOV_MIN_STRIPE_SIZE) {
+               if (*val != 0)
+                       LCONSOLE_INFO("Increasing default stripe size to "
+                                     "minimum %u\n",
+                                     LOV_DEFAULT_STRIPE_SIZE);
+               *val = LOV_DEFAULT_STRIPE_SIZE;
+       } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
+               *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
+               LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
+                             "multiple of %u)\n",
+                             *val, LOV_MIN_STRIPE_SIZE);
+       }
 }
 
 void lov_fix_desc_stripe_count(__u32 *val)
@@ -806,6 +834,8 @@ int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
         cfs_atomic_set(&lov->lov_refcount, 0);
         lov->lov_sp_me = LUSTRE_SP_CLI;
 
+       init_rwsem(&lov->lov_notify_lock);
+
         lov->lov_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
                                                    HASH_POOLS_MAX_BITS,
                                                    HASH_POOLS_BKT_BITS, 0,
@@ -1004,13 +1034,14 @@ static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
             !lov->lov_tgts[ost_idx])
                 GOTO(out, rc = -EINVAL);
 
-        for (i = 0; i < lsm->lsm_stripe_count; i++) {
-                if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
-                        if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
-                                GOTO(out, rc = -EINVAL);
-                        break;
-                }
-        }
+       for (i = 0; i < lsm->lsm_stripe_count; i++) {
+               if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
+                       if (ostid_id(&lsm->lsm_oinfo[i]->loi_oi) !=
+                                       ostid_id(&src_oa->o_oi))
+                               GOTO(out, rc = -EINVAL);
+                       break;
+               }
+       }
         if (i == lsm->lsm_stripe_count)
                 GOTO(out, rc = -EINVAL);
 
@@ -1098,17 +1129,18 @@ static int lov_destroy(const struct lu_env *env, struct obd_export *exp,
                 if (oa->o_valid & OBD_MD_FLCOOKIE)
                         oti->oti_logcookies = set->set_cookies + req->rq_stripe;
 
-                err = obd_destroy(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                  req->rq_oi.oi_oa, NULL, oti, NULL, capa);
-                err = lov_update_common_set(set, req, err);
-                if (err) {
-                        CERROR("error: destroying objid "LPX64" subobj "
-                               LPX64" on OST idx %d: rc = %d\n",
-                               oa->o_id, req->rq_oi.oi_oa->o_id,
-                               req->rq_idx, err);
-                        if (!rc)
-                                rc = err;
-                }
+               err = obd_destroy(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
+                                 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
+               err = lov_update_common_set(set, req, err);
+               if (err) {
+                       CERROR("%s: destroying objid "DOSTID" subobj "
+                              DOSTID" on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name, POSTID(&oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi),
+                              req->rq_idx, err);
+                       if (!rc)
+                               rc = err;
+               }
         }
 
         if (rc == 0) {
@@ -1146,20 +1178,22 @@ static int lov_getattr(const struct lu_env *env, struct obd_export *exp,
         cfs_list_for_each (pos, &set->set_list) {
                 req = cfs_list_entry(pos, struct lov_request, rq_link);
 
-                CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
-                       "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
-                       req->rq_oi.oi_oa->o_id, req->rq_idx);
+               CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
+                      " %u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
+                      POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
 
                 rc = obd_getattr(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
                                  &req->rq_oi);
-                err = lov_update_common_set(set, req, rc);
-                if (err) {
-                        CERROR("error: getattr objid "LPX64" subobj "
-                               LPX64" on OST idx %d: rc = %d\n",
-                               oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
-                               req->rq_idx, err);
-                        break;
-                }
+               err = lov_update_common_set(set, req, rc);
+               if (err) {
+                       CERROR("%s: getattr objid "DOSTID" subobj "
+                              DOSTID" on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name,
+                              POSTID(&oinfo->oi_oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi),
+                              req->rq_idx, err);
+                       break;
+               }
         }
 
         rc = lov_fini_getattr_set(set);
@@ -1204,26 +1238,28 @@ static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
         if (rc)
                 RETURN(rc);
 
-        CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
-               oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
-               oinfo->oi_md->lsm_stripe_size);
-
-        cfs_list_for_each (pos, &lovset->set_list) {
-                req = cfs_list_entry(pos, struct lov_request, rq_link);
-
-                CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
-                       "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
-                       req->rq_oi.oi_oa->o_id, req->rq_idx);
-                rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                       &req->rq_oi, rqset);
-                if (rc) {
-                        CERROR("error: getattr objid "LPX64" subobj "
-                               LPX64" on OST idx %d: rc = %d\n",
-                               oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
-                               req->rq_idx, rc);
-                        GOTO(out, rc);
-                }
-        }
+       CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes\n",
+              POSTID(&oinfo->oi_md->lsm_oi), oinfo->oi_md->lsm_stripe_count,
+              oinfo->oi_md->lsm_stripe_size);
+
+       cfs_list_for_each(pos, &lovset->set_list) {
+               req = cfs_list_entry(pos, struct lov_request, rq_link);
+
+               CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
+                      "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
+                      POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
+               rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
+                                      &req->rq_oi, rqset);
+               if (rc) {
+                       CERROR("%s: getattr objid "DOSTID" subobj"
+                              DOSTID" on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name,
+                              POSTID(&oinfo->oi_oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi),
+                              req->rq_idx, rc);
+                       GOTO(out, rc);
+               }
+       }
 
         if (!cfs_list_empty(&rqset->set_requests)) {
                 LASSERT(rc == 0);
@@ -1271,17 +1307,19 @@ static int lov_setattr(const struct lu_env *env, struct obd_export *exp,
         cfs_list_for_each (pos, &set->set_list) {
                 req = cfs_list_entry(pos, struct lov_request, rq_link);
 
-                rc = obd_setattr(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                 &req->rq_oi, NULL);
-                err = lov_update_setattr_set(set, req, rc);
-                if (err) {
-                        CERROR("error: setattr objid "LPX64" subobj "
-                               LPX64" on OST idx %d: rc = %d\n",
-                               set->set_oi->oi_oa->o_id,
-                               req->rq_oi.oi_oa->o_id, req->rq_idx, err);
-                        if (!rc)
-                                rc = err;
-                }
+               rc = obd_setattr(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
+                                &req->rq_oi, NULL);
+               err = lov_update_setattr_set(set, req, rc);
+               if (err) {
+                       CERROR("%s: setattr objid "DOSTID" subobj "
+                              DOSTID" on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name,
+                              POSTID(&set->set_oi->oi_oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx,
+                              err);
+                       if (!rc)
+                               rc = err;
+               }
         }
         err = lov_fini_setattr_set(set);
         if (!rc)
@@ -1330,31 +1368,32 @@ static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
         if (rc)
                 RETURN(rc);
 
-        CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
-               oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
-               oinfo->oi_md->lsm_stripe_size);
-
-        cfs_list_for_each (pos, &set->set_list) {
-                req = cfs_list_entry(pos, struct lov_request, rq_link);
-
-                if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
-                        oti->oti_logcookies = set->set_cookies + req->rq_stripe;
-
-                CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
-                       "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
-                       req->rq_oi.oi_oa->o_id, req->rq_idx);
-
-                rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                       &req->rq_oi, oti, rqset);
-                if (rc) {
-                        CERROR("error: setattr objid "LPX64" subobj "
-                               LPX64" on OST idx %d: rc = %d\n",
-                               set->set_oi->oi_oa->o_id,
-                               req->rq_oi.oi_oa->o_id,
-                               req->rq_idx, rc);
-                        break;
-                }
-        }
+       CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes\n",
+              POSTID(&oinfo->oi_md->lsm_oi),
+              oinfo->oi_md->lsm_stripe_count,
+              oinfo->oi_md->lsm_stripe_size);
+
+       cfs_list_for_each(pos, &set->set_list) {
+               req = cfs_list_entry(pos, struct lov_request, rq_link);
+
+               if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
+                       oti->oti_logcookies = set->set_cookies + req->rq_stripe;
+
+               CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
+                      "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
+                      POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
+
+               rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
+                                      &req->rq_oi, oti, rqset);
+               if (rc) {
+                       CERROR("error: setattr objid "DOSTID" subobj"
+                              DOSTID" on OST idx %d: rc = %d\n",
+                              POSTID(&set->set_oi->oi_oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi),
+                              req->rq_idx, rc);
+                       break;
+               }
+       }
 
         /* If we are not waiting for responses on async requests, return. */
         if (rc || !rqset || cfs_list_empty(&rqset->set_requests)) {
@@ -1413,15 +1452,16 @@ static int lov_punch(const struct lu_env *env, struct obd_export *exp,
         cfs_list_for_each (pos, &set->set_list) {
                 req = cfs_list_entry(pos, struct lov_request, rq_link);
 
-                rc = obd_punch(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
-                               &req->rq_oi, NULL, rqset);
-                if (rc) {
-                        CERROR("error: punch objid "LPX64" subobj "LPX64
-                               " on OST idx %d: rc = %d\n",
-                               set->set_oi->oi_oa->o_id,
-                               req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
-                        break;
-                }
+               rc = obd_punch(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
+                              &req->rq_oi, NULL, rqset);
+               if (rc) {
+                       CERROR("%s: punch objid "DOSTID" subobj "DOSTID
+                              " on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name,
+                              POSTID(&set->set_oi->oi_oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx, rc);
+                       break;
+               }
         }
 
         if (rc || cfs_list_empty(&rqset->set_requests)) {
@@ -1472,8 +1512,8 @@ static int lov_sync(const struct lu_env *env, struct obd_export *exp,
         if (rc)
                 RETURN(rc);
 
-        CDEBUG(D_INFO, "fsync objid "LPX64" ["LPX64", "LPX64"]\n",
-               set->set_oi->oi_oa->o_id, start, end);
+       CDEBUG(D_INFO, "fsync objid "DOSTID" ["LPX64", "LPX64"]\n",
+              POSTID(&set->set_oi->oi_oa->o_oi), start, end);
 
         cfs_list_for_each (pos, &set->set_list) {
                 req = cfs_list_entry(pos, struct lov_request, rq_link);
@@ -1481,13 +1521,15 @@ static int lov_sync(const struct lu_env *env, struct obd_export *exp,
                 rc = obd_sync(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
                               &req->rq_oi, req->rq_oi.oi_policy.l_extent.start,
                               req->rq_oi.oi_policy.l_extent.end, rqset);
-                if (rc) {
-                        CERROR("error: fsync objid "LPX64" subobj "LPX64
-                               " on OST idx %d: rc = %d\n",
-                               set->set_oi->oi_oa->o_id,
-                               req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
-                        break;
-                }
+               if (rc) {
+                       CERROR("%s: fsync objid "DOSTID" subobj "DOSTID
+                              " on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name,
+                              POSTID(&set->set_oi->oi_oa->o_oi),
+                              POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx,
+                              rc);
+                       break;
+               }
         }
 
         /* If we are not waiting for responses on async requests, return. */
@@ -1659,14 +1701,12 @@ static int lov_change_cbdata(struct obd_export *exp,
                         continue;
                 }
 
-                LASSERT_SEQ_IS_MDT(loi->loi_seq);
-                submd.lsm_object_id = loi->loi_id;
-                submd.lsm_object_seq = loi->loi_seq;
-                submd.lsm_stripe_count = 0;
-                rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
-                                       &submd, it, data);
-        }
-        RETURN(rc);
+               submd.lsm_oi = loi->loi_oi;
+               submd.lsm_stripe_count = 0;
+               rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
+                                      &submd, it, data);
+       }
+       RETURN(rc);
 }
 
 /* find any ldlm lock of the inode in lov
@@ -1695,17 +1735,14 @@ static int lov_find_cbdata(struct obd_export *exp,
                         CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
                         continue;
                 }
-
-                LASSERT_SEQ_IS_MDT(loi->loi_seq);
-                submd.lsm_object_id = loi->loi_id;
-                submd.lsm_object_seq = loi->loi_seq;
-                submd.lsm_stripe_count = 0;
-                rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
-                                     &submd, it, data);
-                if (rc != 0)
-                        RETURN(rc);
-        }
-        RETURN(rc);
+               submd.lsm_oi = loi->loi_oi;
+               submd.lsm_stripe_count = 0;
+               rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
+                                    &submd, it, data);
+               if (rc != 0)
+                       RETURN(rc);
+       }
+       RETURN(rc);
 }
 
 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
@@ -1725,32 +1762,31 @@ static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
         if (!exp || !exp->exp_obd)
                 RETURN(-ENODEV);
 
-        LASSERT_SEQ_IS_MDT(lsm->lsm_object_seq);
         LASSERT(lockh);
         lov = &exp->exp_obd->u.lov;
         rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
         if (rc)
                 RETURN(rc);
 
-        cfs_list_for_each (pos, &set->set_list) {
-                req = cfs_list_entry(pos, struct lov_request, rq_link);
-                lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
+       cfs_list_for_each(pos, &set->set_list) {
+               req = cfs_list_entry(pos, struct lov_request, rq_link);
+               lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
+
+               rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
+                               req->rq_oi.oi_md, mode, lov_lockhp);
+               rc = lov_update_common_set(set, req, rc);
+               if (rc) {
+                       CERROR("%s: cancel objid "DOSTID" subobj "
+                              DOSTID" on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name, POSTID(&lsm->lsm_oi),
+                              POSTID(&req->rq_oi.oi_md->lsm_oi),
+                              req->rq_idx, rc);
+                       err = rc;
+               }
 
-                rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                req->rq_oi.oi_md, mode, lov_lockhp);
-                rc = lov_update_common_set(set, req, rc);
-                if (rc) {
-                        CERROR("error: cancel objid "LPX64" subobj "
-                               LPX64" on OST idx %d: rc = %d\n",
-                               lsm->lsm_object_id,
-                               req->rq_oi.oi_md->lsm_object_id,
-                               req->rq_idx, rc);
-                        err = rc;
-                }
-
-        }
-        lov_fini_cancel_set(set);
-        RETURN(err);
+       }
+       lov_fini_cancel_set(set);
+       RETURN(err);
 }
 
 static int lov_cancel_unused(struct obd_export *exp,
@@ -1781,34 +1817,34 @@ static int lov_cancel_unused(struct obd_export *exp,
 
         ASSERT_LSM_MAGIC(lsm);
 
-        LASSERT_SEQ_IS_MDT(lsm->lsm_object_seq);
-        for (i = 0; i < lsm->lsm_stripe_count; i++) {
-                struct lov_stripe_md submd;
-                struct lov_oinfo *loi = lsm->lsm_oinfo[i];
-                int err;
-
-                if (!lov->lov_tgts[loi->loi_ost_idx]) {
-                        CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
-                        continue;
-                }
-
-                if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
-                        CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
-
-                submd.lsm_object_id = loi->loi_id;
-                submd.lsm_object_seq = loi->loi_seq;
-                submd.lsm_stripe_count = 0;
-                err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
-                                        &submd, flags, opaque);
-                if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
-                        CERROR("error: cancel unused objid "LPX64" subobj "LPX64
-                               " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
-                               loi->loi_id, loi->loi_ost_idx, err);
-                        if (!rc)
-                                rc = err;
-                }
-        }
-        RETURN(rc);
+       for (i = 0; i < lsm->lsm_stripe_count; i++) {
+               struct lov_stripe_md submd;
+               struct lov_oinfo *loi = lsm->lsm_oinfo[i];
+               int idx = loi->loi_ost_idx;
+               int err;
+
+               if (!lov->lov_tgts[idx]) {
+                       CDEBUG(D_HA, "lov idx %d NULL\n", idx);
+                       continue;
+               }
+
+               if (!lov->lov_tgts[idx]->ltd_active)
+                       CDEBUG(D_HA, "lov idx %d inactive\n", idx);
+
+               submd.lsm_oi = loi->loi_oi;
+               submd.lsm_stripe_count = 0;
+               err = obd_cancel_unused(lov->lov_tgts[idx]->ltd_exp,
+                                       &submd, flags, opaque);
+               if (err && lov->lov_tgts[idx]->ltd_active) {
+                       CERROR("%s: cancel unused objid "DOSTID
+                              " subobj "DOSTID" on OST idx %d: rc = %d\n",
+                              exp->exp_obd->obd_name, POSTID(&lsm->lsm_oi),
+                              POSTID(&loi->loi_oi), idx, err);
+                       if (!rc)
+                               rc = err;
+               }
+       }
+       RETURN(rc);
 }
 
 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
@@ -1922,9 +1958,9 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         RETURN(-EINVAL);
 
                 /* copy UUID */
-                if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
-                                     min((int) data->ioc_plen2,
-                                         (int) sizeof(struct obd_uuid))))
+               if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
+                                min((int)data->ioc_plen2,
+                                    (int)sizeof(struct obd_uuid))))
                         RETURN(-EFAULT);
 
                flags = uarg ? *(__u32*)uarg : 0;
@@ -1934,7 +1970,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                                 flags);
                 if (rc)
                         RETURN(rc);
-                if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
+               if (copy_to_user(data->ioc_pbuf1, &stat_buf,
                                      min((int) data->ioc_plen1,
                                          (int) sizeof(stat_buf))))
                         RETURN(-EFAULT);
@@ -1980,7 +2016,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         *genp = lov->lov_tgts[i]->ltd_gen;
                 }
 
-                if (cfs_copy_to_user((void *)uarg, buf, len))
+               if (copy_to_user((void *)uarg, buf, len))
                         rc = -EFAULT;
                 obd_ioctl_freedata(buf, len);
                 break;
@@ -1999,13 +2035,13 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 struct lov_tgt_desc *tgt = NULL;
                 struct obd_quotactl *oqctl;
 
-                if (qctl->qc_valid == QC_OSTIDX) {
-                        if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
-                                RETURN(-EINVAL);
+               if (qctl->qc_valid == QC_OSTIDX) {
+                       if (count <= qctl->qc_idx)
+                               RETURN(-EINVAL);
 
-                        tgt = lov->lov_tgts[qctl->qc_idx];
-                        if (!tgt || !tgt->ltd_exp)
-                                RETURN(-EINVAL);
+                       tgt = lov->lov_tgts[qctl->qc_idx];
+                       if (!tgt || !tgt->ltd_exp)
+                               RETURN(-EINVAL);
                 } else if (qctl->qc_valid == QC_UUID) {
                         for (i = 0; i < count; i++) {
                                 tgt = lov->lov_tgts[i];
@@ -2240,8 +2276,29 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
         int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
         unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
 
-        if (lsm == NULL)
-                GOTO(out, rc = 0);
+       if (!lsm_has_objects(lsm)) {
+               if (lsm && lsm_is_released(lsm) && (fm_key->fiemap.fm_start <
+                   fm_key->oa.o_size)) {
+                       /* released file, return a minimal FIEMAP if
+                        * request fits in file-size.
+                        */
+                       fiemap->fm_mapped_extents = 1;
+                       fiemap->fm_extents[0].fe_logical =
+                                               fm_key->fiemap.fm_start;
+                       if (fm_key->fiemap.fm_start + fm_key->fiemap.fm_length <
+                           fm_key->oa.o_size)
+                               fiemap->fm_extents[0].fe_length =
+                                               fm_key->fiemap.fm_length;
+                       else
+                               fiemap->fm_extents[0].fe_length =
+                                               fm_key->oa.o_size -
+                                               fm_key->fiemap.fm_start;
+                       fiemap->fm_extents[0].fe_flags |=
+                                               (FIEMAP_EXTENT_UNKNOWN |
+                                                FIEMAP_EXTENT_LAST);
+               }
+               GOTO(out, rc = 0);
+       }
 
         if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
                 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
@@ -2335,8 +2392,7 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
                         fm_local->fm_mapped_extents = 0;
                         fm_local->fm_flags = fiemap->fm_flags;
 
-                        fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
-                        fm_key->oa.o_seq = lsm->lsm_oinfo[cur_stripe]->loi_seq;
+                       fm_key->oa.o_oi = lsm->lsm_oinfo[cur_stripe]->loi_oi;
                         ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
 
                         if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
@@ -2440,7 +2496,8 @@ skip_last_device_calc:
         fiemap->fm_mapped_extents = current_extent;
 
 out:
-        OBD_FREE_LARGE(fm_local, buffer_size);
+       if (fm_local)
+               OBD_FREE_LARGE(fm_local, buffer_size);
         return rc;
 }
 
@@ -2524,7 +2581,7 @@ static int lov_get_info(const struct lu_env *env, struct obd_export *exp,
                 if (!tgt || !tgt->ltd_exp)
                         GOTO(out, rc = -ESRCH);
 
-                *((__u64*)val) = tgt->ltd_exp->exp_connect_flags;
+               *((__u64 *)val) = exp_connect_flags(tgt->ltd_exp);
                 GOTO(out, rc = 0);
         } else if (KEY_IS(KEY_TGT_COUNT)) {
                 *((int *)val) = lov->desc.ld_tgt_count;
@@ -2678,16 +2735,16 @@ static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
 
 void lov_stripe_lock(struct lov_stripe_md *md)
 {
-       LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
+       LASSERT(md->lsm_lock_owner != current_pid());
        spin_lock(&md->lsm_lock);
        LASSERT(md->lsm_lock_owner == 0);
-       md->lsm_lock_owner = cfs_curproc_pid();
+       md->lsm_lock_owner = current_pid();
 }
 EXPORT_SYMBOL(lov_stripe_lock);
 
 void lov_stripe_unlock(struct lov_stripe_md *md)
 {
-       LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
+       LASSERT(md->lsm_lock_owner == current_pid());
        md->lsm_lock_owner = 0;
        spin_unlock(&md->lsm_lock);
 }
@@ -2844,14 +2901,14 @@ struct obd_ops lov_obd_ops = {
         .o_quotacheck          = lov_quotacheck,
 };
 
-cfs_mem_cache_t *lov_oinfo_slab;
+struct kmem_cache *lov_oinfo_slab;
 
 extern struct lu_kmem_descr lov_caches[];
 
 int __init lov_init(void)
 {
         struct lprocfs_static_vars lvars = { 0 };
-        int rc, rc2;
+       int rc;
         ENTRY;
 
         /* print an address of _any_ initialized kernel symbol from this
@@ -2863,9 +2920,9 @@ int __init lov_init(void)
         if (rc)
                 return rc;
 
-        lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
-                                              sizeof(struct lov_oinfo),
-                                              0, CFS_SLAB_HWCACHE_ALIGN);
+       lov_oinfo_slab = kmem_cache_create("lov_oinfo",
+                                          sizeof(struct lov_oinfo), 0,
+                                          SLAB_HWCACHE_ALIGN, NULL);
         if (lov_oinfo_slab == NULL) {
                 lu_kmem_fini(lov_caches);
                 return -ENOMEM;
@@ -2876,8 +2933,7 @@ int __init lov_init(void)
                                  LUSTRE_LOV_NAME, &lov_device_type);
 
         if (rc) {
-                rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
-                LASSERT(rc2 == 0);
+               kmem_cache_destroy(lov_oinfo_slab);
                 lu_kmem_fini(lov_caches);
         }
 
@@ -2887,12 +2943,8 @@ int __init lov_init(void)
 #ifdef __KERNEL__
 static void /*__exit*/ lov_exit(void)
 {
-        int rc;
-
-        class_unregister_type(LUSTRE_LOV_NAME);
-        rc = cfs_mem_cache_destroy(lov_oinfo_slab);
-        LASSERT(rc == 0);
-
+       class_unregister_type(LUSTRE_LOV_NAME);
+       kmem_cache_destroy(lov_oinfo_slab);
        lu_kmem_fini(lov_caches);
 }