xref: /freebsd/sys/geom/raid/g_raid_md_if.m (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
1#-
2# Copyright (c) 2010 Alexander Motin
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
16# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25#
26
27#include <sys/param.h>
28#include <sys/lock.h>
29#include <sys/malloc.h>
30#include <sys/mutex.h>
31#include <sys/sbuf.h>
32#include <sys/bus.h>
33#include <machine/bus.h>
34#include <sys/systm.h>
35#include <geom/geom.h>
36#include <geom/raid/g_raid.h>
37
38# The G_RAID metadata class interface.
39
40INTERFACE g_raid_md;
41
42HEADER {
43#define G_RAID_MD_TASTE_FAIL		-1
44#define G_RAID_MD_TASTE_EXISTING	 0
45#define G_RAID_MD_TASTE_NEW		 1
46};
47
48# Default implementations of methods.
49CODE {
50	static int
51	g_raid_md_create_default(struct g_raid_md_object *md,
52	    struct g_class *mp, struct g_geom **gp)
53	{
54
55		return (G_RAID_MD_TASTE_FAIL);
56	}
57
58	static int
59	g_raid_md_create_req_default(struct g_raid_md_object *md,
60	    struct g_class *mp, struct gctl_req *req, struct g_geom **gp)
61	{
62
63		return (G_RAID_MD_CREATE(md, mp, gp));
64	}
65
66	static int
67	g_raid_md_ctl_default(struct g_raid_md_object *md,
68	    struct gctl_req *req)
69	{
70
71		return (-1);
72	}
73
74	static int
75	g_raid_md_volume_event_default(struct g_raid_md_object *md,
76	    struct g_raid_volume *vol, u_int event)
77	{
78
79		return (-1);
80	}
81
82	static int
83	g_raid_md_free_disk_default(struct g_raid_md_object *md,
84	    struct g_raid_volume *vol)
85	{
86
87		return (0);
88	}
89
90	static int
91	g_raid_md_free_volume_default(struct g_raid_md_object *md,
92	    struct g_raid_volume *vol)
93	{
94
95		return (0);
96	}
97};
98
99# create() - create new node from scratch.
100METHOD int create {
101	struct g_raid_md_object *md;
102	struct g_class *mp;
103	struct g_geom **gp;
104} DEFAULT g_raid_md_create_default;
105
106# create_req() - create new node from scratch, with request argument.
107METHOD int create_req {
108	struct g_raid_md_object *md;
109	struct g_class *mp;
110	struct gctl_req *req;
111	struct g_geom **gp;
112} DEFAULT g_raid_md_create_req_default;
113
114# taste() - taste disk and, if needed, create new node.
115METHOD int taste {
116	struct g_raid_md_object *md;
117	struct g_class *mp;
118	struct g_consumer *cp;
119	struct g_geom **gp;
120};
121
122# ctl() - user-level control commands handling method.
123METHOD int ctl {
124	struct g_raid_md_object *md;
125	struct gctl_req *req;
126} DEFAULT g_raid_md_ctl_default;
127
128# event() - events handling method.
129METHOD int event {
130	struct g_raid_md_object *md;
131	struct g_raid_disk *disk;
132	u_int event;
133};
134
135# volume_event() - events handling method.
136METHOD int volume_event {
137	struct g_raid_md_object *md;
138	struct g_raid_volume *vol;
139	u_int event;
140} DEFAULT g_raid_md_volume_event_default;
141
142# write() - metadata write method.
143METHOD int write {
144	struct g_raid_md_object *md;
145	struct g_raid_volume *vol;
146	struct g_raid_subdisk *sd;
147	struct g_raid_disk *disk;
148};
149
150# fail_disk() - mark disk as failed and remove it from use.
151METHOD int fail_disk {
152	struct g_raid_md_object *md;
153	struct g_raid_subdisk *sd;
154	struct g_raid_disk *disk;
155};
156
157# free_disk() - disk destructor.
158METHOD int free_disk {
159	struct g_raid_md_object *md;
160	struct g_raid_disk *disk;
161} DEFAULT g_raid_md_free_disk_default;
162
163# free_volume() - volume destructor.
164METHOD int free_volume {
165	struct g_raid_md_object *md;
166	struct g_raid_volume *vol;
167} DEFAULT g_raid_md_free_volume_default;
168
169# free() - destructor.
170METHOD int free {
171	struct g_raid_md_object *md;
172};
173