From 1bd1be8bee38262465a3c0385a8f4608e17b04f6 Mon Sep 17 00:00:00 2001
From: niu <niu>
Date: Wed, 10 Dec 2003 01:51:01 +0000
Subject: [PATCH] b: 1988 r: Andreas

Make log record alignment 8 bytes.
---
 lustre/include/linux/lustre_idl.h | 12 ++++++------
 lustre/include/linux/lustre_log.h |  9 ++-------
 lustre/obdclass/llog_lvfs.c       |  5 +++--
 lustre/obdclass/llog_test.c       |  1 -
 4 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/lustre/include/linux/lustre_idl.h b/lustre/include/linux/lustre_idl.h
index e2e68460a6..368f35c85e 100644
--- a/lustre/include/linux/lustre_idl.h
+++ b/lustre/include/linux/lustre_idl.h
@@ -878,7 +878,7 @@ struct llog_rec_tail {
 struct llog_logid_rec {
         struct llog_rec_hdr     lid_hdr;
         struct llog_logid       lid_id;
-        __u32                   padding[5];
+        __u32                   padding;
         struct llog_rec_tail    lid_tail;
 } __attribute__((packed));
 
@@ -887,7 +887,7 @@ struct llog_create_rec {
         struct ll_fid           lcr_fid;
         obd_id                  lcr_oid;
         obd_count               lcr_ogen;
-        __u32                   padding[3];
+        __u32                   padding;
         struct llog_rec_tail    lcr_tail;
 } __attribute__((packed));
 
@@ -895,7 +895,7 @@ struct llog_orphan_rec {
         struct llog_rec_hdr     lor_hdr;
         obd_id                  lor_oid;
         obd_count               lor_ogen;
-        __u32                   padding[7];
+        __u32                   padding;
         struct llog_rec_tail    lor_tail;
 } __attribute__((packed));
 
@@ -903,7 +903,7 @@ struct llog_unlink_rec {
         struct llog_rec_hdr     lur_hdr;
         obd_id                  lur_oid;
         obd_count               lur_ogen;
-        __u32                   padding[7];
+        __u32                   padding;
         struct llog_rec_tail    lur_tail;
 } __attribute__((packed));
 
@@ -911,7 +911,7 @@ struct llog_size_change_rec {
         struct llog_rec_hdr     lsc_hdr;
         struct ll_fid           lsc_fid;
         __u32                   lsc_io_epoch;
-        __u32                   padding[5];
+        __u32                   padding;
         struct llog_rec_tail    lsc_tail;
 } __attribute__((packed));
 
@@ -920,7 +920,7 @@ struct llog_size_change_rec {
 #define LLOG_HEADER_SIZE        (96)
 #define LLOG_BITMAP_BYTES       (LLOG_CHUNK_SIZE - LLOG_HEADER_SIZE)
 
-#define LLOG_MIN_REC_SIZE       (32) /* round(struct llog_rec_hdr+end_len) */
+#define LLOG_MIN_REC_SIZE       (24) /* round(llog_rec_hdr + llog_rec_tail) */
 
 /* flags for the logs */
 #define LLOG_F_ZAP_WHEN_EMPTY   0x1
diff --git a/lustre/include/linux/lustre_log.h b/lustre/include/linux/lustre_log.h
index 4a7b12443a..ad60e1b462 100644
--- a/lustre/include/linux/lustre_log.h
+++ b/lustre/include/linux/lustre_log.h
@@ -231,12 +231,7 @@ static inline int llog_handle2ops(struct llog_handle *loghandle,
 
 static inline int llog_data_len(int len)
 {
-        int mask = LLOG_MIN_REC_SIZE - 1;
-        int remains = LLOG_MIN_REC_SIZE - sizeof(struct llog_rec_hdr) -
-                sizeof(struct llog_rec_tail); 
-        
-        return (len <= remains) ? 
-                remains : (((len + mask) & (~mask)) + remains);
+        return size_round(len);
 }
 
 static inline struct llog_ctxt *llog_get_context(struct obd_device *obd,
@@ -268,7 +263,7 @@ static inline int llog_write_rec(struct llog_handle *handle,
                                 + sizeof(struct llog_rec_tail);
         else
                 buflen = le32_to_cpu(rec->lrh_len);
-        LASSERT((buflen % LLOG_MIN_REC_SIZE) == 0);
+        LASSERT(size_round(buflen) == buflen);
 
         rc = lop->lop_write_rec(handle, rec, logcookies, numcookies, buf, idx);
         RETURN(rc);
diff --git a/lustre/obdclass/llog_lvfs.c b/lustre/obdclass/llog_lvfs.c
index 21992991e7..a5a94eb67f 100644
--- a/lustre/obdclass/llog_lvfs.c
+++ b/lustre/obdclass/llog_lvfs.c
@@ -57,7 +57,7 @@ static int llog_lvfs_pad(struct obd_device *obd, struct l_file *file,
         int rc;
         ENTRY;
 
-        LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0xf) == 0);
+        LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0);
 
         tail.lrt_len = rec.lrh_len = cpu_to_le32(len);
         tail.lrt_index = rec.lrh_index = cpu_to_le32(index);
@@ -247,7 +247,8 @@ static int llog_lvfs_write_rec(struct llog_handle *loghandle,
                         sizeof(struct llog_rec_tail);
 
         /* NOTE: padding is a record, but no bit is set */
-        if (left != 0 && left < reclen) {
+        if (left != 0 && left != reclen && 
+            left < (reclen + LLOG_MIN_REC_SIZE)) {
                 loghandle->lgh_last_idx++;
                 rc = llog_lvfs_pad(obd, file, left, loghandle->lgh_last_idx);
                 if (rc)
diff --git a/lustre/obdclass/llog_test.c b/lustre/obdclass/llog_test.c
index 4f58a40eda..137b5b759d 100644
--- a/lustre/obdclass/llog_test.c
+++ b/lustre/obdclass/llog_test.c
@@ -40,7 +40,6 @@ static struct llog_logid cat_logid;
 
 struct llog_mini_rec {
         struct llog_rec_hdr     lmr_hdr;
-        __u32                   padding[2];
         struct llog_rec_tail    lmr_tail;
 } __attribute__((packed));
 
-- 
GitLab