Skip to content
/ linux Public

Commit a46cec9

Browse files
ethanwu-synoSasha Levin
authored andcommitted
ceph: supply snapshot context in ceph_uninline_data()
[ Upstream commit 305ff6b ] The ceph_uninline_data function was missing proper snapshot context handling for its OSD write operations. Both CEPH_OSD_OP_CREATE and CEPH_OSD_OP_WRITE requests were passing NULL instead of the appropriate snapshot context, which could lead to unnecessary object clone. Reproducer: ../src/vstart.sh --new -x --localhost --bluestore // turn on cephfs inline data ./bin/ceph fs set a inline_data true --yes-i-really-really-mean-it // allow fs_a client to take snapshot ./bin/ceph auth caps client.fs_a mds 'allow rwps fsname=a' mon 'allow r fsname=a' osd 'allow rw tag cephfs data=a' // mount cephfs with fuse, since kernel cephfs doesn't support inline write ceph-fuse --id fs_a -m 127.0.0.1:40318 --conf ceph.conf -d /mnt/mycephfs/ // bump snapshot seq mkdir /mnt/mycephfs/.snap/snap1 echo "foo" > /mnt/mycephfs/test // umount and mount it again using kernel cephfs client umount /mnt/mycephfs mount -t ceph fs_a@.a=/ /mnt/mycephfs/ -o conf=./ceph.conf echo "bar" >> /mnt/mycephfs/test ./bin/rados listsnaps -p cephfs.a.data $(printf "%x\n" $(stat -c %i /mnt/mycephfs/test)).00000000 will see this object does unnecessary clone 1000000000a.00000000 (seq:2): cloneid snaps size overlap 2 2 4 [] head - 8 but it's expected to see 10000000000.00000000 (seq:2): cloneid snaps size overlap head - 8 since there's no snapshot between these 2 writes clone happened because the first osd request CEPH_OSD_OP_CREATE doesn't pass snap context so object is created with snap seq 0, but later data writeback is equipped with snapshot context. snap.seq(1) > object snap seq(0), so osd does object clone. This fix properly acquiring the snapshot context before performing write operations. Signed-off-by: ethanwu <ethanwu@synology.com> Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com> Tested-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 39aef90 commit a46cec9

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

fs/ceph/addr.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ int ceph_uninline_data(struct file *file)
18671867
struct ceph_osd_request *req = NULL;
18681868
struct ceph_cap_flush *prealloc_cf = NULL;
18691869
struct folio *folio = NULL;
1870+
struct ceph_snap_context *snapc = NULL;
18701871
u64 inline_version = CEPH_INLINE_NONE;
18711872
struct page *pages[1];
18721873
int err = 0;
@@ -1894,6 +1895,24 @@ int ceph_uninline_data(struct file *file)
18941895
if (inline_version == 1) /* initial version, no data */
18951896
goto out_uninline;
18961897

1898+
down_read(&fsc->mdsc->snap_rwsem);
1899+
spin_lock(&ci->i_ceph_lock);
1900+
if (__ceph_have_pending_cap_snap(ci)) {
1901+
struct ceph_cap_snap *capsnap =
1902+
list_last_entry(&ci->i_cap_snaps,
1903+
struct ceph_cap_snap,
1904+
ci_item);
1905+
snapc = ceph_get_snap_context(capsnap->context);
1906+
} else {
1907+
if (!ci->i_head_snapc) {
1908+
ci->i_head_snapc = ceph_get_snap_context(
1909+
ci->i_snap_realm->cached_context);
1910+
}
1911+
snapc = ceph_get_snap_context(ci->i_head_snapc);
1912+
}
1913+
spin_unlock(&ci->i_ceph_lock);
1914+
up_read(&fsc->mdsc->snap_rwsem);
1915+
18971916
folio = read_mapping_folio(inode->i_mapping, 0, file);
18981917
if (IS_ERR(folio)) {
18991918
err = PTR_ERR(folio);
@@ -1909,7 +1928,7 @@ int ceph_uninline_data(struct file *file)
19091928
req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
19101929
ceph_vino(inode), 0, &len, 0, 1,
19111930
CEPH_OSD_OP_CREATE, CEPH_OSD_FLAG_WRITE,
1912-
NULL, 0, 0, false);
1931+
snapc, 0, 0, false);
19131932
if (IS_ERR(req)) {
19141933
err = PTR_ERR(req);
19151934
goto out_unlock;
@@ -1925,7 +1944,7 @@ int ceph_uninline_data(struct file *file)
19251944
req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout,
19261945
ceph_vino(inode), 0, &len, 1, 3,
19271946
CEPH_OSD_OP_WRITE, CEPH_OSD_FLAG_WRITE,
1928-
NULL, ci->i_truncate_seq,
1947+
snapc, ci->i_truncate_seq,
19291948
ci->i_truncate_size, false);
19301949
if (IS_ERR(req)) {
19311950
err = PTR_ERR(req);
@@ -1988,6 +2007,7 @@ int ceph_uninline_data(struct file *file)
19882007
folio_put(folio);
19892008
}
19902009
out:
2010+
ceph_put_snap_context(snapc);
19912011
ceph_free_cap_flush(prealloc_cf);
19922012
doutc(cl, "%llx.%llx inline_version %llu = %d\n",
19932013
ceph_vinop(inode), inline_version, err);

0 commit comments

Comments
 (0)