From patchwork Mon Nov 6 08:04:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10042729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 05B9A6032D for ; Mon, 6 Nov 2017 08:06:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAA1D1FFB1 for ; Mon, 6 Nov 2017 08:06:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF6D5297A4; Mon, 6 Nov 2017 08:06:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F2F81FFB1 for ; Mon, 6 Nov 2017 08:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751622AbdKFIFE (ORCPT ); Mon, 6 Nov 2017 03:05:04 -0500 Received: from mout.web.de ([212.227.17.12]:61853 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751073AbdKFIFD (ORCPT ); Mon, 6 Nov 2017 03:05:03 -0500 Received: from [192.168.1.3] ([78.48.227.228]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LpO4v-1eqhmh3vNt-00f8uI; Mon, 06 Nov 2017 09:04:51 +0100 To: linux-btrfs@vger.kernel.org, Chris Mason , David Sterba , Josef Bacik Cc: linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org, LKML From: SF Markus Elfring Subject: [PATCH] btrfs/volumes: Improve unlocking of a mutex in __btrfs_balance() Message-ID: Date: Mon, 6 Nov 2017 09:04:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:3gJdungiS/9ucIWKIP5WDZBzKuYMCkgJlxFhrHgfcX1IBaSZG+v U1PliXiarzXhmJqqoAz2/O/KQg3pBHpFeadOeJsZip9wBl5OTujw0ji4QqPXf2VGYBIY9Wy BnwM2mUaoE4pIO3+KUd+PEAC3rUQT1g+mSGVdHMTTA8qM3uZLWm4pBFWeVq2lboYsPslXxP cUR84ml74MEYw9eMAj+mA== X-UI-Out-Filterresults: notjunk:1; V01:K0:gpUMvrQyXAw=:J3LWn+RieSCcWEA3wQydbb PKohcdXaT2As8fWv8VImnTZF/W8xirtNXQN9TQoxLySgL/d0NNswUc4NPo5lOOGGKo83l1tNU AQN9MYzeLmMOk5HH4aWQ8F0xQnQDevVi2bx0+GNt7OWc7D1diF+4RXIMJpiAA4ElFMm3BWscx e6o641vGr+lKOVZeEfOfFBOxsL+71CnUga+XIvHvRMvArMiZ+klrsAb7Ji2EVxm0blqDosRLm aFBZ7eA6OAWAo/ot9+I0PlgekoE0igUS/Ehwg3MTfTfXH4/gL55OJV1IcdsO+mceVqsaU36TK b9fwW6Zjz7a/6Om8Pez6lxK/WQoqBeFv6eya3yvvURIo3poXffRQJa8PIsamtg43ZPBvQdJS7 c6yhTD9epFG7Lg6t1qxfcTKAJnCiBhwvrbr7RtbBVDPhEAbVy9W9MGSXlxWeWdYlzMmen+uJ6 xJtW7ZR4+1ZKCbJwCC7pq+LlFgSjhZaS5fcnYlyd4gnjudtbd5HzKJA9eOvKdebDbA8xYJztp hohQG35zPGNIzh3jBNScWfjtESss6qOa9OH3xLMNM4qqs/c6/qqrwyjoMw5PEkm3F4hgyqS2S /20EqsjuKuRxWnuYcSeMNDRhj4GPturxE3d715CtsVAqaW1GngEqJyPy35v2tgwKaLr+LfIU8 TQHMJGicPH+o+bq3EdWQRzBPAWzOw4+wMMiFf9VXEKVX5/z3CibY19Dgx80IWMME1qfEKDqyf eeN7AKzDgnZSywZPxMM7cUrn6NwurCaZnoGTWAgqQlpsWeNqfUeWAkWM0/CNqtj7AYKY+O7rj n86DEOZvlnX9hRe/S5rz9Y5wNkoppN1z+hS8odlrgDajZLaQow= Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 5 Nov 2017 22:03:22 +0100 * Adjust jump targets so that a call of the function "mutex_unlock" can be better reused for error cases at the end of this function. * Replace three calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- fs/btrfs/volumes.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ea8b20839ac0..3bc430623849 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3497,7 +3497,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) if (ret) { /* btrfs_shrink_device never returns ret > 0 */ WARN_ON(ret > 0); - goto error; + goto free_path; } trans = btrfs_start_transaction(dev_root, 0); @@ -3507,7 +3507,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) "resize: unable to start transaction after shrinking device %s (error %d), old size %llu, new size %llu", rcu_str_deref(device->name), ret, old_size, old_size - size_to_free); - goto error; + goto free_path; } ret = btrfs_grow_device(trans, device, old_size); @@ -3519,7 +3519,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) "resize: unable to grow device after shrinking device %s (error %d), old size %llu, new size %llu", rcu_str_deref(device->name), ret, old_size, old_size - size_to_free); - goto error; + goto free_path; } btrfs_end_transaction(trans); @@ -3529,7 +3529,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) path = btrfs_alloc_path(); if (!path) { ret = -ENOMEM; - goto error; + goto free_path; } /* zero out stat counters */ @@ -3554,15 +3554,13 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) if ((!counting && atomic_read(&fs_info->balance_pause_req)) || atomic_read(&fs_info->balance_cancel_req)) { ret = -ECANCELED; - goto error; + goto free_path; } mutex_lock(&fs_info->delete_unused_bgs_mutex); ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0); - if (ret < 0) { - mutex_unlock(&fs_info->delete_unused_bgs_mutex); - goto error; - } + if (ret < 0) + goto unlock; /* * this shouldn't happen, it means the last relocate @@ -3645,25 +3643,23 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) !chunk_reserved && !bytes_used) { trans = btrfs_start_transaction(chunk_root, 0); if (IS_ERR(trans)) { - mutex_unlock(&fs_info->delete_unused_bgs_mutex); ret = PTR_ERR(trans); - goto error; + goto unlock; } ret = btrfs_force_chunk_alloc(trans, fs_info, BTRFS_BLOCK_GROUP_DATA); btrfs_end_transaction(trans); - if (ret < 0) { - mutex_unlock(&fs_info->delete_unused_bgs_mutex); - goto error; - } + if (ret < 0) + goto unlock; + chunk_reserved = 1; } ret = btrfs_relocate_chunk(fs_info, found_key.offset); mutex_unlock(&fs_info->delete_unused_bgs_mutex); if (ret && ret != -ENOSPC) - goto error; + goto free_path; if (ret == -ENOSPC) { enospc_errors++; } else { @@ -3682,7 +3678,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) counting = false; goto again; } -error: +free_path: btrfs_free_path(path); if (enospc_errors) { btrfs_info(fs_info, "%d enospc errors during balance", @@ -3692,6 +3688,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) } return ret; + +unlock: + mutex_unlock(&fs_info->delete_unused_bgs_mutex); + goto free_path; } /**