Statistics
| Branch: | Revision:

root / drivers / tapdisk-vbd.h @ abdb293f

History | View | Annotate | Download (6.1 kB)

1
/* 
2
 * Copyright (c) 2008, XenSource Inc.
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 are met:
7
 *     * Redistributions of source code must retain the above copyright
8
 *       notice, this list of conditions and the following disclaimer.
9
 *     * Redistributions in binary form must reproduce the above copyright
10
 *       notice, this list of conditions and the following disclaimer in the
11
 *       documentation and/or other materials provided with the distribution.
12
 *     * Neither the name of XenSource Inc. nor the names of its contributors
13
 *       may be used to endorse or promote products derived from this software
14
 *       without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
20
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
#ifndef _TAPDISK_VBD_H_
29
#define _TAPDISK_VBD_H_
30

    
31
#include <sys/time.h>
32

    
33
#include "tapdisk.h"
34
#include "scheduler.h"
35
#include "tapdisk-image.h"
36
#include "tapdisk-blktap.h"
37

    
38
#define TD_VBD_REQUEST_TIMEOUT      120
39
#define TD_VBD_MAX_RETRIES          100
40
#define TD_VBD_RETRY_INTERVAL       1
41

    
42
#define TD_VBD_DEAD                 0x0001
43
#define TD_VBD_CLOSED               0x0002
44
#define TD_VBD_QUIESCE_REQUESTED    0x0004
45
#define TD_VBD_QUIESCED             0x0008
46
#define TD_VBD_PAUSE_REQUESTED      0x0010
47
#define TD_VBD_PAUSED               0x0020
48
#define TD_VBD_SHUTDOWN_REQUESTED   0x0040
49
#define TD_VBD_LOCKING              0x0080
50
#define TD_VBD_LOG_DROPPED          0x0100
51

    
52
#define TD_VBD_SECONDARY_DISABLED   0 
53
#define TD_VBD_SECONDARY_MIRROR     1
54
#define TD_VBD_SECONDARY_STANDBY    2
55

    
56
struct td_vbd_handle {
57
        char                       *name;
58

    
59
        td_blktap_t                *tap;
60

    
61
        td_uuid_t                   uuid;
62

    
63
        td_flag_t                   flags;
64
        td_flag_t                   state;
65

    
66
        struct list_head            images;
67

    
68
        int                         parent_devnum;
69
        char                       *secondary_name;
70
        td_image_t                 *secondary;
71
        uint8_t                     secondary_mode;
72

    
73
        int                         FIXME_enospc_redirect_count_enabled;
74
        uint64_t                    FIXME_enospc_redirect_count;
75

    
76
        /* when we encounter ENOSPC on the primary leaf image in mirror mode, 
77
         * we need to remove it from the VBD chain so that writes start going 
78
         * on the secondary leaf. However, we cannot free the image at that 
79
         * time since it might still have in-flight treqs referencing it.  
80
         * Therefore, we move it into 'retired' until shutdown. */
81
        td_image_t                 *retired;
82

    
83
        struct list_head            new_requests;
84
        struct list_head            pending_requests;
85
        struct list_head            failed_requests;
86
        struct list_head            completed_requests;
87

    
88
        td_vbd_request_t            request_list[MAX_REQUESTS]; /* XXX */
89

    
90
        struct list_head            next;
91

    
92
        struct timeval              ts;
93

    
94
        uint64_t                    received;
95
        uint64_t                    returned;
96
        uint64_t                    kicked;
97
        uint64_t                    secs_pending;
98
        uint64_t                    retries;
99
        uint64_t                    errors;
100
        td_sector_count_t           secs;
101
};
102

    
103
#define tapdisk_vbd_for_each_request(vreq, tmp, list)                        \
104
        list_for_each_entry_safe((vreq), (tmp), (list), next)
105

    
106
#define tapdisk_vbd_for_each_image(vbd, image, tmp)        \
107
        tapdisk_for_each_image_safe(image, tmp, &vbd->images)
108

    
109
static inline void
110
tapdisk_vbd_move_request(td_vbd_request_t *vreq, struct list_head *dest)
111
{
112
        list_del(&vreq->next);
113
        INIT_LIST_HEAD(&vreq->next);
114
        list_add_tail(&vreq->next, dest);
115
        vreq->list_head = dest;
116
}
117

    
118
static inline void
119
tapdisk_vbd_add_image(td_vbd_t *vbd, td_image_t *image)
120
{
121
        list_add_tail(&image->next, &vbd->images);
122
}
123

    
124
static inline int
125
tapdisk_vbd_is_last_image(td_vbd_t *vbd, td_image_t *image)
126
{
127
        return list_is_last(&image->next, &vbd->images);
128
}
129

    
130
static inline td_image_t *
131
tapdisk_vbd_first_image(td_vbd_t *vbd)
132
{
133
        td_image_t *image = NULL;
134
        if (!list_empty(&vbd->images))
135
                image = list_entry(vbd->images.next, td_image_t, next);
136
        return image;
137
}
138

    
139
static inline td_image_t *
140
tapdisk_vbd_last_image(td_vbd_t *vbd)
141
{
142
        td_image_t *image = NULL;
143
        if (!list_empty(&vbd->images))
144
                image = list_entry(vbd->images.prev, td_image_t, next);
145
        return image;
146
}
147

    
148
static inline td_image_t *
149
tapdisk_vbd_next_image(td_image_t *image)
150
{
151
        return list_entry(image->next.next, td_image_t, next);
152
}
153

    
154
td_vbd_t *tapdisk_vbd_create(td_uuid_t);
155
int tapdisk_vbd_initialize(int, int, td_uuid_t);
156
int tapdisk_vbd_open(td_vbd_t *, const char *, int, const char *, td_flag_t);
157
int tapdisk_vbd_close(td_vbd_t *);
158

    
159
int tapdisk_vbd_open_vdi(td_vbd_t *, const char *, td_flag_t, int);
160
void tapdisk_vbd_close_vdi(td_vbd_t *);
161

    
162
int tapdisk_vbd_attach(td_vbd_t *, const char *, int);
163
void tapdisk_vbd_detach(td_vbd_t *);
164

    
165
int tapdisk_vbd_queue_request(td_vbd_t *, td_vbd_request_t *);
166
void tapdisk_vbd_forward_request(td_request_t);
167

    
168
int tapdisk_vbd_get_disk_info(td_vbd_t *, td_disk_info_t *);
169
int tapdisk_vbd_retry_needed(td_vbd_t *);
170
int tapdisk_vbd_quiesce_queue(td_vbd_t *);
171
int tapdisk_vbd_start_queue(td_vbd_t *);
172
int tapdisk_vbd_issue_requests(td_vbd_t *);
173
int tapdisk_vbd_kill_queue(td_vbd_t *);
174
int tapdisk_vbd_pause(td_vbd_t *);
175
int tapdisk_vbd_resume(td_vbd_t *, const char *);
176
void tapdisk_vbd_kick(td_vbd_t *);
177
void tapdisk_vbd_check_state(td_vbd_t *);
178
int tapdisk_vbd_recheck_state(td_vbd_t *);
179
void tapdisk_vbd_check_progress(td_vbd_t *);
180
void tapdisk_vbd_debug(td_vbd_t *);
181
void tapdisk_vbd_stats(td_vbd_t *, td_stats_t *);
182

    
183
#endif