]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/FileStore: only try BTRFS_IOC_SUBVOL_CREATE on btrfs
authorSage Weil <sage@inktank.com>
Fri, 16 Nov 2012 00:50:39 +0000 (16:50 -0800)
committerSage Weil <sage@inktank.com>
Fri, 16 Nov 2012 00:50:55 +0000 (16:50 -0800)
Only try to create a btrfs subvolume if the fs is btrfs.  Otherwise, just
create a directory.  Then we can error out on *any* ioctl error, and not
rely on the ioctl error code to determine if we failed because we are on
a non-btrfs or a real error.

Fixes: #3052
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
src/os/FileStore.cc

index db689447271044650f5dbde2e8467c7954e67492..f6dfcf26d8532bdaf5376e09b7be0d67b710e832 100644 (file)
@@ -654,6 +654,15 @@ int FileStore::mkfs()
     goto close_fsid_fd;
   }
 
+  struct statfs basefs;
+  ret = ::fstatfs(basedir_fd, &basefs);
+  if (ret < 0) {
+    ret = -errno;
+    derr << "mkfs cannot fstatfs basedir "
+        << cpp_strerror(ret) << dendl;
+    goto close_fsid_fd;
+  }
+
   // current
   ret = ::stat(current_fn.c_str(), &st);
   if (ret == 0) {
@@ -668,7 +677,7 @@ int FileStore::mkfs()
     // is current/ a btrfs subvolume?
     //  check fsid, and compare st_dev to see if it's a subvolume.
     struct stat basest;
-    struct statfs basefs, currentfs;
+    struct statfs currentfs;
     ret = ::fstat(basedir_fd, &basest);
     if (ret < 0) {
       ret = -errno;
@@ -676,13 +685,6 @@ int FileStore::mkfs()
           << cpp_strerror(ret) << dendl;
       goto close_fsid_fd;
     }
-    ret = ::fstatfs(basedir_fd, &basefs);
-    if (ret < 0) {
-      ret = -errno;
-      derr << "mkfs cannot fstatfs basedir "
-          << cpp_strerror(ret) << dendl;
-      goto close_fsid_fd;
-    }
     ret = ::statfs(current_fn.c_str(), &currentfs);
     if (ret < 0) {
       ret = -errno;
@@ -699,40 +701,34 @@ int FileStore::mkfs()
 #endif
   } else {
 #if defined(__linux__)
-    volargs.fd = 0;
-    strcpy(volargs.name, "current");
-    if (::ioctl(basedir_fd, BTRFS_IOC_SUBVOL_CREATE, (unsigned long int)&volargs)) {
-      ret = -errno;
-      if (ret == -EOPNOTSUPP || ret == -ENOTTY) {
-       dout(2) << " BTRFS_IOC_SUBVOL_CREATE ioctl failed, trying mkdir "
-               << current_fn << dendl;
-#endif
-       if (::mkdir(current_fn.c_str(), 0755)) {
-         ret = -errno;
-         derr << "mkfs: mkdir " << current_fn << " failed: "
-              << cpp_strerror(ret) << dendl;
-         goto close_fsid_fd;
-       }
-#if defined(__linux__)
-      }
-      else {
+    if (basefs.f_type == BTRFS_SUPER_MAGIC) {
+      volargs.fd = 0;
+      strcpy(volargs.name, "current");
+      if (::ioctl(basedir_fd, BTRFS_IOC_SUBVOL_CREATE, (unsigned long int)&volargs) < 0) {
+       ret = -errno;
        derr << "mkfs: BTRFS_IOC_SUBVOL_CREATE failed with error "
             << cpp_strerror(ret) << dendl;
        goto close_fsid_fd;
       }
-    }
-    else {
-      // ioctl succeeded. yay
+
       dout(2) << " created btrfs subvol " << current_fn << dendl;
-      if (::chmod(current_fn.c_str(), 0755)) {
+      if (::chmod(current_fn.c_str(), 0755) < 0) {
        ret = -errno;
        derr << "mkfs: failed to chmod " << current_fn << " to 0755: "
             << cpp_strerror(ret) << dendl;
        goto close_fsid_fd;
       }
       btrfs_stable_commits = true;
-    }
+    } else
 #endif
+    {
+      if (::mkdir(current_fn.c_str(), 0755) < 0) {
+       ret = -errno;
+       derr << "mkfs: mkdir " << current_fn << " failed: "
+            << cpp_strerror(ret) << dendl;
+       goto close_fsid_fd;
+      }
+    }
   }
 
   // write initial op_seq