Whamcloud - gitweb
LU-11765 ofd: return EAGAIN during 1st CLEANUP_ORPHAN
[fs/lustre-release.git] / lustre / ofd / ofd_lvb.c
index aecd1b6..7c21683 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);
 
@@ -120,8 +126,24 @@ static int ofd_lvbo_init(const struct lu_env *env, struct ldlm_resource *res)
                GOTO(out_lvb, rc = PTR_ERR(fo));
 
        rc = ofd_attr_get(env, fo, &info->fti_attr);
-       if (rc)
+       if (rc) {
+               struct ofd_seq          *oseq;
+               __u64                    seq;
+
+               /* Object could be recreated during the first
+                * CLEANUP_ORPHAN request. */
+               if (rc == -ENOENT) {
+                       seq = fid_seq(&info->fti_fid);
+                       oseq = ofd_seq_load(env, ofd, fid_seq_is_idif(seq) ?
+                                           FID_SEQ_OST_MDT0 : seq);
+                       if (!IS_ERR_OR_NULL(oseq)) {
+                               if (!oseq->os_last_id_synced)
+                                       rc = -EAGAIN;
+                               ofd_seq_put(env, oseq);
+                       }
+               }
                GOTO(out_obj, rc);
+       }
 
        lvb->lvb_size = info->fti_attr.la_size;
        lvb->lvb_blocks = info->fti_attr.la_blocks;
@@ -144,6 +166,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 +369,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 +377,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 +389,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);