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>
52 #define DSCHED_FOREACH_DISK(dev_fd, diocp) \
53 for ((diocp)->num_elem = 0; \
55 DSCHED_LIST_DISKS, (diocp)) != -1); \
58 #define DSCHED_FOREACH_POLICY(dev_fd, diocp) \
59 for ((diocp)->num_elem = 0; \
61 DSCHED_LIST_POLICIES, (diocp)) != -1); \
65 static int verbose = 0;
71 "Usage: dschedctl <commands>\n"
72 "Valid commands are:\n"
74 "\t Lists all disks and their policies, or just for [disk]\n"
76 "\t Lists all available I/O scheduling policies\n"
77 " -s <policy> [disk]\n"
78 "\t Switches the policy of [disk] or otherwise all disks to "
85 dsched_ioctl(unsigned long cmd, struct dsched_ioctl *pdioc)
87 if (ioctl(dev_fd, cmd, pdioc) == -1)
94 dsched_set_disk_policy(char *disk_name, char *policy)
96 struct dsched_ioctl dioc;
99 bzero(&dioc, sizeof(dioc));
100 strncpy(dioc.dev_name, disk_name, DSCHED_NAME_LENGTH);
101 strncpy(dioc.pol_name, policy, DSCHED_NAME_LENGTH);
102 error = dsched_ioctl(DSCHED_SET_DEVICE_POLICY, &dioc);
104 if ((!error) && verbose) {
105 printf("Switched scheduler policy of %s successfully to %s\n",
113 main(int argc, char *argv[])
115 struct dsched_ioctl dioc;
116 char *disk_name = NULL;
118 int dflag = 0, lflag = 0, pflag = 0, sflag = 0;
119 int ch, error = 0, found;
121 while ((ch = getopt(argc, argv, "hlps:v")) != -1) {
149 disk_name = basename(argv[0]);
152 } else if (argc > 1) {
159 * - need to use at least one mode
161 if (!(lflag || pflag || sflag)) {
166 dev_fd = open("/dev/dsched", O_RDWR);
168 err(1, "open(/dev/dsched)");
172 strncpy(dioc.dev_name, disk_name, DSCHED_NAME_LENGTH);
173 error = dsched_ioctl(DSCHED_LIST_DISK, &dioc);
175 printf("%s\t=>\t%s\n",
176 disk_name, dioc.pol_name);
179 DSCHED_FOREACH_DISK(dev_fd, &dioc) {
180 printf("%s\t=>\t%s\n",
181 dioc.dev_name, dioc.pol_name);
187 DSCHED_FOREACH_POLICY(dev_fd, &dioc) {
188 printf("%s\n", dioc.pol_name);
194 DSCHED_FOREACH_POLICY(dev_fd, &dioc) {
195 if (strcmp(policy, dioc.pol_name) == 0) {
201 errx(1, "Policy '%s' not available", policy);
204 error = dsched_set_disk_policy(disk_name, policy);
206 DSCHED_FOREACH_DISK(dev_fd, &dioc) {
207 error = dsched_set_disk_policy(dioc.dev_name,