Ticket #222: omindex-noatime.patch
File omindex-noatime.patch, 4.7 KB (added by , 17 years ago) |
---|
-
omindex.cc
132 132 file_to_string(const string &file) 133 133 { 134 134 string out; 135 if (!load_file(file, out )) throw ReadError();135 if (!load_file(file, out, NOCACHE|NOATIME)) throw ReadError(); 136 136 return out; 137 137 } 138 138 -
md5wrap.cc
1 1 /* md5wrap.cc: wrapper functions to allow easy use of MD5 from C++. 2 2 * 3 * Copyright (C) 2006 Olly Betts3 * Copyright (C) 2006,2007 Olly Betts 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by … … 42 42 # endif 43 43 #endif 44 44 45 #ifndef O_NOATIME 46 # define O_NOATIME 0 47 #endif 48 45 49 #include "md5.h" 46 50 #include "md5wrap.h" 47 51 … … 51 55 md5_file(const string &file_name, string &md5) 52 56 { 53 57 mode_t mode = O_RDONLY; 54 mode |= O_STREAMING ;58 mode |= O_STREAMING|O_NOATIME; 55 59 56 60 int fd = open(file_name.c_str(), mode); 61 if (fd < 0 && (mode & O_NOATIME)) { 62 mode &= ~O_NOATIME; 63 fd = open(file_name.c_str(), mode); 64 } 57 65 if (fd < 0) return false; 58 66 59 67 #ifdef HAVE_POSIX_FADVISE -
scriptindex.cc
505 505 break; 506 506 case Action::LOAD: { 507 507 bool truncated = false; 508 if (!load_file(value, i->get_num_arg(), true,508 if (!load_file(value, i->get_num_arg(), NOCACHE|NOATIME, 509 509 value, truncated)) { 510 510 cerr << "Couldn't load file '" << value << "': " 511 511 << strerror(errno) << endl; -
loadfile.cc
1 1 /* loadfile.cc: load a file into a std::string. 2 2 * 3 * Copyright (C) 2006 Olly Betts3 * Copyright (C) 2006,2007 Olly Betts 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by … … 26 26 # endif 27 27 #endif 28 28 29 #include "loadfile.h" 30 29 31 #include <algorithm> 30 32 #include <string> 31 33 … … 39 41 # ifdef __linux__ 40 42 // This is the value used by rml's O_STREAMING patch for 2.4. 41 43 # define O_STREAMING 04000000 42 # else43 // Define as 0 otherwise, so we don't need ifdefs in the code.44 # define O_STREAMING 045 44 # endif 46 45 #endif 47 46 48 #include "loadfile.h"49 50 47 using namespace std; 51 48 52 49 bool 53 load_file(const string &file_name, size_t max_to_read, 54 bool try_not_to_cache, 50 load_file(const string &file_name, size_t max_to_read, int flags, 55 51 string &output, bool &truncated) 56 52 { 53 (void)flags; // Avoid possible "unused" warning. 57 54 mode_t mode = O_RDONLY; 58 if (try_not_to_cache) mode |= O_STREAMING; 55 #ifdef O_STREAMING 56 if (flags & NOCACHE) mode |= O_STREAMING; 57 #endif 58 #ifdef O_NOATIME 59 if (flags & NOATIME) mode |= O_NOATIME; 60 #endif 59 61 60 62 int fd = open(file_name.c_str(), mode); 63 #ifdef O_NOATIME 64 if (fd < 0 && (mode & O_NOATIME)) { 65 mode &= ~O_NOATIME; 66 fd = open(file_name.c_str(), mode); 67 } 68 #endif 61 69 if (fd < 0) return false; 62 70 63 71 #ifdef HAVE_POSIX_FADVISE 64 if ( try_not_to_cache)72 if (flags & NOCACHE) 65 73 posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE); // or POSIX_FADV_SEQUENTIAL 66 74 #endif 67 75 … … 97 105 } 98 106 99 107 #ifdef HAVE_POSIX_FADVISE 100 if ( try_not_to_cache)108 if (flags & NOCACHE) 101 109 posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED); 102 110 #endif 103 111 -
loadfile.h
1 1 /* loadfile.h: load a file into a std::string. 2 2 * 3 * Copyright (C) 2006 Olly Betts3 * Copyright (C) 2006,2007 Olly Betts 4 4 * 5 5 * This program is free software; you can redistribute it and/or modify 6 6 * it under the terms of the GNU General Public License as published by … … 22 22 23 23 #include <string> 24 24 25 extern bool load_file(const std::string &file_name, size_t max_to_read, 26 bool try_not_to_cache, 27 std::string &output, bool &truncated); 25 enum { NOCACHE = 0x1, NOATIME = 0x2 }; 26 27 bool load_file(const std::string &file_name, size_t max_to_read, int flags, 28 std::string &output, bool &truncated); 28 29 29 30 inline bool 30 load_file(const std::string &file_name, std::string &output, 31 bool try_not_to_cache = false) 31 load_file(const std::string &file_name, std::string &output, int flags = 0) 32 32 { 33 33 bool dummy; 34 return load_file(file_name, 0, try_not_to_cache, output, dummy);34 return load_file(file_name, 0, flags, output, dummy); 35 35 } 36 36 37 37 #endif // OMEGA_INCLUDED_LOADFILE_H