Whamcloud - gitweb
LU-1199 build: Remove unused LB_LDISKFS_RELEASE macros
[fs/lustre-release.git] / lustre / ofd / ofd_obd.c
index 88943af..059d0e2 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -530,7 +530,7 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                        struct lov_stripe_md *lsm)
 {
        struct ofd_device       *ofd;
-       int                      rc = 0;
+       int                     rc = 0;
 
        ENTRY;
 
@@ -539,13 +539,21 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                RETURN(-EINVAL);
        }
 
+       /* Because ofd_get_info might be called from
+        * handle_request_in as well(see LU-3239), where env might
+        * not be initilaized correctly, and le_ses might be in
+        * an un-initialized state, so only refill le_ctx here */
+       rc = lu_env_refill((struct lu_env *)env);
+       if (rc != 0)
+               RETURN(rc);
+
        ofd = ofd_exp(exp);
 
        if (KEY_IS(KEY_BLOCKSIZE)) {
                __u32 *blocksize = val;
                if (blocksize) {
                        if (*vallen < sizeof(*blocksize))
-                               RETURN(-EOVERFLOW);
+                               GOTO(out, rc = -EOVERFLOW);
                        *blocksize = 1 << ofd->ofd_dt_conf.ddp_block_shift;
                }
                *vallen = sizeof(*blocksize);
@@ -553,7 +561,7 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                __u32 *blocksize_bits = val;
                if (blocksize_bits) {
                        if (*vallen < sizeof(*blocksize_bits))
-                               RETURN(-EOVERFLOW);
+                               GOTO(out, rc = -EOVERFLOW);
                        *blocksize_bits = ofd->ofd_dt_conf.ddp_block_shift;
                }
                *vallen = sizeof(*blocksize_bits);
@@ -563,7 +571,7 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
 
                if (val == NULL) {
                        *vallen = sizeof(obd_id);
-                       RETURN(0);
+                       GOTO(out, rc = 0);
                }
                ofd_info_init(env, exp);
                oseq = ofd_seq_load(env, ofd,
@@ -572,7 +580,7 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                if (last_id) {
                        if (*vallen < sizeof(*last_id)) {
                                ofd_seq_put(env, oseq);
-                               RETURN(-EOVERFLOW);
+                               GOTO(out, rc = -EOVERFLOW);
                        }
                        *last_id = ofd_seq_last_oid(oseq);
                }
@@ -587,13 +595,13 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                if (val == NULL) {
                        *vallen = fiemap_count_to_size(
                                               fm_key->fiemap.fm_extent_count);
-                       RETURN(0);
+                       GOTO(out, rc = 0);
                }
 
                info = ofd_info_init(env, exp);
                rc = ostid_to_fid(&info->fti_fid, &fm_key->oa.o_oi, 0);
                if (rc != 0)
-                       RETURN(rc);
+                       GOTO(out, rc);
                CDEBUG(D_INODE, "get FIEMAP of object "DFID"\n",
                       PFID(&info->fti_fid));
 
@@ -621,7 +629,6 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                *((__u32 *) val) = ofd->ofd_sync_lock_cancel;
                *vallen = sizeof(__u32);
        } else if (KEY_IS(KEY_LAST_FID)) {
-               struct lu_env           env;
                struct ofd_device       *ofd = ofd_exp(exp);
                struct ofd_seq          *oseq;
                struct lu_fid           *fid = val;
@@ -629,22 +636,20 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
 
                if (fid == NULL) {
                        *vallen = sizeof(struct lu_fid);
-                       RETURN(0);
+                       GOTO(out, rc = 0);
                }
 
                if (*vallen < sizeof(*fid))
-                       RETURN(-EOVERFLOW);
+                       GOTO(out, rc = -EOVERFLOW);
 
-               rc = lu_env_init(&env, LCT_DT_THREAD);
-               if (rc != 0)
-                       RETURN(rc);
-               ofd_info_init(&env, exp);
+               ofd_info_init(env, exp);
 
                fid_le_to_cpu(fid, fid);
 
-               oseq = ofd_seq_load(&env, ofd, ostid_seq((struct ost_id *)fid));
+               oseq = ofd_seq_load(env, ofd,
+                                   ostid_seq((struct ost_id *)fid));
                if (IS_ERR(oseq))
-                       GOTO(out_fini, rc = PTR_ERR(oseq));
+                       GOTO(out, rc = PTR_ERR(oseq));
 
                rc = ostid_to_fid(fid, &oseq->os_oi,
                             ofd->ofd_lut.lut_lsd.lsd_osd_index);
@@ -655,14 +660,12 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
                       PFID(fid));
                *vallen = sizeof(*fid);
 out_put:
-               ofd_seq_put(&env, oseq);
-out_fini:
-               lu_env_fini(&env);
+               ofd_seq_put(env, oseq);
        } else {
                CERROR("Not supported key %s\n", (char*)key);
                rc = -EOPNOTSUPP;
        }
-
+out:
        RETURN(rc);
 }
 
@@ -1230,6 +1233,7 @@ int ofd_create(const struct lu_env *env, struct obd_export *exp,
                        CERROR("%s:["LPU64"] destroys_in_progress already"
                               " cleared\n", exp->exp_obd->obd_name,
                               ostid_seq(&oa->o_oi));
+                       ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
                        GOTO(out, rc = 0);
                }
                diff = ostid_id(&oa->o_oi) - ofd_seq_last_oid(oseq);