]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sbin/geom/class/sched/geom_sched.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sbin / geom / class / sched / geom_sched.c
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$
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 static char 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_ARGNAME
65 #define G_TYPE_BOOL     G_TYPE_NUMBER
66 #else
67 #define G_ARGNAME       NULL,
68 #endif
69
70 static void
71 gcmd_createinsert(struct gctl_req *req, unsigned flags __unused)
72 {
73         const char *reqalgo;
74         char name[64];
75
76         if (gctl_has_param(req, "algo"))
77                 reqalgo = gctl_get_ascii(req, "algo");
78         else
79                 reqalgo = algo;
80
81         snprintf(name, sizeof(name), "gsched_%s", reqalgo);
82         /*
83          * Do not complain about errors here, gctl_issue()
84          * will fail anyway.
85          */
86         if (modfind(name) < 0)
87                 kldload(name);
88         gctl_issue(req);
89 }
90
91 struct g_command class_commands[] = {
92         { "create", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert,
93             {
94                 { 'a', "algo", algo, G_TYPE_STRING },
95                 G_OPT_SENTINEL
96             },
97             G_ARGNAME "[-v] [-a algorithm_name] dev ..."
98         },
99         { "insert", G_FLAG_VERBOSE | G_FLAG_LOADKLD, gcmd_createinsert,
100             {
101                 { 'a', "algo", algo, G_TYPE_STRING },
102                 G_OPT_SENTINEL
103             },
104             G_ARGNAME "[-v] [-a algorithm_name] dev ..."
105         },
106         { "configure", G_FLAG_VERBOSE, NULL,
107             {
108                 { 'a', "algo", algo, G_TYPE_STRING },
109                 G_OPT_SENTINEL
110             },
111             G_ARGNAME "[-v] [-a algorithm_name] prov ..."
112         },
113         { "destroy", G_FLAG_VERBOSE, NULL,
114             {
115                 { 'f', "force", NULL, G_TYPE_BOOL },
116                 G_OPT_SENTINEL
117             },
118             G_ARGNAME "[-fv] prov ..."
119         },
120         { "reset", G_FLAG_VERBOSE, NULL, G_NULL_OPTS,
121             G_ARGNAME "[-v] prov ..."
122         },
123         G_CMD_SENTINEL
124 };