Whamcloud - gitweb
LU-10773 obdclass: yield cpu during changelog_block_trim_ext
[fs/lustre-release.git] / lustre / obdclass / llog_osd.c
index f1c4b22..f25126d 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -362,7 +362,7 @@ static int llog_osd_declare_write_rec(const struct lu_env *env,
  *                             the full llog record to write. This is
  *                             the beginning of buffer to write, the length
  *                             of buffer is stored in \a rec::lrh_len
- * \param[out] reccookie       pointer to the cookie to return back if needed.
+ * \param[in,out] reccookie    pointer to the cookie to return back if needed.
  *                             It is used for further cancel of this llog
  *                             record.
  * \param[in]  idx             index of the llog record. If \a idx == -1 then
@@ -490,26 +490,26 @@ static int llog_osd_write_rec(const struct lu_env *env,
                                             &lgi->lgi_off, th);
 
                        RETURN(rc);
-               } else if (loghandle->lgh_cur_idx > 0) {
+               } else if (llh->llh_flags & LLOG_F_IS_FIXSIZE) {
+                       lgi->lgi_off = llh->llh_hdr.lrh_len +
+                                      (idx - 1) * reclen;
+               } else if (reccookie != NULL && reccookie->lgc_index > 0) {
                        /**
-                        * The lgh_cur_offset can be used only if index is
+                        * The lgc_offset can be used only if index is
                         * the same.
                         */
-                       if (idx != loghandle->lgh_cur_idx) {
+                       if (idx != reccookie->lgc_index) {
                                CERROR("%s: modify index mismatch %d %d\n",
                                       o->do_lu.lo_dev->ld_obd->obd_name, idx,
-                                      loghandle->lgh_cur_idx);
+                                      reccookie->lgc_index);
                                RETURN(-EFAULT);
                        }
 
-                       lgi->lgi_off = loghandle->lgh_cur_offset;
+                       lgi->lgi_off = reccookie->lgc_offset;
                        CDEBUG(D_OTHER, "modify record "DFID": idx:%u, "
                               "len:%u offset %llu\n",
                               PFID(&loghandle->lgh_id.lgl_oi.oi_fid), idx,
                               rec->lrh_len, (long long)lgi->lgi_off);
-               } else if (llh->llh_flags & LLOG_F_IS_FIXSIZE) {
-                       lgi->lgi_off = llh->llh_hdr.lrh_len +
-                                      (idx - 1) * reclen;
                } else {
                        /* This can be result of lgh_cur_idx is not set during
                         * llog processing or llh_size is not set to proper
@@ -788,9 +788,27 @@ static inline void llog_skip_over(struct llog_handle *lgh, __u64 *off,
  */
 static void changelog_block_trim_ext(struct llog_rec_hdr *hdr,
                                     struct llog_rec_hdr *last_hdr,
-                                    enum changelog_rec_flags flags,
-                                    enum changelog_rec_extra_flags extra_flags)
+                                    struct llog_handle *loghandle)
 {
+       enum changelog_rec_flags flags = CLF_SUPPORTED;
+       enum changelog_rec_extra_flags extra_flags = CLFE_SUPPORTED;
+
+       if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_X_XATTR))
+               extra_flags &= ~CLFE_XATTR;
+       if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_X_OMODE))
+               extra_flags &= ~CLFE_OPEN;
+       if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_X_NID))
+               extra_flags &= ~CLFE_NID;
+       if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_X_UIDGID))
+               extra_flags &= ~CLFE_UIDGID;
+       if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_EXTRA_FLAGS))
+               flags &= ~CLF_EXTRA_FLAGS;
+       if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_JOBID))
+               flags &= ~CLF_JOBID;
+
+       if (flags == CLF_SUPPORTED && extra_flags == CLFE_SUPPORTED)
+               return;
+
        if (hdr->lrh_type != CHANGELOG_REC)
                return;
 
@@ -804,8 +822,26 @@ static void changelog_block_trim_ext(struct llog_rec_hdr *hdr,
                                extra_flags;
                }
 
+               if (unlikely(hdr->lrh_len == 0)) {
+                       /* It is corruption case, we cannot know the next rec,
+                        * jump to the last one directly to avoid dead loop. */
+                       LCONSOLE(D_WARNING, "Hit invalid llog record: "
+                                "idx %u, type %u, id %u\n",
+                                hdr->lrh_index, hdr->lrh_type, hdr->lrh_id);
+                       hdr = llog_rec_hdr_next(last_hdr);
+                       if (unlikely(hdr == last_hdr))
+                               LCONSOLE(D_WARNING, "The last record crashed: "
+                                        "idx %u, type %u, id %u\n",
+                                        hdr->lrh_index, hdr->lrh_type,
+                                        hdr->lrh_id);
+                       break;
+               }
+
                changelog_remap_rec(rec, rec->cr_flags & flags, xflag);
                hdr = llog_rec_hdr_next(hdr);
+               /* Yield CPU to avoid soft-lockup if there are too many records
+                * to be handled. */
+               cond_resched();
        } while ((char *)hdr <= (char *)last_hdr);
 }
 
@@ -840,8 +876,6 @@ static int llog_osd_next_block(const struct lu_env *env,
        int last_idx = *cur_idx;
        __u64 last_offset = *cur_offset;
        bool force_mini_rec = false;
-       enum changelog_rec_flags flags;
-       enum changelog_rec_extra_flags xflags;
 
        ENTRY;
 
@@ -973,16 +1007,7 @@ static int llog_osd_next_block(const struct lu_env *env,
                }
 
                /* Trim unsupported extensions for compat w/ older clients */
-               flags = CLF_SUPPORTED;
-               xflags = CLFE_SUPPORTED;
-               if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_X_UIDGID))
-                       xflags &= ~CLFE_UIDGID;
-               if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_EXTRA_FLAGS))
-                       flags &= ~CLF_EXTRA_FLAGS;
-               if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_JOBID))
-                       flags &= ~CLF_JOBID;
-               if (flags != CLF_SUPPORTED || xflags != CLFE_SUPPORTED)
-                       changelog_block_trim_ext(rec, last_rec, flags, xflags);
+               changelog_block_trim_ext(rec, last_rec, loghandle);
 
                GOTO(out, rc = 0);
 
@@ -1025,8 +1050,6 @@ static int llog_osd_prev_block(const struct lu_env *env,
        struct dt_device        *dt;
        loff_t                   cur_offset;
        __u32                   chunk_size;
-       enum changelog_rec_flags flags;
-       enum changelog_rec_extra_flags xflags;
        int                      rc;
 
        ENTRY;
@@ -1119,16 +1142,7 @@ static int llog_osd_prev_block(const struct lu_env *env,
                }
 
                /* Trim unsupported extensions for compat w/ older clients */
-               flags = CLF_SUPPORTED;
-               xflags = CLFE_SUPPORTED;
-               if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_X_UIDGID))
-                       xflags &= ~CLFE_UIDGID;
-               if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_EXTRA_FLAGS))
-                       flags &= ~CLF_EXTRA_FLAGS;
-               if (!(loghandle->lgh_hdr->llh_flags & LLOG_F_EXT_JOBID))
-                       flags &= ~CLF_JOBID;
-               if (flags != CLF_SUPPORTED || xflags != CLFE_SUPPORTED)
-                       changelog_block_trim_ext(rec, last_rec, flags, xflags);
+               changelog_block_trim_ext(rec, last_rec, loghandle);
 
                GOTO(out, rc = 0);
        }