From patchwork Tue Jul 17 22:05:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Borowski X-Patchwork-Id: 10530889 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 51011600D0 for ; Tue, 17 Jul 2018 22:06:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3755029261 for ; Tue, 17 Jul 2018 22:06:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28E7129295; Tue, 17 Jul 2018 22:06:36 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_TVD_MIME_EPI 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 38D3729261 for ; Tue, 17 Jul 2018 22:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730652AbeGQWlP (ORCPT ); Tue, 17 Jul 2018 18:41:15 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:47964 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729742AbeGQWlP (ORCPT ); Tue, 17 Jul 2018 18:41:15 -0400 Received: from kilobyte by tartarus.angband.pl with local (Exim 4.89) (envelope-from ) id 1ffY5r-0006Sw-C0; Wed, 18 Jul 2018 00:05:49 +0200 Date: Wed, 18 Jul 2018 00:05:08 +0200 From: Adam Borowski To: linux-btrfs@vger.kernel.org, David Sterba , Mark Fasheh Subject: [PATCH resend 0/2] btrfs: fix races between exec and defrag Message-ID: <20180717220357.hn7mvajicpy7hu3l@angband.pl> MIME-Version: 1.0 Content-Disposition: inline X-Junkbait: aaron@angband.pl, zzyx@angband.pl User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: kilobyte@angband.pl X-SA-Exim-Scanned: No (on tartarus.angband.pl); SAEximRunCond expanded to false 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 Hi! Here's a ping for a patch to fix ETXTBSY races between defrag and exec, just like the dedupe counterpart. Unlike that one which is shared to multiple filesystems and thus lives in Al Viro's land, it is btrfs only. Attached: a simple tool to fragment a file, by ten O_SYNC rewrites of length 1 at random positions; racey vs concurrent writes or execs but shouldn't damage the file otherwise. Also attached: a preliminary patch for -progs; it yet lacks a check for the kernel version, but to add such a check we'd need to know which kernels actually permit ro defrag for non-root. No man page patch -- there's no man page to be patched... Meow! From d040af09adb03daadbba4336700f40425a860320 Mon Sep 17 00:00:00 2001 From: Adam Borowski Date: Tue, 28 Nov 2017 01:00:21 +0100 Subject: [PATCH] defrag: open files RO NOT FOR MERGING -- requires kernel versioning Fixes EXTXBSY races. Signed-off-by: Adam Borowski --- cmds-filesystem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 30a50bf5..7eb6b7bb 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -876,7 +876,7 @@ static int defrag_callback(const char *fpath, const struct stat *sb, if ((typeflag == FTW_F) && S_ISREG(sb->st_mode)) { if (defrag_global_verbose) printf("%s\n", fpath); - fd = open(fpath, O_RDWR); + fd = open(fpath, O_RDONLY); if (fd < 0) { goto error; } @@ -1012,7 +1012,7 @@ static int cmd_filesystem_defrag(int argc, char **argv) int defrag_err = 0; dirstream = NULL; - fd = open_file_or_dir(argv[i], &dirstream); + fd = open_file_or_dir3(argv[i], &dirstream, O_RDONLY); if (fd < 0) { error("cannot open %s: %m", argv[i]); ret = -errno; -- 2.18.0