2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/types.h>
36 #include <sys/cdefs.h>
37 #include <sys/syslimits.h>
38 #include <sys/ioctl.h>
39 #include <sys/device.h>
40 #include <sys/queue.h>
42 #include <sys/dsched.h>
57 #define DSCHED_FOREACH_DISK(dev_fd, diocp) \
58 for ((diocp)->num_elem = 0; \
60 DSCHED_LIST_DISKS, (diocp)) != -1); \
63 #define DSCHED_FOREACH_POLICY(dev_fd, diocp) \
64 for ((diocp)->num_elem = 0; \
66 DSCHED_LIST_POLICIES, (diocp)) != -1); \
70 static int verbose = 0;
76 "Usage: dschedctl <commands>\n"
77 "Valid commands are:\n"
79 "\t Lists all disks and their policies, or just for [disk]\n"
81 "\t Lists all available I/O scheduling policies\n"
82 " -s <policy> [disk]\n"
83 "\t Switches the policy of [disk] or otherwise all disks to "
90 dsched_ioctl(unsigned long cmd, struct dsched_ioctl *pdioc)
92 if (ioctl(dev_fd, cmd, pdioc) == -1)
98 static int dsched_set_disk_policy(char *disk_name, char *policy)
100 struct dsched_ioctl dioc;
103 bzero(&dioc, sizeof(dioc));
104 strncpy(dioc.dev_name, disk_name, DSCHED_NAME_LENGTH);
105 strncpy(dioc.pol_name, policy, DSCHED_NAME_LENGTH);
106 error = dsched_ioctl(DSCHED_SET_DEVICE_POLICY, &dioc);
108 if ((!error) && verbose) {
109 printf("Switched scheduler policy of %s successfully to %s\n",
116 int main(int argc, char *argv[])
118 struct dsched_ioctl dioc;
119 char *disk_name = NULL;
121 int dflag = 0, lflag = 0, pflag = 0, sflag = 0;
124 while ((ch = getopt(argc, argv, "hlps:v")) != -1) {
153 } else if (argc > 1) {
160 * - need to use at least one mode
162 if (!(lflag || pflag || sflag)) {
167 dev_fd = open("/dev/dsched", O_RDWR);
169 err(1, "open(/dev/dsched)");
173 strncpy(dioc.dev_name, disk_name, DSCHED_NAME_LENGTH);
174 error = dsched_ioctl(DSCHED_LIST_DISK, &dioc);
176 printf("%s\t=>\t%s\n",
177 disk_name, dioc.pol_name);
180 DSCHED_FOREACH_DISK(dev_fd, &dioc) {
181 printf("%s\t=>\t%s\n",
182 dioc.dev_name, dioc.pol_name);
188 DSCHED_FOREACH_POLICY(dev_fd, &dioc) {
189 printf("%s\n", dioc.pol_name);
195 error = dsched_set_disk_policy(disk_name, policy);
197 DSCHED_FOREACH_DISK(dev_fd, &dioc) {
198 error = dsched_set_disk_policy(dioc.dev_name,