Whamcloud - gitweb
LU-8592 mdt: hold mdt_device::mdt_md_root until service stop
[fs/lustre-release.git] / lustre / ptlrpc / llog_client.c
index 2a30db5..e57a331 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_LOG
 
+#include <linux/list.h>
 #include <libcfs/libcfs.h>
 
 #include <obd_class.h>
 #include <lustre_log.h>
 #include <lustre_net.h>
-#include <libcfs/list.h>
 
 #define LLOG_CLIENT_ENTRY(ctxt, imp) do {                             \
        mutex_lock(&ctxt->loc_mutex);                             \
@@ -141,7 +137,8 @@ out:
 }
 
 static int llog_client_destroy(const struct lu_env *env,
-                              struct llog_handle *loghandle)
+                              struct llog_handle *loghandle,
+                              struct thandle *th)
 {
         struct obd_import     *imp;
         struct ptlrpc_request *req = NULL;
@@ -310,23 +307,31 @@ static int llog_client_read_header(const struct lu_env *env,
         if (hdr == NULL)
                 GOTO(out, rc =-EFAULT);
 
-        memcpy(handle->lgh_hdr, hdr, sizeof (*hdr));
-        handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
-
-        /* sanity checks */
-        llh_hdr = &handle->lgh_hdr->llh_hdr;
-        if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
-                CERROR("bad log header magic: %#x (expecting %#x)\n",
-                       llh_hdr->lrh_type, LLOG_HDR_MAGIC);
-                rc = -EIO;
-        } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
-                CERROR("incorrectly sized log header: %#x "
-                       "(expecting %#x)\n",
-                       llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
-                CERROR("you may need to re-run lconf --write_conf.\n");
-                rc = -EIO;
-        }
-        EXIT;
+       if (handle->lgh_hdr_size < hdr->llh_hdr.lrh_len)
+               GOTO(out, rc = -EFAULT);
+
+       memcpy(handle->lgh_hdr, hdr, hdr->llh_hdr.lrh_len);
+       handle->lgh_last_idx = LLOG_HDR_TAIL(handle->lgh_hdr)->lrt_index;
+
+       /* sanity checks */
+       llh_hdr = &handle->lgh_hdr->llh_hdr;
+       if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
+               CERROR("bad log header magic: %#x (expecting %#x)\n",
+                      llh_hdr->lrh_type, LLOG_HDR_MAGIC);
+               rc = -EIO;
+       } else if (llh_hdr->lrh_len !=
+                  LLOG_HDR_TAIL(handle->lgh_hdr)->lrt_len ||
+                  (llh_hdr->lrh_len & (llh_hdr->lrh_len - 1)) != 0 ||
+                  llh_hdr->lrh_len < LLOG_MIN_CHUNK_SIZE ||
+                  llh_hdr->lrh_len > handle->lgh_hdr_size) {
+               CERROR("incorrectly sized log header: %#x, "
+                      "expecting %#x (power of two > 8192)\n",
+                      llh_hdr->lrh_len,
+                      LLOG_HDR_TAIL(handle->lgh_hdr)->lrt_len);
+               CERROR("you may need to re-run lconf --write_conf.\n");
+               rc = -EIO;
+       }
+       EXIT;
 out:
         ptlrpc_req_finished(req);
 err_exit: