]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - spaceman/prealloc.c
xfs: add firstblock field to xfs_trans
[thirdparty/xfsprogs-dev.git] / spaceman / prealloc.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
c98132d1
DC
2/*
3 * Copyright (c) 2012 Red Hat, Inc.
4 * All Rights Reserved.
c98132d1
DC
5 */
6
7#include "libxfs.h"
8#include "command.h"
9#include "input.h"
10#include "init.h"
cccf6abc 11#include "path.h"
c98132d1
DC
12#include "space.h"
13
14static cmdinfo_t prealloc_cmd;
15
16/*
17 * Control preallocation amounts.
18 */
19static int
20prealloc_f(
21 int argc,
22 char **argv)
23{
24 struct xfs_fs_eofblocks eofb = {0};
25 int c;
26
27 eofb.eof_version = XFS_EOFBLOCKS_VERSION;
28
29 while ((c = getopt(argc, argv, "g:m:p:su:")) != EOF) {
30 switch (c) {
31 case 'g':
32 eofb.eof_flags |= XFS_EOF_FLAGS_GID;
33 eofb.eof_gid = cvt_u32(optarg, 10);
34 if (errno)
35 return command_usage(&prealloc_cmd);
36 break;
37 case 'u':
38 eofb.eof_flags |= XFS_EOF_FLAGS_UID;
39 eofb.eof_uid = cvt_u32(optarg, 10);
40 if (errno)
41 return command_usage(&prealloc_cmd);
42 break;
43 case 'p':
44 eofb.eof_flags |= XFS_EOF_FLAGS_PRID;
45 eofb.eof_prid = cvt_u32(optarg, 10);
46 if (errno)
47 return command_usage(&prealloc_cmd);
48 break;
49 case 's':
50 eofb.eof_flags |= XFS_EOF_FLAGS_SYNC;
51 break;
52 case 'm':
53 eofb.eof_flags |= XFS_EOF_FLAGS_MINFILESIZE;
54 eofb.eof_min_file_size = cvtnum(file->geom.blocksize,
55 file->geom.sectsize,
56 optarg);
57 break;
58 case '?':
59 default:
60 return command_usage(&prealloc_cmd);
61 }
62 }
63 if (optind != argc)
64 return command_usage(&prealloc_cmd);
65
66 if (ioctl(file->fd, XFS_IOC_FREE_EOFBLOCKS, &eofb) < 0) {
67 fprintf(stderr, _("%s: XFS_IOC_FREE_EOFBLOCKS on %s: %s\n"),
68 progname, file->name, strerror(errno));
69 }
70 return 0;
71}
72
73static void
74prealloc_help(void)
75{
76 printf(_(
77"\n"
78"Remove speculative preallocation\n"
79"\n"
80" -g gid -- remove prealloc on files matching group <gid>\n"
81" -m minlen -- only consider files larger than <minlen>\n"
82" -p prid -- remove prealloc on files matching project <prid>\n"
83" -s -- wait for removal to complete\n"
84" -u uid -- remove prealloc on files matching user <uid>\n"
85"\n"
86"If none of -u, -g, or -p are specified, this command acts on all files.\n"
87"minlen can take units.\n"
88"\n"));
89
90}
91
92void
93prealloc_init(void)
94{
95 prealloc_cmd.name = "prealloc";
96 prealloc_cmd.altname = "prealloc";
97 prealloc_cmd.cfunc = prealloc_f;
98 prealloc_cmd.argmin = 1;
99 prealloc_cmd.argmax = -1;
100 prealloc_cmd.args = "[-s] [-u id] [-g id] [-p id] [-m minlen]";
101 prealloc_cmd.flags = CMD_FLAG_ONESHOT;
102 prealloc_cmd.oneline = _("Remove speculative preallocation");
103 prealloc_cmd.help = prealloc_help;
104
105 add_command(&prealloc_cmd);
106}
107