Skip to content

Commit 973e524

Browse files
huww98idryomov
authored andcommitted
ceph: fix duplicate increment of opened_inodes metric
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: 1dd8d47 ("ceph: metrics for opened files, pinned caps and opened inodes") Signed-off-by: Hu Weiwen <[email protected]> Reviewed-by: Xiubo Li <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent d58071a commit 973e524

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

fs/ceph/caps.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,27 +4350,27 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
43504350
{
43514351
struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->vfs_inode.i_sb);
43524352
int bits = (fmode << 1) | 1;
4353-
bool is_opened = false;
4353+
bool already_opened = false;
43544354
int i;
43554355

43564356
if (count == 1)
43574357
atomic64_inc(&mdsc->metric.opened_files);
43584358

43594359
spin_lock(&ci->i_ceph_lock);
43604360
for (i = 0; i < CEPH_FILE_MODE_BITS; i++) {
4361-
if (bits & (1 << i))
4362-
ci->i_nr_by_mode[i] += count;
4363-
43644361
/*
4365-
* If any of the mode ref is larger than 1,
4362+
* If any of the mode ref is larger than 0,
43664363
* that means it has been already opened by
43674364
* others. Just skip checking the PIN ref.
43684365
*/
4369-
if (i && ci->i_nr_by_mode[i] > 1)
4370-
is_opened = true;
4366+
if (i && ci->i_nr_by_mode[i])
4367+
already_opened = true;
4368+
4369+
if (bits & (1 << i))
4370+
ci->i_nr_by_mode[i] += count;
43714371
}
43724372

4373-
if (!is_opened)
4373+
if (!already_opened)
43744374
percpu_counter_inc(&mdsc->metric.opened_inodes);
43754375
spin_unlock(&ci->i_ceph_lock);
43764376
}

0 commit comments

Comments
 (0)