From: yanhuan916@gmail.com
To: linux-bcache@vger.kernel.org
Cc: colyli@suse.de, dahefanteng@gmail.com, Huan Yan <yanhuan916@gmail.com>
Subject: [PATCH 1/2] bcache-tools: make --discard a per device option
Date: Fri, 25 Jun 2021 09:30:29 +0800 [thread overview]
Message-ID: <1624584630-9283-1-git-send-email-yanhuan916@gmail.com> (raw)
From: Huan Yan <yanhuan916@gmail.com>
This patch make --discard option more flexible, it can be indicated after each
backing or cache device.
---
make.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 48 insertions(+), 14 deletions(-)
diff --git a/make.c b/make.c
index 34d8011..39b381a 100644
--- a/make.c
+++ b/make.c
@@ -402,6 +402,18 @@ static void write_sb(char *dev, struct sb_context *sbc, bool bdev, bool force)
(unsigned int) sb.version,
sb.block_size,
data_offset);
+
+ /* Attempting to discard backing device
+ */
+ if (discard) {
+ if (blkdiscard_all(dev, fd) < 0) {
+ fprintf(stderr,
+ "Failed to discard device %s, %s\n",
+ dev, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
+
putchar('\n');
} else {
if (nvdimm_meta)
@@ -446,8 +458,15 @@ static void write_sb(char *dev, struct sb_context *sbc, bool bdev, bool force)
/* Attempting to discard cache device
*/
- if (discard)
- blkdiscard_all(dev, fd);
+ if (discard) {
+ if (blkdiscard_all(dev, fd) < 0) {
+ fprintf(stderr,
+ "Failed to discard device %s, %s\n",
+ dev, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
+
putchar('\n');
}
@@ -660,21 +679,27 @@ static unsigned int get_blocksize(const char *path)
int make_bcache(int argc, char **argv)
{
int c;
- unsigned int i;
+ unsigned int i, n;
int cdev = -1, bdev = -1, mdev = -1;
unsigned int ncache_devices = 0, ncache_nvm_devices = 0;
unsigned int nbacking_devices = 0;
char *cache_devices[argc];
char *cache_nvm_devices[argc];
char *backing_devices[argc];
+ bool cache_devices_discard[argc];
+ bool backing_devices_discard[argc];
+ bool *device_discard = NULL;
char label[SB_LABEL_SIZE] = { 0 };
unsigned int block_size = 0, bucket_size = 1024;
- int writeback = 0, discard = 0, wipe_bcache = 0, force = 0;
+ int writeback = 0, wipe_bcache = 0, force = 0;
unsigned int cache_replacement_policy = 0;
uint64_t data_offset = BDEV_DATA_START_DEFAULT;
uuid_t set_uuid;
struct sb_context sbc;
+ memset(cache_devices_discard, 0, sizeof(cache_devices_discard));
+ memset(backing_devices_discard, 0, sizeof(backing_devices_discard));
+
uuid_generate(set_uuid);
struct option opts[] = {
@@ -685,10 +710,8 @@ int make_bcache(int argc, char **argv)
{ "block", 1, NULL, 'w' },
{ "writeback", 0, &writeback, 1 },
{ "wipe-bcache", 0, &wipe_bcache, 1 },
- { "discard", 0, &discard, 1 },
- { "cache_replacement_policy", 1, NULL, 'p' },
+ { "discard", 0, NULL, 'd' },
{ "cache-replacement-policy", 1, NULL, 'p' },
- { "data_offset", 1, NULL, 'o' },
{ "data-offset", 1, NULL, 'o' },
{ "cset-uuid", 1, NULL, 'u' },
{ "help", 0, NULL, 'h' },
@@ -710,6 +733,10 @@ int make_bcache(int argc, char **argv)
case 'M':
mdev = 1;
break;
+ case 'd':
+ if (device_discard)
+ *device_discard = true;
+ break;
case 'b':
bucket_size =
hatoi_validate(optarg, "bucket size", UINT_MAX);
@@ -762,15 +789,20 @@ int make_bcache(int argc, char **argv)
}
if (bdev > 0) {
- backing_devices[nbacking_devices++] = optarg;
- printf("backing_devices[%d]: %s\n", nbacking_devices - 1, optarg);
+ n = nbacking_devices++;
+ backing_devices[n] = optarg;
+ printf("backing_devices[%d]: %s\n", n, optarg);
+ device_discard = &backing_devices_discard[n];
bdev = -1;
} else if (cdev > 0) {
- cache_devices[ncache_devices++] = optarg;
- printf("cache_devices[%d]: %s\n", ncache_devices - 1, optarg);
+ n = ncache_devices++;
+ cache_devices[n] = optarg;
+ printf("cache_devices[%d]: %s\n", n, optarg);
+ device_discard = &cache_devices_discard[n];
cdev = -1;
} else if (mdev > 0) {
- cache_nvm_devices[ncache_nvm_devices++] = optarg;
+ n = ncache_nvm_devices++;
+ cache_nvm_devices[n] = optarg;
mdev = -1;
}
break;
@@ -806,7 +838,6 @@ int make_bcache(int argc, char **argv)
sbc.block_size = block_size;
sbc.bucket_size = bucket_size;
sbc.writeback = writeback;
- sbc.discard = discard;
sbc.wipe_bcache = wipe_bcache;
sbc.cache_replacement_policy = cache_replacement_policy;
sbc.data_offset = data_offset;
@@ -814,13 +845,16 @@ int make_bcache(int argc, char **argv)
sbc.label = label;
sbc.nvdimm_meta = (ncache_nvm_devices > 0) ? true : false;
- for (i = 0; i < ncache_devices; i++)
+ for (i = 0; i < ncache_devices; i++) {
+ sbc.discard = cache_devices_discard[i];
write_sb(cache_devices[i], &sbc, false, force);
+ }
for (i = 0; i < nbacking_devices; i++) {
check_data_offset_for_zoned_device(backing_devices[i],
&sbc.data_offset);
+ sbc.discard = backing_devices_discard[i];
write_sb(backing_devices[i], &sbc, true, force);
}
--
1.8.3.1
next reply other threads:[~2021-06-25 1:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-25 1:30 yanhuan916 [this message]
2021-06-25 1:30 ` [PATCH 2/2] bcache-tools: Correct super block version check codes yanhuan916
2021-06-28 8:15 ` Wu Bo
2022-05-13 15:05 ` Coly Li
2021-06-28 16:09 ` [PATCH 1/2] bcache-tools: make --discard a per device option Coly Li
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=1624584630-9283-1-git-send-email-yanhuan916@gmail.com \
--to=yanhuan916@gmail.com \
--cc=colyli@suse.de \
--cc=dahefanteng@gmail.com \
--cc=linux-bcache@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).