Skip to contentSkip to conversation

GFS2: Support discard requests

Cluster-devel Steven Whitehouse 1 participant 1 message Feb 6, 2009 GFS2 file system

lore
Share & tools
lore
#0 lore raw

This patch allows GFS2 to generate discard requests for blocks which are no longer useful to the filesystem (i.e. those which have been freed as the result of an unlink operation). The requests are generated at the time which those blocks become available for reuse in the filesystem.

In order to use this new feature, you have to specify the "discard" mount option. The code coalesces adjacent blocks into a single extent when generating the discard requests, thus generating the minimum number.

If an error occurs when the request has been sent to the block device, then it will print a message and turn off the requests for that filesystem. If the problem is temporary, then you can use remount to turn the option back on again.

I've been unable to test this properly so far as I don't have any hardware which supports the requests (I don't need it to actually do anything with them, just ignoring them rather than returning EOPNOTSUPP would be enough). It should be possible to create a test program for this feature using a combination of stat, FIEMAP and blktrace. If I can find a block device which supports discard requests, I'll try and create a suitable test program.

fs/gfs2/incore.h +1 -1
index 8fe0675..3f29bd2 100644
@@ -416,7 +416,7 @@ struct gfs2_args {
 	unsigned int ar_suiddir:1;		/* suiddir support */
 	unsigned int ar_data:2;			/* ordered/writeback */
 	unsigned int ar_meta:1;			/* mount metafs */
-	unsigned int ar_num_glockd;		/* Number of glockd threads */
+	unsigned int ar_discard:1;		/* discard requests */
 };
 
 struct gfs2_tune {
fs/gfs2/mount.c +5 -0
index fba502a..88217b5 100644
@@ -41,6 +41,7 @@ enum {
 	Opt_data_writeback,
 	Opt_data_ordered,
 	Opt_meta,
+	Opt_discard,
 	Opt_err,
 };
 
@@ -65,6 +66,7 @@ static const match_table_t tokens = {
 	{Opt_data_writeback, "data=writeback"},
 	{Opt_data_ordered, "data=ordered"},
 	{Opt_meta, "meta"},
+	{Opt_discard, "discard"},
 	{Opt_err, NULL}
 };
 
@@ -157,6 +159,9 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
 		case Opt_meta:
 			args->ar_meta = 1;
 			break;
+		case Opt_discard:
+			args->ar_discard = 1;
+			break;
 		case Opt_err:
 		default:
 			fs_info(sdp, "invalid mount option: %s\n", o);
fs/gfs2/ops_super.c +2 -0
index 4ecdad0..4580195 100644
@@ -608,6 +608,8 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
 		}
 		seq_printf(s, ",data=%s", state);
 	}
+	if (args->ar_discard)
+		seq_printf(s, ",discard");
 
 	return 0;
 }
fs/gfs2/rgrp.c +57 -0

75 lines not on this page · raw message