]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/FileJournal: Fix journal write fail, align for direct io 5619/head
authorSage Weil <sage@redhat.com>
Thu, 15 Jan 2015 19:20:18 +0000 (11:20 -0800)
committerSage Weil <sage@redhat.com>
Thu, 20 Aug 2015 12:52:44 +0000 (08:52 -0400)
when config journal_zero_on_create true, osd mkfs will fail when zeroing journal.
journal open with O_DIRECT, buf should align with blocksize.

Backport: giant, firefly, dumpling
Signed-off-by: Xie Rui <875016668@qq.com>
Reviewed-by: Sage Weil <sage@redhat.com>
(cherry picked from commit 80473f63853593e53d72f17c098152caf17f5e9e)

src/os/FileJournal.cc

index b1d2db15cb3160ce5f3a6ccde647330e45b77080..3d2fc8aa89831366426e8f58c1e1395018170402 100644 (file)
@@ -27,6 +27,7 @@
 #include <limits.h>
 #include <sstream>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
@@ -296,24 +297,28 @@ int FileJournal::_open_file(int64_t oldsize, blksize_t blksize,
   if (create && g_conf->journal_zero_on_create) {
     derr << "FileJournal::_open_file : zeroing journal" << dendl;
     uint64_t write_size = 1 << 20;
-    char *buf = new char[write_size];
+    char *buf;
+    ret = ::posix_memalign((void **)&buf, block_size, write_size);
+    if (ret != 0) {
+      return ret;
+    }
     memset(static_cast<void*>(buf), 0, write_size);
     uint64_t i = 0;
     for (; (i + write_size) <= (unsigned)max_size; i += write_size) {
       ret = ::pwrite(fd, static_cast<void*>(buf), write_size, i);
       if (ret < 0) {
-       delete [] buf;
+       free(buf);
        return -errno;
       }
     }
     if (i < (unsigned)max_size) {
       ret = ::pwrite(fd, static_cast<void*>(buf), max_size - i, i);
       if (ret < 0) {
-       delete [] buf;
+       free(buf);
        return -errno;
       }
     }
-    delete [] buf;
+    free(buf);
   }