]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - spaceman/trim.c
2 * Copyright (c) 2012 Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 static cmdinfo_t trim_cmd
;
29 * Trim unused space in xfs filesystem.
36 struct fstrim_range trim
= {0};
37 xfs_agnumber_t agno
= 0;
46 while ((c
= getopt(argc
, argv
, "a:fm:")) != EOF
) {
50 agno
= cvt_u32(optarg
, 10);
52 printf(_("bad agno value %s\n"), optarg
);
53 return command_usage(&trim_cmd
);
60 minlen
= cvtnum(file
->geom
.blocksize
,
61 file
->geom
.sectsize
, optarg
);
64 return command_usage(&trim_cmd
);
69 return command_usage(&trim_cmd
);
71 if (optind
!= argc
- 2 && !(aflag
|| fflag
))
72 return command_usage(&trim_cmd
);
74 offset
= cvtnum(file
->geom
.blocksize
, file
->geom
.sectsize
,
76 length
= cvtnum(file
->geom
.blocksize
, file
->geom
.sectsize
,
79 offset
= (off64_t
)agno
* file
->geom
.agblocks
* file
->geom
.blocksize
;
80 length
= file
->geom
.agblocks
* file
->geom
.blocksize
;
83 length
= file
->geom
.datablocks
* file
->geom
.blocksize
;
90 ret
= ioctl(file
->fd
, FITRIM
, (unsigned long)&trim
);
92 fprintf(stderr
, "%s: ioctl(FITRIM) [\"%s\"]: %s\n",
93 progname
, file
->name
, strerror(errno
));
104 "Discard filesystem free space\n"
106 " -a agno -- trim all the freespace in the given AG agno\n"
107 " -f -- trim all the freespace in the entire filesystem\n"
108 " offset length -- trim the freespace in the range {offset, length}\n"
109 " -m minlen -- skip freespace extents smaller than minlen\n"
111 "One of -a, -f, or the offset/length pair are required.\n"
119 trim_cmd
.name
= "trim";
120 trim_cmd
.altname
= "tr";
121 trim_cmd
.cfunc
= trim_f
;
124 trim_cmd
.args
= "[-m minlen] ( -a agno | -f | offset length )";
125 trim_cmd
.flags
= CMD_FLAG_ONESHOT
;
126 trim_cmd
.oneline
= _("Discard filesystem free space");
127 trim_cmd
.help
= trim_help
;
129 add_command(&trim_cmd
);