1219974Smav#-
2219974Smav# Copyright (c) 2010 Alexander Motin
3219974Smav# All rights reserved.
4219974Smav#
5219974Smav# Redistribution and use in source and binary forms, with or without
6219974Smav# modification, are permitted provided that the following conditions
7219974Smav# are met:
8219974Smav#
9219974Smav# 1. Redistributions of source code must retain the above copyright
10219974Smav#    notice, this list of conditions and the following disclaimer.
11219974Smav# 2. Redistributions in binary form must reproduce the above copyright
12219974Smav#    notice, this list of conditions and the following disclaimer in the
13219974Smav#    documentation and/or other materials provided with the distribution.
14219974Smav#
15219974Smav# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16219974Smav# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17219974Smav# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18219974Smav# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19219974Smav# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20219974Smav# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21219974Smav# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22219974Smav# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23219974Smav# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24219974Smav# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25219974Smav#
26219974Smav# $FreeBSD: releng/10.2/sys/geom/raid/g_raid_md_if.m 234940 2012-05-03 05:32:56Z mav $
27219974Smav
28219974Smav#include <sys/param.h>
29219974Smav#include <sys/lock.h>
30219974Smav#include <sys/malloc.h>
31219974Smav#include <sys/mutex.h>
32219974Smav#include <sys/sbuf.h>
33219974Smav#include <sys/bus.h>
34219974Smav#include <machine/bus.h>
35219974Smav#include <sys/systm.h>
36219974Smav#include <geom/geom.h>
37219974Smav#include <geom/raid/g_raid.h>
38219974Smav
39219974Smav# The G_RAID metadata class interface.
40219974Smav
41219974SmavINTERFACE g_raid_md;
42219974Smav
43219974SmavHEADER {
44219974Smav#define G_RAID_MD_TASTE_FAIL		-1
45219974Smav#define G_RAID_MD_TASTE_EXISTING	 0
46219974Smav#define G_RAID_MD_TASTE_NEW		 1
47219974Smav};
48219974Smav
49219974Smav# Default implementations of methods.
50219974SmavCODE {
51219974Smav	static int
52234940Smav	g_raid_md_create_default(struct g_raid_md_object *md,
53234940Smav	    struct g_class *mp, struct g_geom **gp)
54219974Smav	{
55219974Smav
56219974Smav		return (G_RAID_MD_TASTE_FAIL);
57219974Smav	}
58219974Smav
59219974Smav	static int
60234940Smav	g_raid_md_create_req_default(struct g_raid_md_object *md,
61234940Smav	    struct g_class *mp, struct gctl_req *req, struct g_geom **gp)
62234940Smav	{
63234940Smav
64234940Smav		return (G_RAID_MD_CREATE(md, mp, gp));
65234940Smav	}
66234940Smav
67234940Smav	static int
68219974Smav	g_raid_md_ctl_default(struct g_raid_md_object *md,
69219974Smav	    struct gctl_req *req)
70219974Smav	{
71219974Smav
72219974Smav		return (-1);
73219974Smav	}
74219974Smav
75219974Smav	static int
76219974Smav	g_raid_md_volume_event_default(struct g_raid_md_object *md,
77219974Smav	    struct g_raid_volume *vol, u_int event)
78219974Smav	{
79219974Smav
80219974Smav		return (-1);
81219974Smav	}
82219974Smav
83219974Smav	static int
84219974Smav	g_raid_md_free_disk_default(struct g_raid_md_object *md,
85219974Smav	    struct g_raid_volume *vol)
86219974Smav	{
87219974Smav
88219974Smav		return (0);
89219974Smav	}
90219974Smav
91219974Smav	static int
92219974Smav	g_raid_md_free_volume_default(struct g_raid_md_object *md,
93219974Smav	    struct g_raid_volume *vol)
94219974Smav	{
95219974Smav
96219974Smav		return (0);
97219974Smav	}
98219974Smav};
99219974Smav
100219974Smav# create() - create new node from scratch.
101219974SmavMETHOD int create {
102219974Smav	struct g_raid_md_object *md;
103219974Smav	struct g_class *mp;
104219974Smav	struct g_geom **gp;
105219974Smav} DEFAULT g_raid_md_create_default;
106219974Smav
107234940Smav# create_req() - create new node from scratch, with request argument.
108234940SmavMETHOD int create_req {
109234940Smav	struct g_raid_md_object *md;
110234940Smav	struct g_class *mp;
111234940Smav	struct gctl_req *req;
112234940Smav	struct g_geom **gp;
113234940Smav} DEFAULT g_raid_md_create_req_default;
114234940Smav
115219974Smav# taste() - taste disk and, if needed, create new node.
116219974SmavMETHOD int taste {
117219974Smav	struct g_raid_md_object *md;
118219974Smav	struct g_class *mp;
119219974Smav	struct g_consumer *cp;
120219974Smav	struct g_geom **gp;
121219974Smav};
122219974Smav
123219974Smav# ctl() - user-level control commands handling method.
124219974SmavMETHOD int ctl {
125219974Smav	struct g_raid_md_object *md;
126219974Smav	struct gctl_req *req;
127219974Smav} DEFAULT g_raid_md_ctl_default;
128219974Smav
129219974Smav# event() - events handling method.
130219974SmavMETHOD int event {
131219974Smav	struct g_raid_md_object *md;
132219974Smav	struct g_raid_disk *disk;
133219974Smav	u_int event;
134219974Smav};
135219974Smav
136219974Smav# volume_event() - events handling method.
137219974SmavMETHOD int volume_event {
138219974Smav	struct g_raid_md_object *md;
139219974Smav	struct g_raid_volume *vol;
140219974Smav	u_int event;
141219974Smav} DEFAULT g_raid_md_volume_event_default;
142219974Smav
143219974Smav# write() - metadata write method.
144219974SmavMETHOD int write {
145219974Smav	struct g_raid_md_object *md;
146219974Smav	struct g_raid_volume *vol;
147219974Smav	struct g_raid_subdisk *sd;
148219974Smav	struct g_raid_disk *disk;
149219974Smav};
150219974Smav
151219974Smav# fail_disk() - mark disk as failed and remove it from use.
152219974SmavMETHOD int fail_disk {
153219974Smav	struct g_raid_md_object *md;
154219974Smav	struct g_raid_subdisk *sd;
155219974Smav	struct g_raid_disk *disk;
156219974Smav};
157219974Smav
158219974Smav# free_disk() - disk destructor.
159219974SmavMETHOD int free_disk {
160219974Smav	struct g_raid_md_object *md;
161219974Smav	struct g_raid_disk *disk;
162219974Smav} DEFAULT g_raid_md_free_disk_default;
163219974Smav
164219974Smav# free_volume() - volume destructor.
165219974SmavMETHOD int free_volume {
166219974Smav	struct g_raid_md_object *md;
167219974Smav	struct g_raid_volume *vol;
168219974Smav} DEFAULT g_raid_md_free_volume_default;
169219974Smav
170219974Smav# free() - destructor.
171219974SmavMETHOD int free {
172219974Smav	struct g_raid_md_object *md;
173219974Smav};
174