]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/elvtune.c
Imported from util-linux-2.10s tarball.
[thirdparty/util-linux.git] / disk-utils / elvtune.c
CommitLineData
22853e4a
KZ
1/*
2 * elvtune.c - I/O elevator tuner
3 *
4 * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * This file may be redistributed under the terms of the GNU General
20 * Public License, version 2.
21 */
22
23#include <getopt.h>
24#include <fcntl.h>
25#include <stdio.h>
26#include <sys/ioctl.h>
27#include <unistd.h>
28#include <stdlib.h>
66ee8158 29#include "nls.h"
22853e4a
KZ
30
31/* this has to match with the kernel structure */
66ee8158 32/* current version for ac19 and 2.2.16 */
22853e4a 33typedef struct blkelv_ioctl_arg_s {
66ee8158 34 int queue_ID;
22853e4a
KZ
35 int read_latency;
36 int write_latency;
37 int max_bomb_segments;
38} blkelv_ioctl_arg_t;
39
66ee8158
KZ
40#define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t))
41#define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t))
42
22853e4a
KZ
43static void
44usage(void) {
66ee8158
KZ
45 fprintf(stderr, "elvtune (%s)\n", util_linux_version);
46 fprintf(stderr, _("usage:\n"));
47 fprintf(stderr, "\telvtune [-r r_lat] [-w w_lat] [-b b_lat]"
48 " /dev/blkdev1 [/dev/blkdev2...]\n");
22853e4a
KZ
49 fprintf(stderr, "\telvtune -h\n");
50 fprintf(stderr, "\telvtune -v\n");
51}
52
53static void
54version(void) {
66ee8158 55 fprintf(stderr, "elvtune (%s)\n", util_linux_version);
22853e4a
KZ
56}
57
58int
59main(int argc, char * argv[]) {
60 int read_value = 0xbeefbeef, write_value = 0xbeefbeef, bomb_value = 0xbeefbeef;
61 int read_set, write_set, bomb_set, set;
62 char * devname;
63 int fd;
64 blkelv_ioctl_arg_t elevator;
65
66 read_set = write_set = bomb_set = set = 0;
67
68 for (;;) {
69 int opt;
70
71 opt = getopt(argc, argv, "r:w:b:hv");
72 if (opt < 0)
73 break;
74 switch (opt) {
75 case 'r':
76 read_value = atoi(optarg);
77 read_set = set = 1;
78 break;
79 case 'w':
80 write_value = atoi(optarg);
81 write_set = set = 1;
82 break;
83 case 'b':
84 bomb_value = atoi(optarg);
85 bomb_set = set = 1;
86 break;
87
88 case 'h':
89 usage(), exit(0);
90 case 'v':
91 version(), exit(0);
92
93 case '?':
94 default:
95 case ':':
96 fprintf(stderr, "parse error\n");
97 exit(1);
98 }
99 }
100
101 if (optind >= argc)
102 fprintf(stderr, "missing blockdevice, use -h for help\n"), exit(1);
103
104 while (optind < argc) {
105 devname = argv[optind++];
106
107 fd = open(devname, O_RDONLY|O_NONBLOCK);
108 if (fd < 0) {
109 perror("open");
110 break;
111 }
112
113 if (ioctl(fd, BLKELVGET, &elevator) < 0) {
114 perror("ioctl get");
115 break;
116 }
117
118 if (set) {
119 if (read_set)
120 elevator.read_latency = read_value;
121 if (write_set)
122 elevator.write_latency = write_value;
123 if (bomb_set)
124 elevator.max_bomb_segments = bomb_value;
125
126 if (ioctl(fd, BLKELVSET, &elevator) < 0) {
127 perror("ioctl set");
128 break;
129 }
130 if (ioctl(fd, BLKELVGET, &elevator) < 0) {
131 perror("ioctl reget");
132 break;
133 }
134 }
135
66ee8158 136 printf("\n%s elevator ID\t\t%d\n", devname, elevator.queue_ID);
22853e4a
KZ
137 printf("\tread_latency:\t\t%d\n", elevator.read_latency);
138 printf("\twrite_latency:\t\t%d\n", elevator.write_latency);
139 printf("\tmax_bomb_segments:\t%d\n\n", elevator.max_bomb_segments);
140
141 if (close(fd) < 0) {
142 perror("close");
143 break;
144 }
145 }
146
147 return 0;
148}