summaryrefslogtreecommitdiff
path: root/c_src
diff options
context:
space:
mode:
Diffstat (limited to 'c_src')
-rw-r--r--c_src/cmd_data.c25
-rw-r--r--c_src/cmd_device.c33
-rw-r--r--c_src/cmd_fsck.c18
-rw-r--r--c_src/cmd_key.c18
-rw-r--r--c_src/cmd_kill_btree_node.c36
-rw-r--r--c_src/cmd_migrate.c14
6 files changed, 107 insertions, 37 deletions
diff --git a/c_src/cmd_data.c b/c_src/cmd_data.c
index 5a1a1485..70d945a6 100644
--- a/c_src/cmd_data.c
+++ b/c_src/cmd_data.c
@@ -26,9 +26,13 @@ static void data_rereplicate_usage(void)
static int cmd_data_rereplicate(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "help", 0, NULL, 'h' },
+ { NULL }
+ };
int opt;
- while ((opt = getopt(argc, argv, "h")) != -1)
+ while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
switch (opt) {
case 'h':
data_rereplicate_usage();
@@ -262,16 +266,23 @@ static void data_job_usage(void)
"job: one of scrub, rereplicate, migrate, rewrite_old_nodes, or drop_extra_replicas\n"
"\n"
"Options:\n"
- " -b btree btree to operate on\n"
- " -s inode:offset start position\n"
- " -e inode:offset end position\n"
- " -h, --help display this help and exit\n"
+ " -b, --btree btree btree to operate on\n"
+ " -s, --start inode:offset start position\n"
+ " -e, --end inode:offset end position\n"
+ " -h, --help display this help and exit\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
exit(EXIT_SUCCESS);
}
static int cmd_data_job(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "btree", required_argument, NULL, 'b' },
+ { "start", required_argument, NULL, 's' },
+ { "end", required_argument, NULL, 'e' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL }
+ };
struct bch_ioctl_data op = {
.start_btree = 0,
.start_pos = POS_MIN,
@@ -280,7 +291,7 @@ static int cmd_data_job(int argc, char *argv[])
};
int opt;
- while ((opt = getopt(argc, argv, "s:e:h")) != -1)
+ while ((opt = getopt_long(argc, argv, "b:s:e:h", longopts, NULL)) != -1)
switch (opt) {
case 'b':
op.start_btree = read_string_list_or_die(optarg,
@@ -290,8 +301,8 @@ static int cmd_data_job(int argc, char *argv[])
case 's':
op.start_pos = bpos_parse(optarg);
break;
- op.end_pos = bpos_parse(optarg);
case 'e':
+ op.end_pos = bpos_parse(optarg);
break;
case 'h':
data_job_usage();
diff --git a/c_src/cmd_device.c b/c_src/cmd_device.c
index e7c40d0a..267385ac 100644
--- a/c_src/cmd_device.c
+++ b/c_src/cmd_device.c
@@ -212,9 +212,13 @@ static void device_online_usage(void)
static int cmd_device_online(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "help", 0, NULL, 'h' },
+ { NULL }
+ };
int opt;
- while ((opt = getopt(argc, argv, "h")) != -1)
+ while ((opt = getopt_long(argc, argv, "h", longopts, NULL)) != -1)
switch (opt) {
case 'h':
device_online_usage();
@@ -286,6 +290,7 @@ static void device_evacuate_usage(void)
"Usage: bcachefs device evacuate [OPTION]... device\n"
"\n"
"Options:\n"
+ " -f, --force Force if data redundancy will be degraded\n"
" -h, --help Display this help and exit\n"
"\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
@@ -293,10 +298,18 @@ static void device_evacuate_usage(void)
static int cmd_device_evacuate(int argc, char *argv[])
{
- int opt;
+ static const struct option longopts[] = {
+ { "force", no_argument, NULL, 'f' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL }
+ };
+ int opt, flags = 0;
- while ((opt = getopt(argc, argv, "h")) != -1)
+ while ((opt = getopt_long(argc, argv, "fh", longopts, NULL)) != -1)
switch (opt) {
+ case 'f':
+ flags |= BCH_FORCE_IF_DEGRADED;
+ break;
case 'h':
device_evacuate_usage();
exit(EXIT_SUCCESS);
@@ -317,7 +330,7 @@ static int cmd_device_evacuate(int argc, char *argv[])
if (u->state == BCH_MEMBER_STATE_rw) {
printf("Setting %s readonly\n", dev_path);
- bchu_disk_set_state(fs, dev_idx, BCH_MEMBER_STATE_ro, 0);
+ bchu_disk_set_state(fs, dev_idx, BCH_MEMBER_STATE_ro, flags);
}
free(u);
@@ -341,8 +354,8 @@ static void device_set_state_usage(void)
"<path>: path to mounted filesystem, optional unless specifying device by id\n"
"\n"
"Options:\n"
- " -f, --force Force, if data redundancy will be degraded\n"
- " --force-if-data-lost Force, if data will be lost\n"
+ " -f, --force Force if data redundancy will be degraded\n"
+ " --force-if-data-lost Force if data will be lost\n"
" -o, --offline Set state of an offline device\n"
" -h, --help display this help and exit\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
@@ -352,10 +365,10 @@ static void device_set_state_usage(void)
static int cmd_device_set_state(int argc, char *argv[])
{
static const struct option longopts[] = {
- { "force", 0, NULL, 'f' },
- { "force-if-data-lost", 0, NULL, 'F' },
- { "offline", 0, NULL, 'o' },
- { "help", 0, NULL, 'h' },
+ { "force", no_argument, NULL, 'f' },
+ { "force-if-data-lost", no_argument, NULL, 'F' },
+ { "offline", no_argument, NULL, 'o' },
+ { "help", no_argument, NULL, 'h' },
{ NULL }
};
struct bchfs_handle fs;
diff --git a/c_src/cmd_fsck.c b/c_src/cmd_fsck.c
index a3fd1d6a..66669e67 100644
--- a/c_src/cmd_fsck.c
+++ b/c_src/cmd_fsck.c
@@ -47,6 +47,24 @@ static int do_splice(int rfd, int wfd)
return 1;
do {
ssize_t w = write(wfd, b, r);
+
+ /*
+ * Ugly, but we have no way of doing nonblocking reads and
+ * blocking writes.
+ *
+ * Yes, this means that if one thread has stopped reading (or
+ * isn't keeping up) we block traffic on the other direction of
+ * the pipe. No, I don't care.
+ */
+ if (w < 0 && errno == EAGAIN) {
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(wfd, &fds);
+ if (select(wfd + 1, NULL, &fds, NULL, NULL) < 0)
+ die("select error: %m");
+ continue;
+ }
+
if (w < 0)
die("%s: write error: %m", __func__);
r -= w;
diff --git a/c_src/cmd_key.c b/c_src/cmd_key.c
index c1b72ff4..6cdf1d3f 100644
--- a/c_src/cmd_key.c
+++ b/c_src/cmd_key.c
@@ -1,5 +1,6 @@
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <unistd.h>
#include <uuid/uuid.h>
@@ -15,16 +16,23 @@ static void unlock_usage(void)
"Usage: bcachefs unlock [OPTION] device\n"
"\n"
"Options:\n"
- " -c Check if a device is encrypted\n"
- " -k (session|user|user_session)\n"
+ " -c, --check Check if a device is encrypted\n"
+ " -k, --keyring (session|user|user_session)\n"
" Keyring to add to (default: user)\n"
- " -f Passphrase file to read from (disables passphrase prompt)\n"
- " -h Display this help and exit\n"
+ " -f, --file Passphrase file to read from (disables passphrase prompt)\n"
+ " -h, --help Display this help and exit\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
}
int cmd_unlock(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "check", no_argument, NULL, 'c' },
+ { "keyring", required_argument, NULL, 'k' },
+ { "file", required_argument, NULL, 'f' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL }
+ };
const char *keyring = "user";
bool check = false;
const char *passphrase_file_path = NULL;
@@ -32,7 +40,7 @@ int cmd_unlock(int argc, char *argv[])
int opt;
- while ((opt = getopt(argc, argv, "cf:k:h")) != -1)
+ while ((opt = getopt_long(argc, argv, "cf:k:h", longopts, NULL)) != -1)
switch (opt) {
case 'c':
check = true;
diff --git a/c_src/cmd_kill_btree_node.c b/c_src/cmd_kill_btree_node.c
index 81dbdd4b..817cd580 100644
--- a/c_src/cmd_kill_btree_node.c
+++ b/c_src/cmd_kill_btree_node.c
@@ -1,4 +1,5 @@
#include <fcntl.h>
+#include <getopt.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -20,9 +21,8 @@ static void kill_btree_node_usage(void)
"Usage: bcachefs kill_btree_node [OPTION]... <devices>\n"
"\n"
"Options:\n"
- " -b (extents|inodes|dirents|xattrs) Btree to delete from\n"
- " -l level Levle to delete from (0 == leaves)\n"
- " -i index Index of btree node to kill\n"
+ " -n, --node btree:level:idx Node to kill\n"
+ " -d, --dev dev Device index (default: kill all replicas)\n"
" -h Display this help and exit\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
}
@@ -35,13 +35,19 @@ struct kill_node {
int cmd_kill_btree_node(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "node", required_argument, NULL, 'n' },
+ { "dev", required_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL }
+ };
struct bch_opts opts = bch2_opts_empty();
DARRAY(struct kill_node) kill_nodes = {};
- int opt;
+ int opt, dev_idx = -1;
opt_set(opts, read_only, true);
- while ((opt = getopt(argc, argv, "n:h")) != -1)
+ while ((opt = getopt_long(argc, argv, "n:d:h", longopts, NULL)) != -1)
switch (opt) {
case 'n': {
char *p = optarg;
@@ -65,6 +71,10 @@ int cmd_kill_btree_node(int argc, char *argv[])
darray_push(&kill_nodes, n);
break;
}
+ case 'd':
+ if (kstrtoint(optarg, 10, &dev_idx))
+ die("invalid device index %s", optarg);
+ break;
case 'h':
kill_btree_node_usage();
exit(EXIT_SUCCESS);
@@ -96,20 +106,24 @@ int cmd_kill_btree_node(int argc, char *argv[])
int ret2 = 0;
if (!i->idx) {
- struct printbuf buf = PRINTBUF;
- bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
- bch_info(c, "killing btree node %s l=%u %s",
- bch2_btree_id_str(i->btree), i->level, buf.buf);
- printbuf_exit(&buf);
-
ret2 = 1;
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(&b->key));
bkey_for_each_ptr(ptrs, ptr) {
+ if (dev_idx >= 0 && ptr->dev != dev_idx)
+ continue;
+
struct bch_dev *ca = bch2_dev_tryget(c, ptr->dev);
if (!ca)
continue;
+ struct printbuf buf = PRINTBUF;
+ bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
+ bch_info(c, "killing btree node on dev %i %s l=%u\n %s",
+ ptr->dev,
+ bch2_btree_id_str(i->btree), i->level, buf.buf);
+ printbuf_exit(&buf);
+
int ret3 = pwrite(ca->disk_sb.bdev->bd_fd, zeroes,
c->opts.block_size, ptr->offset << 9);
bch2_dev_put(ca);
diff --git a/c_src/cmd_migrate.c b/c_src/cmd_migrate.c
index 91c42302..0d24018c 100644
--- a/c_src/cmd_migrate.c
+++ b/c_src/cmd_migrate.c
@@ -370,19 +370,25 @@ static void migrate_superblock_usage(void)
"Usage: bcachefs migrate-superblock [OPTION]...\n"
"\n"
"Options:\n"
- " -d device Device to create superblock for\n"
- " -o offset Offset of existing superblock\n"
- " -h Display this help and exit\n"
+ " -d, --dev device Device to create superblock for\n"
+ " -o, --offset offset Offset of existing superblock\n"
+ " -h, --help Display this help and exit\n"
"Report bugs to <linux-bcachefs@vger.kernel.org>");
}
int cmd_migrate_superblock(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "dev", required_argument, NULL, 'd' },
+ { "offset", required_argument, NULL, 'o' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL }
+ };
darray_const_str devs = {};
u64 sb_offset = 0;
int opt, ret;
- while ((opt = getopt(argc, argv, "d:o:h")) != -1)
+ while ((opt = getopt_long(argc, argv, "d:o:h", longopts, NULL)) != -1)
switch (opt) {
case 'd':
darray_push(&devs, optarg);