From patchwork Thu Jun 15 16:49:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9789381 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 CDF1060325 for ; Thu, 15 Jun 2017 16:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC480286CF for ; Thu, 15 Jun 2017 16:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEEC92860B; Thu, 15 Jun 2017 16:50:51 +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.9 required=2.0 tests=BAYES_00,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 6EB112860B for ; Thu, 15 Jun 2017 16:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752151AbdFOQus (ORCPT ); Thu, 15 Jun 2017 12:50:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:56912 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750961AbdFOQus (ORCPT ); Thu, 15 Jun 2017 12:50:48 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 997C7AB9D for ; Thu, 15 Jun 2017 16:50:36 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5C48FDA8FD; Thu, 15 Jun 2017 18:49:32 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 5/5] btrfs: sysfs: export the force_dev_flush flag Date: Thu, 15 Jun 2017 18:49:32 +0200 Message-Id: <6957a4896cc64a1ff44b712bb6723ada016d76b9.1497544265.git.dsterba@suse.com> X-Mailer: git-send-email 2.13.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 Add per-filesystem tunable to switch on/off the device barriers, regardless of the actual device support. This is a debugging feature. The path to the sysfs file is /sys/fs/btrfs/UUID/force_dev_flush, allowed values are 0 and 1. Default is 0. Signed-off-by: David Sterba --- fs/btrfs/sysfs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index c2d5f3580b4c..197d43911936 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -487,12 +487,59 @@ static ssize_t quota_override_store(struct kobject *kobj, BTRFS_ATTR_RW(quota_override, quota_override_show, quota_override_store); +static ssize_t force_dev_flush_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + struct btrfs_fs_info *fs_info = to_fs_info(kobj); + int force; + + if (!fs_info) + return -EPERM; + + force = !!(test_bit(BTRFS_FS_FORCE_DEV_FLUSH, &fs_info->flags)); + return snprintf(buf, PAGE_SIZE, "%d\n", force); +} + +static ssize_t force_dev_flush_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_fs_info *fs_info = to_fs_info(kobj); + unsigned long force; + int err; + + if (!fs_info) + return -EPERM; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + err = kstrtoul(buf, 10, &force); + if (err) + return err; + if (force > 1) + return -EINVAL; + + if (force) { + set_bit(BTRFS_FS_FORCE_DEV_FLUSH, &fs_info->flags); + btrfs_info(fs_info, "Forced device flushes enabled"); + } else { + clear_bit(BTRFS_FS_FORCE_DEV_FLUSH, &fs_info->flags); + btrfs_info(fs_info, "Forced device flushes disabled"); + } + + return len; +} + +BTRFS_ATTR_RW(force_dev_flush, force_dev_flush_show, force_dev_flush_store); + static const struct attribute *btrfs_attrs[] = { BTRFS_ATTR_PTR(label), BTRFS_ATTR_PTR(nodesize), BTRFS_ATTR_PTR(sectorsize), BTRFS_ATTR_PTR(clone_alignment), BTRFS_ATTR_PTR(quota_override), + BTRFS_ATTR_PTR(force_dev_flush), NULL, };