From: Jianpeng Ma Date: Sat, 7 May 2016 10:49:53 +0000 (+0800) Subject: common/config_opt: add bool option: bluestore_block_preallocate_file. X-Git-Tag: v11.0.0~582^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bd5f06702ee5b2a3f41de7f2bb699b8c052291ab;p=ceph.git common/config_opt: add bool option: bluestore_block_preallocate_file. Using this option control whether preallocate space when bluesotre block/db_path/wal_path use file instead block device. Signed-off-by: Jianpeng Ma --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index c98945690f96..10cd1908238e 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -938,6 +938,7 @@ OPTION(bluestore_block_db_create, OPT_BOOL, false) OPTION(bluestore_block_wal_path, OPT_STR, "") OPTION(bluestore_block_wal_size, OPT_U64, 96 * 1024*1024) // rocksdb wal OPTION(bluestore_block_wal_create, OPT_BOOL, false) +OPTION(bluestore_block_preallocate_file, OPT_BOOL, false) //whether preallocate space if block/db_path/wal_path is file rather that block device. OPTION(bluestore_min_alloc_size, OPT_U32, 64*1024) OPTION(bluestore_onode_map_size, OPT_U32, 1024) // onodes per collection OPTION(bluestore_cache_tails, OPT_BOOL, true) // cache tail blocks in Onode diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index d77d3cdb8c10..f7b83a596c8d 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1639,31 +1639,34 @@ int BlueStore::_setup_block_symlink_or_file( VOID_TEMP_FAILURE_RETRY(::close(fd)); return r; } + + if (g_conf->bluestore_block_preallocate_file) { #ifdef HAVE_POSIX_FALLOCATE - r = ::posix_fallocate(fd, 0, size); - if (r < 0) { - r = -errno; - derr << __func__ << " failed to prefallocate " << name << " file to " - << size << ": " << cpp_strerror(r) << dendl; - VOID_TEMP_FAILURE_RETRY(::close(fd)); - return r; - } -#else - char data[1024*128]; - for (uint64_t off = 0; off < size; off += sizeof(data)) { - if (off + sizeof(data) > size) - r = ::write(fd, data, size - off); - else - r = ::write(fd, data, sizeof(data)); + r = ::posix_fallocate(fd, 0, size); if (r < 0) { r = -errno; - derr << __func__ << " failed to prefallocate w/ write " << name << " file to " + derr << __func__ << " failed to prefallocate " << name << " file to " << size << ": " << cpp_strerror(r) << dendl; VOID_TEMP_FAILURE_RETRY(::close(fd)); return r; } - } +#else + char data[1024*128]; + for (uint64_t off = 0; off < size; off += sizeof(data)) { + if (off + sizeof(data) > size) + r = ::write(fd, data, size - off); + else + r = ::write(fd, data, sizeof(data)); + if (r < 0) { + r = -errno; + derr << __func__ << " failed to prefallocate w/ write " << name << " file to " + << size << ": " << cpp_strerror(r) << dendl; + VOID_TEMP_FAILURE_RETRY(::close(fd)); + return r; + } + } #endif + } dout(1) << __func__ << " resized " << name << " file to " << pretty_si_t(size) << "B" << dendl; }