Date: Sat, 29 Jan 2011 22:51:46 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r218080 - in stable/8/sbin: dumpfs geom/class/sched newfs tunefs Message-ID: <201101292251.p0TMpk0I048417@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sat Jan 29 22:51:46 2011 New Revision: 218080 URL: http://svn.freebsd.org/changeset/base/218080 Log: MFC r216798: Add support for FS_TRIM to user-mode UFS utilities. Tested by: pho Modified: stable/8/sbin/dumpfs/dumpfs.c stable/8/sbin/newfs/mkfs.c stable/8/sbin/newfs/newfs.8 stable/8/sbin/newfs/newfs.c stable/8/sbin/newfs/newfs.h stable/8/sbin/tunefs/tunefs.8 stable/8/sbin/tunefs/tunefs.c Directory Properties: stable/8/sbin/ (props changed) stable/8/sbin/atacontrol/ (props changed) stable/8/sbin/bsdlabel/ (props changed) stable/8/sbin/camcontrol/ (props changed) stable/8/sbin/ddb/ (props changed) stable/8/sbin/devd/ (props changed) stable/8/sbin/devfs/ (props changed) stable/8/sbin/dhclient/ (props changed) stable/8/sbin/dump/ (props changed) stable/8/sbin/dumpfs/ (props changed) stable/8/sbin/fdisk/ (props changed) stable/8/sbin/fsck/ (props changed) stable/8/sbin/fsck_ffs/ (props changed) stable/8/sbin/fsck_msdosfs/ (props changed) stable/8/sbin/fsirand/ (props changed) stable/8/sbin/geom/ (props changed) stable/8/sbin/geom/class/multipath/ (props changed) stable/8/sbin/geom/class/part/ (props changed) stable/8/sbin/geom/class/sched/gsched.8 (props changed) stable/8/sbin/geom/class/stripe/ (props changed) stable/8/sbin/ggate/ (props changed) stable/8/sbin/growfs/ (props changed) stable/8/sbin/hastctl/ (props changed) stable/8/sbin/hastd/ (props changed) stable/8/sbin/ifconfig/ (props changed) stable/8/sbin/ipfw/ (props changed) stable/8/sbin/iscontrol/ (props changed) stable/8/sbin/kldload/ (props changed) stable/8/sbin/kldstat/ (props changed) stable/8/sbin/mdconfig/ (props changed) stable/8/sbin/mksnap_ffs/ (props changed) stable/8/sbin/mount/ (props changed) stable/8/sbin/mount_cd9660/ (props changed) stable/8/sbin/mount_msdosfs/ (props changed) stable/8/sbin/mount_nfs/ (props changed) stable/8/sbin/natd/ (props changed) stable/8/sbin/newfs/ (props changed) stable/8/sbin/newfs_msdos/ (props changed) stable/8/sbin/ping6/ (props changed) stable/8/sbin/reboot/ (props changed) stable/8/sbin/restore/ (props changed) stable/8/sbin/route/ (props changed) stable/8/sbin/routed/ (props changed) stable/8/sbin/setkey/ (props changed) stable/8/sbin/spppcontrol/ (props changed) stable/8/sbin/sysctl/ (props changed) stable/8/sbin/tunefs/ (props changed) stable/8/sbin/umount/ (props changed) Modified: stable/8/sbin/dumpfs/dumpfs.c ============================================================================== --- stable/8/sbin/dumpfs/dumpfs.c Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/dumpfs/dumpfs.c Sat Jan 29 22:51:46 2011 (r218080) @@ -253,9 +253,11 @@ dumpfs(const char *name) printf("fs_flags expanded "); if (fsflags & FS_NFS4ACLS) printf("nfsv4acls "); + if (fsflags & FS_TRIM) + printf("trim "); fsflags &= ~(FS_UNCLEAN | FS_DOSOFTDEP | FS_NEEDSFSCK | FS_INDEXDIRS | FS_ACLS | FS_MULTILABEL | FS_GJOURNAL | FS_FLAGS_UPDATED | - FS_NFS4ACLS); + FS_NFS4ACLS | FS_TRIM); if (fsflags != 0) printf("unknown flags (%#x)", fsflags); putchar('\n'); Modified: stable/8/sbin/newfs/mkfs.c ============================================================================== --- stable/8/sbin/newfs/mkfs.c Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/newfs/mkfs.c Sat Jan 29 22:51:46 2011 (r218080) @@ -151,6 +151,8 @@ mkfs(struct partition *pp, char *fsys) sblock.fs_flags |= FS_GJOURNAL; if (lflag) sblock.fs_flags |= FS_MULTILABEL; + if (tflag) + sblock.fs_flags |= FS_TRIM; /* * Validate the given file system size. * Verify that its last block can actually be accessed. Modified: stable/8/sbin/newfs/newfs.8 ============================================================================== --- stable/8/sbin/newfs/newfs.8 Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/newfs/newfs.8 Sat Jan 29 22:51:46 2011 (r218080) @@ -28,7 +28,7 @@ .\" @(#)newfs.8 8.6 (Berkeley) 5/3/95 .\" $FreeBSD$ .\" -.Dd March 21, 2008 +.Dd December 9, 2010 .Dt NEWFS 8 .Os .Sh NAME @@ -36,7 +36,7 @@ .Nd construct a new UFS1/UFS2 file system .Sh SYNOPSIS .Nm -.Op Fl EJNUln +.Op Fl EJNUlnt .Op Fl L Ar volname .Op Fl O Ar filesystem-type .Op Fl S Ar sector-size @@ -240,6 +240,14 @@ A valid .Ar size value cannot be larger than the default one, which means that the file system cannot extend into the reserved space. +.It Fl t +Turn on the TRIM enable flag. +If enabled, and if the underlying device supports the BIO_DELETE +command, the file system will send a delete request to the underlying +device for each freed block. +The trim enable flag is typically set when the underlying device +uses flash-memory as the device can use the delete command to +pre-zero or at least avoid copying blocks that have been deleted. .El .Pp The following options override the standard sizes for the disk geometry. Modified: stable/8/sbin/newfs/newfs.c ============================================================================== --- stable/8/sbin/newfs/newfs.c Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/newfs/newfs.c Sat Jan 29 22:51:46 2011 (r218080) @@ -89,6 +89,7 @@ int Xflag = 0; /* exit in middle of new int Jflag; /* enable gjournal for file system */ int lflag; /* enable multilabel for file system */ int nflag; /* do not create .snap directory */ +int tflag; /* enable TRIM */ intmax_t fssize; /* file system size */ int sectorsize; /* bytes/sector */ int realsectorsize; /* bytes/sector in hardware */ @@ -136,7 +137,7 @@ main(int argc, char *argv[]) part_name = 'c'; reserved = 0; while ((ch = getopt(argc, argv, - "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:p:r:s:")) != -1) + "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:p:r:s:t")) != -1) switch (ch) { case 'E': Eflag = 1; @@ -263,6 +264,9 @@ main(int argc, char *argv[]) *cp != '\0' || fssize < 0) errx(1, "%s: bad file system size", optarg); break; + case 't': + tflag = 1; + break; case '?': default: usage(); @@ -479,5 +483,6 @@ usage() fprintf(stderr, "\t-p partition name (a..h)\n"); fprintf(stderr, "\t-r reserved sectors at the end of device\n"); fprintf(stderr, "\t-s file system size (sectors)\n"); + fprintf(stderr, "\t-t enable TRIM\n"); exit(1); } Modified: stable/8/sbin/newfs/newfs.h ============================================================================== --- stable/8/sbin/newfs/newfs.h Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/newfs/newfs.h Sat Jan 29 22:51:46 2011 (r218080) @@ -85,6 +85,7 @@ extern int Xflag; /* exit in middle of extern int Jflag; /* enable gjournal for file system */ extern int lflag; /* enable multilabel MAC for file system */ extern int nflag; /* do not create .snap directory */ +extern int tflag; /* enable TRIM */ extern intmax_t fssize; /* file system size */ extern int sectorsize; /* bytes/sector */ extern int realsectorsize; /* bytes/sector in hardware*/ Modified: stable/8/sbin/tunefs/tunefs.8 ============================================================================== --- stable/8/sbin/tunefs/tunefs.8 Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/tunefs/tunefs.8 Sat Jan 29 22:51:46 2011 (r218080) @@ -28,7 +28,7 @@ .\" @(#)tunefs.8 8.2 (Berkeley) 12/11/93 .\" $FreeBSD$ .\" -.Dd August 13, 2007 +.Dd December 9, 2010 .Dt TUNEFS 8 .Os .Sh NAME @@ -49,6 +49,7 @@ .Op Fl o Cm space | time .Op Fl p .Op Fl s Ar avgfpdir +.Op Fl t Cm enable | disable .Ar special | filesystem .Sh DESCRIPTION The @@ -136,6 +137,14 @@ obtained from the utility. .It Fl s Ar avgfpdir Specify the expected number of files per directory. +.It Fl t Cm enable | disable +Turn on/off the TRIM enable flag. +If enabled, and if the underlying device supports the BIO_DELETE +command, the file system will send a delete request to the underlying +device for each freed block. +The trim enable flag is typically set when the underlying device +uses flash-memory as the device can use the delete command to +pre-zero or at least avoid copying blocks that have been deleted. .El .Pp At least one of the above flags is required. Modified: stable/8/sbin/tunefs/tunefs.c ============================================================================== --- stable/8/sbin/tunefs/tunefs.c Sat Jan 29 22:51:27 2011 (r218079) +++ stable/8/sbin/tunefs/tunefs.c Sat Jan 29 22:51:46 2011 (r218080) @@ -77,11 +77,13 @@ int main(int argc, char *argv[]) { char *avalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue; + char *tvalue; const char *special, *on; const char *name; int active; int Aflag, aflag, eflag, evalue, fflag, fvalue, Jflag, Lflag, lflag; int mflag, mvalue, Nflag, nflag, oflag, ovalue, pflag, sflag, svalue; + int tflag; int ch, found_arg, i; const char *chg[2]; struct ufs_args args; @@ -90,12 +92,12 @@ main(int argc, char *argv[]) if (argc < 3) usage(); Aflag = aflag = eflag = fflag = Jflag = Lflag = lflag = mflag = 0; - Nflag = nflag = oflag = pflag = sflag = 0; + Nflag = nflag = oflag = pflag = sflag = tflag = 0; avalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL; evalue = fvalue = mvalue = ovalue = svalue = 0; active = 0; found_arg = 0; /* At least one arg is required. */ - while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:N:n:o:ps:")) != -1) + while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:N:n:o:ps:t:")) != -1) switch (ch) { case 'A': @@ -240,6 +242,18 @@ main(int argc, char *argv[]) sflag = 1; break; + case 't': + found_arg = 1; + name = "trim"; + tvalue = optarg; + if (strcmp(tvalue, "enable") != 0 && + strcmp(tvalue, "disable") != 0) { + errx(10, "bad %s (options are %s)", + name, "`enable' or `disable'"); + } + tflag = 1; + break; + default: usage(); } @@ -436,6 +450,24 @@ main(int argc, char *argv[]) sblock.fs_avgfpdir = svalue; } } + if (tflag) { + name = "issue TRIM to the disk"; + if (strcmp(tvalue, "enable") == 0) { + if (sblock.fs_flags & FS_TRIM) + warnx("%s remains unchanged as enabled", name); + else { + sblock.fs_flags |= FS_TRIM; + warnx("%s set", name); + } + } else if (strcmp(tvalue, "disable") == 0) { + if ((~sblock.fs_flags & FS_TRIM) == FS_TRIM) + warnx("%s remains unchanged as disabled", name); + else { + sblock.fs_flags &= ~FS_TRIM; + warnx("%s cleared", name); + } + } + } if (sbwrite(&disk, Aflag) == -1) goto err; @@ -458,11 +490,12 @@ err: void usage(void) { - fprintf(stderr, "%s\n%s\n%s\n%s\n", + fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]", " [-J enable | disable ] [-L volname] [-l enable | disable]", " [-m minfree] [-N enable | disable] [-n enable | disable]", -" [-o space | time] [-p] [-s avgfpdir] special | filesystem"); +" [-o space | time] [-p] [-s avgfpdir] [-t enable | disable]", +" special | filesystem"); exit(2); } @@ -479,6 +512,8 @@ printfs(void) (sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled"); warnx("gjournal: (-J) %s", (sblock.fs_flags & FS_GJOURNAL)? "enabled" : "disabled"); + warnx("trim: (-t) %s", + (sblock.fs_flags & FS_TRIM)? "enabled" : "disabled"); warnx("maximum blocks per file in a cylinder group: (-e) %d", sblock.fs_maxbpg); warnx("average file size: (-f) %d",
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101292251.p0TMpk0I048417>