From: Ilya Dryomov Date: Mon, 16 Dec 2013 16:57:22 +0000 (+0200) Subject: FileJournal: switch to get_linux_version() X-Git-Tag: v0.75~96^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6696ab647973d67e1639f7177b211ebd52bf8463;p=ceph.git FileJournal: switch to get_linux_version() For the purposes of FileJournal::_check_disk_write_cache(), use get_linux_version(), which is based on uname(2), instead of parsing the contents of /proc/version. Signed-off-by: Ilya Dryomov --- diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 4a2af08dd4c0..b42d9f8b39c5 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -31,7 +31,7 @@ #include #include "common/blkdev.h" - +#include "common/linux_version.h" #define dout_subsys ceph_subsys_journal #undef dout_prefix @@ -158,49 +158,10 @@ int FileJournal::_open_block_device() return 0; } -static int get_kernel_version(int *a, int *b, int *c) -{ - int ret; - char buf[128]; - memset(buf, 0, sizeof(buf)); - int fd = TEMP_FAILURE_RETRY(::open("/proc/version", O_RDONLY)); - if (fd < 0) { - ret = errno; - derr << "get_kernel_version: failed to open /proc/version: " - << cpp_strerror(ret) << dendl; - goto out; - } - ret = safe_read(fd, buf, sizeof(buf) - 1); - if (ret < 0) { - derr << "get_kernel_version: failed to read from /proc/version: " - << cpp_strerror(ret) << dendl; - goto close_fd; - } - - if (sscanf(buf, "Linux version %d.%d.%d", a, b, c) != 3) { - if (sscanf(buf, "Linux version %d.%d", a, b) != 2) { - derr << "get_kernel_version: failed to parse string: '" - << buf << "'" << dendl; - ret = EIO; - goto close_fd; - } - *c = 0; - } - - dout(0) << " kernel version is " << *a <<"." << *b << "." << *c << dendl; - ret = 0; - -close_fd: - TEMP_FAILURE_RETRY(::close(fd)); -out: - return ret; -} - void FileJournal::_check_disk_write_cache() const { ostringstream hdparm_cmd; FILE *fp = NULL; - int a, b, c; if (geteuid() != 0) { dout(10) << "_check_disk_write_cache: not root, NOT checking disk write " @@ -243,11 +204,10 @@ void FileJournal::_check_disk_write_cache() const } // is our kernel new enough? - if (get_kernel_version(&a, &b, &c)) { - dout(10) << "_check_disk_write_cache: failed to get kernel version." - << dendl; - } - else if ((a >= 2 && b >= 6 && c >= 33) || a >= 3) { + 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;