2012-08-07 10:37:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 STRATO. 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2018-01-25 09:35:27 +00:00
|
|
|
#include <btrfsutil.h>
|
|
|
|
|
2012-08-07 10:37:54 +00:00
|
|
|
#include "ctree.h"
|
|
|
|
#include "ioctl.h"
|
|
|
|
|
2019-06-19 23:46:21 +00:00
|
|
|
#include "cmds/commands.h"
|
2013-01-20 21:04:15 +00:00
|
|
|
#include "qgroup.h"
|
2019-06-19 23:46:21 +00:00
|
|
|
#include "common/utils.h"
|
2019-06-19 23:46:21 +00:00
|
|
|
#include "common/help.h"
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
static const char * const qgroup_cmd_group_usage[] = {
|
|
|
|
"btrfs qgroup <command> [options] <path>",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:42:01 +00:00
|
|
|
static int _cmd_qgroup_assign(const struct cmd_struct *cmd, int assign,
|
|
|
|
int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int fd;
|
2018-08-06 06:00:07 +00:00
|
|
|
bool rescan = true;
|
2015-07-27 14:16:52 +00:00
|
|
|
char *path;
|
2012-08-07 10:37:54 +00:00
|
|
|
struct btrfs_ioctl_qgroup_assign_args args;
|
2013-07-15 11:36:50 +00:00
|
|
|
DIR *dirstream = NULL;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2020-02-02 14:45:42 +00:00
|
|
|
optind = 0;
|
|
|
|
while (1) {
|
|
|
|
enum { GETOPT_VAL_RESCAN = 256, GETOPT_VAL_NO_RESCAN };
|
|
|
|
static const struct option long_options[] = {
|
|
|
|
{ "rescan", no_argument, NULL, GETOPT_VAL_RESCAN },
|
|
|
|
{ "no-rescan", no_argument, NULL, GETOPT_VAL_NO_RESCAN },
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, "", long_options, NULL);
|
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case GETOPT_VAL_RESCAN:
|
|
|
|
rescan = true;
|
|
|
|
break;
|
|
|
|
case GETOPT_VAL_NO_RESCAN:
|
|
|
|
rescan = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage_unknown_option(cmd, argv);
|
2015-07-27 14:27:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_argc_exact(argc - optind, 3))
|
2019-03-04 13:49:15 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
memset(&args, 0, sizeof(args));
|
|
|
|
args.assign = assign;
|
2015-07-27 14:27:28 +00:00
|
|
|
args.src = parse_qgroupid(argv[optind]);
|
|
|
|
args.dst = parse_qgroupid(argv[optind + 1]);
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2015-07-27 14:27:28 +00:00
|
|
|
path = argv[optind + 2];
|
2015-07-27 14:16:52 +00:00
|
|
|
|
2012-08-07 10:37:54 +00:00
|
|
|
/*
|
|
|
|
* FIXME src should accept subvol path
|
|
|
|
*/
|
2015-02-27 08:26:33 +00:00
|
|
|
if (btrfs_qgroup_level(args.src) >= btrfs_qgroup_level(args.dst)) {
|
2016-01-11 10:01:47 +00:00
|
|
|
error("bad relation requested: %s", path);
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2015-10-12 13:23:00 +00:00
|
|
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
|
|
|
if (fd < 0)
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
|
|
|
|
if (ret < 0) {
|
2019-11-27 03:48:51 +00:00
|
|
|
error("unable to assign quota group: %s",
|
|
|
|
errno == ENOTCONN ? "quota not enabled"
|
|
|
|
: strerror(errno));
|
2015-02-27 08:26:39 +00:00
|
|
|
close_file_or_dir(fd, dirstream);
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2015-02-27 08:26:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If ret > 0, it means assign caused qgroup data inconsistent state.
|
|
|
|
* Schedule a quota rescan if requested.
|
|
|
|
*
|
|
|
|
* The return value change only happens in newer kernel. But will not
|
|
|
|
* cause problem since old kernel has a bug that will never clear
|
|
|
|
* INCONSISTENT bit.
|
|
|
|
*/
|
|
|
|
if (ret > 0) {
|
2015-07-27 14:27:28 +00:00
|
|
|
if (rescan) {
|
2016-01-12 13:34:41 +00:00
|
|
|
struct btrfs_ioctl_quota_rescan_args qargs;
|
2015-07-27 14:27:28 +00:00
|
|
|
|
|
|
|
printf("Quota data changed, rescan scheduled\n");
|
2016-01-12 13:34:41 +00:00
|
|
|
memset(&qargs, 0, sizeof(qargs));
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &qargs);
|
2015-07-27 14:27:28 +00:00
|
|
|
if (ret < 0)
|
2018-01-07 21:54:21 +00:00
|
|
|
error("quota rescan failed: %m");
|
2015-07-27 14:27:28 +00:00
|
|
|
} else {
|
2016-01-11 10:01:47 +00:00
|
|
|
warning("quotas may be inconsistent, rescan needed");
|
2018-08-10 02:34:06 +00:00
|
|
|
ret = 0;
|
2015-07-27 14:27:28 +00:00
|
|
|
}
|
2015-02-27 08:26:39 +00:00
|
|
|
}
|
|
|
|
close_file_or_dir(fd, dirstream);
|
|
|
|
return ret;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 15:06:27 +00:00
|
|
|
static int _cmd_qgroup_create(int create, int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int fd;
|
2016-03-01 15:02:08 +00:00
|
|
|
char *path;
|
2012-08-07 10:37:54 +00:00
|
|
|
struct btrfs_ioctl_qgroup_create_args args;
|
2013-07-15 11:36:50 +00:00
|
|
|
DIR *dirstream = NULL;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2016-03-18 01:29:50 +00:00
|
|
|
if (check_argc_exact(argc - optind, 2))
|
2019-03-04 15:42:00 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
memset(&args, 0, sizeof(args));
|
|
|
|
args.create = create;
|
2016-03-01 15:02:08 +00:00
|
|
|
args.qgroupid = parse_qgroupid(argv[optind]);
|
|
|
|
path = argv[optind + 1];
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2015-10-12 13:23:00 +00:00
|
|
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
|
|
|
if (fd < 0)
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_QGROUP_CREATE, &args);
|
2013-07-15 11:36:50 +00:00
|
|
|
close_file_or_dir(fd, dirstream);
|
2012-08-07 10:37:54 +00:00
|
|
|
if (ret < 0) {
|
2019-11-27 03:48:51 +00:00
|
|
|
error("unable to %s quota group: %s",
|
|
|
|
create ? "create":"destroy",
|
|
|
|
errno == ENOTCONN ? "quota not enabled"
|
|
|
|
: strerror(errno));
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const cmd_qgroup_assign_usage[] = {
|
2015-07-27 14:27:28 +00:00
|
|
|
"btrfs qgroup assign [options] <src> <dst> <path>",
|
2015-07-27 15:36:03 +00:00
|
|
|
"Assign SRC as the child qgroup of DST",
|
2015-07-27 14:27:28 +00:00
|
|
|
"",
|
|
|
|
"--rescan schedule qutoa rescan if needed",
|
2016-03-18 01:36:29 +00:00
|
|
|
"--no-rescan don't schedule quota rescan",
|
2012-08-07 10:37:54 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:24:46 +00:00
|
|
|
static int cmd_qgroup_assign(const struct cmd_struct *cmd,
|
|
|
|
int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
2018-03-07 02:42:01 +00:00
|
|
|
return _cmd_qgroup_assign(cmd, 1, argc, argv);
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2018-03-07 02:07:03 +00:00
|
|
|
static DEFINE_SIMPLE_COMMAND(qgroup_assign, "assign");
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
static const char * const cmd_qgroup_remove_usage[] = {
|
2020-02-02 14:45:42 +00:00
|
|
|
"btrfs qgroup remove [options] <src> <dst> <path>",
|
2015-07-27 15:36:03 +00:00
|
|
|
"Remove a child qgroup SRC from DST.",
|
2020-02-02 14:45:42 +00:00
|
|
|
"",
|
|
|
|
"--rescan schedule qutoa rescan if needed",
|
|
|
|
"--no-rescan don't schedule quota rescan",
|
2012-08-07 10:37:54 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:24:46 +00:00
|
|
|
static int cmd_qgroup_remove(const struct cmd_struct *cmd,
|
|
|
|
int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
2018-03-07 02:42:01 +00:00
|
|
|
return _cmd_qgroup_assign(cmd, 0, argc, argv);
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2018-03-07 02:07:03 +00:00
|
|
|
static DEFINE_SIMPLE_COMMAND(qgroup_remove, "remove");
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
static const char * const cmd_qgroup_create_usage[] = {
|
|
|
|
"btrfs qgroup create <qgroupid> <path>",
|
|
|
|
"Create a subvolume quota group.",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:24:46 +00:00
|
|
|
static int cmd_qgroup_create(const struct cmd_struct *cmd,
|
|
|
|
int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
2018-03-07 02:42:01 +00:00
|
|
|
clean_args_no_options(cmd, argc, argv);
|
2016-03-01 15:02:08 +00:00
|
|
|
|
2019-03-04 15:42:00 +00:00
|
|
|
return _cmd_qgroup_create(1, argc, argv);
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2018-03-07 02:07:03 +00:00
|
|
|
static DEFINE_SIMPLE_COMMAND(qgroup_create, "create");
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
static const char * const cmd_qgroup_destroy_usage[] = {
|
|
|
|
"btrfs qgroup destroy <qgroupid> <path>",
|
2015-07-27 15:36:03 +00:00
|
|
|
"Destroy a quota group.",
|
2012-08-07 10:37:54 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:24:46 +00:00
|
|
|
static int cmd_qgroup_destroy(const struct cmd_struct *cmd,
|
|
|
|
int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
2018-03-07 02:42:01 +00:00
|
|
|
clean_args_no_options(cmd, argc, argv);
|
2016-03-01 15:02:08 +00:00
|
|
|
|
2019-03-04 15:42:00 +00:00
|
|
|
return _cmd_qgroup_create(0, argc, argv);
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2018-03-07 02:07:03 +00:00
|
|
|
static DEFINE_SIMPLE_COMMAND(qgroup_destroy, "destroy");
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
static const char * const cmd_qgroup_show_usage[] = {
|
2016-12-15 04:29:28 +00:00
|
|
|
"btrfs qgroup show [options] <path>",
|
2013-10-07 07:21:42 +00:00
|
|
|
"Show subvolume quota groups.",
|
2019-06-21 13:36:04 +00:00
|
|
|
"",
|
2015-01-19 07:18:18 +00:00
|
|
|
"-p print parent qgroup id",
|
|
|
|
"-c print child qgroup id",
|
2015-01-27 16:07:40 +00:00
|
|
|
"-r print limit of referenced size of qgroup",
|
|
|
|
"-e print limit of exclusive size of qgroup",
|
|
|
|
"-F list all qgroups which impact the given path",
|
|
|
|
" (including ancestral qgroups)",
|
|
|
|
"-f list all qgroups which impact the given path",
|
|
|
|
" (excluding ancestral qgroups)",
|
2015-11-06 15:39:49 +00:00
|
|
|
HELPINFO_UNITS_LONG,
|
Btrfs-progs: enhance btrfs qgroup show to sort qgroups
You might want to list qgroups in order of some items, such as 'qgroupid', 'rfer'
and so on, you can use '--sort'. Now you can sort the qgroups by 'qgroupid',
'rfer','excl','max_rfer' and 'max_excl'.
For example:
If you want to list qgroups in order of 'qgroupid'.
You can use the option like that:
btrfs qgroup show --sort=+/-qgroupid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs qgroup show --sort=-qgroupid,+rfer,max_rfer,excl <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-07 07:21:44 +00:00
|
|
|
"--sort=qgroupid,rfer,excl,max_rfer,max_excl",
|
2015-02-03 17:34:14 +00:00
|
|
|
" list qgroups sorted by specified items",
|
2015-01-19 07:18:18 +00:00
|
|
|
" you can use '+' or '-' in front of each item.",
|
|
|
|
" (+:ascending, -:descending, ascending default)",
|
2016-12-15 04:29:28 +00:00
|
|
|
"--sync force sync of the filesystem before getting info",
|
2012-08-07 10:37:54 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:24:46 +00:00
|
|
|
static int cmd_qgroup_show(const struct cmd_struct *cmd, int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
2013-10-07 07:21:38 +00:00
|
|
|
char *path;
|
2012-08-07 10:37:54 +00:00
|
|
|
int ret = 0;
|
|
|
|
int fd;
|
2013-07-15 11:36:50 +00:00
|
|
|
DIR *dirstream = NULL;
|
2013-10-07 07:21:42 +00:00
|
|
|
u64 qgroupid;
|
|
|
|
int filter_flag = 0;
|
2015-08-31 11:03:44 +00:00
|
|
|
unsigned unit_mode;
|
2016-12-15 04:29:28 +00:00
|
|
|
int sync = 0;
|
2018-01-25 09:35:27 +00:00
|
|
|
enum btrfs_util_error err;
|
2013-10-07 07:21:42 +00:00
|
|
|
|
Btrfs-progs: enhance btrfs qgroup show to sort qgroups
You might want to list qgroups in order of some items, such as 'qgroupid', 'rfer'
and so on, you can use '--sort'. Now you can sort the qgroups by 'qgroupid',
'rfer','excl','max_rfer' and 'max_excl'.
For example:
If you want to list qgroups in order of 'qgroupid'.
You can use the option like that:
btrfs qgroup show --sort=+/-qgroupid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs qgroup show --sort=-qgroupid,+rfer,max_rfer,excl <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-07 07:21:44 +00:00
|
|
|
struct btrfs_qgroup_comparer_set *comparer_set;
|
2013-10-07 07:21:42 +00:00
|
|
|
struct btrfs_qgroup_filter_set *filter_set;
|
|
|
|
filter_set = btrfs_qgroup_alloc_filter_set();
|
Btrfs-progs: enhance btrfs qgroup show to sort qgroups
You might want to list qgroups in order of some items, such as 'qgroupid', 'rfer'
and so on, you can use '--sort'. Now you can sort the qgroups by 'qgroupid',
'rfer','excl','max_rfer' and 'max_excl'.
For example:
If you want to list qgroups in order of 'qgroupid'.
You can use the option like that:
btrfs qgroup show --sort=+/-qgroupid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs qgroup show --sort=-qgroupid,+rfer,max_rfer,excl <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-07 07:21:44 +00:00
|
|
|
comparer_set = btrfs_qgroup_alloc_comparer_set();
|
2013-10-07 07:21:38 +00:00
|
|
|
|
2015-08-31 11:03:44 +00:00
|
|
|
unit_mode = get_unit_mode_from_arg(&argc, argv, 0);
|
|
|
|
|
2018-06-20 00:38:38 +00:00
|
|
|
optind = 0;
|
2013-10-07 07:21:38 +00:00
|
|
|
while (1) {
|
2015-01-19 12:30:06 +00:00
|
|
|
int c;
|
2016-12-15 04:29:28 +00:00
|
|
|
enum {
|
2016-12-15 04:30:55 +00:00
|
|
|
GETOPT_VAL_SORT = 256,
|
|
|
|
GETOPT_VAL_SYNC
|
2016-12-15 04:29:28 +00:00
|
|
|
};
|
2015-01-19 12:44:49 +00:00
|
|
|
static const struct option long_options[] = {
|
2016-12-15 04:30:55 +00:00
|
|
|
{"sort", required_argument, NULL, GETOPT_VAL_SORT},
|
2016-12-15 04:29:28 +00:00
|
|
|
{"sync", no_argument, NULL, GETOPT_VAL_SYNC},
|
2015-01-21 17:53:02 +00:00
|
|
|
{ NULL, 0, NULL, 0 }
|
2015-01-19 12:30:06 +00:00
|
|
|
};
|
|
|
|
|
2015-04-08 15:33:55 +00:00
|
|
|
c = getopt_long(argc, argv, "pcreFf", long_options, NULL);
|
2013-10-07 07:21:38 +00:00
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
switch (c) {
|
|
|
|
case 'p':
|
|
|
|
btrfs_qgroup_setup_print_column(
|
|
|
|
BTRFS_QGROUP_PARENT);
|
|
|
|
break;
|
2013-10-07 07:21:39 +00:00
|
|
|
case 'c':
|
|
|
|
btrfs_qgroup_setup_print_column(
|
|
|
|
BTRFS_QGROUP_CHILD);
|
|
|
|
break;
|
2013-10-07 07:21:40 +00:00
|
|
|
case 'r':
|
|
|
|
btrfs_qgroup_setup_print_column(
|
|
|
|
BTRFS_QGROUP_MAX_RFER);
|
|
|
|
break;
|
2013-10-07 07:21:41 +00:00
|
|
|
case 'e':
|
|
|
|
btrfs_qgroup_setup_print_column(
|
|
|
|
BTRFS_QGROUP_MAX_EXCL);
|
|
|
|
break;
|
2013-10-07 07:21:42 +00:00
|
|
|
case 'F':
|
|
|
|
filter_flag |= 0x1;
|
|
|
|
break;
|
2013-10-07 07:21:43 +00:00
|
|
|
case 'f':
|
|
|
|
filter_flag |= 0x2;
|
|
|
|
break;
|
2016-12-15 04:30:55 +00:00
|
|
|
case GETOPT_VAL_SORT:
|
Btrfs-progs: enhance btrfs qgroup show to sort qgroups
You might want to list qgroups in order of some items, such as 'qgroupid', 'rfer'
and so on, you can use '--sort'. Now you can sort the qgroups by 'qgroupid',
'rfer','excl','max_rfer' and 'max_excl'.
For example:
If you want to list qgroups in order of 'qgroupid'.
You can use the option like that:
btrfs qgroup show --sort=+/-qgroupid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs qgroup show --sort=-qgroupid,+rfer,max_rfer,excl <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-07 07:21:44 +00:00
|
|
|
ret = btrfs_qgroup_parse_sort_string(optarg,
|
|
|
|
&comparer_set);
|
2019-03-04 15:56:04 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
errno = -ret;
|
|
|
|
error("cannot parse sort string: %m");
|
|
|
|
return 1;
|
|
|
|
}
|
2019-03-04 16:00:06 +00:00
|
|
|
if (ret > 0) {
|
|
|
|
error("unrecognized format of sort string");
|
|
|
|
return 1;
|
|
|
|
}
|
Btrfs-progs: enhance btrfs qgroup show to sort qgroups
You might want to list qgroups in order of some items, such as 'qgroupid', 'rfer'
and so on, you can use '--sort'. Now you can sort the qgroups by 'qgroupid',
'rfer','excl','max_rfer' and 'max_excl'.
For example:
If you want to list qgroups in order of 'qgroupid'.
You can use the option like that:
btrfs qgroup show --sort=+/-qgroupid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs qgroup show --sort=-qgroupid,+rfer,max_rfer,excl <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-07 07:21:44 +00:00
|
|
|
break;
|
2016-12-15 04:29:28 +00:00
|
|
|
case GETOPT_VAL_SYNC:
|
|
|
|
sync = 1;
|
|
|
|
break;
|
2013-10-07 07:21:38 +00:00
|
|
|
default:
|
2018-03-07 02:54:38 +00:00
|
|
|
usage_unknown_option(cmd, argv);
|
2013-10-07 07:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-19 07:18:18 +00:00
|
|
|
btrfs_qgroup_setup_units(unit_mode);
|
|
|
|
|
2013-10-07 07:21:38 +00:00
|
|
|
if (check_argc_exact(argc - optind, 1))
|
2019-03-04 13:49:15 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2013-10-07 07:21:38 +00:00
|
|
|
path = argv[optind];
|
2015-10-12 13:23:00 +00:00
|
|
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
2015-10-19 11:37:59 +00:00
|
|
|
if (fd < 0) {
|
2016-09-06 13:30:31 +00:00
|
|
|
free(filter_set);
|
|
|
|
free(comparer_set);
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2015-10-19 11:37:59 +00:00
|
|
|
}
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2016-12-15 04:29:28 +00:00
|
|
|
if (sync) {
|
2018-01-25 09:35:27 +00:00
|
|
|
err = btrfs_util_sync_fd(fd);
|
|
|
|
if (err)
|
2018-09-13 00:52:16 +00:00
|
|
|
warning("sync ioctl failed on '%s': %m", path);
|
2016-12-15 04:29:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 07:21:42 +00:00
|
|
|
if (filter_flag) {
|
2016-10-31 09:34:37 +00:00
|
|
|
ret = lookup_path_rootid(fd, &qgroupid);
|
2016-10-31 09:27:25 +00:00
|
|
|
if (ret < 0) {
|
2018-10-25 12:10:54 +00:00
|
|
|
errno = -ret;
|
|
|
|
error("cannot resolve rootid for %s: %m", path);
|
2016-10-31 09:27:25 +00:00
|
|
|
close_file_or_dir(fd, dirstream);
|
|
|
|
goto out;
|
|
|
|
}
|
2013-10-07 07:21:43 +00:00
|
|
|
if (filter_flag & 0x1)
|
|
|
|
btrfs_qgroup_setup_filter(&filter_set,
|
|
|
|
BTRFS_QGROUP_FILTER_ALL_PARENT,
|
|
|
|
qgroupid);
|
|
|
|
if (filter_flag & 0x2)
|
|
|
|
btrfs_qgroup_setup_filter(&filter_set,
|
|
|
|
BTRFS_QGROUP_FILTER_PARENT,
|
|
|
|
qgroupid);
|
2013-10-07 07:21:42 +00:00
|
|
|
}
|
Btrfs-progs: enhance btrfs qgroup show to sort qgroups
You might want to list qgroups in order of some items, such as 'qgroupid', 'rfer'
and so on, you can use '--sort'. Now you can sort the qgroups by 'qgroupid',
'rfer','excl','max_rfer' and 'max_excl'.
For example:
If you want to list qgroups in order of 'qgroupid'.
You can use the option like that:
btrfs qgroup show --sort=+/-qgroupid <path>
Here, '+' means the result is sorted by ascending order. '-' is by descending
order. If you don't specify either '+' nor '-', the result is sorted by
default - ascending order.
If you want to combine sort items, you do it like that:
btrfs qgroup show --sort=-qgroupid,+rfer,max_rfer,excl <path>
Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
2013-10-07 07:21:44 +00:00
|
|
|
ret = btrfs_show_qgroups(fd, filter_set, comparer_set);
|
2017-01-20 16:52:12 +00:00
|
|
|
close_file_or_dir(fd, dirstream);
|
2018-02-15 17:13:35 +00:00
|
|
|
free(filter_set);
|
|
|
|
free(comparer_set);
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2016-10-31 09:27:25 +00:00
|
|
|
out:
|
2013-09-04 15:22:25 +00:00
|
|
|
return !!ret;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
2018-03-07 02:07:03 +00:00
|
|
|
static DEFINE_SIMPLE_COMMAND(qgroup_show, "show");
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
static const char * const cmd_qgroup_limit_usage[] = {
|
|
|
|
"btrfs qgroup limit [options] <size>|none [<qgroupid>] <path>",
|
2015-07-27 15:36:03 +00:00
|
|
|
"Set the limits a subvolume quota group.",
|
2012-08-07 10:37:54 +00:00
|
|
|
"",
|
2013-03-27 13:54:12 +00:00
|
|
|
"-c limit amount of data after compression. This is the default,",
|
|
|
|
" it is currently not possible to turn off this option.",
|
2012-08-07 10:37:54 +00:00
|
|
|
"-e limit space exclusively assigned to this qgroup",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:24:46 +00:00
|
|
|
static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
|
2012-08-07 10:37:54 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int fd;
|
2013-01-26 18:10:33 +00:00
|
|
|
char *path = NULL;
|
2012-08-07 10:37:54 +00:00
|
|
|
struct btrfs_ioctl_qgroup_limit_args args;
|
|
|
|
unsigned long long size;
|
|
|
|
int compressed = 0;
|
|
|
|
int exclusive = 0;
|
2013-07-15 11:36:50 +00:00
|
|
|
DIR *dirstream = NULL;
|
2018-01-21 08:24:50 +00:00
|
|
|
enum btrfs_util_error err;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2018-06-20 00:38:38 +00:00
|
|
|
optind = 0;
|
2012-08-07 10:37:54 +00:00
|
|
|
while (1) {
|
|
|
|
int c = getopt(argc, argv, "ce");
|
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
compressed = 1;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
exclusive = 1;
|
|
|
|
break;
|
|
|
|
default:
|
2018-03-07 02:54:38 +00:00
|
|
|
usage_unknown_option(cmd, argv);
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-12 04:30:19 +00:00
|
|
|
if (check_argc_min(argc - optind, 2))
|
2019-03-04 13:49:15 +00:00
|
|
|
return 1;
|
2012-09-12 04:30:19 +00:00
|
|
|
|
2019-08-14 01:04:00 +00:00
|
|
|
if (!strcasecmp(argv[optind], "none"))
|
|
|
|
size = -1ULL;
|
|
|
|
else
|
|
|
|
size = parse_size(argv[optind]);
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
memset(&args, 0, sizeof(args));
|
2015-06-03 06:57:33 +00:00
|
|
|
if (compressed)
|
|
|
|
args.lim.flags |= BTRFS_QGROUP_LIMIT_RFER_CMPR |
|
|
|
|
BTRFS_QGROUP_LIMIT_EXCL_CMPR;
|
|
|
|
if (exclusive) {
|
|
|
|
args.lim.flags |= BTRFS_QGROUP_LIMIT_MAX_EXCL;
|
|
|
|
args.lim.max_exclusive = size;
|
|
|
|
} else {
|
|
|
|
args.lim.flags |= BTRFS_QGROUP_LIMIT_MAX_RFER;
|
|
|
|
args.lim.max_referenced = size;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
|
2013-01-20 21:04:14 +00:00
|
|
|
if (argc - optind == 2) {
|
|
|
|
args.qgroupid = 0;
|
2012-08-07 10:37:54 +00:00
|
|
|
path = argv[optind + 1];
|
2018-01-21 08:24:50 +00:00
|
|
|
err = btrfs_util_is_subvolume(path);
|
|
|
|
if (err) {
|
|
|
|
error_btrfs_util(err);
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* keep qgroupid at 0, this indicates that the subvolume the
|
|
|
|
* fd refers to is to be limited
|
|
|
|
*/
|
2013-01-20 21:04:14 +00:00
|
|
|
} else if (argc - optind == 3) {
|
|
|
|
args.qgroupid = parse_qgroupid(argv[optind + 1]);
|
2012-08-07 10:37:54 +00:00
|
|
|
path = argv[optind + 2];
|
2013-01-20 21:04:14 +00:00
|
|
|
} else
|
2018-03-07 02:54:38 +00:00
|
|
|
usage(cmd);
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2015-10-12 13:23:00 +00:00
|
|
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
|
|
|
if (fd < 0)
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
|
|
|
|
ret = ioctl(fd, BTRFS_IOC_QGROUP_LIMIT, &args);
|
2013-07-15 11:36:50 +00:00
|
|
|
close_file_or_dir(fd, dirstream);
|
2012-08-07 10:37:54 +00:00
|
|
|
if (ret < 0) {
|
2019-11-27 03:48:51 +00:00
|
|
|
error("unable to limit requested quota group: %s",
|
|
|
|
errno == ENOTCONN ? "quota not enabled"
|
|
|
|
: strerror(errno));
|
|
|
|
|
2013-09-04 15:22:25 +00:00
|
|
|
return 1;
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-07 02:07:03 +00:00
|
|
|
static DEFINE_SIMPLE_COMMAND(qgroup_limit, "limit");
|
2012-08-07 10:37:54 +00:00
|
|
|
|
2015-06-09 12:22:05 +00:00
|
|
|
static const char qgroup_cmd_group_info[] =
|
|
|
|
"manage quota groups";
|
|
|
|
|
2018-03-07 02:07:03 +00:00
|
|
|
static const struct cmd_group qgroup_cmd_group = {
|
2015-06-09 12:22:05 +00:00
|
|
|
qgroup_cmd_group_usage, qgroup_cmd_group_info, {
|
2018-03-07 02:07:03 +00:00
|
|
|
&cmd_struct_qgroup_assign,
|
|
|
|
&cmd_struct_qgroup_remove,
|
|
|
|
&cmd_struct_qgroup_create,
|
|
|
|
&cmd_struct_qgroup_destroy,
|
|
|
|
&cmd_struct_qgroup_show,
|
|
|
|
&cmd_struct_qgroup_limit,
|
|
|
|
NULL
|
2012-08-07 10:37:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-07 02:07:03 +00:00
|
|
|
DEFINE_GROUP_COMMAND_TOKEN(qgroup);
|