1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
6 #include "dumb_backend.h"
8 string DumbBackend::get_full_path(const string &oid)
10 return path + "/" + oid;
13 void DumbBackend::_write(
20 string full_path(get_full_path(oid));
22 full_path.c_str(), O_CREAT|O_WRONLY, 0777);
24 std::cout << full_path << ": errno is " << errno << std::endl;
28 int r = ::lseek(fd, offset, SEEK_SET);
31 std::cout << "lseek failed, errno is: " << r << std::endl;
36 on_applied->complete(0);
39 #ifdef HAVE_SYNC_FILE_RANGE
40 if (do_sync_file_range)
41 ::sync_file_range(fd, offset, bl.length(),
42 SYNC_FILE_RANGE_WAIT_AFTER);
44 # warning "sync_file_range not supported!"
46 #ifdef HAVE_POSIX_FADVISE
48 int fa_r = ::posix_fadvise(fd, offset, bl.length(), POSIX_FADV_DONTNEED);
50 std::cout << "posix_fadvise failed, errno is: " << fa_r << std::endl;
54 # warning "posix_fadvise not supported!"
58 Mutex::Locker l(pending_commit_mutex);
59 pending_commits.insert(on_commit);
64 void DumbBackend::read(
71 string full_path(get_full_path(oid));
73 full_path.c_str(), 0, O_RDONLY);
76 int r = ::lseek(fd, offset, SEEK_SET);
79 std::cout << "lseek failed, errno is: " << r << std::endl;
84 bl->read_fd(fd, length);
86 on_complete->complete(0);
89 void DumbBackend::sync_loop()
94 Mutex::Locker l(sync_loop_mutex);
95 if (sync_loop_stop != 0) {
97 sync_loop_cond.Signal();
102 #ifdef HAVE_SYS_SYNCFS
108 Mutex::Locker l(pending_commit_mutex);
109 for (set<Context*>::iterator i = pending_commits.begin();
110 i != pending_commits.end();
111 pending_commits.erase(i++)) {