]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
FileJournal: switch to get_linux_version()
authorIlya Dryomov <ilya.dryomov@inktank.com>
Mon, 16 Dec 2013 16:57:22 +0000 (18:57 +0200)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Mon, 16 Dec 2013 16:57:22 +0000 (18:57 +0200)
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 <ilya.dryomov@inktank.com>
src/os/FileJournal.cc

index 4a2af08dd4c0a2b03a9b42161ae08738808cc41b..b42d9f8b39c57721a099f2735472079444547f41 100644 (file)
@@ -31,7 +31,7 @@
 #include <sys/mount.h>
 
 #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;