From patchwork Mon Aug 11 00:17:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timofey Titovets X-Patchwork-Id: 4705201 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CD186C0338 for ; Mon, 11 Aug 2014 00:19:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 39CC12015D for ; Mon, 11 Aug 2014 00:19:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABFDC20155 for ; Mon, 11 Aug 2014 00:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751711AbaHKARQ (ORCPT ); Sun, 10 Aug 2014 20:17:16 -0400 Received: from mail-we0-f171.google.com ([74.125.82.171]:60207 "EHLO mail-we0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751173AbaHKARO (ORCPT ); Sun, 10 Aug 2014 20:17:14 -0400 Received: by mail-we0-f171.google.com with SMTP id p10so7990309wes.2 for ; Sun, 10 Aug 2014 17:17:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=svWALp9w65yo/8N4NBxTjgpWZeTqv7YIy44F+UdK51M=; b=SXWz7fHtyTHRNJFu4SunEK+LfhQDozCb5WUj7s48YfatZG1y8r7LXq7UyDez988kXz zGgGcLmmGAtFTcmLZh00TuOiy+u9ETwvgWV0nIitFlz69Gs5WGug4ns6VO06cMwZSXOO ngwpHuUrKWmpk44876axKcVf38/TBp2ikSjibBEhfN6iTELeMY8ruRG6Yb0ReSDjujYn hNY8GVHbboyUIG3umR1v19ko4UTtz1nvA/GFo/s6eauw+a8lG2AJIsmKsmX3IkgF00oX HjKyTK4ltx4ahVkiUSnYe2KodflltL3PbxD8yA9clW95bRkf0xbzaa/XU5SbM8ecRHgm ff+Q== X-Received: by 10.194.184.230 with SMTP id ex6mr49128579wjc.83.1407716233070; Sun, 10 Aug 2014 17:17:13 -0700 (PDT) Received: from beplan.lan (nat3-minsk-pool-46-53-181-8.telecom.by. [46.53.181.8]) by mx.google.com with ESMTPSA id gl4sm36864741wib.19.2014.08.10.17.17.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Aug 2014 17:17:12 -0700 (PDT) Message-ID: <53E80B87.30504@gmail.com> Date: Mon, 11 Aug 2014 03:17:11 +0300 From: Timofey Titovets User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org Subject: [RFC PATCH] btrfs-progs: Move btrfstune to btrfs device tune Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Good time of day, According to https://btrfs.wiki.kernel.org/index.php/Project_ideas#btrfs Quote: merge functionality of btrfstune, eg. under btrfs dev set-seed /dev/ (discuss the command name though) This patch is just code move After, user can tune btrfs parameters through: btrfs dev tune -xr /dev/sda2 Also i merge two functions in one: static int enable_extrefs_flag(struct btrfs_root *root) and static int enable_skinny_metadata(struct btrfs_root *root) to static void enable_flag(struct btrfs_root *root, u64 flag) Where flag is: BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF Because function is identical. P.S. I write this patch on branch: git://repo.or.cz/btrfs-progs-unstable/devel.git But i think, what it can be safety applied on stable branch. If it needed, i can redo and resend patch. P.S.S If it needed, i can move seed function in separated command, like in project ideas (btrfs dev set-seed /dev/ or something else). And if seed is same as readonly, may be command must named like "readonly" 1/0 ? Signed-off-by: Timofey Titovets --- Documentation/Makefile | 3 +- Documentation/btrfs-device.txt | 19 +++- Makefile | 10 +-- btrfstune.c | 197 ----------------------------------------- cmds-device.c | 156 ++++++++++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 208 deletions(-) { "add", cmd_add_dev, cmd_add_dev_usage, NULL, 0 }, @@ -429,6 +584,7 @@ const struct cmd_group device_cmd_group = { { "scan", cmd_scan_dev, cmd_scan_dev_usage, NULL, 0 }, { "ready", cmd_ready_dev, cmd_ready_dev_usage, NULL, 0 }, { "stats", cmd_dev_stats, cmd_dev_stats_usage, NULL, 0 }, + { "tune", cmd_dev_tune, cmd_dev_tune_usage, NULL, 0 }, NULL_CMD_STRUCT } }; diff --git a/Documentation/Makefile b/Documentation/Makefile index 45299bb..75f50a2 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -9,7 +9,6 @@ MAN8_TXT += btrfs-find-root.txt MAN8_TXT += btrfs-image.txt MAN8_TXT += btrfs-map-logical.txt MAN8_TXT += btrfs-show-super.txt -MAN8_TXT += btrfstune.txt MAN8_TXT += btrfs-zero-log.txt MAN8_TXT += fsck.btrfs.txt MAN8_TXT += mkfs.btrfs.txt @@ -82,7 +81,7 @@ clean: %.8.gz : %.8 $(QUIET_GZIP)$(GZIP) -n -c $< > $@ -%.8 : %.xml +%.8 : %.xml $(QUIET_XMLTO)$(RM) $@ && \ $(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $< %.xml : %.txt asciidoc.conf diff --git a/Documentation/btrfs-device.txt b/Documentation/btrfs-device.txt index 0f7917d..8f21672 100644 --- a/Documentation/btrfs-device.txt +++ b/Documentation/btrfs-device.txt @@ -80,10 +80,10 @@ Remove device(s) from a filesystem identified by . *scan* [(--all-devices|-d)| [...]]:: Scan devices for a btrfs filesystem. + -If one or more devices are passed, these are scanned for a btrfs filesystem. +If one or more devices are passed, these are scanned for a btrfs filesystem. If no devices are passed, btrfs uses block devices containing btrfs filesystem as listed by blkid. -Finally, if '--all-devices' or '-d' is passed, all the devices under /dev are +Finally, if '--all-devices' or '-d' is passed, all the devices under /dev are scanned. *ready* :: @@ -98,6 +98,21 @@ identified by or for a single . -z:::: Reset stats to zero after reading them. +*tune* [options] :: +Used to tune various btrfs filesystem parameters, you can enable +some extended features for btrfs and set seeding flag. ++ +`Options` ++ +-S :: +Updates the seeding value, it forces a fs readonly so that you can use it to +build other filesystems. +-r:: +Enable extended inode refs. +-x:: +Enable skinny metadata extent refs. + + EXIT STATUS ----------- *btrfs device* returns a zero exist status if it succeeds. Non zero is diff --git a/Makefile b/Makefile index 76565e8..28e190f 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ MAKEOPTS = --no-print-directory Q=$(Q) progs = mkfs.btrfs btrfs-debug-tree btrfsck \ btrfs btrfs-map-logical btrfs-image btrfs-zero-log btrfs-convert \ - btrfs-find-root btrfstune btrfs-show-super + btrfs-find-root btrfs-show-super # external libs required by various binaries; for btrfs-foo, # specify btrfs_foo_libs = ; see $($(subst...)) rules below @@ -85,7 +85,7 @@ lib_links = libbtrfs.so.0 libbtrfs.so headers = $(libbtrfs_headers) # make C=1 to enable sparse -check_defs := .cc-defines.h +check_defs := .cc-defines.h ifdef C # # We're trying to use sparse against glibc headers which go wild @@ -200,10 +200,6 @@ mkfs.btrfs.static: $(static_objects) mkfs.static.o $(static_libbtrfs_objects) $(Q)$(CC) $(STATIC_CFLAGS) -o mkfs.btrfs.static mkfs.static.o $(static_objects) \ $(static_libbtrfs_objects) $(STATIC_LDFLAGS) $(STATIC_LIBS) -btrfstune: $(objects) $(libs) btrfstune.o - @echo " [LD] $@" - $(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o $(LDFLAGS) $(LIBS) - dir-test: $(objects) $(libs) dir-test.o @echo " [LD] $@" $(Q)$(CC) $(CFLAGS) -o dir-test $(objects) dir-test.o $(LDFLAGS) $(LIBS) @@ -228,7 +224,7 @@ clean-all: clean-doc clean clean: $(CLEANDIRS) @echo "Cleaning" $(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \ - btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \ + btrfs-zero-log dir-test ioctl-test quick-test send-test btrfsck \ btrfs.static mkfs.btrfs.static btrfs-calc-size \ version.h $(check_defs) \ $(libs) $(lib_links) diff --git a/btrfstune.c b/btrfstune.c deleted file mode 100644 index 2c26fe9..0000000 --- a/btrfstune.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2008 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License v2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#define _XOPEN_SOURCE 500 -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include -#include -#include -#include "kerncompat.h" -#include "ctree.h" -#include "disk-io.h" -#include "transaction.h" -#include "utils.h" -#include "version.h" - -static char *device; - -static int update_seeding_flag(struct btrfs_root *root, int set_flag) -{ - struct btrfs_trans_handle *trans; - struct btrfs_super_block *disk_super; - u64 super_flags; - - disk_super = root->fs_info->super_copy; - super_flags = btrfs_super_flags(disk_super); - if (set_flag) { - if (super_flags & BTRFS_SUPER_FLAG_SEEDING) { - fprintf(stderr, "seeding flag is already set on %s\n", - device); - return 1; - } - super_flags |= BTRFS_SUPER_FLAG_SEEDING; - } else { - if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) { - fprintf(stderr, "seeding flag is not set on %s\n", - device); - return 1; - } - super_flags &= ~BTRFS_SUPER_FLAG_SEEDING; - } - - trans = btrfs_start_transaction(root, 1); - btrfs_set_super_flags(disk_super, super_flags); - btrfs_commit_transaction(trans, root); - - return 0; -} - -static int enable_extrefs_flag(struct btrfs_root *root) -{ - struct btrfs_trans_handle *trans; - struct btrfs_super_block *disk_super; - u64 super_flags; - - disk_super = root->fs_info->super_copy; - super_flags = btrfs_super_incompat_flags(disk_super); - super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF; - trans = btrfs_start_transaction(root, 1); - btrfs_set_super_incompat_flags(disk_super, super_flags); - btrfs_commit_transaction(trans, root); - - return 0; -} - -static int enable_skinny_metadata(struct btrfs_root *root) -{ - struct btrfs_trans_handle *trans; - struct btrfs_super_block *disk_super; - u64 super_flags; - - disk_super = root->fs_info->super_copy; - super_flags = btrfs_super_incompat_flags(disk_super); - super_flags |= BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA; - trans = btrfs_start_transaction(root, 1); - btrfs_set_super_incompat_flags(disk_super, super_flags); - btrfs_commit_transaction(trans, root); - - return 0; -} - -static void print_usage(void) -{ - fprintf(stderr, "usage: btrfstune [options] device\n"); - fprintf(stderr, "\t-S value\tenable/disable seeding\n"); - fprintf(stderr, "\t-r \t\tenable extended inode refs\n"); - fprintf(stderr, "\t-x enable skinny metadata extent refs\n"); -} - -int main(int argc, char *argv[]) -{ - struct btrfs_root *root; - int success = 0; - int extrefs_flag = 0; - int seeding_flag = 0; - u64 seeding_value = 0; - int skinny_flag = 0; - int ret; - - optind = 1; - while(1) { - int c = getopt(argc, argv, "S:rx"); - if (c < 0) - break; - switch(c) { - case 'S': - seeding_flag = 1; - seeding_value = arg_strtou64(optarg); - break; - case 'r': - extrefs_flag = 1; - break; - case 'x': - skinny_flag = 1; - break; - default: - print_usage(); - return 1; - } - } - - argc = argc - optind; - device = argv[optind]; - if (argc != 1) { - print_usage(); - return 1; - } - - if (!(seeding_flag + extrefs_flag + skinny_flag)) { - fprintf(stderr, - "ERROR: At least one option should be assigned.\n"); - print_usage(); - return 1; - } - - ret = check_mounted(device); - if (ret < 0) { - fprintf(stderr, "Could not check mount status: %s\n", - strerror(-ret)); - return 1; - } else if (ret) { - fprintf(stderr, "%s is mounted\n", device); - return 1; - } - - root = open_ctree(device, 0, OPEN_CTREE_WRITES); - - if (!root) { - fprintf(stderr, "Open ctree failed\n"); - return 1; - } - - if (seeding_flag) { - ret = update_seeding_flag(root, seeding_value); - if (!ret) - success++; - } - - if (extrefs_flag) { - enable_extrefs_flag(root); - success++; - } - - if (skinny_flag) { - enable_skinny_metadata(root); - success++; - } - - if (success > 0) { - ret = 0; - } else { - root->fs_info->readonly = 1; - ret = 1; - fprintf(stderr, "btrfstune failed\n"); - } - close_ctree(root); - - return ret; -} diff --git a/cmds-device.c b/cmds-device.c index c8586a0..eea02a5 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -14,6 +14,9 @@ * Boston, MA 021110-1307, USA. */ + + + #include #include #include @@ -24,10 +27,18 @@ #include #include +#define _XOPEN_SOURCE 500 +#define _GNU_SOURCE 1 +#include +#include +#include + #include "kerncompat.h" #include "ctree.h" #include "ioctl.h" #include "utils.h" +#include "disk-io.h" +#include "transaction.h" #include "commands.h" @@ -422,6 +433,150 @@ out: return err; } +static const char * const cmd_dev_tune_usage[] = { + "btrfs device tune [options] device", + "-S value enable/disable seeding", + "-r enable extended inode refs", + "-x enable skinny metadata extent refs", + NULL +}; + +static int update_seeding_flag(struct btrfs_root *root, int set_flag, char *device) +{ + struct btrfs_trans_handle *trans; + struct btrfs_super_block *disk_super; + u64 super_flags; + + disk_super = root->fs_info->super_copy; + super_flags = btrfs_super_flags(disk_super); + if (set_flag) { + if (super_flags & BTRFS_SUPER_FLAG_SEEDING) { + fprintf(stderr, "seeding flag is already set on %s\n", + device); + return 1; + } + super_flags |= BTRFS_SUPER_FLAG_SEEDING; + } else { + if (!(super_flags & BTRFS_SUPER_FLAG_SEEDING)) { + fprintf(stderr, "seeding flag is not set on %s\n", + device); + return 1; + } + super_flags &= ~BTRFS_SUPER_FLAG_SEEDING; + } + + trans = btrfs_start_transaction(root, 1); + btrfs_set_super_flags(disk_super, super_flags); + btrfs_commit_transaction(trans, root); + + return 0; +} + +static void enable_flag(struct btrfs_root *root, u64 flag) +{ + struct btrfs_trans_handle *trans; + struct btrfs_super_block *disk_super; + u64 super_flags; + + disk_super = root->fs_info->super_copy; + super_flags = btrfs_super_incompat_flags(disk_super); + super_flags |= flag; + trans = btrfs_start_transaction(root, 1); + btrfs_set_super_incompat_flags(disk_super, super_flags); + btrfs_commit_transaction(trans, root); +} + +static int cmd_dev_tune(int argc, char **argv) +{ + struct btrfs_root *root; + char *device; + int success = 0; + int extrefs_flag = 0; + int seeding_flag = 0; + u64 seeding_value = 0; + int skinny_flag = 0; + int ret; + + optind = 1; + while(1) { + int c = getopt(argc, argv, "S:rx"); + if (c < 0 && argc) + break; + switch(c) { + case 'S': + seeding_flag = 1; + seeding_value = arg_strtou64(optarg); + break; + case 'r': + extrefs_flag = 1; + break; + case 'x': + skinny_flag = 1; + break; + default: + usage(cmd_dev_tune_usage); + return 1; + } + } + + argc = argc - optind; + device = argv[optind]; + if (argc != 1) { + usage(cmd_dev_tune_usage); + return 1; + } + + if (!(seeding_flag + extrefs_flag + skinny_flag)) { + fprintf(stderr, + "ERROR: At least one option should be assigned.\n"); + return 1; + } + + ret = check_mounted(device); + if (ret < 0) { + fprintf(stderr, "Could not check mount status: %s\n", + strerror(-ret)); + return 1; + } else if (ret) { + fprintf(stderr, "%s is mounted\n", device); + return 1; + } + + root = open_ctree(device, 0, OPEN_CTREE_WRITES); + + if (!root) { + fprintf(stderr, "Open ctree failed\n"); + return 1; + } + + if (seeding_flag) { + ret = update_seeding_flag(root, seeding_value, device); + if (!ret) + success++; + } + + if (extrefs_flag) { + enable_flag(root, BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF); + success++; + } + + if (skinny_flag) { + enable_flag(root, BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA); + success++; + } + + if (success > 0) { + ret = 0; + } else { + root->fs_info->readonly = 1; + ret = 1; + fprintf(stderr, "btrfs device tune failed\n"); + } + close_ctree(root); + + return ret; +} + const struct cmd_group device_cmd_group = { device_cmd_group_usage, NULL, {