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 prealloc_cmd
;
29 * Control preallocation amounts.
36 struct xfs_fs_eofblocks eofb
= {0};
39 eofb
.eof_version
= XFS_EOFBLOCKS_VERSION
;
41 while ((c
= getopt(argc
, argv
, "g:m:p:su:")) != EOF
) {
44 eofb
.eof_flags
|= XFS_EOF_FLAGS_GID
;
45 eofb
.eof_gid
= cvt_u32(optarg
, 10);
47 return command_usage(&prealloc_cmd
);
50 eofb
.eof_flags
|= XFS_EOF_FLAGS_UID
;
51 eofb
.eof_uid
= cvt_u32(optarg
, 10);
53 return command_usage(&prealloc_cmd
);
56 eofb
.eof_flags
|= XFS_EOF_FLAGS_PRID
;
57 eofb
.eof_prid
= cvt_u32(optarg
, 10);
59 return command_usage(&prealloc_cmd
);
62 eofb
.eof_flags
|= XFS_EOF_FLAGS_SYNC
;
65 eofb
.eof_flags
|= XFS_EOF_FLAGS_MINFILESIZE
;
66 eofb
.eof_min_file_size
= cvtnum(file
->geom
.blocksize
,
72 return command_usage(&prealloc_cmd
);
76 return command_usage(&prealloc_cmd
);
78 if (ioctl(file
->fd
, XFS_IOC_FREE_EOFBLOCKS
, &eofb
) < 0) {
79 fprintf(stderr
, _("%s: XFS_IOC_FREE_EOFBLOCKS on %s: %s\n"),
80 progname
, file
->name
, strerror(errno
));
90 "Remove speculative preallocation\n"
92 " -g gid -- remove prealloc on files matching group <gid>\n"
93 " -m minlen -- only consider files larger than <minlen>\n"
94 " -p prid -- remove prealloc on files matching project <prid>\n"
95 " -s -- wait for removal to complete\n"
96 " -u uid -- remove prealloc on files matching user <uid>\n"
98 "If none of -u, -g, or -p are specified, this command acts on all files.\n"
99 "minlen can take units.\n"
107 prealloc_cmd
.name
= "prealloc";
108 prealloc_cmd
.altname
= "prealloc";
109 prealloc_cmd
.cfunc
= prealloc_f
;
110 prealloc_cmd
.argmin
= 1;
111 prealloc_cmd
.argmax
= -1;
112 prealloc_cmd
.args
= "[-s] [-u id] [-g id] [-p id] [-m minlen]";
113 prealloc_cmd
.flags
= CMD_FLAG_ONESHOT
;
114 prealloc_cmd
.oneline
= _("Remove speculative preallocation");
115 prealloc_cmd
.help
= prealloc_help
;
117 add_command(&prealloc_cmd
);