Received: from mail.synology.com (mail.synology.com [211.23.38.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CE832FB609 for ; Thu, 25 Sep 2025 10:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.23.38.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758796983; cv=none; b=lgDulhoZhxW3JlwB/LsbMKxm8f1GXdy6wpBMkWU/5R2abAz0/U+buAAKT+HDY5iDzFQOi7tvK9KJsFn9o8C6v7ZRoCXHG4AVGZHz/l9Rmpcoeu22Cfyygmm1EH3Vhus7VtW3twuJWyM7BXQAmTdeRG8Awpo23CrVun040G4Vigo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758796983; c=relaxed/simple; bh=u8SVkKHG+9/Vw0Hyy2MyM0mDrD8UrAY3Pu+Z4yV7Wzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A8UR5WAS/Vzaue1neUY8IqX15FY5sAOSOEJa3T+v77uEhAWMYvusvoIHKm09XKA1NrAapnNPiAlCICFX9pfhp2bDDN6r+O/O5xKinHk2+PNx3cJldFef/560xBVaJx8J9bresiJxoHbV7kDqYuNSbdnK7xdHfHGHtzobP5pEI6k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=synology.com; spf=pass smtp.mailfrom=synology.com; dkim=pass (1024-bit key) header.d=synology.com header.i=@synology.com header.b=G1AjCgns; arc=none smtp.client-ip=211.23.38.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=synology.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=synology.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=synology.com header.i=@synology.com header.b="G1AjCgns" From: ethanwu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1758796980; bh=u8SVkKHG+9/Vw0Hyy2MyM0mDrD8UrAY3Pu+Z4yV7Wzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=G1AjCgnshuUJhmRb0mmLSF/AbhJx20zkEYfMKyAtmHucJ+rlo6hXsQPpOW+p4GnH+ 7YVuTCBk4vQTVL7S8L9zo/E3dRZV2cMbZNIh6Em3biSz/c6L4m3m/2n0yX/tH5+eYq FpC7i3nJavUMxulsiPi8UAMUZWS4q2DF87TtrPKA= To: ceph-devel@vger.kernel.org Cc: xiubli@redhat.com, idryomov@gmail.com, Slava.Dubeyko@ibm.com, Pavan.Rallabhandi@ibm.com, ethanwu@synology.com Subject: [PATCH 1/2] ceph: fix snapshot context missing in ceph_zero_partial_object Date: Thu, 25 Sep 2025 18:42:05 +0800 Message-ID: <20250925104228.95018-2-ethanwu@synology.com> In-Reply-To: <20250925104228.95018-1-ethanwu@synology.com> References: <20250925104228.95018-1-ethanwu@synology.com> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Spam-Flag: no X-Synology-Virus-Status: no X-Synology-MCP-Status: no Content-Type: text/plain The ceph_zero_partial_object function was missing proper snapshot context for its OSD write operations, which could lead to data inconsistencies in snapshots. Reproducer: ../src/vstart.sh --new -x --localhost --bluestore ./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 -t ceph fs_a@.a=/ /mnt/mycephfs/ -o conf=./ceph.conf dd if=/dev/urandom of=/mnt/mycephfs/foo bs=64K count=1 mkdir /mnt/mycephfs/.snap/snap1 md5sum /mnt/mycephfs/.snap/snap1/foo fallocate -p -o 0 -l 4096 /mnt/mycephfs/foo echo 3 > /proc/sys/vm/drop/caches md5sum /mnt/mycephfs/.snap/snap1/foo # get different md5sum!! Fixes: ad7a60de882ac ("ceph: punch hole support") Signed-off-by: ethanwu --- fs/ceph/file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index c02f100f8552..58cc2cbae8bc 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -2572,6 +2572,7 @@ static int ceph_zero_partial_object(struct inode *inode, struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_fs_client *fsc = ceph_inode_to_fs_client(inode); struct ceph_osd_request *req; + struct ceph_snap_context *snapc; int ret = 0; loff_t zero = 0; int op; @@ -2586,12 +2587,25 @@ static int ceph_zero_partial_object(struct inode *inode, op = CEPH_OSD_OP_ZERO; } + spin_lock(&ci->i_ceph_lock); + if (__ceph_have_pending_cap_snap(ci)) { + struct ceph_cap_snap *capsnap = + list_last_entry(&ci->i_cap_snaps, + struct ceph_cap_snap, + ci_item); + snapc = ceph_get_snap_context(capsnap->context); + } else { + BUG_ON(!ci->i_head_snapc); + snapc = ceph_get_snap_context(ci->i_head_snapc); + } + spin_unlock(&ci->i_ceph_lock); + req = ceph_osdc_new_request(&fsc->client->osdc, &ci->i_layout, ceph_vino(inode), offset, length, 0, 1, op, CEPH_OSD_FLAG_WRITE, - NULL, 0, 0, false); + snapc, 0, 0, false); if (IS_ERR(req)) { ret = PTR_ERR(req); goto out; @@ -2605,6 +2619,7 @@ static int ceph_zero_partial_object(struct inode *inode, ceph_osdc_put_request(req); out: + ceph_put_snap_context(snapc); return ret; } -- 2.43.0 Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.