Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1054754ybt; Wed, 1 Jul 2020 17:31:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAbMbB1DzxZEet78Qx9LQK2o+nqKrvW6saUhV8WO6RVYWGL8uJ/oDtF2Tq+N4Wkrrz0Zx4 X-Received: by 2002:a05:6402:128c:: with SMTP id w12mr21200095edv.65.1593649890577; Wed, 01 Jul 2020 17:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593649890; cv=none; d=google.com; s=arc-20160816; b=KKfoWA8Q6IMr6VbX0mniwEg3OVQmrfss1mGVSg8RKXUNG3HXkob/ZwhEAWXc/cwF08 Nj6f3QCs7iMtM3H6oGfaLq/jXFuUV2pKogVnXbtqYohJngqBuF52QbLp/Ta9ST8mYSIj DnVLaKlEHJOyOAuiknlOJ8UkrWVNtBSra1GV7uArQZbGN7O2x8VlPPLZoiyRFoqHWOu+ KrwQcROuJmAR9Kzti3ycSZj7gbc9ifiIKNPqUahv1pJndbRLW44hH0GVIXzR4g9jMs6n 8j6bn00GPGEaDC2FiIchhyfU7rhRSbM3pYnb7L0xeQlIJ7tM9pD7msPKk44lew8Hif5l LBjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:references :in-reply-to:subject:cc:date:to:from; bh=TLUnlkXy0Pa+GbNPkZu8gCX6i7Dtc7S2ui3vXPsohw8=; b=GreZfHC7aPpnJaYc2E61Muys+wOPwps9aooLBgh4WYC+eVFTv4rr3ZuupPRSQuy6F6 lqjj/ZLlrcSPel1OI8gnz7HFRiclxojshGCkjxnHGMMsHW7ADfTUBOU9UGybIurAOW3E EdOy5A9QPYmWIzu5SMBf41aR86rmFFfyDw5eckh8mg/dRnvP3Ff8pU/GevpUe7aUivIF 3ai6iW15aaVFHkKb6rL2pOC1hKCT9rqfGE2XMcu+XqwKWpn22AKlnaVHDR4vpqJ3W/6f oaViyEQXQtBwdTgOZXLNkM+py/E+5nNBxM508FcNzaE1hzV2dAfjUqFefQjNzjV1gckr NQ7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e24si5119387edy.323.2020.07.01.17.30.54; Wed, 01 Jul 2020 17:31:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727812AbgGBAat (ORCPT + 99 others); Wed, 1 Jul 2020 20:30:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:38434 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726985AbgGBAas (ORCPT ); Wed, 1 Jul 2020 20:30:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 28BF2AD4A; Thu, 2 Jul 2020 00:30:47 +0000 (UTC) From: NeilBrown To: Olga Kornievskaia , trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Date: Thu, 02 Jul 2020 10:30:40 +1000 Cc: linux-nfs@vger.kernel.org Subject: [PATCH] NFS: simplify inode_dio_begin/end calls. In-Reply-To: <20200624175408.74678-1-olga.kornievskaia@gmail.com> References: <20200624175408.74678-1-olga.kornievskaia@gmail.com> Message-ID: <87366a3gi7.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable As a recent patch highlighted, inode_dio_end() must be called after nfs_direct_req_release() is called. It would make the code more robust if nfs_direct_req_release() did that call itself, placing it after put_nfs_open_context(). To achieve this: - move the inode_dio_begin() calls to the moment when a 'struct nfs_direct_req' is allocated, - move the inode_dio_end() calls to just before the 'struct nfs_direct_req' is freed, - use igrab to make req->inode a counted reference so that it can be used after put_nfs_open_context() (which calls dput(), that releasing the only reference we previously held on the inode). This patch doesn't change behaviour at all, it just simplifies the code a little. Signed-off-by: NeilBrown =2D-- fs/nfs/direct.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 3d113cf8908a..ab32b23639d3 100644 =2D-- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -221,6 +221,8 @@ static void nfs_direct_req_free(struct kref *kref) nfs_put_lock_context(dreq->l_ctx); if (dreq->ctx !=3D NULL) put_nfs_open_context(dreq->ctx); + inode_dio_end(dreq->inode); + iput(dreq->inode); kmem_cache_free(nfs_direct_cachep, dreq); } =20 @@ -278,10 +280,7 @@ static void nfs_direct_complete(struct nfs_direct_req = *dreq) =20 complete(&dreq->completion); =20 =2D igrab(inode); nfs_direct_req_release(dreq); =2D inode_dio_end(inode); =2D iput(inode); } =20 static void nfs_direct_read_completion(struct nfs_pgio_header *hdr) @@ -359,7 +358,6 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nf= s_direct_req *dreq, &nfs_direct_read_completion_ops); get_dreq(dreq); desc.pg_dreq =3D dreq; =2D inode_dio_begin(inode); =20 while (iov_iter_count(iter)) { struct page **pagevec; @@ -411,10 +409,7 @@ static ssize_t nfs_direct_read_schedule_iovec(struct n= fs_direct_req *dreq, * generic layer handle the completion. */ if (requested_bytes =3D=3D 0) { =2D igrab(inode); nfs_direct_req_release(dreq); =2D inode_dio_end(inode); =2D iput(inode); return result < 0 ? result : -EIO; } =20 @@ -467,7 +462,8 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct= iov_iter *iter) if (dreq =3D=3D NULL) goto out; =20 =2D dreq->inode =3D inode; + dreq->inode =3D igrab(inode); + inode_dio_begin(inode); dreq->bytes_left =3D dreq->max_count =3D count; dreq->io_start =3D iocb->ki_pos; dreq->ctx =3D get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); @@ -807,7 +803,6 @@ static ssize_t nfs_direct_write_schedule_iovec(struct n= fs_direct_req *dreq, &nfs_direct_write_completion_ops); desc.pg_dreq =3D dreq; get_dreq(dreq); =2D inode_dio_begin(inode); =20 NFS_I(inode)->write_io +=3D iov_iter_count(iter); while (iov_iter_count(iter)) { @@ -867,10 +862,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct = nfs_direct_req *dreq, * generic layer handle the completion. */ if (requested_bytes =3D=3D 0) { =2D igrab(inode); nfs_direct_req_release(dreq); =2D inode_dio_end(inode); =2D iput(inode); return result < 0 ? result : -EIO; } =20 @@ -929,7 +921,8 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struc= t iov_iter *iter) if (!dreq) goto out; =20 =2D dreq->inode =3D inode; + dreq->inode =3D igrab(inode); + inode_dio_begin(inode); dreq->bytes_left =3D dreq->max_count =3D count; dreq->io_start =3D pos; dreq->ctx =3D get_nfs_open_context(nfs_file_open_context(iocb->ki_filp)); =2D-=20 2.26.2 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAl79KrAACgkQOeye3VZi gbluQBAAjNhXPN7XLRmihIeYKqj8GCMUxGz99oFKiXKAmQN1KXS/AvWggBFNmSJB 3pWLEBFztBst/+5XzIu13FyBZVJ2WHyYHviN4xDXPKdVj2WWyr7z/AAFO1nMQmzO DRuBn2ydlBgxc6bqjAABJEZxENAtgn7NpCwPd5z7d26UgmOpl4pGX8iuTcNK/AA5 n3/2OhqqhUnsyoxf8FoNjEn8wDtboE1AYYA1JeXov7r9kl84+fBQ9CftvgNMsiIU v6vlptxL3Nt0Dj8gs36slUWWHjmBG8QjMET0Db4a/TGxmVdljazszSRmYDssZdlL 9GE1Iv0wvcj2q+3kxPVLpBP6ZXJWB+wtBz2igSDDmBPlwmJqsxhv68ZgT/dEAdoY BaFWRjTlELKGKPt66f9sdIGw+kZlTy/3TuerK4fec6ChgS6u1ScUzIeEmMlNpbNd HsDJJNz1KtMa/uvz0aFWrWYdxLb2miIbK9Wozq9HawEGrmRXS8wbRMquh9XAFtj+ 3mHvfYFKCeEfAlL/+zSmApd1HuW83esltdO5pWQA+D/6BTmbKgC71CkyEaQGWo53 H+MD9PLLc1TPWXf6d8GbeFRoAiHpz714njDhoycpDJVEapyx/hzQyegUSwgoW6XH 0/SFtoF4+QUUAZ068YxHWY3fcCBmt/CM9IX7eTHK+6KLM8/0jlU= =oytk -----END PGP SIGNATURE----- --=-=-=--