bcachefs-tools/bcachefs.c

175 lines
4.9 KiB
C
Raw Normal View History

2016-03-12 09:18:42 +03:00
/*
* Authors: Kent Overstreet <kent.overstreet@gmail.com>
* Gabriel de Perthuis <g2p.code@gmail.com>
* Jacob Malevich <jam@datera.io>
*
* GPLv2
*/
2016-03-12 09:18:42 +03:00
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
2016-03-12 09:18:42 +03:00
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
2016-03-12 09:18:42 +03:00
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
2017-02-02 06:16:42 +03:00
#include "cmds.h"
2016-08-24 06:50:31 +03:00
static void usage(void)
{
puts("bcachefs - tool for managing bcachefs filesystems\n"
"usage: bcachefs <command> [<args>]\n"
2016-08-24 06:50:31 +03:00
"\n"
"Superblock commands:\n"
" format Format a new filesystem\n"
" show-super Dump superblock information to stdout\n"
2016-08-24 06:50:31 +03:00
"\n"
"Repair:\n"
" fsck Check an existing filesystem for errors\n"
"\n"
"Startup/shutdown, assembly of multi device filesystems:\n"
" assemble Assemble an existing multi device filesystem\n"
" incremental Incrementally assemble an existing multi device filesystem\n"
" run Start a partially assembled filesystem\n"
" stop Stop a running filesystem\n"
"\n"
2017-01-08 12:13:18 +03:00
"Commands for managing a running filesystem:\n"
2017-12-23 08:50:55 +03:00
" fs usage Show disk usage\n"
2016-08-24 06:50:31 +03:00
"\n"
"Commands for managing devices within a running filesystem:\n"
" device add Add a new device to an existing filesystem\n"
" device remove Remove a device from an existing filesystem\n"
" device online Re-add an existing member to a filesystem\n"
" device offline Take a device offline, without removing it\n"
" device evacuate Migrate data off of a specific device\n"
" device set-state Mark a device as failed\n"
2017-12-28 09:01:16 +03:00
" device resize Resize filesystem on a device\n"
2017-01-08 12:13:18 +03:00
"\n"
"Encryption:\n"
" unlock Unlock an encrypted filesystem prior to running/mounting\n"
" set-passphrase Change passphrase on an existing (unmounted) filesystem\n"
" remove-passphrase Remove passphrase on an existing (unmounted) filesystem\n"
"\n"
"Migrate:\n"
" migrate Migrate an existing filesystem to bcachefs, in place\n"
" migrate-superblock Add default superblock, after bcachefs migrate\n"
2016-10-04 06:22:17 +03:00
"\n"
"Debug:\n"
"These commands work on offline, unmounted filesystems\n"
" dump Dump filesystem metadata to a qcow2 image\n"
" list List filesystem metadata in textual form\n");
2016-03-12 09:18:42 +03:00
}
static char *full_cmd;
2017-01-08 12:13:18 +03:00
static char *pop_cmd(int *argc, char *argv[])
{
if (*argc < 2) {
2016-08-24 06:50:31 +03:00
printf("%s: missing command\n", argv[0]);
2017-01-08 12:13:18 +03:00
usage();
exit(EXIT_FAILURE);
2016-08-24 06:50:31 +03:00
}
char *cmd = argv[1];
memmove(&argv[1], &argv[2], *argc * sizeof(argv[0]));
(*argc)--;
full_cmd = mprintf("%s %s", full_cmd, cmd);
return cmd;
}
static int fs_cmds(int argc, char *argv[])
{
char *cmd = pop_cmd(&argc, argv);
2017-12-23 08:50:55 +03:00
if (!strcmp(cmd, "usage"))
return cmd_fs_usage(argc, argv);
2016-08-24 06:50:31 +03:00
usage();
return 0;
}
static int device_cmds(int argc, char *argv[])
{
char *cmd = pop_cmd(&argc, argv);
if (!strcmp(cmd, "add"))
return cmd_device_add(argc, argv);
if (!strcmp(cmd, "remove"))
return cmd_device_remove(argc, argv);
if (!strcmp(cmd, "online"))
return cmd_device_online(argc, argv);
if (!strcmp(cmd, "offline"))
return cmd_device_offline(argc, argv);
if (!strcmp(cmd, "evacuate"))
return cmd_device_offline(argc, argv);
if (!strcmp(cmd, "set-state"))
return cmd_device_set_state(argc, argv);
2017-12-28 09:01:16 +03:00
if (!strcmp(cmd, "resize"))
return cmd_device_resize(argc, argv);
usage();
return 0;
}
int main(int argc, char *argv[])
{
full_cmd = argv[0];
setvbuf(stdout, NULL, _IOLBF, 0);
char *cmd = pop_cmd(&argc, argv);
2016-08-24 06:50:31 +03:00
if (!strcmp(cmd, "format"))
return cmd_format(argc, argv);
if (!strcmp(cmd, "show-super"))
return cmd_show_super(argc, argv);
if (!strcmp(cmd, "fsck"))
return cmd_fsck(argc, argv);
2016-08-24 06:50:31 +03:00
if (!strcmp(cmd, "assemble"))
return cmd_assemble(argc, argv);
if (!strcmp(cmd, "incremental"))
return cmd_incremental(argc, argv);
if (!strcmp(cmd, "run"))
return cmd_run(argc, argv);
if (!strcmp(cmd, "stop"))
return cmd_stop(argc, argv);
if (!strcmp(cmd, "fs"))
return fs_cmds(argc, argv);
2016-08-24 06:50:31 +03:00
if (!strcmp(cmd, "device"))
return device_cmds(argc, argv);
2016-08-24 06:50:31 +03:00
if (!strcmp(cmd, "unlock"))
return cmd_unlock(argc, argv);
if (!strcmp(cmd, "set-passphrase"))
return cmd_set_passphrase(argc, argv);
if (!strcmp(cmd, "remove-passphrase"))
return cmd_remove_passphrase(argc, argv);
if (!strcmp(cmd, "migrate"))
return cmd_migrate(argc, argv);
if (!strcmp(cmd, "migrate-superblock"))
return cmd_migrate_superblock(argc, argv);
2016-10-04 06:22:17 +03:00
if (!strcmp(cmd, "dump"))
return cmd_dump(argc, argv);
if (!strcmp(cmd, "list"))
return cmd_list(argc, argv);
printf("Unknown command %s\n", cmd);
2016-08-24 06:50:31 +03:00
usage();
exit(EXIT_FAILURE);
}