From 229a6dfe7dc28c16773aa6d78c9666276eb0ccb0 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Mon, 13 Oct 2014 13:33:38 +0800 Subject: [PATCH] FileStore:Round offset of fiemap down aligned with CEPH_PAGE_SIZE. 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 --- src/os/GenericFileStoreBackend.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/os/GenericFileStoreBackend.cc b/src/os/GenericFileStoreBackend.cc index e152c51dc28fb..09a0228569afb 100644 --- a/src/os/GenericFileStoreBackend.cc +++ b/src/os/GenericFileStoreBackend.cc @@ -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) { -- 2.39.5