From patchwork Tue Mar 10 11:34:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 11429179 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5EA2138D for ; Tue, 10 Mar 2020 11:34:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4EF924681 for ; Tue, 10 Mar 2020 11:34:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LgWoPB+R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726268AbgCJLed (ORCPT ); Tue, 10 Mar 2020 07:34:33 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:42306 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725937AbgCJLed (ORCPT ); Tue, 10 Mar 2020 07:34:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583840072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fGMpmqhWlovdhsZ7LggLnbE573ynsmE5QVdPGOph9Gc=; b=LgWoPB+RNrFd70+XE8gzHS5hc1KLjEVhTeVoKNHnMpH9FL4uAu//oVHLOZ+h/QzNd4hCt0 LRt/sOeR+6GAVhArTGC+1zmEkwWOY/Vttccd1gH4921ZG+5o0gS4qM19tRorMwmebi45jc /RtIhH6S8B9YOhM6Imy1FqTxCMn46So= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-ZGn5ie-7OM-EGaNjbUD2og-1; Tue, 10 Mar 2020 07:34:30 -0400 X-MC-Unique: ZGn5ie-7OM-EGaNjbUD2og-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C29CDBA9; Tue, 10 Mar 2020 11:34:29 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-12-165.pek2.redhat.com [10.72.12.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 877605D9C5; Tue, 10 Mar 2020 11:34:27 +0000 (UTC) From: "Yan, Zheng" To: ceph-devel@vger.kernel.org Cc: jlayton@kernel.org, "Yan, Zheng" Subject: [PATCH 1/4] ceph: cleanup return error of try_get_cap_refs() Date: Tue, 10 Mar 2020 19:34:18 +0800 Message-Id: <20200310113421.174873-2-zyan@redhat.com> In-Reply-To: <20200310113421.174873-1-zyan@redhat.com> References: <20200310113421.174873-1-zyan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Returns 0 if caps were not able to be acquired (yet), 1 if succeed, or a negative error code. There are 3 speical error codes: -EAGAIN: need to sleep but non-blocking is specified -EFBIG: ask caller to call check_max_size() and try again. -ESTALE: ask caller to call ceph_renew_caps() and try again. Signed-off-by: "Yan, Zheng" --- fs/ceph/caps.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 342a32c74c64..804f4c65251a 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2530,10 +2530,11 @@ void ceph_take_cap_refs(struct ceph_inode_info *ci, int got, * Note that caller is responsible for ensuring max_size increases are * requested from the MDS. * - * Returns 0 if caps were not able to be acquired (yet), a 1 if they were, - * or a negative error code. - * - * FIXME: how does a 0 return differ from -EAGAIN? + * Returns 0 if caps were not able to be acquired (yet), 1 if succeed, + * or a negative error code. There are 3 speical error codes: + * -EAGAIN: need to sleep but non-blocking is specified + * -EFBIG: ask caller to call check_max_size() and try again. + * -ESTALE: ask caller to call ceph_renew_caps() and try again. */ enum { /* first 8 bits are reserved for CEPH_FILE_MODE_FOO */ @@ -2581,7 +2582,7 @@ static int try_get_cap_refs(struct inode *inode, int need, int want, dout("get_cap_refs %p endoff %llu > maxsize %llu\n", inode, endoff, ci->i_max_size); if (endoff > ci->i_requested_max_size) - ret = -EAGAIN; + ret = -EFBIG; goto out_unlock; } /* @@ -2743,7 +2744,10 @@ int ceph_try_get_caps(struct inode *inode, int need, int want, flags |= NON_BLOCKING; ret = try_get_cap_refs(inode, need, want, 0, flags, got); - return ret == -EAGAIN ? 0 : ret; + /* three special error codes */ + if (ret == -EAGAIN || ret == -EFBIG || ret == -EAGAIN) + ret = 0; + return ret; } /* @@ -2771,17 +2775,12 @@ int ceph_get_caps(struct file *filp, int need, int want, flags = get_used_fmode(need | want); while (true) { - if (endoff > 0) - check_max_size(inode, endoff); - flags &= CEPH_FILE_MODE_MASK; if (atomic_read(&fi->num_locks)) flags |= CHECK_FILELOCK; _got = 0; ret = try_get_cap_refs(inode, need, want, endoff, flags, &_got); - if (ret == -EAGAIN) - continue; if (!ret) { struct ceph_mds_client *mdsc = fsc->mdsc; struct cap_wait cw; @@ -2829,6 +2828,10 @@ int ceph_get_caps(struct file *filp, int need, int want, } if (ret < 0) { + if (ret == -EFBIG) { + check_max_size(inode, endoff); + continue; + } if (ret == -ESTALE) { /* session was killed, try renew caps */ ret = ceph_renew_caps(inode, flags); From patchwork Tue Mar 10 11:34:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 11429183 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E14B138D for ; Tue, 10 Mar 2020 11:34:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D821524684 for ; Tue, 10 Mar 2020 11:34:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YHQuOiOv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726315AbgCJLeg (ORCPT ); Tue, 10 Mar 2020 07:34:36 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25800 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726211AbgCJLef (ORCPT ); Tue, 10 Mar 2020 07:34:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583840075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=80phVWs2HK+HrFyyvtT2NcltG906Tx1yse0pWekepwg=; b=YHQuOiOvzunvEnx5EJED9UhMupOZagNuLWGR/UJP/F7Vkan03LIYf95LxEMLi3/k7vlFvM jaKm6GuW5RQgJiZoddn6+OYbm6Rb5gEtXK0t6E2LmOZdWDwLXGViZWqEjwd45QO9mSk38E odr6jGwOTHMIemyNgYQsVjrYYAbWUpA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-230-VRVz7-tIPhSlG3_nEC6zdg-1; Tue, 10 Mar 2020 07:34:33 -0400 X-MC-Unique: VRVz7-tIPhSlG3_nEC6zdg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79077DBA5; Tue, 10 Mar 2020 11:34:32 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-12-165.pek2.redhat.com [10.72.12.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6686B5D9C5; Tue, 10 Mar 2020 11:34:30 +0000 (UTC) From: "Yan, Zheng" To: ceph-devel@vger.kernel.org Cc: jlayton@kernel.org, "Yan, Zheng" Subject: [PATCH 2/4] ceph: request new max size only when there is auth cap Date: Tue, 10 Mar 2020 19:34:19 +0800 Message-Id: <20200310113421.174873-3-zyan@redhat.com> In-Reply-To: <20200310113421.174873-1-zyan@redhat.com> References: <20200310113421.174873-1-zyan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org When there is no auth cap, check_max_size() can't do anything, may cause infinite loop inside ceph_get_caps(). Signed-off-by: "Yan, Zheng" --- fs/ceph/caps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 804f4c65251a..295b61201d85 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2582,7 +2582,7 @@ static int try_get_cap_refs(struct inode *inode, int need, int want, dout("get_cap_refs %p endoff %llu > maxsize %llu\n", inode, endoff, ci->i_max_size); if (endoff > ci->i_requested_max_size) - ret = -EFBIG; + ret = ci->i_auth_cap ? -EFBIG : -ESTALE; goto out_unlock; } /* From patchwork Tue Mar 10 11:34:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 11429185 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D829138D for ; Tue, 10 Mar 2020 11:34:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43B0524681 for ; Tue, 10 Mar 2020 11:34:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fI04R4j5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726331AbgCJLei (ORCPT ); Tue, 10 Mar 2020 07:34:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:52799 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726283AbgCJLei (ORCPT ); Tue, 10 Mar 2020 07:34:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583840077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQGRXGNVhL/4lQE6KaDr+NPkR47gBgs+0PVmahX+COg=; b=fI04R4j5K/s7Z/P8P7B6c7F5gaflECPqeNfBGQ38giDXr3HzfLzRwQTYDX3pm7fmC/cZUV vUQ69aHToBUGe9USAQDh16E5kJK92x4PTT9u4qjnawoceGnDYjKF3qMSXRhnwnFPokWy1e judt1QQCG6sGYt+pZuAoeHydD3GI5b0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-FbqLOOlAPuaDYBBH51WOuQ-1; Tue, 10 Mar 2020 07:34:35 -0400 X-MC-Unique: FbqLOOlAPuaDYBBH51WOuQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E63AADBA3; Tue, 10 Mar 2020 11:34:34 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-12-165.pek2.redhat.com [10.72.12.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46A495D9C5; Tue, 10 Mar 2020 11:34:32 +0000 (UTC) From: "Yan, Zheng" To: ceph-devel@vger.kernel.org Cc: jlayton@kernel.org, "Yan, Zheng" Subject: [PATCH 3/4] ceph: don't skip updating wanted caps when cap is stale Date: Tue, 10 Mar 2020 19:34:20 +0800 Message-Id: <20200310113421.174873-4-zyan@redhat.com> In-Reply-To: <20200310113421.174873-1-zyan@redhat.com> References: <20200310113421.174873-1-zyan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org 1. try_get_cap_refs() fails to get caps and finds that mds_wanted does not include what it wants. It return -ESTALE. 2. ceph_get_caps() calls ceph_renew_caps(). ceph_renew_caps() finds that inode has cap, so it calls ceph_check_caps(). 3. ceph_check_caps() finds that issued caps (without checking if it's stale) already includes caps wanted by open file, so it skips updating wanted caps. Above events can cause infinite loop inside ceph_get_caps() Signed-off-by: "Yan, Zheng" --- fs/ceph/caps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 295b61201d85..f63db3cb9c4f 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2008,8 +2008,12 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags, } /* want more caps from mds? */ - if (want & ~(cap->mds_wanted | cap->issued)) - goto ack; + if (want & ~cap->mds_wanted) { + if (want & ~(cap->mds_wanted | cap->issued)) + goto ack; + if (!__cap_is_valid(cap)) + goto ack; + } /* things we might delay */ if ((cap->issued & ~retain) == 0) From patchwork Tue Mar 10 11:34:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 11429187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBEE0138D for ; Tue, 10 Mar 2020 11:34:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A22E924686 for ; Tue, 10 Mar 2020 11:34:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B4JTEmOA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726391AbgCJLel (ORCPT ); Tue, 10 Mar 2020 07:34:41 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:57193 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726205AbgCJLek (ORCPT ); Tue, 10 Mar 2020 07:34:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583840080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YVk5a9TiK5PWniqGB7ZrjMQ0UJfZTlT7mK21+dvLRTs=; b=B4JTEmOAWKtLnCKnSmXcjOpxNZYfp6QICJfAm8ciypO1E499sepNKE715fso9QhAI/44jx Ry4AlpQc0y+/QCklBtRMq0Ll6M/ZiVKQMw+Uj3BkjUVFHX1FNgoinYbwBCYChl5BiL+r0C oqGLJKyeef/0hjaCNIGA9ellHo/eC5U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-178-pV71SgLoMUKjp6lw6-O0Ug-1; Tue, 10 Mar 2020 07:34:38 -0400 X-MC-Unique: pV71SgLoMUKjp6lw6-O0Ug-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67138DBA3; Tue, 10 Mar 2020 11:34:37 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-12-165.pek2.redhat.com [10.72.12.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id B61BE5D9C5; Tue, 10 Mar 2020 11:34:35 +0000 (UTC) From: "Yan, Zheng" To: ceph-devel@vger.kernel.org Cc: jlayton@kernel.org, "Yan, Zheng" Subject: [PATCH 4/4] ceph: wait for async creating inode before requesting new max size Date: Tue, 10 Mar 2020 19:34:21 +0800 Message-Id: <20200310113421.174873-5-zyan@redhat.com> In-Reply-To: <20200310113421.174873-1-zyan@redhat.com> References: <20200310113421.174873-1-zyan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org ceph_check_caps() can't request new max size for async creating inode. This may make ceph_get_caps() loop busily until getting reply of the async create. This patch also waits for async creating inode before calling ceph_renew_caps() Signed-off-by: "Yan, Zheng" --- fs/ceph/caps.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index f63db3cb9c4f..14bedf2c16cd 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2832,6 +2832,11 @@ int ceph_get_caps(struct file *filp, int need, int want, } if (ret < 0) { + if (ret == -EFBIG || ret == -ESTALE) { + int ret2 = ceph_wait_on_async_create(inode); + if (ret2 < 0) + return ret2; + } if (ret == -EFBIG) { check_max_size(inode, endoff); continue;