From 316810d7e74a6a717c262522cbed00c89b0cb86b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 3 Feb 2016 10:51:01 -0500 Subject: [PATCH] os/bluestore: change block file mkfs behavior 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 --- src/os/bluestore/BlueStore.cc | 47 ++++++++++++++++++++--------------- src/vstart.sh | 13 +++++++--- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 268ed5529801a..8fdff56988aed 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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; } diff --git a/src/vstart.sh b/src/vstart.sh index c3c54a4ce5a60..a7aba2b5c8876 100755 --- a/src/vstart.sh +++ b/src/vstart.sh @@ -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 -- 2.39.5