]>
Commit | Line | Data |
---|---|---|
c98132d1 DC |
1 | /* |
2 | * Copyright (c) 2012 Red Hat, Inc. | |
3 | * All Rights Reserved. | |
4 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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 | |
17 | */ | |
18 | ||
19 | #include "libxfs.h" | |
20 | #include "command.h" | |
21 | #include "input.h" | |
22 | #include "init.h" | |
cccf6abc | 23 | #include "path.h" |
c98132d1 DC |
24 | #include "space.h" |
25 | ||
26 | static cmdinfo_t prealloc_cmd; | |
27 | ||
28 | /* | |
29 | * Control preallocation amounts. | |
30 | */ | |
31 | static int | |
32 | prealloc_f( | |
33 | int argc, | |
34 | char **argv) | |
35 | { | |
36 | struct xfs_fs_eofblocks eofb = {0}; | |
37 | int c; | |
38 | ||
39 | eofb.eof_version = XFS_EOFBLOCKS_VERSION; | |
40 | ||
41 | while ((c = getopt(argc, argv, "g:m:p:su:")) != EOF) { | |
42 | switch (c) { | |
43 | case 'g': | |
44 | eofb.eof_flags |= XFS_EOF_FLAGS_GID; | |
45 | eofb.eof_gid = cvt_u32(optarg, 10); | |
46 | if (errno) | |
47 | return command_usage(&prealloc_cmd); | |
48 | break; | |
49 | case 'u': | |
50 | eofb.eof_flags |= XFS_EOF_FLAGS_UID; | |
51 | eofb.eof_uid = cvt_u32(optarg, 10); | |
52 | if (errno) | |
53 | return command_usage(&prealloc_cmd); | |
54 | break; | |
55 | case 'p': | |
56 | eofb.eof_flags |= XFS_EOF_FLAGS_PRID; | |
57 | eofb.eof_prid = cvt_u32(optarg, 10); | |
58 | if (errno) | |
59 | return command_usage(&prealloc_cmd); | |
60 | break; | |
61 | case 's': | |
62 | eofb.eof_flags |= XFS_EOF_FLAGS_SYNC; | |
63 | break; | |
64 | case 'm': | |
65 | eofb.eof_flags |= XFS_EOF_FLAGS_MINFILESIZE; | |
66 | eofb.eof_min_file_size = cvtnum(file->geom.blocksize, | |
67 | file->geom.sectsize, | |
68 | optarg); | |
69 | break; | |
70 | case '?': | |
71 | default: | |
72 | return command_usage(&prealloc_cmd); | |
73 | } | |
74 | } | |
75 | if (optind != argc) | |
76 | return command_usage(&prealloc_cmd); | |
77 | ||
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)); | |
81 | } | |
82 | return 0; | |
83 | } | |
84 | ||
85 | static void | |
86 | prealloc_help(void) | |
87 | { | |
88 | printf(_( | |
89 | "\n" | |
90 | "Remove speculative preallocation\n" | |
91 | "\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" | |
97 | "\n" | |
98 | "If none of -u, -g, or -p are specified, this command acts on all files.\n" | |
99 | "minlen can take units.\n" | |
100 | "\n")); | |
101 | ||
102 | } | |
103 | ||
104 | void | |
105 | prealloc_init(void) | |
106 | { | |
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; | |
116 | ||
117 | add_command(&prealloc_cmd); | |
118 | } | |
119 |