From patchwork Fri Mar 3 17:02:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9603285 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 B8649602B4 for ; Fri, 3 Mar 2017 17:12:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A333926E90 for ; Fri, 3 Mar 2017 17:12:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97F78276D6; Fri, 3 Mar 2017 17:12:27 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 88BAD26E90 for ; Fri, 3 Mar 2017 17:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751722AbdCCRMP (ORCPT ); Fri, 3 Mar 2017 12:12:15 -0500 Received: from mail-pg0-f46.google.com ([74.125.83.46]:34885 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbdCCRMN (ORCPT ); Fri, 3 Mar 2017 12:12:13 -0500 Received: by mail-pg0-f46.google.com with SMTP id b129so45882176pgc.2 for ; Fri, 03 Mar 2017 09:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dqMRyGpilwf+ijCtnRhRE0ZLH3REB8KQQHZuOQslPqc=; b=RRmQ3N/RlPTlfApYqf25eLtDrQiIUkrDTV8KRlNIV1608zQLtBNET2v8sLi4b215GU 3NTSMWYSmTj5cgRkWHm9A7ZTiPwCCICY3923MfbVCfBfLleoDaWnCcaIznJJVZiZryl3 89faSfDfE1oNMikCUTRROVqs68ld8ey+kWAOQFkT1QvQxHi5e6sg71EeNqvZoF/mOz8Y baltdP00L1AilxJg+X84jOje1+oQacBCNXXU+VsRcAUy+lRZ4es8RUnqkybBbLc6oQb7 YKhSqbCFWv7lhfqSzt6Br1f6BYSW0CmuT1hbd5NcKgExhBAvUXJLRw4D/ihNdSgDscMN xabg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dqMRyGpilwf+ijCtnRhRE0ZLH3REB8KQQHZuOQslPqc=; b=CjH9cdbisEpQa0JbOLkprGC4mDVDA0WLRNGhrwkpzD3ncJtTDjHlSjfBo/xF7Pb20t I0jXl5dU2byG5JSw/DqvT30AMbAHkLKMWvrdjVTKFqsxNXcM5pO0i4/yeeK5ef3AAtkG FpLbwzZ1iyGyENywPj6Sc0vT4KTH70VR5fuDJCm8P1MOAX1Zgj73T/ZRwCqamH8OFmmd II3UW8orofLWsOkcqYsC0q4rkVP1w201IKYVjGcfjjgf7aoFtroOnrQJByB6eyMoizZA ZzengjMoWer4Ew68iRwa/ymld6svb8YazE4nGl1Jhpzk74SqzJlMlAfX1BkbtRkW0oYr 7xHw== X-Gm-Message-State: AMke39l1mhoS6LiAqQLtrGL4yd22ghIO9J7pkJhOXbx7aQpvSWdqUUdXyn7ay7wqOcq3LSmw X-Received: by 10.99.161.17 with SMTP id b17mr4692341pgf.72.1488560581680; Fri, 03 Mar 2017 09:03:01 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::8cb7]) by smtp.gmail.com with ESMTPSA id x2sm24483830pfb.49.2017.03.03.09.03.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Mar 2017 09:03:01 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org, David Sterba Cc: kernel-team@fb.com Subject: [PATCH v2] btrfs-progs: report I/O errors when closing the filesystem Date: Fri, 3 Mar 2017 09:02:14 -0800 Message-Id: <105e3aa192a47f3936c2ac47ad8d673745cccaea.1488560489.git.osandov@fb.com> X-Mailer: git-send-email 2.12.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 From: Omar Sandoval If the final fsync() on the Btrfs device fails, we just swallow the error and don't alert the user in any way. This was uncovered by xfstest generic/405, which checks that mkfs fails when it encounters EIO. Signed-off-by: Omar Sandoval Reviewed-by: Qu Wenruo --- Changes from v1: return -errno instead of -1 disk-io.c | 4 ++-- volumes.c | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/disk-io.c b/disk-io.c index 2a94d4fc..48fb3c6b 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1817,10 +1817,10 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info) free_fs_roots_tree(&fs_info->fs_root_tree); btrfs_release_all_roots(fs_info); - btrfs_close_devices(fs_info->fs_devices); + ret = btrfs_close_devices(fs_info->fs_devices); btrfs_cleanup_all_caches(fs_info); btrfs_free_fs_info(fs_info); - return 0; + return ret; } int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, diff --git a/volumes.c b/volumes.c index a0a85edd..f7d82d51 100644 --- a/volumes.c +++ b/volumes.c @@ -160,6 +160,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices) { struct btrfs_fs_devices *seed_devices; struct btrfs_device *device; + int ret = 0; again: if (!fs_devices) @@ -168,7 +169,11 @@ again: device = list_entry(fs_devices->devices.next, struct btrfs_device, dev_list); if (device->fd != -1) { - fsync(device->fd); + if (fsync(device->fd) == -1) { + warning("fsync on device %llu failed: %s", + device->devid, strerror(errno)); + ret = -errno; + } if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED)) fprintf(stderr, "Warning, could not drop caches\n"); close(device->fd); @@ -197,7 +202,7 @@ again: free(fs_devices); } - return 0; + return ret; } void btrfs_close_all_devices(void)