From patchwork Fri Jul 14 17:35:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9841479 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 C43A260212 for ; Fri, 14 Jul 2017 17:36:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A90812874B for ; Fri, 14 Jul 2017 17:36:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E2EC28750; Fri, 14 Jul 2017 17:36:45 +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=ham 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 473732874B for ; Fri, 14 Jul 2017 17:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754768AbdGNRgn (ORCPT ); Fri, 14 Jul 2017 13:36:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:49336 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754698AbdGNRgm (ORCPT ); Fri, 14 Jul 2017 13:36:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2FFC2AAC5 for ; Fri, 14 Jul 2017 17:36:36 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 1F15ADA8A2; Fri, 14 Jul 2017 19:35:23 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 3/5] btrfs: defrag: make readahead state allocation failure non-fatal Date: Fri, 14 Jul 2017 19:35:23 +0200 Message-Id: <42a7e40bf0bc8b52f4e958e76e9a1421a472edce.1500053599.git.dsterba@suse.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP All sorts of readahead errors are not considered fatal. We can continue defragmentation without it, with some potential slow down, which will last only for the current inode. Signed-off-by: David Sterba --- fs/btrfs/ioctl.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index d260c4c57338..f418d29b0b92 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1304,14 +1304,14 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, extent_thresh = SZ_256K; /* - * if we were not given a file, allocate a readahead - * context + * If we were not given a file, allocate a readahead context. As + * readahead is just an optimization, defrag will work without it so + * we don't error out. */ if (!file) { ra = kzalloc(sizeof(*ra), GFP_KERNEL); - if (!ra) - return -ENOMEM; - file_ra_state_init(ra, inode->i_mapping); + if (ra) + file_ra_state_init(ra, inode->i_mapping); } else { ra = &file->f_ra; } @@ -1394,8 +1394,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, if (i + cluster > ra_index) { ra_index = max(i, ra_index); - btrfs_force_ra(inode->i_mapping, ra, file, ra_index, - cluster); + if (ra) + btrfs_force_ra(inode->i_mapping, ra, file, + ra_index, cluster); ra_index += cluster; }