From patchwork Wed Jun 6 06:30:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: james harvey X-Patchwork-Id: 10449721 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 147076053F for ; Wed, 6 Jun 2018 06:30:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1933297F9 for ; Wed, 6 Jun 2018 06:30:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4334297FD; Wed, 6 Jun 2018 06:30: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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 89D25297F9 for ; Wed, 6 Jun 2018 06:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932109AbeFFGan (ORCPT ); Wed, 6 Jun 2018 02:30:43 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:45124 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932097AbeFFGam (ORCPT ); Wed, 6 Jun 2018 02:30:42 -0400 Received: by mail-oi0-f68.google.com with SMTP id b130-v6so4380335oif.12 for ; Tue, 05 Jun 2018 23:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=m3a3F2rBK0asp+wQK4AseUHqb4dv8msoSf3uhGDk0/c=; b=F+/HtCZkLL+ogmBQWlzGNoYn9G1QeA/oRPsYn4IDGriIMDrheZEgtng8N5+VKADKaA cC96w5MpYimutOgT0crCrtWWkUXORDp/bL2IFFUqFdllkk4RZ9ilxw+d29e+Xz4Z708D hzc3inK1s9oKKMiRphzbFwf6MjAa6P9a7Wql9Jvn/HRGaBfbkeKgKbnXWSVunb6J3nzC PamG/Nd4Y7/jcNLPt8CxHDGVwWepfukJizHYs/34++b4qWZA0wAqnsSGEiVObDm53YTU CJgTdKYEkkiDbmMCQBUHQyJzz0REeAgzWqbrFhTj0eJHGrKg9jSZsVkzTNdcm6cpH/0r yhoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=m3a3F2rBK0asp+wQK4AseUHqb4dv8msoSf3uhGDk0/c=; b=t9C/7K3Mkr2NAPOr0/szY/X0Jb9DHxoJAdGO779G+XP3qAF7eJLvFJAqPf7p5rx19T aYgMyLOuidn77M67Ws77e36uy17JKAJLsB1L5+mTVuvAPxFoSsmHhV4AWa1sG+861J0h +Lem6nyP0AR4J2s4ChHGyzUx01wsfIXdsCYWWaa4WNTqfdR8Gq6a3WnxIONDobk0Ady1 IC6NMSVcm34cafF3OlXFXADlxifG1D78CLWtf2/mJxLaNHPPYxOI9aW4tXGNpcdragm9 Xdkpxvu5zZC9zhSFvxQ+d198jMolt/bNP7p4TCtJJK/zaxYr+M3rNMQPZ7RwiESTXDsb jj1g== X-Gm-Message-State: APt69E00rjv970+OkDOYhurh1xmw6lddcmd+iOIKbSKvA3xNn+Akvzc2 uxo/9EdFKsYEKvk/86GKAPSeCFPNpLHWmTO8sidcTg== X-Google-Smtp-Source: ADUXVKIb+1lNjSnccab4FgPUtbc/OuwaJJcrfistIMExfpXC/WdwDiPBWund0ihhPRkdgZx2TmZ89K9mFIkMAmaiP3k= X-Received: by 2002:aca:fcc8:: with SMTP id a191-v6mr1070881oii.34.1528266641927; Tue, 05 Jun 2018 23:30:41 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:3535:0:0:0:0:0 with HTTP; Tue, 5 Jun 2018 23:30:41 -0700 (PDT) From: james harvey Date: Wed, 6 Jun 2018 02:30:41 -0400 Message-ID: Subject: [PATCH] btrfs-progs: btrfs_close_devices(): only fsync() if device->writeable To: Btrfs BTRFS 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 Prevent unnecessary error from failing fsync(), if opened read only. Performed 'grep "writeable = " *.h *.c' to make sure there were no odd situations where fsync() might still be desired here. They're all straight- forward. The only situation where writeable will be 0 is if btrfs_open_devices is given flags without O_RDWR. There is no situation where a writeable volume temporarily becomes unwriteable, or anything like that. Given that it's being opened O_RDWR, there's no reason to attempt fsync(). utils.c int btrfs_add_to_fsid() { ... device->writeable = 1; volumes.c int btrfs_close_devices() { ... while (!list_empty(&fs_devices->devices)) { ... // just after the fsync() being patched 267: device->writeable = 0; ... int btrfs_open_devices() { ... list_for_each_entry(device, &fs_devices->devices, dev_list) { ... if (flags & O_RDWR) 332: device->writeable = 1 kernel btrfs_close_devices() does not have a corresponding fsync() that I see. Signed-off-by: James Harvey --- volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/volumes.c b/volumes.c index c6e34321..36d1bde6 100644 --- a/volumes.c +++ b/volumes.c @@ -254,7 +254,7 @@ again: device = list_entry(fs_devices->devices.next, struct btrfs_device, dev_list); if (device->fd != -1) { - if (fsync(device->fd) == -1) { + if (device->writeable && fsync(device->fd) == -1) { warning("fsync on device %llu failed: %m", device->devid); ret = -errno;