Whamcloud - gitweb
LU-6634 llog: destroy plain llog if init fails
[fs/lustre-release.git] / lustre / obdclass / llog_osd.c
index fb8fba4..e7ae395 100644 (file)
@@ -111,6 +111,23 @@ static int llog_osd_create_new_object(const struct lu_env *env,
 }
 
 /**
+ * Implementation of the llog_operations::lop_exist
+ *
+ * This function checks that llog exists on storage.
+ *
+ * \param[in] handle   llog handle of the current llog
+ *
+ * \retval             true if llog object exists and is not just destroyed
+ * \retval             false if llog doesn't exist or just destroyed
+ */
+static int llog_osd_exist(struct llog_handle *handle)
+{
+       LASSERT(handle->lgh_obj);
+       return dt_object_exists(handle->lgh_obj) &&
+               !lu_object_is_dying(handle->lgh_obj->do_lu.lo_header);
+}
+
+/**
  * Write a padding record to the llog
  *
  * This function writes a padding record to the end of llog. That may
@@ -378,6 +395,9 @@ static int llog_osd_write_rec(const struct lu_env *env,
        CDEBUG(D_OTHER, "new record %x to "DFID"\n",
               rec->lrh_type, PFID(lu_object_fid(&o->do_lu)));
 
+       if (!llog_osd_exist(loghandle))
+               RETURN(-ENOENT);
+
        /* record length should not bigger than  */
        if (reclen > loghandle->lgh_hdr->llh_hdr.lrh_len)
                RETURN(-E2BIG);
@@ -521,6 +541,14 @@ static int llog_osd_write_rec(const struct lu_env *env,
         * process them page-at-a-time if needed.  If it will cross a chunk
         * boundary, write in a fake (but referenced) entry to pad the chunk.
         */
+
+
+       /* simulate ENOSPC when new plain llog is being added to the
+        * catalog */
+       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED2) &&
+           llh->llh_flags & LLOG_F_IS_CAT)
+               RETURN(-ENOSPC);
+
        LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
        lgi->lgi_off = lgi->lgi_attr.la_size;
        left = chunk_size - (lgi->lgi_off & (chunk_size - 1));
@@ -535,7 +563,7 @@ static int llog_osd_write_rec(const struct lu_env *env,
        }
        /* if it's the last idx in log file, then return -ENOSPC
         * or wrap around if a catalog */
-       if ((loghandle->lgh_last_idx >= LLOG_HDR_BITMAP_SIZE(llh) - 1) ||
+       if (llog_is_full(loghandle) ||
            unlikely(llh->llh_flags & LLOG_F_IS_CAT &&
                     OBD_FAIL_PRECHECK(OBD_FAIL_CAT_RECORDS) &&
                     loghandle->lgh_last_idx >= cfs_fail_val)) {
@@ -1223,23 +1251,6 @@ out:
 }
 
 /**
- * Implementation of the llog_operations::lop_exist
- *
- * This function checks that llog exists on storage.
- *
- * \param[in] handle   llog handle of the current llog
- *
- * \retval             true if llog object exists and is not just destroyed
- * \retval             false if llog doesn't exist or just destroyed
- */
-static int llog_osd_exist(struct llog_handle *handle)
-{
-       LASSERT(handle->lgh_obj);
-       return (dt_object_exists(handle->lgh_obj) &&
-               !lu_object_is_dying(handle->lgh_obj->do_lu.lo_header));
-}
-
-/**
  * Get dir for regular fid log object
  *
  * Get directory for regular fid log object, and these regular fid log