Whamcloud - gitweb
LU-11483 ldlm ofd_lvbo_init() and mdt_lvbo_fill() create env
[fs/lustre-release.git] / lustre / ofd / ofd_lvb.c
index aecd1b6..7b46388 100644 (file)
@@ -88,12 +88,10 @@ static int ofd_lvbo_init(const struct lu_env *env, struct ldlm_resource *res)
        struct ofd_device       *ofd;
        struct ofd_object       *fo;
        struct ofd_thread_info  *info;
-       int                      rc = 0;
-
+       struct lu_env _env;
+       int rc = 0;
        ENTRY;
 
-       LASSERT(env);
-       info = ofd_info(env);
        LASSERT(res);
        LASSERT(mutex_is_locked(&res->lr_lvb_mutex));
 
@@ -106,10 +104,18 @@ static int ofd_lvbo_init(const struct lu_env *env, struct ldlm_resource *res)
        if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_OST_LVB))
                RETURN(-ENOMEM);
 
+       if (!env) {
+               rc = lu_env_init(&_env, LCT_DT_THREAD);
+               if (rc)
+                       RETURN(rc);
+               env = &_env;
+       }
+
        OBD_ALLOC_PTR(lvb);
        if (lvb == NULL)
                GOTO(out, rc = -ENOMEM);
 
+       info = ofd_info(env);
        res->lr_lvb_data = lvb;
        res->lr_lvb_len = sizeof(*lvb);
 
@@ -144,6 +150,8 @@ out_lvb:
                OST_LVB_SET_ERR(lvb->lvb_blocks, rc);
 out:
        /* Don't free lvb data on lookup error */
+       if (env && env == &_env)
+               lu_env_fini(&_env);
        return rc;
 }
 
@@ -345,6 +353,7 @@ static int ofd_lvbo_size(struct ldlm_lock *lock)
  *
  * This function is called to fill the given RPC buffer \a buf with LVB data
  *
+ * \param[in] env      execution environment
  * \param[in] lock     LDLM lock
  * \param[in] buf      RPC buffer to fill
  * \param[in] buflen   buffer length
@@ -352,7 +361,7 @@ static int ofd_lvbo_size(struct ldlm_lock *lock)
  * \retval             size of LVB data written into \a buf buffer
  */
 static int ofd_lvbo_fill(const struct lu_env *env, struct ldlm_lock *lock,
-                        void *buf, int buflen)
+                        void *buf, int *buflen)
 {
        struct ldlm_resource *res = lock->l_resource;
        int lvb_len;
@@ -364,8 +373,8 @@ static int ofd_lvbo_fill(const struct lu_env *env, struct ldlm_lock *lock,
        lvb_len = ofd_lvbo_size(lock);
        LASSERT(lvb_len <= res->lr_lvb_len);
 
-       if (lvb_len > buflen)
-               lvb_len = buflen;
+       if (lvb_len > *buflen)
+               lvb_len = *buflen;
 
        lock_res(res);
        memcpy(buf, res->lr_lvb_data, lvb_len);