summaryrefslogtreecommitdiff
path: root/btrfs-defrag.c
diff options
context:
space:
mode:
authorghigo <ghigo@kreijack.homelinux.net>2010-01-24 18:00:05 +0100
committerChris Mason <chris.mason@oracle.com>2010-03-11 13:45:47 -0500
commit6d2cf042471cc728b5399b2beae54603739bc66a (patch)
tree0d8ea823ec7c1e4676630153eee998cc6fcfb62c /btrfs-defrag.c
parent06cbf62fda156d1399022158d671353d1a3aeaec (diff)
new util: 'btrfs'
This commit introduces a new command called 'btrfs' for managing a btrfs filesystem. 'btrfs' handles: - snapshot/subvolume creation - adding/removal of volume (ie: disk) - defragment of a tree - scan of a device searching a btrfs filesystem - re-balancing of the chunk on the disks - listing subvolumes and snapshots This has also been updated to include the new defrag range ioctl. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'btrfs-defrag.c')
-rw-r--r--btrfs-defrag.c112
1 files changed, 0 insertions, 112 deletions
diff --git a/btrfs-defrag.c b/btrfs-defrag.c
index 9aab3ba4..8f1525a3 100644
--- a/btrfs-defrag.c
+++ b/btrfs-defrag.c
@@ -37,115 +37,3 @@
#include "utils.h"
#include "version.h"
-static u64 parse_size(char *s)
-{
- int len = strlen(s);
- char c;
- u64 mult = 1;
-
- if (!isdigit(s[len - 1])) {
- c = tolower(s[len - 1]);
- switch (c) {
- case 'g':
- mult *= 1024;
- case 'm':
- mult *= 1024;
- case 'k':
- mult *= 1024;
- case 'b':
- break;
- default:
- fprintf(stderr, "Unknown size descriptor %c\n", c);
- exit(1);
- }
- s[len - 1] = '\0';
- }
- return atoll(s) * mult;
-}
-
-static void print_usage(void)
-{
- printf("usage: btrfs-defrag [-c] [-f] [-s start] [-l len] "
- "[-t threshold] file ...\n");
- exit(1);
-}
-
-int main(int ac, char **av)
-{
- int fd;
- int compress = 0;
- int flush = 0;
- u64 start = 0;
- u64 len = (u64)-1;
- u32 thresh = 0;
- int i;
- int errors = 0;
- int ret = 0;
- int verbose = 0;
- struct btrfs_ioctl_defrag_range_args range;
-
- while(1) {
- int c = getopt(ac, av, "vcfs:l:t:");
- if (c < 0)
- break;
- switch(c) {
- case 'c':
- compress = 1;
- break;
- case 'f':
- flush = 1;
- break;
- case 'v':
- verbose = 1;
- break;
- case 's':
- start = parse_size(optarg);
- break;
- case 'l':
- len = parse_size(optarg);
- break;
- case 't':
- thresh = parse_size(optarg);
- break;
- default:
- print_usage();
- return 1;
- }
- }
- if (ac - optind == 0)
- print_usage();
-
- memset(&range, 0, sizeof(range));
- range.start = start;
- range.len = len;
- range.extent_thresh = thresh;
- if (compress)
- range.flags |= BTRFS_DEFRAG_RANGE_COMPRESS;
- if (flush)
- range.flags |= BTRFS_DEFRAG_RANGE_START_IO;
-
- for (i = optind; i < ac; i++) {
- fd = open(av[i], O_RDWR);
- if (fd < 0) {
- fprintf(stderr, "failed to open %s\n", av[i]);
- perror("open:");
- errors++;
- continue;
- }
- ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &range);
- if (ret) {
- fprintf(stderr, "ioctl failed on %s ret %d\n",
- av[i], ret);
- errors++;
- }
- close(fd);
- }
- if (verbose)
- printf("%s\n", BTRFS_BUILD_VERSION);
- if (errors) {
- fprintf(stderr, "total %d failures\n", errors);
- exit(1);
- }
- return 0;
-}
-