discard = block_device_support_discard(fn.c_str());
dout(10) << fn << " support discard: " << (int)discard << dendl;
}
- _check_disk_write_cache();
- return 0;
-}
-
-void FileJournal::_check_disk_write_cache() const
-{
-#if !defined(__linux__)
- dout(10) << "_check_disk_write_cache: not linux, NOT checking disk write "
- << "cache on raw block device " << fn << dendl;
- return;
-#else
- ostringstream hdparm_cmd;
- FILE *fp = NULL;
-
- if (geteuid() != 0) {
- dout(10) << "_check_disk_write_cache: not root, NOT checking disk write "
- << "cache on raw block device " << fn << dendl;
- goto done;
- }
-
- hdparm_cmd << "/sbin/hdparm -W " << fn;
- fp = popen(hdparm_cmd.str().c_str(), "r");
- if (!fp) {
- dout(10) << "_check_disk_write_cache: failed to run /sbin/hdparm: NOT "
- << "checking disk write cache on raw block device " << fn << dendl;
- goto done;
- }
-
- while (true) {
- char buf[256];
- memset(buf, 0, sizeof(buf));
- char *line = fgets(buf, sizeof(buf) - 1, fp);
- if (!line) {
- if (ferror(fp)) {
- int ret = -errno;
- derr << "_check_disk_write_cache: fgets error: " << cpp_strerror(ret)
- << dendl;
- goto close_f;
- }
- else {
- // EOF.
- break;
- }
- }
-
- int on;
- if (sscanf(line, " write-caching = %d", &on) != 1)
- continue;
- if (!on) {
- dout(10) << "_check_disk_write_cache: disk write cache is off (good) on "
- << fn << dendl;
- break;
- }
-
- // is our kernel new enough?
- int ver = get_linux_version();
- if (ver == 0) {
- dout(10) << "_check_disk_write_cache: get_linux_version failed" << dendl;
- } else if (ver >= KERNEL_VERSION(2, 6, 33)) {
- dout(20) << "_check_disk_write_cache: disk write cache is on, but your "
- << "kernel is new enough to handle it correctly. (fn:"
- << fn << ")" << dendl;
- break;
- }
- derr << TEXT_RED
- << " ** WARNING: disk write cache is ON on " << fn << ".\n"
- << " Journaling will not be reliable on kernels prior to 2.6.33\n"
- << " (recent kernels are safe). You can disable the write cache with\n"
- << " 'hdparm -W 0 " << fn << "'"
- << TEXT_NORMAL
- << dendl;
- break;
- }
-close_f:
- if (pclose(fp)) {
- int ret = -errno;
- derr << "_check_disk_write_cache: pclose failed: " << cpp_strerror(ret)
- << dendl;
- }
-done:
- ;
-#endif // __linux__
+ return 0;
}
int FileJournal::_open_file(int64_t oldsize, blksize_t blksize,
int _open(bool wr, bool create=false);
int _open_block_device();
void _close(int fd) const;
- void _check_disk_write_cache() const;
int _open_file(int64_t oldsize, blksize_t blksize, bool create);
int _dump(ostream& out, bool simple);
void print_header(const header_t &hdr) const;