From patchwork Fri Mar 3 16:59:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9603277 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 BD11F604E2 for ; Fri, 3 Mar 2017 17:00:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC3F4285CF for ; Fri, 3 Mar 2017 17:00:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0C7D285D3; Fri, 3 Mar 2017 17:00: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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 14097285D2 for ; Fri, 3 Mar 2017 17:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752117AbdCCRAA (ORCPT ); Fri, 3 Mar 2017 12:00:00 -0500 Received: from mail-pg0-f52.google.com ([74.125.83.52]:36189 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbdCCQ77 (ORCPT ); Fri, 3 Mar 2017 11:59:59 -0500 Received: by mail-pg0-f52.google.com with SMTP id s67so45783018pgb.3 for ; Fri, 03 Mar 2017 08:59:53 -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; bh=oD5deu0YdbixIbeAP/Br7sW9gRX6FnHGNFS98bKP4wE=; b=eluOR6BHUVtw0K4GDcvoZ6bBK54VFHExOho745Ut3zVrXe+i5E4dPkdiXn9r/VwOXG NnhN3VtG/+pLD2a9xMqXabIOeSncPiqaoSKoXRN+I98LED7yXgg7AQxAlpg65/wCNRWt E3Bb8qUv0r5FkzKoLg7faKHu+BNpLdQsP03COYnzOLTYCUuVvUC2/jIPrI774SthIYP3 6xZVDe4MjHG8p1rMH+p4F8EovHsuOnKC/1hnVXobav35BmlTnJ/WoOGIsYw/hvwsYjkI io8m3b45JpNjFCxMi2cegMv3oaO5g360b57p1wfw3d6an8lpnqJcJ+2GMHKOD44bM+vg QL7g== 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; bh=oD5deu0YdbixIbeAP/Br7sW9gRX6FnHGNFS98bKP4wE=; b=F6u1WgEOYI1HydaR+XPPM59nTEsbMSuq/tbnNFMxbTG9WKOJaPG7u92dJysizhSX6y vwiUmNUS7JZhfVj2rzViCF8zpQwK0mViWHkfobxJ6t+n2zgi5gE4rhH713va8hiETe0E 7gosoynzPQzvn5XGt3h6ktI5JdBujuLZpq0vURQ3LsAjXSYcFO/q7IUc8ylHPKv0ODqY lX/KruOL7U5L+3Q2EUPFlDxOBZx1wtqk9Nzv4CGydNXveNwvQ4qEJlKz2zidW/h/tDuv /LiMTg0X080/4cZayRYlKKsulEXD46/SOAHat3yhW7cwC3c6Yx3cb59G0RgOuZFH8xdl 8hmA== X-Gm-Message-State: AMke39nPYyob8pwV/vKi0gK2AndMCyB4lmM9EPCMJ8rpAAfsoYVt3ouMZH7HJzBoX964j5AB X-Received: by 10.98.142.1 with SMTP id k1mr4598863pfe.98.1488560393105; Fri, 03 Mar 2017 08:59:53 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:180::8cb7]) by smtp.gmail.com with ESMTPSA id 199sm5878807pfu.40.2017.03.03.08.59.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Mar 2017 08:59:52 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org, David Sterba Cc: kernel-team@fb.com Subject: [PATCH] btrfs-progs: report I/O errors when closing the filesystem Date: Fri, 3 Mar 2017 08:59:02 -0800 Message-Id: X-Mailer: git-send-email 2.12.0 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 --- 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..89335d35 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 = -1; + } 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)