From patchwork Thu Aug 8 16:40:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 2841307 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 68F19BF546 for ; Thu, 8 Aug 2013 16:40:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 18F60202F7 for ; Thu, 8 Aug 2013 16:40:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D4A9E203E9 for ; Thu, 8 Aug 2013 16:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757992Ab3HHQkl (ORCPT ); Thu, 8 Aug 2013 12:40:41 -0400 Received: from cobra.newdream.net ([66.33.216.30]:53906 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757988Ab3HHQkk (ORCPT ); Thu, 8 Aug 2013 12:40:40 -0400 Received: from cobra.newdream.net (localhost [127.0.0.1]) by cobra.newdream.net (Postfix) with ESMTP id 320538047E; Thu, 8 Aug 2013 09:40:40 -0700 (PDT) Received: by cobra.newdream.net (Postfix, from userid 1031) id 1CAD18048A; Thu, 8 Aug 2013 09:40:39 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by cobra.newdream.net (Postfix) with ESMTP id F3EB98047E; Thu, 8 Aug 2013 09:40:39 -0700 (PDT) Date: Thu, 8 Aug 2013 09:40:39 -0700 (PDT) From: Sage Weil X-X-Sender: sage@cobra.newdream.net To: majianpeng cc: ceph-devel Subject: Re: [PATCH TRIVIVAL] ceph: Move the place for EOLDSNAPC handle in ceph_aio_write to easily understand In-Reply-To: <201308081532168498411@gmail.com> Message-ID: References: <201308081532168498411@gmail.com> User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Looks good; I've applied this to the tree. Canyou review the below patch while we are looking at this code? Thanks! sage From 26d0d7b213d87db0ef46e885ae749c27395c11b1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Aug 2013 09:39:44 -0700 Subject: [PATCH] ceph: replace hold_mutex flag with goto All of the early exit paths need to drop the mutex; it is only the normal path through the function that does not. Skip the unlock in that case with a goto out_unlocked. Signed-off-by: Sage Weil --- fs/ceph/file.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 7478d5d..a17ffe4 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -710,13 +710,11 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov, &ceph_sb_to_client(inode->i_sb)->client->osdc; ssize_t count, written = 0; int err, want, got; - bool hold_mutex; if (ceph_snap(inode) != CEPH_NOSNAP) return -EROFS; mutex_lock(&inode->i_mutex); - hold_mutex = true; err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ); if (err) @@ -772,7 +770,6 @@ retry_snap: inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len); mutex_lock(&inode->i_mutex); - hold_mutex = true; goto retry_snap; } } else { @@ -781,7 +778,6 @@ retry_snap: count, 0); mutex_unlock(&inode->i_mutex); } - hold_mutex = false; if (written >= 0) { int dirty; @@ -805,11 +801,12 @@ retry_snap: written = err; } + goto out_unlocked; + out: - if (hold_mutex) - mutex_unlock(&inode->i_mutex); + mutex_unlock(&inode->i_mutex); +out_unlocked: current->backing_dev_info = NULL; - return written ? written : err; }