summaryrefslogtreecommitdiff
path: root/bcache.c
blob: 511db7ba11290540ea5a998ef17ac66fc246c7a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Authors: Kent Overstreet <kent.overstreet@gmail.com>
 *	    Gabriel de Perthuis <g2p.code@gmail.com>
 *	    Jacob Malevich <jam@datera.io>
 *
 * GPLv2
 */

#include <nih/option.h>
#include <nih/command.h>
#include <nih/main.h>
#include <nih/logging.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "bcache.h"
#include "bcache-assemble.h"
#include "bcache-device.h"
#include "bcache-format.h"
#include "bcache-fs.h"
#include "bcache-run.h"

#define PACKAGE_NAME "bcache"
#define PACKAGE_VERSION "1.0"
#define PACKAGE_BUGREPORT "linux-bcache@vger.kernel.org"

const char * const cache_state[] = {
	"active",
	"ro",
	"failed",
	"spare",
	NULL
};

const char * const replacement_policies[] = {
	"lru",
	"fifo",
	"random",
	NULL
};

const char * const csum_types[] = {
	"none",
	"crc32c",
	"crc64",
	NULL
};

const char * const compression_types[] = {
	"none",
	"lz4",
	"gzip",
	NULL
};

const char * const error_actions[] = {
	"continue",
	"readonly",
	"panic",
	NULL
};

const char * const bdev_cache_mode[] = {
	"writethrough",
	"writeback",
	"writearound",
	"none",
	NULL
};

const char * const bdev_state[] = {
	"detached",
	"clean",
	"dirty",
	"inconsistent",
	NULL
};

#define CMD(_command, _usage, _synopsis)				\
{									\
	.command	= #_command,					\
	.usage		= _usage,					\
	.synopsis	= _synopsis,					\
	.help		= NULL,						\
	.group		= NULL,						\
	.options	= opts_##_command,				\
	.action		= cmd_##_command,				\
}

static NihCommand commands[] = {
	CMD(format, N_("<list of devices>"),
	    "Create a new bcache volume from one or more devices"),

	/* Bringup, shutdown */

	CMD(assemble, N_("<devices>"),
	    "Assembles one or more devices into a bcache volume"),
	CMD(incremental, N_("<device"),
	    "Incrementally assemble a bcache filesystem"),
	CMD(run, N_("<volume>"),
	    "Start a partially assembled volume"),
	CMD(stop, N_("<volume>"),
	    "Stops a running bcache volume"),

	/* Filesystem commands: */

	CMD(fs_show, N_("<fs>"),
	    "Show information about a filesystem"),
	CMD(fs_set, N_("<fs>"),
	    "Change various filesystem options"),

	/* Device commands: */

	CMD(device_show, N_("<fs>"),
	    "Show information about component devices of a filesystem"),
	CMD(device_add, N_("<volume> <devices>"),
	    "Adds a list of devices to a volume"),
	CMD(device_remove, N_("<volume> <devices>"),
	    "Removes a device from its volume"),

#if 0
	CMD(modify, N_("<options>"),
	    "Modifies attributes related to the volume",
	    N_("Modifies attributes related to the volume")),
	CMD(list, N_("list-cachesets"),
	    "Lists cachesets in /sys/fs/bcache"),
	CMD(query, N_("query <list of devices>"),
	    "Gives info about the superblock of a list of devices"),
	CMD(status, N_("status <list of devices>"),
	    "Finds the status of the most up to date superblock"),
#endif
	NIH_COMMAND_LAST
};

static NihOption options[] = {
	NIH_OPTION_LAST
};

int main(int argc, char *argv[])
{
	nih_main_init(argv[0]);
	nih_option_set_synopsis(_("Manage bcache devices"));
	nih_option_set_help( _("Helps you manage bcache devices"));

	int ret = nih_command_parser(NULL, argc, argv, options, commands);
	if (ret < 0)
		exit(EXIT_FAILURE);

	nih_signal_reset();

	return 0;
}