]> git.apps.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)
committerPere Diaz Bou <pere-altea@hotmail.com>
Fri, 23 Aug 2024 09:49:24 +0000 (11:49 +0200)
If required location is outside device size, just skip it.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
(cherry picked from commit 7c4a8642f6c995087091e35bde4e921f12086edd)

src/os/bluestore/BlueStore.cc

index 65705e87f6d094bdfeedc1211b0f8f8902d0064b..e00aedc1f7172b63ddd3f38935138ae1df2d5b5c 100644 (file)
@@ -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);