提交 2c356528 编写于 作者: C Chip Turner

Add OS_LINUX ifdef protections around fallocate parts

Summary: fallocate is linux only, so let's protect it with ifdef's

Test Plan: make

Reviewers: sheki, dhruba

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D8223
上级 11ce6a06
...@@ -332,6 +332,7 @@ class PosixMmapFile : public WritableFile { ...@@ -332,6 +332,7 @@ class PosixMmapFile : public WritableFile {
return file_offset_ + used; return file_offset_ + used;
} }
#ifdef OS_LINUX
virtual Status Allocate(off_t offset, off_t len) { virtual Status Allocate(off_t offset, off_t len) {
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) { if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
return Status::OK(); return Status::OK();
...@@ -339,6 +340,7 @@ class PosixMmapFile : public WritableFile { ...@@ -339,6 +340,7 @@ class PosixMmapFile : public WritableFile {
return IOError(filename_, errno); return IOError(filename_, errno);
} }
} }
#endif
}; };
// Use posix write to write data to a file. // Use posix write to write data to a file.
...@@ -466,6 +468,7 @@ class PosixWritableFile : public WritableFile { ...@@ -466,6 +468,7 @@ class PosixWritableFile : public WritableFile {
return filesize_; return filesize_;
} }
#ifdef OS_LINUX
virtual Status Allocate(off_t offset, off_t len) { virtual Status Allocate(off_t offset, off_t len) {
if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) { if (!fallocate(fd_, FALLOC_FL_KEEP_SIZE, offset, len)) {
return Status::OK(); return Status::OK();
...@@ -473,6 +476,7 @@ class PosixWritableFile : public WritableFile { ...@@ -473,6 +476,7 @@ class PosixWritableFile : public WritableFile {
return IOError(filename_, errno); return IOError(filename_, errno);
} }
} }
#endif
}; };
static int LockOrUnlock(const std::string& fname, int fd, bool lock) { static int LockOrUnlock(const std::string& fname, int fd, bool lock) {
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
#include <time.h> #include <time.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#ifdef OS_LINUX
#include <linux/falloc.h> #include <linux/falloc.h>
#endif
#include "leveldb/env.h" #include "leveldb/env.h"
namespace leveldb { namespace leveldb {
...@@ -93,6 +95,7 @@ class PosixLogger : public Logger { ...@@ -93,6 +95,7 @@ class PosixLogger : public Logger {
assert(p <= limit); assert(p <= limit);
#ifdef OS_LINUX
// If this write would cross a boundary of kDebugLogChunkSize // If this write would cross a boundary of kDebugLogChunkSize
// space, pre-allocate more space to avoid overly large // space, pre-allocate more space to avoid overly large
// allocations from filesystem allocsize options. // allocations from filesystem allocsize options.
...@@ -106,6 +109,7 @@ class PosixLogger : public Logger { ...@@ -106,6 +109,7 @@ class PosixLogger : public Logger {
fallocate(fd_, FALLOC_FL_KEEP_SIZE, 0, fallocate(fd_, FALLOC_FL_KEEP_SIZE, 0,
desired_allocation_chunk * kDebugLogChunkSize); desired_allocation_chunk * kDebugLogChunkSize);
} }
#endif
fwrite(base, 1, write_size, file_); fwrite(base, 1, write_size, file_);
fflush(file_); fflush(file_);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册