Whamcloud - gitweb
LU-3042 build: fix 'NULL pointer dereference' errors
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_actions.c
index ea2187a..2e831c3 100644 (file)
@@ -43,7 +43,8 @@
 #include <lustre_log.h>
 #include "mdt_internal.h"
 
-void dump_llog_agent_req_rec(char *prefix, struct llog_agent_req_rec *larr)
+void dump_llog_agent_req_rec(const char *prefix,
+                            const struct llog_agent_req_rec *larr)
 {
        char    buf[12];
        int     sz;
@@ -92,10 +93,10 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
        ENTRY;
 
        lctxt = llog_get_context(obd, LLOG_AGENT_ORIG_CTXT);
-       if ((lctxt == NULL) || (lctxt->loc_handle == NULL))
+       if (lctxt == NULL || lctxt->loc_handle == NULL)
                RETURN(-ENOENT);
 
-       down(&cdt->cdt_llog_lock);
+       mutex_lock(&cdt->cdt_llog_lock);
 
        rc = llog_cat_process(env, lctxt->loc_handle, cb, data, 0, 0);
        if (rc < 0)
@@ -105,7 +106,7 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
                rc = 0;
 
        llog_ctxt_put(lctxt);
-       up(&cdt->cdt_llog_lock);
+       mutex_unlock(&cdt->cdt_llog_lock);
        RETURN(rc);
 }
 
@@ -147,10 +148,10 @@ int mdt_agent_record_add(const struct lu_env *env,
        memcpy(&larr->arr_hai, hai, hai->hai_len);
 
        lctxt = llog_get_context(obd, LLOG_AGENT_ORIG_CTXT);
-       if ((lctxt == NULL) || (lctxt->loc_handle == NULL))
+       if (lctxt == NULL || lctxt->loc_handle == NULL)
                GOTO(free, rc = -ENOENT);
 
-       down(&cdt->cdt_llog_lock);
+       mutex_lock(&cdt->cdt_llog_lock);
 
        /* in case of cancel request, the cookie is already set to the
         * value of the request cookie to be cancelled
@@ -164,7 +165,7 @@ int mdt_agent_record_add(const struct lu_env *env,
        if (rc > 0)
                rc = 0;
 
-       up(&cdt->cdt_llog_lock);
+       mutex_unlock(&cdt->cdt_llog_lock);
        llog_ctxt_put(lctxt);
 
        EXIT;
@@ -222,8 +223,8 @@ static int mdt_agent_record_update_cb(const struct lu_env *env,
         * the 1st has to be set to ARS_CANCELED and the 2nd to ARS_SUCCEED
         */
        if (agent_req_in_final_state(larr->arr_status) ||
-           ((larr->arr_hai.hai_action == HSMA_CANCEL) &&
-            (ducb->status == ARS_CANCELED)))
+           (larr->arr_hai.hai_action == HSMA_CANCEL &&
+            ducb->status == ARS_CANCELED))
                RETURN(0);
 
        rc = 0;
@@ -340,7 +341,6 @@ struct agent_action_iterator {
        struct lu_env            aai_env;        /**< lustre env for llog */
        struct obd_device       *aai_obd;        /**< metadata device */
        struct llog_ctxt        *aai_ctxt;       /**< llog context */
-       struct llog_handle      *aai_llh;        /**< llog handle */
        int                      aai_index_done; /**< idx already shown */
        int                      aai_index_cb;   /**< current idx in loop cb */
        int                      aai_eof;        /**< all done */
@@ -353,25 +353,16 @@ struct agent_action_iterator {
 static void *mdt_agent_actions_proc_start(struct seq_file *s, loff_t *pos)
 {
        struct agent_action_iterator    *aai = s->private;
-       int                              rc;
        ENTRY;
 
        LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X",
                 aai->aai_magic);
 
        aai->aai_ctxt = llog_get_context(aai->aai_obd, LLOG_AGENT_ORIG_CTXT);
-       if (aai->aai_ctxt == NULL) {
+       if (aai->aai_ctxt == NULL || aai->aai_ctxt->loc_handle == NULL) {
                CERROR("llog_get_context() failed\n");
                RETURN(ERR_PTR(-ENOENT));
        }
-       rc = llog_open(&aai->aai_env, aai->aai_ctxt, &aai->aai_llh, NULL,
-                      HSM_ACTIONS, LLOG_OPEN_EXISTS);
-       if (rc)
-               GOTO(err, rc);
-
-       rc = llog_init_handle(&aai->aai_env, aai->aai_llh, LLOG_F_IS_CAT, NULL);
-       if (rc)
-               GOTO(err, rc);
 
        CDEBUG(D_HSM, "llog succesfully initialized, start from "LPD64"\n",
               *pos);
@@ -383,16 +374,6 @@ static void *mdt_agent_actions_proc_start(struct seq_file *s, loff_t *pos)
        }
 
        RETURN(aai);
-err:
-       if (aai->aai_llh) {
-               llog_cat_close(&aai->aai_env, aai->aai_llh);
-               aai->aai_llh = NULL;
-       }
-
-       if (aai->aai_ctxt)
-               llog_ctxt_put(aai->aai_ctxt);
-
-       RETURN(ERR_PTR(rc));
 }
 
 /**
@@ -492,7 +473,7 @@ static int mdt_agent_actions_proc_show(struct seq_file *s, void *v)
                RETURN(0);
 
        aai->aai_index_cb = 0;
-       rc = llog_cat_process(&aai->aai_env, aai->aai_llh,
+       rc = llog_cat_process(&aai->aai_env, aai->aai_ctxt->loc_handle,
                              agent_actions_show_cb, s, 0, 0);
        /* was all llog parsed? */
        if (rc == 0)
@@ -516,12 +497,9 @@ static void mdt_agent_actions_proc_stop(struct seq_file *s, void *v)
        LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X",
                 aai->aai_magic);
 
-       if (aai->aai_llh) {
-               llog_cat_close(&aai->aai_env, aai->aai_llh);
-               aai->aai_llh = NULL;
-       }
        if (aai->aai_ctxt)
                llog_ctxt_put(aai->aai_ctxt);
+
        EXIT;
        return;
 }
@@ -557,7 +535,6 @@ static int lprocfs_open_agent_actions(struct inode *inode, struct file *file)
        if (rc)
                GOTO(err, rc);
 
-       aai->aai_llh = NULL;
        /* mdt is saved in proc_dir_entry->data by
         * mdt_coordinator_procfs_init() calling lprocfs_register()
         */