From patchwork Wed May 13 16:21:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1289477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Mg196J78z9sRY; Thu, 14 May 2020 02:22:03 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jYu8t-0004zq-An; Wed, 13 May 2020 16:21:59 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jYu8r-0004zG-Ir for kernel-team@lists.ubuntu.com; Wed, 13 May 2020 16:21:57 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jYu8r-0000TN-7t for kernel-team@lists.ubuntu.com; Wed, 13 May 2020 16:21:57 +0000 Received: by mail-qk1-f198.google.com with SMTP id y64so671qkc.19 for ; Wed, 13 May 2020 09:21:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WanmUCL3KC7HVFw2bP77ySa29PY2DhnWlM8X5ghCsxc=; b=lt3r3lZ4nYMeUbaeoBsHT7H0eQu2ZVyCBfdLCw7TNz3DMC3TM6om7EL/W3lkA9tdQ8 TqDb8JmVizHVIVP7fe5Xre3i8c2eGtwmrHT0bH84wJkZjsHHvkXZqiBZrmbKfax8buld svzQ0wUjjE+wvfzqc1Mt63AhpBLrFhHrU0gC5NKyMlWBBYt3boQ3QjnsWST8cR6oqpBS orEOXMnaglJN/VItT3kczi+zo7yJPrgFd0inpgvBity8Kt1JqpmjCQ9udXxdRqovmIrp NaNtapwuXDjQqWrQk9hM6gxMeGoKeJ7P2d7x9MucpefbiWkugCQ8mTcR+i/kDga6mNYZ /qNQ== X-Gm-Message-State: AOAM5329KONT0Sl3VF/dSr03rzwl6Grgr+GwAG0pkwReRq5A1XUHV4GH LSISgTyqMwPkySp78PBPvnphI77AQ3phL7n62S+8nhVtaTKkoT6fT7P/cj2xCEwm5WT2r1ony4O /d9wgoit2jfh3zxu0kM0fkkpzPDuFt10j8PrRZXlu X-Received: by 2002:ac8:2f50:: with SMTP id k16mr6080770qta.392.1589386915956; Wed, 13 May 2020 09:21:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY/Fks3c3hdkx2XkpW/hGaE/X2Ub/Rc8tfewkguWAISiTGIIJfYNA+6Zek5D4Nts1GCPMRPw== X-Received: by 2002:ac8:2f50:: with SMTP id k16mr6080748qta.392.1589386915693; Wed, 13 May 2020 09:21:55 -0700 (PDT) Received: from gallifrey.lan ([2804:14c:4e6:c56:1d71:b49e:7e9c:251a]) by smtp.gmail.com with ESMTPSA id c197sm193432qkg.133.2020.05.13.09.21.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 09:21:54 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [bionic:linux][PATCH 1/2] ceph: don't check quota for snap inode Date: Wed, 13 May 2020 13:21:48 -0300 Message-Id: <20200513162149.4026917-2-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200513162149.4026917-1-marcelo.cerri@canonical.com> References: <20200513162149.4026917-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Yan, Zheng BugLink: https://bugs.launchpad.net/bugs/1875884 snap inode's i_snap_realm is not pointing to ceph_snap_realm. Signed-off-by: "Yan, Zheng" Signed-off-by: Ilya Dryomov (cherry picked from commit 2596366907f872de7be0557720bb55bccf7489d9) Signed-off-by: Marcelo Henrique Cerri --- fs/ceph/dir.c | 3 ++- fs/ceph/quota.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c index 04abc65e1c20..194f8ed6c276 100644 --- a/fs/ceph/dir.c +++ b/fs/ceph/dir.c @@ -932,7 +932,8 @@ static int ceph_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) goto out; } - if (ceph_quota_is_max_files_exceeded(dir)) { + if (op == CEPH_MDS_OP_MKDIR && + ceph_quota_is_max_files_exceeded(dir)) { err = -EDQUOT; goto out; } diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c index c5b1fd26daaa..e1eb95545feb 100644 --- a/fs/ceph/quota.c +++ b/fs/ceph/quota.c @@ -98,8 +98,15 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc, struct inode *in; bool has_quota; + if (ceph_snap(inode) != CEPH_NOSNAP) + return NULL; + realm = ceph_inode(inode)->i_snap_realm; - ceph_get_snap_realm(mdsc, realm); + if (realm) + ceph_get_snap_realm(mdsc, realm); + else + pr_err_ratelimited("get_quota_realm: ino (%llx.%llx) " + "null i_snap_realm\n", ceph_vinop(inode)); while (realm) { vino.ino = realm->ino; vino.snap = CEPH_NOSNAP; @@ -171,9 +178,16 @@ static bool check_quota_exceeded(struct inode *inode, enum quota_check_op op, u64 max, rvalue; bool exceeded = false; + if (ceph_snap(inode) != CEPH_NOSNAP) + return false; + down_read(&mdsc->snap_rwsem); realm = ceph_inode(inode)->i_snap_realm; - ceph_get_snap_realm(mdsc, realm); + if (realm) + ceph_get_snap_realm(mdsc, realm); + else + pr_err_ratelimited("check_quota_exceeded: ino (%llx.%llx) " + "null i_snap_realm\n", ceph_vinop(inode)); while (realm) { vino.ino = realm->ino; vino.snap = CEPH_NOSNAP; From patchwork Wed May 13 16:21:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1289479 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Mg1C6W5Hz9sSg; Thu, 14 May 2020 02:22:07 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jYu8y-00052k-H1; Wed, 13 May 2020 16:22:04 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jYu8w-00051y-IM for kernel-team@lists.ubuntu.com; Wed, 13 May 2020 16:22:02 +0000 Received: from mail-qv1-f72.google.com ([209.85.219.72]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jYu8w-0000Tn-76 for kernel-team@lists.ubuntu.com; Wed, 13 May 2020 16:22:02 +0000 Received: by mail-qv1-f72.google.com with SMTP id z14so280847qvv.6 for ; Wed, 13 May 2020 09:22:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Xryod+4E1xy6Epr6+6JiNvD6SjqExsy8k+LpyAwRkxY=; b=WrkHxwqC6qYfpfz2lb+N/RTSNThUDdELiXyZb8JraPsWx9waoPqudyjAWfdOnGfpf+ A1YBCROJAVmtlhSWBE9nz23d1ObpAGfey8lR+pkKWR6bLbTct+g9EePLEjUCzZ+RWYfX LjEFjFjzA/dao573VMdYlEOTiMduxbQbkmyVXwBzaDvcupVojjcNtrmPV07xjluaRVhX Go5kH8qHHVTSR5M3LX9f+Ivevnwh0rWpJi2j4DuV6qikKJnvWPp0/G6mLTefk+3qxWh6 XShbqIBViEcgPUFAawbBAnEeedSVZEI8C7czrM0fGmjAm2bceaMoBFK3YswpxOjsHqQz bzhA== X-Gm-Message-State: AOAM5326+39/dmVf3doVJU1Ub5VVgexfSegaKFzUSKRK1FSR8W7Vekzn KOrmWw3BhahpR8lR7LPejsAH2bQHsLASAnWfxMcMnQlbJv5m/ltxynHnnylXpYAjMUWKWfI+Qtt 3BPri8A5gbf7Wwq1nkGStCEgeNserHJw5tw2jiSvt X-Received: by 2002:a37:9b83:: with SMTP id d125mr431943qke.289.1589386919433; Wed, 13 May 2020 09:21:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwemeY8gjkF6xgmqZNqU3FrWxDmK4AL/L0vBup8E0AwAyExFNXjeaY8nUu530oO9bJjo0F44Q== X-Received: by 2002:a37:9b83:: with SMTP id d125mr431811qke.289.1589386917670; Wed, 13 May 2020 09:21:57 -0700 (PDT) Received: from gallifrey.lan ([2804:14c:4e6:c56:1d71:b49e:7e9c:251a]) by smtp.gmail.com with ESMTPSA id c197sm193432qkg.133.2020.05.13.09.21.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 09:21:56 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [bionic:linux][PATCH 2/2] ceph: quota: cache inode pointer in ceph_snap_realm Date: Wed, 13 May 2020 13:21:49 -0300 Message-Id: <20200513162149.4026917-3-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200513162149.4026917-1-marcelo.cerri@canonical.com> References: <20200513162149.4026917-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Luis Henriques BugLink: https://bugs.launchpad.net/bugs/1875884 Keep a pointer to the inode in struct ceph_snap_realm. This allows to optimize functions that walk the realms hierarchy (e.g. in quotas). Signed-off-by: Luis Henriques Reviewed-by: "Yan, Zheng" Signed-off-by: Ilya Dryomov (cherry picked from commit e3161f17d92699ce6ca3b7988131b10ad4035cf9) Signed-off-by: Marcelo Henrique Cerri --- fs/ceph/caps.c | 4 +++- fs/ceph/inode.c | 3 +++ fs/ceph/quota.c | 24 ++++++++++-------------- fs/ceph/snap.c | 2 ++ fs/ceph/super.h | 1 + 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 0a6dc9b5a530..60a87710193f 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -585,9 +585,11 @@ void ceph_add_cap(struct inode *inode, realmino); if (realm) { spin_lock(&realm->inodes_with_caps_lock); - ci->i_snap_realm = realm; list_add(&ci->i_snap_realm_item, &realm->inodes_with_caps); + ci->i_snap_realm = realm; + if (realm->ino == ci->i_vino.ino) + realm->inode = inode; spin_unlock(&realm->inodes_with_caps_lock); } else { pr_err("ceph_add_cap: couldn't find snap realm %llx\n", diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 7b101a98b812..0d8b039f5805 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -554,6 +554,9 @@ void ceph_evict_inode(struct inode *inode) dout(" dropping residual ref to snap realm %p\n", realm); spin_lock(&realm->inodes_with_caps_lock); list_del_init(&ci->i_snap_realm_item); + ci->i_snap_realm = NULL; + if (realm->ino == ci->i_vino.ino) + realm->inode = NULL; spin_unlock(&realm->inodes_with_caps_lock); ceph_put_snap_realm(mdsc, realm); } diff --git a/fs/ceph/quota.c b/fs/ceph/quota.c index e1eb95545feb..2cd727ebb87f 100644 --- a/fs/ceph/quota.c +++ b/fs/ceph/quota.c @@ -94,7 +94,6 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc, { struct ceph_inode_info *ci = NULL; struct ceph_snap_realm *realm, *next; - struct ceph_vino vino; struct inode *in; bool has_quota; @@ -108,13 +107,12 @@ static struct ceph_snap_realm *get_quota_realm(struct ceph_mds_client *mdsc, pr_err_ratelimited("get_quota_realm: ino (%llx.%llx) " "null i_snap_realm\n", ceph_vinop(inode)); while (realm) { - vino.ino = realm->ino; - vino.snap = CEPH_NOSNAP; - in = ceph_find_inode(inode->i_sb, vino); - if (!in) { - pr_warn("Failed to find inode for %llu\n", vino.ino); + spin_lock(&realm->inodes_with_caps_lock); + in = realm->inode ? igrab(realm->inode) : NULL; + spin_unlock(&realm->inodes_with_caps_lock); + if (!in) break; - } + ci = ceph_inode(in); has_quota = __ceph_has_any_quota(ci); /* avoid calling iput_final() while holding mdsc->snap_rwsem */ @@ -173,7 +171,6 @@ static bool check_quota_exceeded(struct inode *inode, enum quota_check_op op, struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc; struct ceph_inode_info *ci; struct ceph_snap_realm *realm, *next; - struct ceph_vino vino; struct inode *in; u64 max, rvalue; bool exceeded = false; @@ -189,13 +186,12 @@ static bool check_quota_exceeded(struct inode *inode, enum quota_check_op op, pr_err_ratelimited("check_quota_exceeded: ino (%llx.%llx) " "null i_snap_realm\n", ceph_vinop(inode)); while (realm) { - vino.ino = realm->ino; - vino.snap = CEPH_NOSNAP; - in = ceph_find_inode(inode->i_sb, vino); - if (!in) { - pr_warn("Failed to find inode for %llu\n", vino.ino); + spin_lock(&realm->inodes_with_caps_lock); + in = realm->inode ? igrab(realm->inode) : NULL; + spin_unlock(&realm->inodes_with_caps_lock); + if (!in) break; - } + ci = ceph_inode(in); spin_lock(&ci->i_ceph_lock); if (op == QUOTA_CHECK_MAX_FILES_OP) { diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c index 036d535711c4..fbea7002ad82 100644 --- a/fs/ceph/snap.c +++ b/fs/ceph/snap.c @@ -940,6 +940,8 @@ void ceph_handle_snap(struct ceph_mds_client *mdsc, &realm->inodes_with_caps); oldrealm = ci->i_snap_realm; ci->i_snap_realm = realm; + if (realm->ino == ci->i_vino.ino) + realm->inode = inode; spin_unlock(&realm->inodes_with_caps_lock); spin_unlock(&ci->i_ceph_lock); diff --git a/fs/ceph/super.h b/fs/ceph/super.h index ede462616680..cf16e0dc2f93 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -761,6 +761,7 @@ struct ceph_readdir_cache_control { */ struct ceph_snap_realm { u64 ino; + struct inode *inode; atomic_t nref; struct rb_node node;