]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
FileStore:Round offset of fiemap down aligned with CEPH_PAGE_SIZE. 2591/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Mon, 13 Oct 2014 05:33:38 +0000 (13:33 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Mon, 13 Oct 2014 05:33:38 +0000 (13:33 +0800)
There is a bug on xfs about fiemap. If offset unsigned, the result of
fiemap will leak some data.
Kernel commit eedf32bfcace7d8e20cc66757d74fc68f3439ff7 fix this bug.
To avoid this bug on kernel which don't apply this commit, in ceph we
make the offset down aligned with CEPH_PAGE_SIZE.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/os/GenericFileStoreBackend.cc

index e152c51dc28fba4f93b0060013c40b8e3791e0fb..09a0228569afbd5c2e536b1cffb5d25fd750be61 100644 (file)
@@ -217,9 +217,15 @@ int GenericFileStoreBackend::do_fiemap(int fd, off_t start, size_t len, struct f
   fiemap = (struct fiemap*)calloc(sizeof(struct fiemap), 1);
   if (!fiemap)
     return -ENOMEM;
-
-  fiemap->fm_start = start;
-  fiemap->fm_length = len;
+  /*
+   * There is a bug on xfs about fiemap. Suppose(offset=3990, len=4096),
+   * the result is (logical=4096, len=4096). It leak the [3990, 4096).
+   * Commit:"xfs: fix rounding error of fiemap length parameter
+   * (eedf32bfcace7d8e20cc66757d74fc68f3439ff7)" fix this bug.
+   * Here, we make offset aligned with CEPH_PAGE_SIZE to avoid this bug.
+   */
+  fiemap->fm_start = start - start % CEPH_PAGE_SIZE;
+  fiemap->fm_length = len + start % CEPH_PAGE_SIZE;
   fiemap->fm_flags = FIEMAP_FLAG_SYNC; /* flush extents to disk if needed */
 
   if (ioctl(fd, FS_IOC_FIEMAP, fiemap) < 0) {