add snapshot functionality in xseg-tool
[archipelago] / xseg / peers / kernel / xsegbd.h
1 /*
2  * Copyright 2012 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *   2. Redistributions in binary form must reproduce the above
12  *      copyright notice, this list of conditions and the following
13  *      disclaimer in the documentation and/or other materials
14  *      provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and
30  * documentation are those of the authors and should not be
31  * interpreted as representing official policies, either expressed
32  * or implied, of GRNET S.A.
33  */
34
35 #ifndef _XSEGBD_REAR
36 #define _XSEGBD_REAR
37
38 #define XSEGBD_NAME "xsegbd"
39
40 #define XSEGBD_SEGMENT_NAMELEN 32
41 #define XSEGBD_TARGET_NAMELEN 127
42
43 #include <linux/kernel.h>
44 #include <linux/types.h>
45 #include <linux/wait.h>
46 #include <xseg/xseg.h>
47 #include <xtypes/xq.h>
48
49 struct xsegbd_device;
50
51 struct xsegbd_pending {
52         struct request *request;
53         struct completion *comp;
54         struct xsegbd_device *dev;
55 };
56
57 struct xsegbd {
58         char name[XSEGBD_SEGMENT_NAMELEN];
59         struct xseg_config config;
60         struct xseg *xseg;
61 };
62
63 struct xsegbd_device {
64         struct xseg *xseg;
65         spinlock_t rqlock;
66         struct request_queue *blk_queue;
67         struct gendisk *gd;
68         int id;
69         int major;
70         sector_t sectors;
71         uint64_t segsize;
72         xport src_portno, dst_portno;
73         uint32_t  nr_requests;
74         struct xq blk_queue_pending;
75         struct xsegbd *xsegbd;
76         struct xsegbd_pending *blk_req_pending;
77         struct device dev;
78         struct list_head node;
79         char target[XSEGBD_TARGET_NAMELEN + 1];
80         uint32_t targetlen;
81 };
82
83 void __xsegbd_get(struct xsegbd_device *xsegbd_dev);
84 void __xsegbd_put(struct xsegbd_device *xsegbd_dev);
85 struct xsegbd_device *__xsegbd_get_dev(unsigned long id);
86 #endif