]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/log_writes.c
xfs_io: include io.h to silence static function warnings
[thirdparty/xfsprogs-dev.git] / io / log_writes.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2017 Intel Corporation.
4 * All Rights Reserved.
5 */
6
7 #include "platform_defs.h"
8 #include <libdevmapper.h>
9 #include "command.h"
10 #include "init.h"
11 #include "io.h"
12
13 static cmdinfo_t log_writes_cmd;
14
15 static int
16 mark_log(const char *device, const char *mark)
17 {
18 struct dm_task *dmt;
19 const int size = 80;
20 char message[size];
21 int len, ret = 0;
22
23 len = snprintf(message, size, "mark %s", mark);
24 if (len >= size) {
25 printf("mark '%s' is too long\n", mark);
26 return ret;
27 }
28
29 if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
30 return ret;
31
32 if (!dm_task_set_name(dmt, device))
33 goto out;
34
35 if (!dm_task_set_sector(dmt, 0))
36 goto out;
37
38 if (!dm_task_set_message(dmt, message))
39 goto out;
40
41 if (dm_task_run(dmt))
42 ret = 1;
43 out:
44 dm_task_destroy(dmt);
45 return ret;
46 }
47
48 static int
49 log_writes_f(
50 int argc,
51 char **argv)
52 {
53 const char *device = NULL;
54 const char *mark = NULL;
55 int c;
56
57 exitcode = 1;
58 while ((c = getopt(argc, argv, "d:m:")) != EOF) {
59 switch (c) {
60 case 'd':
61 device = optarg;
62 break;
63 case 'm':
64 mark = optarg;
65 break;
66 default:
67 return command_usage(&log_writes_cmd);
68 }
69 }
70
71 if (device == NULL || mark == NULL)
72 return command_usage(&log_writes_cmd);
73
74 if (mark_log(device, mark))
75 exitcode = 0;
76
77 return 0;
78 }
79
80 void
81 log_writes_init(void)
82 {
83 log_writes_cmd.name = "log_writes";
84 log_writes_cmd.altname = "lw";
85 log_writes_cmd.cfunc = log_writes_f;
86 log_writes_cmd.flags = CMD_NOMAP_OK | CMD_NOFILE_OK | CMD_FOREIGN_OK
87 | CMD_FLAG_ONESHOT;
88 log_writes_cmd.argmin = 0;
89 log_writes_cmd.argmax = -1;
90 log_writes_cmd.args = _("-d device -m mark");
91 log_writes_cmd.oneline =
92 _("create mark <mark> in the dm-log-writes log specified by <device>");
93
94 add_command(&log_writes_cmd);
95 }