From: Adam Kupczyk Date: Tue, 30 Jan 2024 12:52:17 +0000 (+0000) Subject: os/bluestore: Fix write_bdev_label X-Git-Tag: v19.2.1~271^2~36 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1118b272f73cd8a101ab9c109def91bae8496131;p=ceph.git os/bluestore: Fix write_bdev_label If required location is outside device size, just skip it. Signed-off-by: Adam Kupczyk (cherry picked from commit 7c4a8642f6c995087091e35bde4e921f12086edd) --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 65705e87f6d0..e00aedc1f717 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -6512,12 +6512,22 @@ int BlueStore::_write_bdev_label( locations.end()) { locations.push_back(BDEV_LABEL_POSITION); } + struct stat st; + r = ::fstat(fd, &st); + if (r < 0) { + r = -errno; + derr << __func__ << " failed to fstat " << path << ": " << cpp_strerror(r) << dendl; + VOID_TEMP_FAILURE_RETRY(::close(fd)); + return r; + } for (uint64_t position : locations) { - r = bl.write_fd(fd, position); - if (r < 0) { - derr << __func__ << " failed to write to " << path - << ": " << cpp_strerror(r) << dendl; - goto out; + if (int64_t(position + BDEV_LABEL_BLOCK_SIZE) <= st.st_size) { + r = bl.write_fd(fd, position); + if (r < 0) { + derr << __func__ << " failed to write to " << path + << ": " << cpp_strerror(r) << dendl; + goto out; + } } } r = ::fsync(fd);