Skip to contentSkip to conversation

gfs2_grow: Optionally allow not issuing discard requests

PATCH Applied Mark Syms 2 participants 2 messages Feb 19, 2025

lore
Share & tools
lore

Mark Syms

author
#0 lore raw

PATCH v3 1/1 gfs2_grow: Optionally allow not issuing discard requests

mkfs.gfs2 supports a -K option which disables issuing discard requests for unused blocks on the LUN. gfs2_grow does not have an equivalent option so even if the filesystem was originally created with the -K option a subsequent grow operation will incur the, potentially high, cost of performing the discard.

---
v2:
* Fix indentation of break statement
v3:
* Update man page with the new option

---
 gfs2/man/gfs2_grow.8  |  6 ++++++
 gfs2/mkfs/main_grow.c | 11 +++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
gfs2/man/gfs2_grow.8 +6 -0
index f1ba5e4e..ed962dca 100644
@@ -38,6 +38,12 @@ Prints out a short usage message and exits.
 \fB-q\fP
 Be quiet.  Don't print anything.
 .TP
+\fB-K\fP
+Do not attempt to discard the block device contents. Issuing discards to the
+device allows some solid state devices and sparse or thin-provisioned storage
+devices to optimise free space. Other devices may emulate this behaviour by
+zeroing the device contents, which can be a slow process.
+.TP
 \fB-T\fP
 Test. Do all calculations, but do not write any data to the disk and do not
 expand the filesystem. This is used to discover what the tool would have done
gfs2/mkfs/main_grow.c +9 -2
index e378a668..2d74c3fa 100644
@@ -31,6 +31,7 @@
 static uint64_t override_device_size = 0;
 static int test = 0;
 static uint64_t fssize = 0, fsgrowth;
+static int skip_discard = 0;
 int print_level = MSG_NOTICE;
 
 extern int create_new_inode(struct lgfs2_sbd *sdp);
@@ -72,6 +73,7 @@ static void usage(void)
 		"-T", NULL, _("Do everything except update file system"),
 		"-V", NULL, _("Display version information"),
 		"-v", NULL, _("Increase verbosity"),
+		"-K", NULL, _("Don't try to discard unused blocks"),
 		NULL, NULL, NULL /* Must be kept at the end */
 	};
 
@@ -92,7 +94,7 @@ static void decode_arguments(int argc, char *argv[], struct lgfs2_sbd *sdp)
 {
 	int opt;
 
-	while ((opt = getopt(argc, argv, "VD:hqTv?")) != EOF) {
+	while ((opt = getopt(argc, argv, "VD:hqTv?K")) != EOF) {
 		switch (opt) {
 		case 'D':	/* This option is for testing only */
 			override_device_size = atoi(optarg);
@@ -116,6 +118,9 @@ static void decode_arguments(int argc, char *argv[], struct lgfs2_sbd *sdp)
 		case 'v':
 			increase_verbosity();
 			break;
+		case 'K':
+			skip_discard = 1;
+			break;
 		case ':':
 		case '?':
 			/* Unknown flag */
@@ -207,7 +212,9 @@ static unsigned initialize_new_portion(struct lgfs2_sbd *sdp, lgfs2_rgrps_t rgs)
 	unsigned rgcount = 0;
 	uint64_t rgaddr = fssize;
 
-	discard_blocks(sdp->device_fd, rgaddr * sdp->sd_bsize, fsgrowth * sdp->sd_bsize);
+	if (skip_discard == 0)
+		discard_blocks(sdp->device_fd, rgaddr * sdp->sd_bsize, fsgrowth * sdp->sd_bsize);
+
 	/* Build the remaining resource groups */
 	while (1) {
 		int err = 0;
Signature · 1 line
2.48.1
Applied
#1 lore raw
Quoted 6 lines · Mark Syms

mkfs.gfs2 supports a -K option which disables issuing discard requests for unused blocks on the LUN. gfs2_grow does not have an equivalent option so even if the filesystem was originally created with the -K option a subsequent grow operation will incur the, potentially high, cost of performing the discard.

Quoted 7 lines

---
v2:
* Fix indentation of break statement
v3:
* Update man page with the new option

Applied, thanks.

Andy

Quoted 72 lines
---
  gfs2/man/gfs2_grow.8  |  6 ++++++
  gfs2/mkfs/main_grow.c | 11 +++++++++--
  2 files changed, 15 insertions(+), 2 deletions(-)
gfs2/man/gfs2_grow.8 +6 -0
index f1ba5e4e..ed962dca 100644
@@ -38,6 +38,12 @@ Prints out a short usage message and exits.
  \fB-q\fP
  Be quiet.  Don't print anything.
  .TP
+\fB-K\fP
+Do not attempt to discard the block device contents. Issuing discards to the
+device allows some solid state devices and sparse or thin-provisioned storage
+devices to optimise free space. Other devices may emulate this behaviour by
+zeroing the device contents, which can be a slow process.
+.TP
  \fB-T\fP
  Test. Do all calculations, but do not write any data to the disk and do not
  expand the filesystem. This is used to discover what the tool would have done
gfs2/mkfs/main_grow.c +9 -2
index e378a668..2d74c3fa 100644
@@ -31,6 +31,7 @@
  static uint64_t override_device_size = 0;
  static int test = 0;
  static uint64_t fssize = 0, fsgrowth;
+static int skip_discard = 0;
  int print_level = MSG_NOTICE;
 
  extern int create_new_inode(struct lgfs2_sbd *sdp);
@@ -72,6 +73,7 @@ static void usage(void)
  		"-T", NULL, _("Do everything except update file system"),
  		"-V", NULL, _("Display version information"),
  		"-v", NULL, _("Increase verbosity"),
+		"-K", NULL, _("Don't try to discard unused blocks"),
  		NULL, NULL, NULL /* Must be kept at the end */
  	};
 
@@ -92,7 +94,7 @@ static void decode_arguments(int argc, char *argv[], struct lgfs2_sbd *sdp)
  {
  	int opt;
 
-	while ((opt = getopt(argc, argv, "VD:hqTv?")) != EOF) {
+	while ((opt = getopt(argc, argv, "VD:hqTv?K")) != EOF) {
  		switch (opt) {
  		case 'D':	/* This option is for testing only */
  			override_device_size = atoi(optarg);
@@ -116,6 +118,9 @@ static void decode_arguments(int argc, char *argv[], struct lgfs2_sbd *sdp)
  		case 'v':
  			increase_verbosity();
  			break;
+		case 'K':
+			skip_discard = 1;
+			break;
  		case ':':
  		case '?':
  			/* Unknown flag */
@@ -207,7 +212,9 @@ static unsigned initialize_new_portion(struct lgfs2_sbd *sdp, lgfs2_rgrps_t rgs)
  	unsigned rgcount = 0;
  	uint64_t rgaddr = fssize;
 
-	discard_blocks(sdp->device_fd, rgaddr * sdp->sd_bsize, fsgrowth * sdp->sd_bsize);
+	if (skip_discard == 0)
+		discard_blocks(sdp->device_fd, rgaddr * sdp->sd_bsize, fsgrowth * sdp->sd_bsize);
+
  	/* Build the remaining resource groups */
  	while (1) {
  		int err = 0;