Whamcloud - gitweb
LU-7986 hsm: update actions llog in place
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_actions.c
index da7f5a9..137cb4a 100644 (file)
@@ -23,6 +23,7 @@
  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
  *     alternatives
  *
+ * Copyright (c) 2013, 2014, Intel Corporation.
  */
 /*
  * lustre/mdt/mdt_hsm_cdt_actions.c
@@ -161,7 +162,7 @@ int mdt_agent_record_add(const struct lu_env *env,
                hai->hai_cookie = cdt->cdt_last_cookie;
        }
        larr->arr_hai.hai_cookie = hai->hai_cookie;
-       rc = llog_cat_add(env, lctxt->loc_handle, &larr->arr_hdr, NULL, NULL);
+       rc = llog_cat_add(env, lctxt->loc_handle, &larr->arr_hdr, NULL);
        if (rc > 0)
                rc = 0;
 
@@ -204,12 +205,10 @@ static int mdt_agent_record_update_cb(const struct lu_env *env,
        struct llog_agent_req_rec       *larr;
        struct data_update_cb           *ducb;
        int                              rc, i;
-       int                              found;
        ENTRY;
 
        larr = (struct llog_agent_req_rec *)hdr;
        ducb = data;
-       found = 0;
 
        /* check if all done */
        if (ducb->cookies_count == ducb->cookies_done)
@@ -236,10 +235,8 @@ static int mdt_agent_record_update_cb(const struct lu_env *env,
 
                        larr->arr_status = ducb->status;
                        larr->arr_req_change = ducb->change_time;
-                       rc = mdt_agent_llog_update_rec(env, ducb->mdt, llh,
-                                                      larr);
+                       rc = llog_write(env, llh, hdr, hdr->lrh_index);
                        ducb->cookies_done++;
-                       found = 1;
                        break;
                }
        }
@@ -248,9 +245,6 @@ static int mdt_agent_record_update_cb(const struct lu_env *env,
                CERROR("%s: mdt_agent_llog_update_rec() failed, rc = %d\n",
                       mdt_obd_name(ducb->mdt), rc);
 
-       if (found == 1)
-               RETURN(LLOG_DEL_RECORD);
-
        RETURN(rc);
 }
 
@@ -289,35 +283,6 @@ int mdt_agent_record_update(const struct lu_env *env, struct mdt_device *mdt,
        RETURN(rc);
 }
 
-/**
- * update a llog record
- *  cdt_llog_lock must be hold
- * \param env [IN] environment
- * \param mdt [IN] mdt device
- * \param llh [IN] llog handle, must be a catalog handle
- * \param larr [IN] record
- * \retval 0 success
- * \retval -ve failure
- */
-int mdt_agent_llog_update_rec(const struct lu_env *env,
-                             struct mdt_device *mdt, struct llog_handle *llh,
-                             struct llog_agent_req_rec *larr)
-{
-       struct llog_rec_hdr      saved_hdr;
-       int                      rc;
-       ENTRY;
-
-       /* saved old record info */
-       saved_hdr = larr->arr_hdr;
-       /* add new record with updated values */
-       larr->arr_hdr.lrh_id = 0;
-       larr->arr_hdr.lrh_index = 0;
-       rc = llog_cat_add(env, llh->u.phd.phd_cat_handle, &larr->arr_hdr,
-                         NULL, NULL);
-       larr->arr_hdr = saved_hdr;
-       RETURN(rc);
-}
-
 /*
  * Agent actions /proc seq_file methods
  * As llog processing uses a callback for each entry, we cannot do a sequential
@@ -354,7 +319,7 @@ static void *mdt_hsm_actions_proc_start(struct seq_file *s, loff_t *pos)
        struct agent_action_iterator    *aai = s->private;
        ENTRY;
 
-       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X",
+       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X\n",
                 aai->aai_magic);
 
        aai->aai_ctxt = llog_get_context(mdt2obd_dev(aai->aai_mdt),
@@ -364,12 +329,12 @@ static void *mdt_hsm_actions_proc_start(struct seq_file *s, loff_t *pos)
                RETURN(ERR_PTR(-ENOENT));
        }
 
-       CDEBUG(D_HSM, "llog succesfully initialized, start from "LPD64"\n",
+       CDEBUG(D_HSM, "llog successfully initialized, start from "LPD64"\n",
               *pos);
        /* first call = rewind */
        if (*pos == 0) {
                aai->aai_cat_index = 0;
-               aai->aai_index = -1;
+               aai->aai_index = 0;
                aai->aai_eof = false;
                *pos = 1;
        }
@@ -397,13 +362,13 @@ static int hsm_actions_show_cb(const struct lu_env *env,
        struct llog_agent_req_rec    *larr = (struct llog_agent_req_rec *)hdr;
        struct seq_file              *s = data;
        struct agent_action_iterator *aai;
-       int                           rc, sz;
+       int                           sz;
        size_t                        count;
        char                          buf[12];
        ENTRY;
 
        aai = s->private;
-       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X",
+       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X\n",
                 aai->aai_magic);
 
        /* if rec already printed => skip */
@@ -416,35 +381,29 @@ static int hsm_actions_show_cb(const struct lu_env *env,
 
        count = s->count;
        sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
-       rc = seq_printf(s, "lrh=[type=%X len=%d idx=%d/%d] fid="DFID
-                       " dfid="DFID
-                       " compound/cookie="LPX64"/"LPX64
-                       " action=%s archive#=%d flags="LPX64
-                       " extent="LPX64"-"LPX64
-                       " gid="LPX64" datalen=%d status=%s"
-                       " data=[%s]\n",
-                       hdr->lrh_type, hdr->lrh_len,
-                       llh->lgh_hdr->llh_cat_idx, hdr->lrh_index,
-                       PFID(&larr->arr_hai.hai_fid),
-                       PFID(&larr->arr_hai.hai_dfid),
-                       larr->arr_compound_id, larr->arr_hai.hai_cookie,
-                       hsm_copytool_action2name(larr->arr_hai.hai_action),
-                       larr->arr_archive_id,
-                       larr->arr_flags,
-                       larr->arr_hai.hai_extent.offset,
-                       larr->arr_hai.hai_extent.length,
-                       larr->arr_hai.hai_gid, sz,
-                       agent_req_status2name(larr->arr_status),
-                       hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
-       if (rc == 0) {
-               aai->aai_cat_index = llh->lgh_hdr->llh_cat_idx;
-               aai->aai_index = hdr->lrh_index;
-       } else {
-               if (s->count == s->size && count > 0) /* rewind the buffer */
-                       s->count = count;
-               rc = LLOG_PROC_BREAK;
-       }
-       RETURN(rc);
+       seq_printf(s, "lrh=[type=%X len=%d idx=%d/%d] fid="DFID
+                  " dfid="DFID" compound/cookie="LPX64"/"LPX64
+                  " action=%s archive#=%d flags="LPX64
+                  " extent="LPX64"-"LPX64
+                  " gid="LPX64" datalen=%d status=%s data=[%s]\n",
+                  hdr->lrh_type, hdr->lrh_len,
+                  llh->lgh_hdr->llh_cat_idx, hdr->lrh_index,
+                  PFID(&larr->arr_hai.hai_fid),
+                  PFID(&larr->arr_hai.hai_dfid),
+                  larr->arr_compound_id, larr->arr_hai.hai_cookie,
+                  hsm_copytool_action2name(larr->arr_hai.hai_action),
+                  larr->arr_archive_id,
+                  larr->arr_flags,
+                  larr->arr_hai.hai_extent.offset,
+                  larr->arr_hai.hai_extent.length,
+                  larr->arr_hai.hai_gid, sz,
+                  agent_req_status2name(larr->arr_status),
+                  hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
+
+       aai->aai_cat_index = llh->lgh_hdr->llh_cat_idx;
+       aai->aai_index = hdr->lrh_index;
+
+       RETURN(0);
 }
 
 /**
@@ -459,7 +418,7 @@ static int mdt_hsm_actions_proc_show(struct seq_file *s, void *v)
        int                              rc;
        ENTRY;
 
-       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X",
+       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X\n",
                 aai->aai_magic);
 
        CDEBUG(D_HSM, "show from cat %d index %d eof=%d\n",
@@ -470,7 +429,7 @@ static int mdt_hsm_actions_proc_show(struct seq_file *s, void *v)
        mutex_lock(&cdt->cdt_llog_lock);
        rc = llog_cat_process(&aai->aai_env, aai->aai_ctxt->loc_handle,
                              hsm_actions_show_cb, s,
-                             aai->aai_cat_index, aai->aai_index + 1);
+                             aai->aai_cat_index, aai->aai_index);
        mutex_unlock(&cdt->cdt_llog_lock);
        if (rc == 0) /* all llog parsed */
                aai->aai_eof = true;
@@ -488,7 +447,7 @@ static void mdt_hsm_actions_proc_stop(struct seq_file *s, void *v)
        struct agent_action_iterator *aai = s->private;
        ENTRY;
 
-       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X",
+       LASSERTF(aai->aai_magic == AGENT_ACTIONS_IT_MAGIC, "%08X\n",
                 aai->aai_magic);
 
        if (aai->aai_ctxt)
@@ -513,9 +472,6 @@ static int lprocfs_open_hsm_actions(struct inode *inode, struct file *file)
        struct mdt_device               *mdt;
        ENTRY;
 
-       if (LPROCFS_ENTRY_CHECK(PDE(inode)))
-               RETURN(-ENOENT);
-
        rc = seq_open(file, &mdt_hsm_actions_proc_ops);
        if (rc)
                RETURN(rc);
@@ -532,7 +488,7 @@ static int lprocfs_open_hsm_actions(struct inode *inode, struct file *file)
        /* mdt is saved in proc_dir_entry->data by
         * mdt_coordinator_procfs_init() calling lprocfs_register()
         */
-       mdt = (struct mdt_device *)PDE(inode)->data;
+       mdt = (struct mdt_device *)PDE_DATA(inode);
        aai->aai_mdt = mdt;
        s = file->private_data;
        s->private = aai;
@@ -551,7 +507,7 @@ out:
 
 /**
  * lprocfs_release_hsm_actions() is called at end of /proc access.
- * It frees allocated ressources and calls cleanup lprocfs methods.
+ * It frees allocated resources and calls cleanup lprocfs methods.
  */
 static int lprocfs_release_hsm_actions(struct inode *inode, struct file *file)
 {