Patch "ceph: fix duplicate increment of opened_inodes metric" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    ceph: fix duplicate increment of opened_inodes metric

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ceph-fix-duplicate-increment-of-opened_inodes-metric.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 4c091ce39b6fef7827cc20bba06d3f222003de76
Author: Hu Weiwen <sehuww@xxxxxxxxxxxxxxxx>
Date:   Mon Nov 22 22:22:12 2021 +0800

    ceph: fix duplicate increment of opened_inodes metric
    
    [ Upstream commit 973e5245637accc4002843f6b888495a6a7762bc ]
    
    opened_inodes is incremented twice when the same inode is opened twice
    with O_RDONLY and O_WRONLY respectively.
    
    To reproduce, run this python script, then check the metrics:
    
    import os
    for _ in range(10000):
        fd_r = os.open('a', os.O_RDONLY)
        fd_w = os.open('a', os.O_WRONLY)
        os.close(fd_r)
        os.close(fd_w)
    
    Fixes: 1dd8d4708136 ("ceph: metrics for opened files, pinned caps and opened inodes")
    Signed-off-by: Hu Weiwen <sehuww@xxxxxxxxxxxxxxxx>
    Reviewed-by: Xiubo Li <xiubli@xxxxxxxxxx>
    Signed-off-by: Ilya Dryomov <idryomov@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 8f537f1d9d1d3..8be4da2e2b826 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -4349,7 +4349,7 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
 {
 	struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->vfs_inode.i_sb);
 	int bits = (fmode << 1) | 1;
-	bool is_opened = false;
+	bool already_opened = false;
 	int i;
 
 	if (count == 1)
@@ -4357,19 +4357,19 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
 
 	spin_lock(&ci->i_ceph_lock);
 	for (i = 0; i < CEPH_FILE_MODE_BITS; i++) {
-		if (bits & (1 << i))
-			ci->i_nr_by_mode[i] += count;
-
 		/*
-		 * If any of the mode ref is larger than 1,
+		 * If any of the mode ref is larger than 0,
 		 * that means it has been already opened by
 		 * others. Just skip checking the PIN ref.
 		 */
-		if (i && ci->i_nr_by_mode[i] > 1)
-			is_opened = true;
+		if (i && ci->i_nr_by_mode[i])
+			already_opened = true;
+
+		if (bits & (1 << i))
+			ci->i_nr_by_mode[i] += count;
 	}
 
-	if (!is_opened)
+	if (!already_opened)
 		percpu_counter_inc(&mdsc->metric.opened_inodes);
 	spin_unlock(&ci->i_ceph_lock);
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux