hammer2 - Add server-side disk advertisements
[dragonfly.git] / sys / sys / disk.h
1 /*
2  * Copyright (c) 2003,2004 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * ----------------------------------------------------------------------------
35  * "THE BEER-WARE LICENSE" (Revision 42):
36  * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
37  * can do whatever you want with this stuff. If we meet some day, and you think
38  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
39  * ----------------------------------------------------------------------------
40  *
41  * $FreeBSD: src/sys/sys/disk.h,v 1.16.2.3 2001/06/20 16:11:01 scottl Exp $
42  * $DragonFly: src/sys/sys/disk.h,v 1.18 2007/07/30 08:02:40 dillon Exp $
43  */
44
45 #ifndef _SYS_DISK_H_
46 #define _SYS_DISK_H_
47
48 #if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
49 #error "This file should not be included by userland programs."
50 #endif
51
52 #ifndef _SYS_DISKSLICE_H_
53 #include <sys/diskslice.h>
54 #endif
55 #ifndef _SYS_QUEUE_H_
56 #include <sys/queue.h>
57 #endif
58 #ifndef _SYS_MSGPORT_H_
59 #include <sys/msgport.h>
60 #endif
61 #ifndef _SYS_DMSG_H_
62 #include <sys/dmsg.h>
63 #endif
64
65 /*
66  * Media information structure - filled in by the media driver.
67  *
68  * NOTE: d_serialno is copied on the call to setdiskinfo and need
69  *       not be valid after that.
70  */
71 struct disk_info {
72         /*
73          * These fields are required.  Most drivers will load a disk_info
74          * structure in the device open function with the media parameters
75          * and call disk_setdiskinfo().
76          *
77          * Note that only one of d_media_size or d_media_blocks should be
78          * filled in.
79          *
80          * d_media_size         media size in bytes
81          * d_media_blocks       media size in blocks (e.g. total sectors)
82          * d_media_blksize      media block size / sector size
83          * d_dsflags            disklabel management flags
84          */
85         u_int64_t               d_media_size;
86         u_int64_t               d_media_blocks;
87         int                     d_media_blksize;
88         u_int                   d_dsflags;
89
90         /*
91          * Optional fields, leave 0 if not known
92          */
93         u_int                   d_type;         /* DTYPE_xxx */
94         u_int                   d_nheads;
95         u_int                   d_ncylinders;
96         u_int                   d_secpertrack;
97         u_int                   d_secpercyl;
98         u_int                   d_trimflag;
99         char                    *d_serialno;
100 };
101
102 /*
103  * d_dsflags, also used for dsopen() - control disklabel processing
104  *
105  * COMPATPARTA  - used by scsi devices to allow CDs to boot from cd0a.
106  *                cd's don't have disklabels and the default compat label
107  *                does not implement an 'a' partition.
108  *
109  * COMPATMBR    - used by the vn device to request that one sector be
110  *                reserved as if an MBR were present even when one isn't.
111  *
112  * MBRQUIET     - silently ignore MBR probe if unable to read sector 0.
113  *                used by VN.
114  *
115  * DEVICEMAPPER - used by the device mapper (dm). Adds a '.' between the
116  *                device name and the slice/part stuff (i.e. foo.s0).
117  *
118  * RAWPSIZE     - use the dev_psize of the underlying raw device if the top
119  *                psize fails.
120  */
121 #define DSO_NOLABELS            0x0001
122 #define DSO_ONESLICE            0x0002
123 #define DSO_COMPATLABEL         0x0004
124 #define DSO_COMPATPARTA         0x0008
125 #define DSO_COMPATMBR           0x0010
126 #define DSO_RAWEXTENSIONS       0x0020
127 #define DSO_MBRQUIET            0x0040
128 #define DSO_DEVICEMAPPER        0x0080
129 #define DSO_RAWPSIZE            0x0100
130
131 /*
132  * Disk management structure - automated disklabel support.
133  */
134 struct disk {
135         struct dev_ops          *d_dev_ops;     /* our device switch */
136         struct dev_ops          *d_raw_ops;     /* the raw device switch */
137         u_int                   d_flags;
138         int                     d_opencount;    /* The current open count */
139         cdev_t                  d_rawdev;       /* backing raw device */
140         cdev_t                  d_cdev;         /* special whole-disk part */
141         struct diskslices       *d_slice;
142         struct disk_info        d_info;         /* info structure for media */
143         void                    *d_dsched_priv1;/* I/O scheduler priv. data */
144         void                    *d_dsched_priv2;/* I/O scheduler priv. data */
145         struct dsched_policy    *d_sched_policy;/* I/O scheduler policy */
146         const char              *d_disktype;    /* Disk type information */
147         LIST_ENTRY(disk)        d_list;
148         kdmsg_iocom_t           d_iocom;        /* cluster import/export */
149 };
150
151 /*
152  * d_flags
153  */
154 #define DISKFLAG_LOCK           0x1
155 #define DISKFLAG_WANTED         0x2
156
157 #ifdef _KERNEL
158 cdev_t disk_create (int unit, struct disk *disk, struct dev_ops *raw_ops);
159 cdev_t disk_create_clone (int unit, struct disk *disk, struct dev_ops *raw_ops);
160 cdev_t disk_create_named(const char *name, int unit, struct disk *dp, struct dev_ops *raw_ops);
161 cdev_t disk_create_named_clone(const char *name, int unit, struct disk *dp, struct dev_ops *raw_ops);
162 cdev_t disk_locate (const char *devname);
163 void disk_destroy (struct disk *disk);
164 void disk_setdiskinfo (struct disk *disk, struct disk_info *info);
165 int disk_setdisktype(struct disk *disk, const char *type);
166 int disk_getopencount(struct disk *disk);
167 void disk_setdiskinfo_sync(struct disk *disk, struct disk_info *info);
168 int disk_dumpcheck (cdev_t dev, u_int64_t *count, u_int64_t *blkno, u_int *secsize);
169 int disk_dumpconf(cdev_t dev, u_int onoff);
170 struct disk *disk_enumerate (struct disk *disk);
171 void disk_invalidate (struct disk *disk);
172 void disk_unprobe(struct disk *disk);
173
174 void disk_msg_send(uint32_t cmd, void *load, void *load2);
175 void disk_msg_send_sync(uint32_t cmd, void *load, void *load2);
176 void disk_config(void *);
177
178 int bounds_check_with_mediasize(struct bio *bio, int secsize, uint64_t mediasize);
179
180 void disk_iocom_init(struct disk *dp);
181 void disk_iocom_update(struct disk *dp);
182 void disk_iocom_uninit(struct disk *dp);
183 int disk_iocom_ioctl(struct disk *dp, int cmd, void *data);
184 void disk_clusterctl_wakeup(kdmsg_iocom_t *iocom);
185 int disk_lnk_rcvmsg(kdmsg_msg_t *msg);
186 int disk_dbg_rcvmsg(kdmsg_msg_t *msg);
187 int disk_adhoc_input(kdmsg_msg_t *msg);
188
189 typedef struct disk_msg {
190         struct lwkt_msg hdr;
191         void    *load;
192         void    *load2;
193 } *disk_msg_t;
194
195 #define DISK_DISK_PROBE         0x01
196 #define DISK_DISK_DESTROY       0x02
197 #define DISK_SLICE_REPROBE      0x03
198 #define DISK_DISK_REPROBE       0x04
199 #define DISK_UNPROBE            0x05
200 #define DISK_SYNC               0x99
201
202
203 #endif /* _KERNEL */
204
205 #endif /* _SYS_DISK_H_ */