Commit 973e5245 authored by Hu Weiwen's avatar Hu Weiwen Committed by Ilya Dryomov

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: 1dd8d470 ("ceph: metrics for opened files, pinned caps and opened inodes")
Signed-off-by: default avatarHu Weiwen <sehuww@mail.scut.edu.cn>
Reviewed-by: default avatarXiubo Li <xiubli@redhat.com>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent d58071a8
...@@ -4350,7 +4350,7 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count) ...@@ -4350,7 +4350,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); struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(ci->vfs_inode.i_sb);
int bits = (fmode << 1) | 1; int bits = (fmode << 1) | 1;
bool is_opened = false; bool already_opened = false;
int i; int i;
if (count == 1) if (count == 1)
...@@ -4358,19 +4358,19 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count) ...@@ -4358,19 +4358,19 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
spin_lock(&ci->i_ceph_lock); spin_lock(&ci->i_ceph_lock);
for (i = 0; i < CEPH_FILE_MODE_BITS; i++) { 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 * that means it has been already opened by
* others. Just skip checking the PIN ref. * others. Just skip checking the PIN ref.
*/ */
if (i && ci->i_nr_by_mode[i] > 1) if (i && ci->i_nr_by_mode[i])
is_opened = true; 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); percpu_counter_inc(&mdsc->metric.opened_inodes);
spin_unlock(&ci->i_ceph_lock); spin_unlock(&ci->i_ceph_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment