xref: /freebsd/sys/geom/raid/g_raid_md_if.m (revision 9a14aa017b21c292740c00ee098195cd46642730)
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	{
54
55		return (G_RAID_MD_TASTE_FAIL);
56	}
57
58	static int
59	g_raid_md_ctl_default(struct g_raid_md_object *md,
60	    struct gctl_req *req)
61	{
62
63		return (-1);
64	}
65
66	static int
67	g_raid_md_volume_event_default(struct g_raid_md_object *md,
68	    struct g_raid_volume *vol, u_int event)
69	{
70
71		return (-1);
72	}
73
74	static int
75	g_raid_md_free_disk_default(struct g_raid_md_object *md,
76	    struct g_raid_volume *vol)
77	{
78
79		return (0);
80	}
81
82	static int
83	g_raid_md_free_volume_default(struct g_raid_md_object *md,
84	    struct g_raid_volume *vol)
85	{
86
87		return (0);
88	}
89};
90
91# create() - create new node from scratch.
92METHOD int create {
93	struct g_raid_md_object *md;
94	struct g_class *mp;
95	struct g_geom **gp;
96} DEFAULT g_raid_md_create_default;
97
98# taste() - taste disk and, if needed, create new node.
99METHOD int taste {
100	struct g_raid_md_object *md;
101	struct g_class *mp;
102	struct g_consumer *cp;
103	struct g_geom **gp;
104};
105
106# ctl() - user-level control commands handling method.
107METHOD int ctl {
108	struct g_raid_md_object *md;
109	struct gctl_req *req;
110} DEFAULT g_raid_md_ctl_default;
111
112# event() - events handling method.
113METHOD int event {
114	struct g_raid_md_object *md;
115	struct g_raid_disk *disk;
116	u_int event;
117};
118
119# volume_event() - events handling method.
120METHOD int volume_event {
121	struct g_raid_md_object *md;
122	struct g_raid_volume *vol;
123	u_int event;
124} DEFAULT g_raid_md_volume_event_default;
125
126# write() - metadata write method.
127METHOD int write {
128	struct g_raid_md_object *md;
129	struct g_raid_volume *vol;
130	struct g_raid_subdisk *sd;
131	struct g_raid_disk *disk;
132};
133
134# fail_disk() - mark disk as failed and remove it from use.
135METHOD int fail_disk {
136	struct g_raid_md_object *md;
137	struct g_raid_subdisk *sd;
138	struct g_raid_disk *disk;
139};
140
141# free_disk() - disk destructor.
142METHOD int free_disk {
143	struct g_raid_md_object *md;
144	struct g_raid_disk *disk;
145} DEFAULT g_raid_md_free_disk_default;
146
147# free_volume() - volume destructor.
148METHOD int free_volume {
149	struct g_raid_md_object *md;
150	struct g_raid_volume *vol;
151} DEFAULT g_raid_md_free_volume_default;
152
153# free() - destructor.
154METHOD int free {
155	struct g_raid_md_object *md;
156};
157