From: Integral <integral@archlinuxcn.org>
To: lihongbo22@huawei.com
Cc: integral@archlinuxcn.org, kent.overstreet@gmail.com,
kent.overstreet@linux.dev, linux-bcachefs@vger.kernel.org,
mmpgouride@gmail.com
Subject: [PATCH v2 combined] bcachefs-tools: add fs_usage & return -EINVAL when no matching subcommand
Date: Mon, 11 Nov 2024 11:49:17 +0800 [thread overview]
Message-ID: <20241111034917.41805-1-integral@archlinuxcn.org> (raw)
In-Reply-To: <5484f8dd-da46-4d95-8a8a-e0d51778b414@huawei.com>
Add the missing usage function for "fs" subcommand; when no matching
subcommand exists, print the usage and return -EINVAL.
Signed-off-by: Integral <integral@archlinuxcn.org>
---
c_src/bcachefs.c | 15 ++++++++-------
c_src/cmd_fs.c | 12 ++++++++++++
c_src/cmds.h | 1 +
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/c_src/bcachefs.c b/c_src/bcachefs.c
index 77bf6215..89e13b75 100644
--- a/c_src/bcachefs.c
+++ b/c_src/bcachefs.c
@@ -113,14 +113,13 @@ int fs_cmds(int argc, char *argv[])
{
char *cmd = pop_cmd(&argc, argv);
- if (argc < 1) {
- bcachefs_usage();
- exit(EXIT_FAILURE);
- }
+ if (argc < 1)
+ return fs_usage();
if (!strcmp(cmd, "usage"))
return cmd_fs_usage(argc, argv);
- return 0;
+ fs_usage();
+ return -EINVAL;
}
int device_cmds(int argc, char *argv[])
@@ -146,7 +145,8 @@ int device_cmds(int argc, char *argv[])
if (!strcmp(cmd, "resize-journal"))
return cmd_device_resize_journal(argc, argv);
- return 0;
+ device_usage();
+ return -EINVAL;
}
int data_cmds(int argc, char *argv[])
@@ -160,5 +160,6 @@ int data_cmds(int argc, char *argv[])
if (!strcmp(cmd, "job"))
return cmd_data_job(argc, argv);
- return 0;
+ data_usage();
+ return -EINVAL;
}
diff --git a/c_src/cmd_fs.c b/c_src/cmd_fs.c
index 82eeceff..eb8f7d2e 100644
--- a/c_src/cmd_fs.c
+++ b/c_src/cmd_fs.c
@@ -487,6 +487,18 @@ devs:
bcache_fs_close(fs);
}
+int fs_usage(void)
+{
+ puts("bcachefs fs - manage a running filesystem\n"
+ "Usage: bcachefs fs <CMD> [OPTIONS]\n"
+ "\n"
+ "Commands:\n"
+ " usage Display detailed filesystem usage\n"
+ "\n"
+ "Report bugs to <linux-bcachefs@vger.kernel.org>");
+ return 0;
+}
+
static void fs_usage_usage(void)
{
puts("bcachefs fs usage - display detailed filesystem usage\n"
diff --git a/c_src/cmds.h b/c_src/cmds.h
index 64267dc4..99016d52 100644
--- a/c_src/cmds.h
+++ b/c_src/cmds.h
@@ -14,6 +14,7 @@ int cmd_show_super(int argc, char *argv[]);
int cmd_reset_counters(int argc, char *argv[]);
int cmd_set_option(int argc, char *argv[]);
+int fs_usage(void);
int cmd_fs_usage(int argc, char *argv[]);
int device_usage(void);
--
2.47.0
prev parent reply other threads:[~2024-11-11 3:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-09 18:56 [PATCH] bcachefs-tools: add usage function for fs subcommand Integral
2024-11-11 2:17 ` Hongbo Li
2024-11-11 3:49 ` Integral [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241111034917.41805-1-integral@archlinuxcn.org \
--to=integral@archlinuxcn.org \
--cc=kent.overstreet@gmail.com \
--cc=kent.overstreet@linux.dev \
--cc=lihongbo22@huawei.com \
--cc=linux-bcachefs@vger.kernel.org \
--cc=mmpgouride@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox