From patchwork Tue Sep 18 01:30:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hidetoshi Seto X-Patchwork-Id: 1470141 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id D1587DFFCF for ; Tue, 18 Sep 2012 01:30:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755861Ab2IRBab (ORCPT ); Mon, 17 Sep 2012 21:30:31 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:43116 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754375Ab2IRBa3 (ORCPT ); Mon, 17 Sep 2012 21:30:29 -0400 Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id 760A13EE081 for ; Tue, 18 Sep 2012 10:30:28 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 5E32B45DE50 for ; Tue, 18 Sep 2012 10:30:28 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 4026745DE54 for ; Tue, 18 Sep 2012 10:30:28 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 2F7431DB8037 for ; Tue, 18 Sep 2012 10:30:28 +0900 (JST) Received: from m1000.s.css.fujitsu.com (m1000.s.css.fujitsu.com [10.240.81.136]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id CE3ACE18003 for ; Tue, 18 Sep 2012 10:30:27 +0900 (JST) Received: from m1000.css.fujitsu.com (m1000 [127.0.0.1]) by m1000.s.css.fujitsu.com (Postfix) with ESMTP id A61AF6105C; Tue, 18 Sep 2012 10:30:27 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.101.103]) by m1000.s.css.fujitsu.com (Postfix) with ESMTP id 6FFB361021; Tue, 18 Sep 2012 10:30:27 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <5057CEA9.3070707@jp.fujitsu.com> Date: Tue, 18 Sep 2012 10:30:17 +0900 From: Hidetoshi Seto User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] Btrfs-progs: add mount-option command References: <5057CDA7.3090201@jp.fujitsu.com> In-Reply-To: <5057CDA7.3090201@jp.fujitsu.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This patch adds mount-option command. The command can set/get default mount options. Now, the command can set/get 24 options. These options are equal to mount options which store in fs_info/mount-opt. Signed-off-by: Hidetoshi Seto --- Makefile | 5 +- btrfs-parse-mntopt.c | 111 +++++++++++++++++++++++++++++++++++++ btrfs-parse-mntopt.h | 65 ++++++++++++++++++++++ btrfs.c | 1 + cmds-mount.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++ commands.h | 2 + ctree.h | 41 +++++++++++++- 7 files changed, 372 insertions(+), 3 deletions(-) create mode 100644 btrfs-parse-mntopt.c create mode 100644 btrfs-parse-mntopt.h create mode 100644 cmds-mount.c diff --git a/Makefile b/Makefile index c0aaa3d..6f67f4c 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,10 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o file-item.o inode-item.o \ inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ - send-stream.o send-utils.o + send-stream.o send-utils.o btrfs-parse-mntopt.o cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ - cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o + cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ + cmds-mount.o CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef diff --git a/btrfs-parse-mntopt.c b/btrfs-parse-mntopt.c new file mode 100644 index 0000000..87b341c --- /dev/null +++ b/btrfs-parse-mntopt.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include "ctree.h" +#include "btrfs-parse-mntopt.h" + +void btrfs_parse_string2mntopt(struct btrfs_root *root, char **options) +{ + struct btrfs_super_block *sb = &root->fs_info->super_copy; + char *p = NULL; + int i = 0; + + memset(&sb->default_mount_opt, 0, sizeof(unsigned long)); + while ((p = strsep(options, ",")) != NULL) { + int token = DEF_MNTOPT_NUM + 1; + + if (!*p) + continue; + for (i = 0; i < DEF_MNTOPT_NUM; i++) { + if (!strcmp(p, toke[i].pattern)) { + token = toke[i].token; + break; + } + } + if (token > DEF_MNTOPT_NUM) { + printf("error: %s\n", p); + return; + } + + switch (token) { + case Opt_degraded: + btrfs_set_opt(sb->default_mount_opt, DEGRADED); + break; + + case Opt_nodatasum: + btrfs_set_opt(sb->default_mount_opt, NODATASUM); + break; + case Opt_nodatacow: + btrfs_set_opt(sb->default_mount_opt, NODATACOW); + btrfs_set_opt(sb->default_mount_opt, NODATASUM); + break; + case Opt_ssd: + btrfs_set_opt(sb->default_mount_opt, SSD); + break; + case Opt_ssd_spread: + btrfs_set_opt(sb->default_mount_opt, SSD); + btrfs_set_opt(sb->default_mount_opt, SSD_SPREAD); + break; + case Opt_nossd: + btrfs_set_opt(sb->default_mount_opt, NOSSD); + btrfs_clear_opt(sb->default_mount_opt, SSD); + btrfs_clear_opt(sb->default_mount_opt, SSD_SPREAD); + break; + case Opt_nobarrier: + btrfs_set_opt(sb->default_mount_opt, NOBARRIER); + break; + case Opt_notreelog: + btrfs_set_opt(sb->default_mount_opt, NOTREELOG); + break; + case Opt_flushoncommit: + btrfs_set_opt(sb->default_mount_opt, FLUSHONCOMMIT); + break; + case Opt_discard: + btrfs_set_opt(sb->default_mount_opt, DISCARD); + break; + case Opt_space_cache: + btrfs_set_opt(sb->default_mount_opt, SPACE_CACHE); + break; + case Opt_no_space_cache: + btrfs_clear_opt(sb->default_mount_opt, SPACE_CACHE); + break; + case Opt_inode_cache: + btrfs_set_opt(sb->default_mount_opt, INODE_MAP_CACHE); + break; + case Opt_clear_cache: + btrfs_set_opt(sb->default_mount_opt, CLEAR_CACHE); + break; + case Opt_user_subvol_rm_allowed: + btrfs_set_opt(sb->default_mount_opt, + USER_SUBVOL_RM_ALLOWED); + break; + case Opt_enospc_debug: + btrfs_set_opt(sb->default_mount_opt, ENOSPC_DEBUG); + break; + case Opt_defrag: + btrfs_set_opt(sb->default_mount_opt, AUTO_DEFRAG); + break; + case Opt_recovery: + btrfs_set_opt(sb->default_mount_opt, RECOVERY); + break; + case Opt_skip_balance: + btrfs_set_opt(sb->default_mount_opt, SKIP_BALANCE); + break; + default: + break; + } + } +} + +void btrfs_parse_mntopt2string(unsigned long def_opt) +{ + if (!def_opt) + printf("no default options\n"); + else { + int i = 0; + for (i = 0; i < DEF_MNTOPT_NUM; i++) { + if (def_opt & (1 << toke[i].token)) + printf("%s\n", toke[i].pattern); + } + } +} diff --git a/btrfs-parse-mntopt.h b/btrfs-parse-mntopt.h new file mode 100644 index 0000000..a2745ee --- /dev/null +++ b/btrfs-parse-mntopt.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 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. + */ + +struct match_token { + int token; + const char *pattern; +}; + +typedef struct match_token match_table_t[]; + +enum { + Opt_nodatasum, Opt_nodatacow, Opt_nobarrier, Opt_ssd, + Opt_degraded, Opt_compress, Opt_notreelog, Opt_flushoncommit, + Opt_ssd_spread, Opt_nossd, Opt_discard, Opt_compress_force, + Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed, + Opt_enospc_debug, Opt_defrag, Opt_inode_cache, Opt_recovery, + Opt_skip_balance, Opt_check_integrity, + Opt_check_integrity_including_extent_data, Opt_fatal_errors, + Opt_no_space_cache, DEF_MNTOPT_NUM, +}; + +static match_table_t toke = { + {Opt_degraded, "degraded"}, + {Opt_nodatasum, "nodatasum"}, + {Opt_nodatacow, "nodatacow"}, + {Opt_nobarrier, "nobarrier"}, + {Opt_compress, "compress"}, + {Opt_compress_force, "compress-force"}, + {Opt_ssd, "ssd"}, + {Opt_ssd_spread, "ssd_spread"}, + {Opt_nossd, "nossd"}, + {Opt_notreelog, "notreelog"}, + {Opt_flushoncommit, "flushoncommit"}, + {Opt_discard, "discard"}, + {Opt_space_cache, "space_cache"}, + {Opt_no_space_cache, "no_space_cache"}, + {Opt_clear_cache, "clear_cache"}, + {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"}, + {Opt_enospc_debug, "enospc_debug"}, + {Opt_defrag, "auto_defrag"}, + {Opt_inode_cache, "inode_map_cache"}, + {Opt_recovery, "recovery"}, + {Opt_skip_balance, "skip_balance"}, + {Opt_check_integrity, "check_int"}, + {Opt_check_integrity_including_extent_data, "check_int_data"}, + {Opt_fatal_errors, "fatal_errors"}, +}; + +void btrfs_parse_string2mntopt(struct btrfs_root *root, char **options); +void btrfs_parse_mntopt2string(unsigned long def_opt); diff --git a/btrfs.c b/btrfs.c index e9d54f8..0d6c9a7 100644 --- a/btrfs.c +++ b/btrfs.c @@ -246,6 +246,7 @@ const struct cmd_group btrfs_cmd_group = { { "device", cmd_device, NULL, &device_cmd_group, 0 }, { "scrub", cmd_scrub, NULL, &scrub_cmd_group, 0 }, { "inspect-internal", cmd_inspect, NULL, &inspect_cmd_group, 0 }, + { "mount-option", cmd_mount, NULL, &mount_cmd_group, 0 }, { "send", cmd_send, NULL, &send_cmd_group, 0 }, { "receive", cmd_receive, NULL, &receive_cmd_group, 0 }, { "help", cmd_help, cmd_help_usage, NULL, 0 }, diff --git a/cmds-mount.c b/cmds-mount.c new file mode 100644 index 0000000..cbdb006 --- /dev/null +++ b/cmds-mount.c @@ -0,0 +1,150 @@ +/* + * 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. + */ + +#include +#include +#include +#include "ioctl.h" +#include "ctree.h" +#include "transaction.h" +#include "commands.h" +#include "disk-io.h" +#include "utils.h" +#include "btrfs-parse-mntopt.h" + +static const char * const mount_cmd_group_usage[] = { + "btrfs mount-option []", + NULL +}; + +static const char * const cmd_set_mntopt_usage[] = { + "btrfs mount-option set [