From: Jianpeng Ma Date: Mon, 13 Oct 2014 05:33:38 +0000 (+0800) Subject: FileStore:Round offset of fiemap down aligned with CEPH_PAGE_SIZE. X-Git-Tag: v0.88~78^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F2591%2Fhead;p=ceph.git 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 --- diff --git a/src/os/GenericFileStoreBackend.cc b/src/os/GenericFileStoreBackend.cc index e152c51dc28f..09a0228569af 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) {