Whamcloud - gitweb
LU-8014 hsm: remove invalid kuc_free in coordinator
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_agent.c
index 92e0730..c97be71 100644 (file)
@@ -40,6 +40,7 @@
 #include <lustre_export.h>
 #include <lustre/lustre_user.h>
 #include <lprocfs_status.h>
+#include <lustre_kernelcomm.h>
 #include "mdt_internal.h"
 
 /*
@@ -48,7 +49,7 @@
 
 /*
  * find a hsm_agent by uuid
- * lock cdt_agent_lock needs to be hold by caller
+ * lock cdt_agent_lock needs to be held by caller
  * \param cdt [IN] coordinator
  * \param uuid [IN] agent UUID
  * \retval hsm_agent pointer or NULL if not found
@@ -343,18 +344,10 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti,
               hal->hal_archive_id);
 
        len = hal_size(hal);
-       if (kuc_ispayload(hal)) {
-               /* hal is already a kuc payload
-                * we do not need to alloc a new one
-                * this avoid a alloc/memcpy/free
-                */
-               buf = hal;
-       } else {
-               buf = kuc_alloc(len, KUC_TRANSPORT_HSM, HMT_ACTION_LIST);
-               if (IS_ERR(buf))
-                       RETURN(PTR_ERR(buf));
-               memcpy(buf, hal, len);
-       }
+       buf = kuc_alloc(len, KUC_TRANSPORT_HSM, HMT_ACTION_LIST);
+       if (IS_ERR(buf))
+               RETURN(PTR_ERR(buf));
+       memcpy(buf, hal, len);
 
        /* Check if request is still valid (cf file hsm flags) */
        fail_request = false;
@@ -413,6 +406,33 @@ int mdt_hsm_agent_send(struct mdt_thread_info *mti,
                                              hai->hai_cookie, rc);
                                        GOTO(out_buf, rc);
                                }
+
+                               /* if restore and record status updated, give
+                                * back granted layout lock */
+                               if (hai->hai_action == HSMA_RESTORE) {
+                                       struct cdt_restore_handle *crh = NULL;
+                                       struct mdt_object *obj = NULL;
+
+                                       mutex_lock(&cdt->cdt_restore_lock);
+                                       crh = mdt_hsm_restore_hdl_find(cdt,
+                                                               &hai->hai_fid);
+                                       if (crh != NULL)
+                                               list_del(&crh->crh_list);
+                                       mutex_unlock(&cdt->cdt_restore_lock);
+                                       obj = mdt_object_find(mti->mti_env,
+                                                             mti->mti_mdt,
+                                                             &hai->hai_fid);
+                                       if (!IS_ERR(obj) && crh != NULL)
+                                               mdt_object_unlock(mti, obj,
+                                                                 &crh->crh_lh,
+                                                                 1);
+                                       if (crh != NULL)
+                                               OBD_SLAB_FREE_PTR(crh,
+                                                       mdt_hsm_cdt_kmem);
+                                       if (!IS_ERR(obj))
+                                               mdt_object_put(mti->mti_env,
+                                                              obj);
+                               }
                        }
                }
        }
@@ -486,8 +506,7 @@ out:
        }
 
 out_buf:
-       if (buf != hal)
-               kuc_free(buf, len);
+       kuc_free(buf, len);
 
        RETURN(rc);
 }
@@ -505,7 +524,7 @@ int mdt_hsm_coordinator_update(struct mdt_thread_info *mti,
        int      rc;
 
        ENTRY;
-       /* ask to coodinator to update request state and
+       /* ask to coordinator to update request state and
         * to record on disk the result */
        rc = mdt_hsm_update_request_state(mti, pgs, 1);
        RETURN(rc);
@@ -576,15 +595,16 @@ static int mdt_hsm_agent_proc_show(struct seq_file *s, void *v)
                RETURN(0);
 
        ha = list_entry(pos, struct hsm_agent, ha_list);
-       seq_printf(s, "uuid=%s archive#=%d (", ha->ha_uuid.uuid,
-                  ha->ha_archive_cnt);
-       if (ha->ha_archive_cnt == 0)
-               seq_printf(s, "all");
-       else
-               for (i = 0; i < ha->ha_archive_cnt; i++)
-                       seq_printf(s, "%d ", ha->ha_archive_id[i]);
+       seq_printf(s, "uuid=%s archive_id=", ha->ha_uuid.uuid);
+       if (ha->ha_archive_cnt == 0) {
+               seq_printf(s, "ANY");
+       } else {
+               seq_printf(s, "%d", ha->ha_archive_id[0]);
+               for (i = 1; i < ha->ha_archive_cnt; i++)
+                       seq_printf(s, ",%d", ha->ha_archive_id[i]);
+       }
 
-       seq_printf(s, ") r=%d s=%d f=%d\n",
+       seq_printf(s, " requests=[current:%d ok:%d errors:%d]\n",
                   atomic_read(&ha->ha_requests),
                   atomic_read(&ha->ha_success),
                   atomic_read(&ha->ha_failure));
@@ -620,16 +640,12 @@ static int lprocfs_open_hsm_agent(struct inode *inode, struct file *file)
        int              rc;
        ENTRY;
 
-       if (LPROCFS_ENTRY_AND_CHECK(PDE(inode)))
-                       RETURN(-ENOENT);
-
        rc = seq_open(file, &mdt_hsm_agent_proc_ops);
-       if (rc) {
-               LPROCFS_EXIT();
+       if (rc)
                RETURN(rc);
-       }
+
        s = file->private_data;
-       s->private = PDE(inode)->data;
+       s->private = PDE_DATA(inode);
 
        RETURN(rc);
 }