]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: change block file mkfs behavior
authorSage Weil <sage@redhat.com>
Wed, 3 Feb 2016 15:51:01 +0000 (10:51 -0500)
committerSage Weil <sage@redhat.com>
Thu, 4 Feb 2016 02:43:50 +0000 (21:43 -0500)
Previously, if path was set, we'd make a symlink.  Otherwise, if
size was set, we'd create a file and resize it accordingly. This
means that setting the size means we create the block "device"
files, which is only useful for debugging, and we want to set a
size that can be used by ceph-disk when creating partitions.

Instead, if path is set, make a symlink.  Then/also, if size is
set, and the file/symlink points to a regular file, and that
regular file is 0 bytes, then resize it.  This way, vstart.sh
(or a dev) can just touch the file and then mkfs will size it up.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/vstart.sh

index 268ed5529801a2bfa44dd7a9dcfe2141f49c20ff..8fdff56988aed40b8961e1b0e38451b17a7d418b 100644 (file)
@@ -1608,29 +1608,36 @@ int BlueStore::_setup_block_symlink_or_file(
         return r;
       }
     }
-  } else if (size) {
-    struct stat st;
-    r = ::fstatat(path_fd, name.c_str(), &st, 0);
-    if (r < 0)
-      r = -errno;
-    if (r == -ENOENT) {
-      int fd = ::openat(path_fd, name.c_str(), O_CREAT|O_RDWR, 0644);
-      if (fd < 0) {
-       int r = -errno;
-       derr << __func__ << " failed to create " << name << " file: "
+  }
+  if (size) {
+    int fd = ::openat(path_fd, name.c_str(), O_RDWR, 0644);
+    if (fd >= 0) {
+      // block file is present
+      struct stat st;
+      int r = ::fstat(fd, &st);
+      if (r == 0 &&
+         S_ISREG(st.st_mode) &&   // if it is a regular file
+         st.st_size == 0) {       // and is 0 bytes
+       r = ::ftruncate(fd, size);
+       if (r < 0) {
+         r = -errno;
+         derr << __func__ << " failed to resize " << name << " file to "
+              << size << ": " << cpp_strerror(r) << dendl;
+         VOID_TEMP_FAILURE_RETRY(::close(fd));
+         return r;
+       }
+       dout(1) << __func__ << " resized " << name << " file to "
+               << pretty_si_t(size) << "B" << dendl;
+      }
+      VOID_TEMP_FAILURE_RETRY(::close(fd));
+    } else {
+      int r = -errno;
+      if (r != -ENOENT) {
+       derr << __func__ << " failed to open " << name << " file: "
             << cpp_strerror(r) << dendl;
        return r;
       }
-      r = ::ftruncate(fd, size);
-      assert(r == 0);
-      dout(1) << __func__ << " created " << name << " file with size "
-             << pretty_si_t(size) << "B" << dendl;
-      VOID_TEMP_FAILURE_RETRY(::close(fd));
-    } else if (r < 0) {
-      derr << __func__ << " failed to stat " << name << " file: "
-           << cpp_strerror(r) << dendl;
-      return r;
-    } 
+    }
   }
   return 0;
 }
index c3c54a4ce5a60568036d24bb3592cf19f5e55eb9..a7aba2b5c8876c311ae1655cafea68aecee60f2b 100755 (executable)
@@ -348,10 +348,7 @@ if [ "$memstore" -eq 1 ]; then
 fi
 if [ "$bluestore" -eq 1 ]; then
     COSDMEMSTORE='
-       osd objectstore = bluestore
-       bluestore fsck on mount = true
-       bluestore block db size = 67108864
-       bluestore block wal size = 134217728'
+       osd objectstore = bluestore'
 fi
 
 # lockdep everywhere?
@@ -497,6 +494,9 @@ $DAEMONOPTS
         filestore wbthrottle btrfs ios start flusher = 10
         filestore wbthrottle btrfs ios hard limit = 20
         filestore wbthrottle btrfs inodes hard limit = 30
+       bluestore fsck on mount = true
+       bluestore block db size = 67108864
+       bluestore block wal size = 134217728
 $COSDDEBUG
 $COSDMEMSTORE
 $extra_conf
@@ -593,6 +593,11 @@ EOF
            for f in $CEPH_DEV_DIR/osd$osd/* ; do btrfs sub delete $f || true ; done || true
            mkdir -p $CEPH_DEV_DIR/osd$osd
 
+           # for bluestore
+           touch $CEPH_DEV_DIR/osd$osd/block
+           touch $CEPH_DEV_DIR/osd$osd/block.db
+           touch $CEPH_DEV_DIR/osd$osd/block.wal
+
            uuid=`uuidgen`
            echo "add osd$osd $uuid"
            $SUDO $CEPH_ADM osd create $uuid