]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Fix write_bdev_label
authorAdam Kupczyk <akupczyk@ibm.com>
Tue, 30 Jan 2024 12:52:17 +0000 (12:52 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Mon, 22 Jul 2024 12:28:50 +0000 (12:28 +0000)
If required location is outside device size, just skip it.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/os/bluestore/BlueStore.cc

index 5e551a1de662f35dd884ec391e0e76c6e1fe19be..3e513b3b4e13e0ed762a71847125a15a09650f0e 100644 (file)
@@ -6529,12 +6529,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);