Whamcloud - gitweb
LU-2590 obdclass: correct swab lov_mds_md
authorBobi Jam <bobijam.xu@intel.com>
Wed, 23 Jan 2013 03:08:10 +0000 (11:08 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 8 Feb 2013 23:41:16 +0000 (18:41 -0500)
For caller's convenience, the 2nd parameter of obd_free_diskmd()
could be host endianness, it needs swab to LE if necessary, while just
lov_mds_md header needs it for figuring out how much memory needs to
be freed.

Signed-off-by: Bobi Jam <bobijam.xu@intel.com>
Change-Id: I537e83b56b4be6e08a7431bfda1de71efefa33ee
Reviewed-on: http://review.whamcloud.com/5145
Tested-by: Hudson
Reviewed-by: Prakash Surya <surya1@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/include/obd_class.h

index 944c602..c39825c 100644 (file)
@@ -753,11 +753,21 @@ static inline int obd_alloc_diskmd(struct obd_export *exp,
 }
 
 static inline int obd_free_diskmd(struct obd_export *exp,
 }
 
 static inline int obd_free_diskmd(struct obd_export *exp,
-                                  struct lov_mds_md **disk_tgt)
-{
-        LASSERT(disk_tgt);
-        LASSERT(*disk_tgt);
-        return obd_packmd(exp, disk_tgt, NULL);
+                                 struct lov_mds_md **disk_tgt)
+{
+       LASSERT(disk_tgt);
+       LASSERT(*disk_tgt);
+       /*
+        * LU-2590, for caller's convenience, *disk_tgt could be host
+        * endianness, it needs swab to LE if necessary, while just
+        * lov_mds_md header needs it for figuring out how much memory
+        * needs to be freed.
+        */
+       if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
+           (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
+            ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
+               lustre_swab_lov_mds_md(*disk_tgt);
+       return obd_packmd(exp, disk_tgt, NULL);
 }
 
 /* Unpack an MD struct from disk to in-memory format.
 }
 
 /* Unpack an MD struct from disk to in-memory format.