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# $FreeBSD$
27
28#include <sys/param.h>
29#include <sys/lock.h>
30#include <sys/malloc.h>
31#include <sys/mutex.h>
32#include <sys/sbuf.h>
33#include <sys/bus.h>
34#include <machine/bus.h>
35#include <sys/systm.h>
36#include <geom/geom.h>
37#include <geom/raid/g_raid.h>
38
39# The G_RAID metadata class interface.
40
41INTERFACE g_raid_md;
42
43HEADER {
44#define G_RAID_MD_TASTE_FAIL		-1
45#define G_RAID_MD_TASTE_EXISTING	 0
46#define G_RAID_MD_TASTE_NEW		 1
47};
48
49# Default implementations of methods.
50CODE {
51	static int
52	g_raid_md_create_default(struct g_raid_md_object *md,
53	    struct g_class *mp, struct g_geom **gp)
54	{
55
56		return (G_RAID_MD_TASTE_FAIL);
57	}
58
59	static int
60	g_raid_md_create_req_default(struct g_raid_md_object *md,
61	    struct g_class *mp, struct gctl_req *req, struct g_geom **gp)
62	{
63
64		return (G_RAID_MD_CREATE(md, mp, gp));
65	}
66
67	static int
68	g_raid_md_ctl_default(struct g_raid_md_object *md,
69	    struct gctl_req *req)
70	{
71
72		return (-1);
73	}
74
75	static int
76	g_raid_md_volume_event_default(struct g_raid_md_object *md,
77	    struct g_raid_volume *vol, u_int event)
78	{
79
80		return (-1);
81	}
82
83	static int
84	g_raid_md_free_disk_default(struct g_raid_md_object *md,
85	    struct g_raid_volume *vol)
86	{
87
88		return (0);
89	}
90
91	static int
92	g_raid_md_free_volume_default(struct g_raid_md_object *md,
93	    struct g_raid_volume *vol)
94	{
95
96		return (0);
97	}
98};
99
100# create() - create new node from scratch.
101METHOD int create {
102	struct g_raid_md_object *md;
103	struct g_class *mp;
104	struct g_geom **gp;
105} DEFAULT g_raid_md_create_default;
106
107# create_req() - create new node from scratch, with request argument.
108METHOD int create_req {
109	struct g_raid_md_object *md;
110	struct g_class *mp;
111	struct gctl_req *req;
112	struct g_geom **gp;
113} DEFAULT g_raid_md_create_req_default;
114
115# taste() - taste disk and, if needed, create new node.
116METHOD int taste {
117	struct g_raid_md_object *md;
118	struct g_class *mp;
119	struct g_consumer *cp;
120	struct g_geom **gp;
121};
122
123# ctl() - user-level control commands handling method.
124METHOD int ctl {
125	struct g_raid_md_object *md;
126	struct gctl_req *req;
127} DEFAULT g_raid_md_ctl_default;
128
129# event() - events handling method.
130METHOD int event {
131	struct g_raid_md_object *md;
132	struct g_raid_disk *disk;
133	u_int event;
134};
135
136# volume_event() - events handling method.
137METHOD int volume_event {
138	struct g_raid_md_object *md;
139	struct g_raid_volume *vol;
140	u_int event;
141} DEFAULT g_raid_md_volume_event_default;
142
143# write() - metadata write method.
144METHOD int write {
145	struct g_raid_md_object *md;
146	struct g_raid_volume *vol;
147	struct g_raid_subdisk *sd;
148	struct g_raid_disk *disk;
149};
150
151# fail_disk() - mark disk as failed and remove it from use.
152METHOD int fail_disk {
153	struct g_raid_md_object *md;
154	struct g_raid_subdisk *sd;
155	struct g_raid_disk *disk;
156};
157
158# free_disk() - disk destructor.
159METHOD int free_disk {
160	struct g_raid_md_object *md;
161	struct g_raid_disk *disk;
162} DEFAULT g_raid_md_free_disk_default;
163
164# free_volume() - volume destructor.
165METHOD int free_volume {
166	struct g_raid_md_object *md;
167	struct g_raid_volume *vol;
168} DEFAULT g_raid_md_free_volume_default;
169
170# free() - destructor.
171METHOD int free {
172	struct g_raid_md_object *md;
173};
174