From patchwork Mon Sep 3 10:14:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Borowski X-Patchwork-Id: 10585723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA3235A4 for ; Mon, 3 Sep 2018 10:15:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9148329250 for ; Mon, 3 Sep 2018 10:15:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 857CA29578; Mon, 3 Sep 2018 10:15:01 +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 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 AE79E29250 for ; Mon, 3 Sep 2018 10:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727533AbeICOeI (ORCPT ); Mon, 3 Sep 2018 10:34:08 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:42112 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727523AbeICOeI (ORCPT ); Mon, 3 Sep 2018 10:34:08 -0400 Received: from 89-71-158-145.dynamic.chello.pl ([89.71.158.145] helo=umbar.angband.pl) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwlsQ-0008EI-Lc; Mon, 03 Sep 2018 12:14:36 +0200 Received: from kilobyte by umbar.angband.pl with local (Exim 4.91) (envelope-from ) id 1fwlsP-0003uC-UV; Mon, 03 Sep 2018 12:14:33 +0200 From: Adam Borowski To: David Sterba , linux-btrfs@vger.kernel.org, Mark Fasheh Cc: Adam Borowski Date: Mon, 3 Sep 2018 12:14:25 +0200 Message-Id: <20180903101426.14968-1-kilobyte@angband.pl> X-Mailer: git-send-email 2.19.0.rc1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 89.71.158.145 X-SA-Exim-Mail-From: kilobyte@angband.pl Subject: [PATCH 1/2] btrfs-progs: fix kernel version parsing on some versions past 3.0 X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) 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 The code fails if the third section is missing (like "4.18") or is followed by anything but "." or "-". This happens for example if we're not exactly at a tag and CONFIG_LOCALVERSION_AUTO=n (which results in "4.18.5+"). Signed-off-by: Adam Borowski --- fsfeatures.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fsfeatures.c b/fsfeatures.c index 7d85d60f..66111bf4 100644 --- a/fsfeatures.c +++ b/fsfeatures.c @@ -216,11 +216,8 @@ u32 get_running_kernel_version(void) return (u32)-1; version |= atoi(tmp) << 8; tmp = strtok_r(NULL, ".", &saveptr); - if (tmp) { - if (!string_is_numerical(tmp)) - return (u32)-1; + if (tmp && string_is_numerical(tmp)) version |= atoi(tmp); - } return version; } From patchwork Mon Sep 3 10:14:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Borowski X-Patchwork-Id: 10585725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B65BD5A4 for ; Mon, 3 Sep 2018 10:15:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0EF6291EF for ; Mon, 3 Sep 2018 10:15:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9518D29250; Mon, 3 Sep 2018 10:15:02 +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 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 CEF5F2956F for ; Mon, 3 Sep 2018 10:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727545AbeICOeJ (ORCPT ); Mon, 3 Sep 2018 10:34:09 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:42116 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727462AbeICOeI (ORCPT ); Mon, 3 Sep 2018 10:34:08 -0400 Received: from 89-71-158-145.dynamic.chello.pl ([89.71.158.145] helo=umbar.angband.pl) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fwlsR-0008EK-86; Mon, 03 Sep 2018 12:14:38 +0200 Received: from kilobyte by umbar.angband.pl with local (Exim 4.91) (envelope-from ) id 1fwlsQ-0003uF-Sp; Mon, 03 Sep 2018 12:14:34 +0200 From: Adam Borowski To: David Sterba , linux-btrfs@vger.kernel.org, Mark Fasheh Cc: Adam Borowski Date: Mon, 3 Sep 2018 12:14:26 +0200 Message-Id: <20180903101426.14968-2-kilobyte@angband.pl> X-Mailer: git-send-email 2.19.0.rc1 In-Reply-To: <20180903101426.14968-1-kilobyte@angband.pl> References: <20180903101426.14968-1-kilobyte@angband.pl> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 89.71.158.145 X-SA-Exim-Mail-From: kilobyte@angband.pl Subject: [PATCH 2/2] btrfs-progs: defrag: open files RO on new enough kernels or if root X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) 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 Fixes EXTXBSY races. Signed-off-by: Adam Borowski --- cmds-filesystem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 06c8311b..4c9df69f 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -39,12 +40,14 @@ #include "list_sort.h" #include "disk-io.h" #include "help.h" +#include "fsfeatures.h" /* * for btrfs fi show, we maintain a hash of fsids we've already printed. * This way we don't print dups if a given FS is mounted more than once. */ static struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = {NULL,}; +static mode_t defrag_ro = O_RDONLY; static const char * const filesystem_cmd_group_usage[] = { "btrfs filesystem [] []", @@ -877,7 +880,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, defrag_ro); if (fd < 0) { goto error; } @@ -914,6 +917,9 @@ static int cmd_filesystem_defrag(int argc, char **argv) int compress_type = BTRFS_COMPRESS_NONE; DIR *dirstream; + if (get_running_kernel_version() < KERNEL_VERSION(4,19,0) && getuid()) + defrag_ro = O_RDWR; + /* * Kernel has a different default (256K) that is supposed to be safe, * but it does not defragment very well. The 32M will likely lead to @@ -1014,7 +1020,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, defrag_ro); if (fd < 0) { error("cannot open %s: %m", argv[i]); ret = -errno;