Whamcloud - gitweb
LU-8956 llite: set sec ctx on client's inode at create time
[fs/lustre-release.git] / lustre / mdt / mdt_hsm_cdt_actions.c
index 59cbfe2..94bc265 100644 (file)
@@ -23,7 +23,7 @@
  * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
  *     alternatives
  *
- * Copyright (c) 2013, 2014, Intel Corporation.
+ * Copyright (c) 2013, 2016, Intel Corporation.
  */
 /*
  * lustre/mdt/mdt_hsm_cdt_actions.c
@@ -37,7 +37,6 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <obd_support.h>
-#include <lustre_net.h>
 #include <lustre_export.h>
 #include <obd.h>
 #include <lprocfs_status.h>
@@ -53,10 +52,10 @@ void dump_llog_agent_req_rec(const char *prefix,
        sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
        CDEBUG(D_HSM, "%slrh=[type=%X len=%d idx=%d] fid="DFID
               " dfid="DFID
-              " compound/cookie="LPX64"/"LPX64
-              " status=%s action=%s archive#=%d flags="LPX64
-              " create="LPU64" change="LPU64
-              " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
+              " compound/cookie=%#llx/%#llx"
+              " status=%s action=%s archive#=%d flags=%#llx"
+              " create=%llu change=%llu"
+              " extent=%#llx-%#llx gid=%#llx datalen=%d"
               " data=[%s]\n",
               prefix,
               larr->arr_hdr.lrh_type,
@@ -81,11 +80,12 @@ void dump_llog_agent_req_rec(const char *prefix,
  * \param mdt [IN] MDT device
  * \param cb [IN] llog callback funtion
  * \param data [IN] llog callback  data
+ * \param rw [IN] cdt_llog_lock mode (READ or WRITE)
  * \retval 0 success
  * \retval -ve failure
  */
 int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
-                    llog_cb_t cb, void *data)
+                    llog_cb_t cb, void *data, int rw)
 {
        struct obd_device       *obd = mdt2obd_dev(mdt);
        struct llog_ctxt        *lctxt = NULL;
@@ -97,7 +97,10 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
        if (lctxt == NULL || lctxt->loc_handle == NULL)
                RETURN(-ENOENT);
 
-       mutex_lock(&cdt->cdt_llog_lock);
+       if (rw == READ)
+               down_read(&cdt->cdt_llog_lock);
+       else
+               down_write(&cdt->cdt_llog_lock);
 
        rc = llog_cat_process(env, lctxt->loc_handle, cb, data, 0, 0);
        if (rc < 0)
@@ -107,7 +110,12 @@ int cdt_llog_process(const struct lu_env *env, struct mdt_device *mdt,
                rc = 0;
 
        llog_ctxt_put(lctxt);
-       mutex_unlock(&cdt->cdt_llog_lock);
+
+       if (rw == READ)
+               up_read(&cdt->cdt_llog_lock);
+       else
+               up_write(&cdt->cdt_llog_lock);
+
        RETURN(rc);
 }
 
@@ -152,21 +160,23 @@ int mdt_agent_record_add(const struct lu_env *env,
        if (lctxt == NULL || lctxt->loc_handle == NULL)
                GOTO(free, rc = -ENOENT);
 
-       mutex_lock(&cdt->cdt_llog_lock);
+       down_write(&cdt->cdt_llog_lock);
 
        /* in case of cancel request, the cookie is already set to the
         * value of the request cookie to be cancelled
         * so we do not change it */
-       if (hai->hai_action != HSMA_CANCEL) {
+       if (hai->hai_action == HSMA_CANCEL) {
+               larr->arr_hai.hai_cookie = hai->hai_cookie;
+       } else {
                cdt->cdt_last_cookie++;
-               hai->hai_cookie = cdt->cdt_last_cookie;
+               larr->arr_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);
        if (rc > 0)
                rc = 0;
 
-       mutex_unlock(&cdt->cdt_llog_lock);
+       up_write(&cdt->cdt_llog_lock);
        llog_ctxt_put(lctxt);
 
        EXIT;
@@ -205,12 +215,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)
@@ -230,17 +238,15 @@ static int mdt_agent_record_update_cb(const struct lu_env *env,
 
        rc = 0;
        for (i = 0 ; i < ducb->cookies_count ; i++) {
-               CDEBUG(D_HSM, "%s: search "LPX64", found "LPX64"\n",
+               CDEBUG(D_HSM, "%s: search %#llx, found %#llx\n",
                       mdt_obd_name(ducb->mdt), ducb->cookies[i],
                       larr->arr_hai.hai_cookie);
                if (larr->arr_hai.hai_cookie == ducb->cookies[i]) {
 
                        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;
                }
        }
@@ -249,9 +255,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);
 }
 
@@ -280,7 +283,8 @@ int mdt_agent_record_update(const struct lu_env *env, struct mdt_device *mdt,
        ducb.status = status;
        ducb.change_time = cfs_time_current_sec();
 
-       rc = cdt_llog_process(env, mdt, mdt_agent_record_update_cb, &ducb);
+       rc = cdt_llog_process(env, mdt, mdt_agent_record_update_cb, &ducb,
+                             WRITE);
        if (rc < 0)
                CERROR("%s: cdt_llog_process() failed, rc=%d, cannot update "
                       "status to %s for %d cookies, done %d\n",
@@ -290,35 +294,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);
-       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
@@ -365,12 +340,12 @@ static void *mdt_hsm_actions_proc_start(struct seq_file *s, loff_t *pos)
                RETURN(ERR_PTR(-ENOENT));
        }
 
-       CDEBUG(D_HSM, "llog successfully initialized, start from "LPD64"\n",
+       CDEBUG(D_HSM, "llog successfully initialized, start from %lld\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;
        }
@@ -398,8 +373,7 @@ 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;
-       size_t                        count;
+       int                           sz;
        char                          buf[12];
        ENTRY;
 
@@ -415,37 +389,30 @@ static int hsm_actions_show_cb(const struct lu_env *env,
                     hdr->lrh_index <= aai->aai_index))
                RETURN(0);
 
-       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=%#llx/%#llx"
+                  " action=%s archive#=%d flags=%#llx"
+                  " extent=%#llx-%#llx"
+                  " gid=%#llx 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);
 }
 
 /**
@@ -468,11 +435,11 @@ static int mdt_hsm_actions_proc_show(struct seq_file *s, void *v)
        if (aai->aai_eof)
                RETURN(0);
 
-       mutex_lock(&cdt->cdt_llog_lock);
+       down_read(&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);
-       mutex_unlock(&cdt->cdt_llog_lock);
+                             aai->aai_cat_index, aai->aai_index);
+       up_read(&cdt->cdt_llog_lock);
        if (rc == 0) /* all llog parsed */
                aai->aai_eof = true;
        if (rc == LLOG_PROC_BREAK) /* buffer full */