1 /*-
2 * Copyright (c) 2009 Fabio Checconi
3 * Copyright (c) 2010 Luigi Rizzo, Universita` di Pisa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 /*
29 * $Id$
30 * $FreeBSD: stable/9/sbin/geom/class/sched/geom_sched.c 212554 2010-09-13 13:48:18Z pjd $
31 *
32 * This file implements the userspace library used by the 'geom'
33 * command to load and manipulate disk schedulers.
34 */
35
36 #include <sys/cdefs.h>
37 #include <sys/param.h>
38 #include <sys/linker.h>
39 #include <sys/module.h>
40
41 #include <stdio.h>
42 #include <stdint.h>
43 #include <libgeom.h>
44
45 #include "core/geom.h"
46 #include "misc/subr.h"
47
48 #define G_SCHED_VERSION 0
49
50 uint32_t lib_version = G_LIB_VERSION;
51 uint32_t version = G_SCHED_VERSION;
52
53 /*
54 * storage for parameters used by this geom class.
55 * Right now only the scheduler name is used.
56 */
57 #define GSCHED_ALGO "rr" /* default scheduler */
58
59 /*
60 * Adapt to differences in geom library.
61 * in V1 struct g_command misses gc_argname, eld, and G_BOOL is undefined
62 */
63 #if G_LIB_VERSION <= 1
64 #define G_TYPE_BOOL G_TYPE_NUMBER
65 #endif
66 #if G_LIB_VERSION >= 3 && G_LIB_VERSION <= 4
67 #define G_ARGNAME NULL,
68 #else
69 #define G_ARGNAME
70 #endif
71
72 static void
gcmd_createinsert(struct gctl_req * req,unsigned flags __unused)73 gcmd_createinsert(struct gctl_req *req, unsigned flags __unused)
74 {
75 const char *reqalgo;
76 char name[64];
77
78 if (gctl_has_param(req, "algo"))
79 reqalgo = gctl_get_ascii(req, "algo");
80 else
81 reqalgo = GSCHED_ALGO;
82
83 snprintf(name, sizeof(name), "gsched_%s", reqalgo);
84 /*
85 * Do not complain about errors here, gctl_issue()
86 * will fail anyway.
87 */
88 if (modfind(name) < 0)
89 kldload(name);
90 gctl_issue(req);
91 }
92
93 struct g_command class_commands[] = {
94 { "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert,
95 {
96 { 'a', "algo", GSCHED_ALGO, G_TYPE_STRING },
97 G_OPT_SENTINEL
98 },
99 G_ARGNAME "[-v] [-a algorithm_name] dev ..."
100 },
101 { "insert", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert,
102 {
103 { 'a', "algo", GSCHED_ALGO, G_TYPE_STRING },
104 G_OPT_SENTINEL
105 },
106 G_ARGNAME "[-v] [-a algorithm_name] dev ..."
107 },
108 { "configure", G_FLAG_VERBOSE, NULL,
109 {
110 { 'a', "algo", GSCHED_ALGO, G_TYPE_STRING },
111 G_OPT_SENTINEL
112 },
113 G_ARGNAME "[-v] [-a algorithm_name] prov ..."
114 },
115 { "destroy", G_FLAG_VERBOSE, NULL,
116 {
117 { 'f', "force", NULL, G_TYPE_BOOL },
118 G_OPT_SENTINEL
119 },
120 G_ARGNAME "[-fv] prov ..."
121 },
122 { "reset", G_FLAG_VERBOSE, NULL, G_NULL_OPTS,
123 G_ARGNAME "[-v] prov ..."
124 },
125 G_CMD_SENTINEL
126 };
127