~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/libxen/src/xen_sr.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2006-2007, XenSource Inc.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2.1 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
17
 */
 
18
 
 
19
 
 
20
#include <stddef.h>
 
21
#include <stdlib.h>
 
22
 
 
23
#include "xen_internal.h"
 
24
#include <xen/api/xen_common.h>
 
25
#include <xen/api/xen_pbd.h>
 
26
#include <xen/api/xen_sr.h>
 
27
#include <xen/api/xen_vdi.h>
 
28
 
 
29
 
 
30
XEN_FREE(xen_sr)
 
31
XEN_SET_ALLOC_FREE(xen_sr)
 
32
XEN_ALLOC(xen_sr_record)
 
33
XEN_SET_ALLOC_FREE(xen_sr_record)
 
34
XEN_ALLOC(xen_sr_record_opt)
 
35
XEN_RECORD_OPT_FREE(xen_sr)
 
36
XEN_SET_ALLOC_FREE(xen_sr_record_opt)
 
37
 
 
38
 
 
39
static const struct_member xen_sr_record_struct_members[] =
 
40
    {
 
41
        { .key = "uuid",
 
42
          .type = &abstract_type_string,
 
43
          .offset = offsetof(xen_sr_record, uuid) },
 
44
        { .key = "name_label",
 
45
          .type = &abstract_type_string,
 
46
          .offset = offsetof(xen_sr_record, name_label) },
 
47
        { .key = "name_description",
 
48
          .type = &abstract_type_string,
 
49
          .offset = offsetof(xen_sr_record, name_description) },
 
50
        { .key = "VDIs",
 
51
          .type = &abstract_type_ref_set,
 
52
          .offset = offsetof(xen_sr_record, vdis) },
 
53
        { .key = "PBDs",
 
54
          .type = &abstract_type_ref_set,
 
55
          .offset = offsetof(xen_sr_record, pbds) },
 
56
        { .key = "virtual_allocation",
 
57
          .type = &abstract_type_int,
 
58
          .offset = offsetof(xen_sr_record, virtual_allocation) },
 
59
        { .key = "physical_utilisation",
 
60
          .type = &abstract_type_int,
 
61
          .offset = offsetof(xen_sr_record, physical_utilisation) },
 
62
        { .key = "physical_size",
 
63
          .type = &abstract_type_int,
 
64
          .offset = offsetof(xen_sr_record, physical_size) },
 
65
        { .key = "type",
 
66
          .type = &abstract_type_string,
 
67
          .offset = offsetof(xen_sr_record, type) },
 
68
        { .key = "content_type",
 
69
          .type = &abstract_type_string,
 
70
          .offset = offsetof(xen_sr_record, content_type) }
 
71
    };
 
72
 
 
73
const abstract_type xen_sr_record_abstract_type_ =
 
74
    {
 
75
       .typename = STRUCT,
 
76
       .struct_size = sizeof(xen_sr_record),
 
77
       .member_count =
 
78
           sizeof(xen_sr_record_struct_members) / sizeof(struct_member),
 
79
       .members = xen_sr_record_struct_members
 
80
    };
 
81
 
 
82
 
 
83
void
 
84
xen_sr_record_free(xen_sr_record *record)
 
85
{
 
86
    if (record == NULL)
 
87
    {
 
88
        return;
 
89
    }
 
90
    free(record->handle);
 
91
    free(record->uuid);
 
92
    free(record->name_label);
 
93
    free(record->name_description);
 
94
    xen_vdi_record_opt_set_free(record->vdis);
 
95
    xen_pbd_record_opt_set_free(record->pbds);
 
96
    free(record->type);
 
97
    free(record->content_type);
 
98
    free(record);
 
99
}
 
100
 
 
101
 
 
102
bool
 
103
xen_sr_get_record(xen_session *session, xen_sr_record **result, xen_sr sr)
 
104
{
 
105
    abstract_value param_values[] =
 
106
        {
 
107
            { .type = &abstract_type_string,
 
108
              .u.string_val = sr }
 
109
        };
 
110
 
 
111
    abstract_type result_type = xen_sr_record_abstract_type_;
 
112
 
 
113
    *result = NULL;
 
114
    XEN_CALL_("SR.get_record");
 
115
 
 
116
    if (session->ok)
 
117
    {
 
118
       (*result)->handle = xen_strdup_((*result)->uuid);
 
119
    }
 
120
 
 
121
    return session->ok;
 
122
}
 
123
 
 
124
 
 
125
bool
 
126
xen_sr_get_by_uuid(xen_session *session, xen_sr *result, char *uuid)
 
127
{
 
128
    abstract_value param_values[] =
 
129
        {
 
130
            { .type = &abstract_type_string,
 
131
              .u.string_val = uuid }
 
132
        };
 
133
 
 
134
    abstract_type result_type = abstract_type_string;
 
135
 
 
136
    *result = NULL;
 
137
    XEN_CALL_("SR.get_by_uuid");
 
138
    return session->ok;
 
139
}
 
140
 
 
141
 
 
142
bool
 
143
xen_sr_get_by_name_label(xen_session *session, struct xen_sr_set **result, char *label)
 
144
{
 
145
    abstract_value param_values[] =
 
146
        {
 
147
            { .type = &abstract_type_string,
 
148
              .u.string_val = label }
 
149
        };
 
150
 
 
151
    abstract_type result_type = abstract_type_string_set;
 
152
 
 
153
    *result = NULL;
 
154
    XEN_CALL_("SR.get_by_name_label");
 
155
    return session->ok;
 
156
}
 
157
 
 
158
 
 
159
bool
 
160
xen_sr_get_name_label(xen_session *session, char **result, xen_sr sr)
 
161
{
 
162
    abstract_value param_values[] =
 
163
        {
 
164
            { .type = &abstract_type_string,
 
165
              .u.string_val = sr }
 
166
        };
 
167
 
 
168
    abstract_type result_type = abstract_type_string;
 
169
 
 
170
    *result = NULL;
 
171
    XEN_CALL_("SR.get_name_label");
 
172
    return session->ok;
 
173
}
 
174
 
 
175
 
 
176
bool
 
177
xen_sr_get_name_description(xen_session *session, char **result, xen_sr sr)
 
178
{
 
179
    abstract_value param_values[] =
 
180
        {
 
181
            { .type = &abstract_type_string,
 
182
              .u.string_val = sr }
 
183
        };
 
184
 
 
185
    abstract_type result_type = abstract_type_string;
 
186
 
 
187
    *result = NULL;
 
188
    XEN_CALL_("SR.get_name_description");
 
189
    return session->ok;
 
190
}
 
191
 
 
192
 
 
193
bool
 
194
xen_sr_get_vdis(xen_session *session, struct xen_vdi_set **result, xen_sr sr)
 
195
{
 
196
    abstract_value param_values[] =
 
197
        {
 
198
            { .type = &abstract_type_string,
 
199
              .u.string_val = sr }
 
200
        };
 
201
 
 
202
    abstract_type result_type = abstract_type_string_set;
 
203
 
 
204
    *result = NULL;
 
205
    XEN_CALL_("SR.get_VDIs");
 
206
    return session->ok;
 
207
}
 
208
 
 
209
 
 
210
bool
 
211
xen_sr_get_pbds(xen_session *session, struct xen_pbd_set **result, xen_sr sr)
 
212
{
 
213
    abstract_value param_values[] =
 
214
        {
 
215
            { .type = &abstract_type_string,
 
216
              .u.string_val = sr }
 
217
        };
 
218
 
 
219
    abstract_type result_type = abstract_type_string_set;
 
220
 
 
221
    *result = NULL;
 
222
    XEN_CALL_("SR.get_PBDs");
 
223
    return session->ok;
 
224
}
 
225
 
 
226
 
 
227
bool
 
228
xen_sr_get_virtual_allocation(xen_session *session, int64_t *result, xen_sr sr)
 
229
{
 
230
    abstract_value param_values[] =
 
231
        {
 
232
            { .type = &abstract_type_string,
 
233
              .u.string_val = sr }
 
234
        };
 
235
 
 
236
    abstract_type result_type = abstract_type_int;
 
237
 
 
238
    XEN_CALL_("SR.get_virtual_allocation");
 
239
    return session->ok;
 
240
}
 
241
 
 
242
 
 
243
bool
 
244
xen_sr_get_physical_utilisation(xen_session *session, int64_t *result, xen_sr sr)
 
245
{
 
246
    abstract_value param_values[] =
 
247
        {
 
248
            { .type = &abstract_type_string,
 
249
              .u.string_val = sr }
 
250
        };
 
251
 
 
252
    abstract_type result_type = abstract_type_int;
 
253
 
 
254
    XEN_CALL_("SR.get_physical_utilisation");
 
255
    return session->ok;
 
256
}
 
257
 
 
258
 
 
259
bool
 
260
xen_sr_get_physical_size(xen_session *session, int64_t *result, xen_sr sr)
 
261
{
 
262
    abstract_value param_values[] =
 
263
        {
 
264
            { .type = &abstract_type_string,
 
265
              .u.string_val = sr }
 
266
        };
 
267
 
 
268
    abstract_type result_type = abstract_type_int;
 
269
 
 
270
    XEN_CALL_("SR.get_physical_size");
 
271
    return session->ok;
 
272
}
 
273
 
 
274
 
 
275
bool
 
276
xen_sr_get_type(xen_session *session, char **result, xen_sr sr)
 
277
{
 
278
    abstract_value param_values[] =
 
279
        {
 
280
            { .type = &abstract_type_string,
 
281
              .u.string_val = sr }
 
282
        };
 
283
 
 
284
    abstract_type result_type = abstract_type_string;
 
285
 
 
286
    *result = NULL;
 
287
    XEN_CALL_("SR.get_type");
 
288
    return session->ok;
 
289
}
 
290
 
 
291
 
 
292
bool
 
293
xen_sr_get_content_type(xen_session *session, char **result, xen_sr sr)
 
294
{
 
295
    abstract_value param_values[] =
 
296
        {
 
297
            { .type = &abstract_type_string,
 
298
              .u.string_val = sr }
 
299
        };
 
300
 
 
301
    abstract_type result_type = abstract_type_string;
 
302
 
 
303
    *result = NULL;
 
304
    XEN_CALL_("SR.get_content_type");
 
305
    return session->ok;
 
306
}
 
307
 
 
308
 
 
309
bool
 
310
xen_sr_set_name_label(xen_session *session, xen_sr sr, char *label)
 
311
{
 
312
    abstract_value param_values[] =
 
313
        {
 
314
            { .type = &abstract_type_string,
 
315
              .u.string_val = sr },
 
316
            { .type = &abstract_type_string,
 
317
              .u.string_val = label }
 
318
        };
 
319
 
 
320
    xen_call_(session, "SR.set_name_label", param_values, 2, NULL, NULL);
 
321
    return session->ok;
 
322
}
 
323
 
 
324
 
 
325
bool
 
326
xen_sr_set_name_description(xen_session *session, xen_sr sr, char *description)
 
327
{
 
328
    abstract_value param_values[] =
 
329
        {
 
330
            { .type = &abstract_type_string,
 
331
              .u.string_val = sr },
 
332
            { .type = &abstract_type_string,
 
333
              .u.string_val = description }
 
334
        };
 
335
 
 
336
    xen_call_(session, "SR.set_name_description", param_values, 2, NULL, NULL);
 
337
    return session->ok;
 
338
}
 
339
 
 
340
 
 
341
bool
 
342
xen_sr_get_supported_types(xen_session *session, struct xen_string_set **result)
 
343
{
 
344
 
 
345
    abstract_type result_type = abstract_type_string_set;
 
346
 
 
347
    *result = NULL;
 
348
    xen_call_(session, "SR.get_supported_types", NULL, 0, &result_type, result);
 
349
    return session->ok;
 
350
}
 
351
 
 
352
 
 
353
bool
 
354
xen_sr_get_all(xen_session *session, struct xen_sr_set **result)
 
355
{
 
356
 
 
357
    abstract_type result_type = abstract_type_string_set;
 
358
 
 
359
    *result = NULL;
 
360
    xen_call_(session, "SR.get_all", NULL, 0, &result_type, result);
 
361
    return session->ok;
 
362
}
 
363
 
 
364
 
 
365
bool
 
366
xen_sr_get_uuid(xen_session *session, char **result, xen_sr sr)
 
367
{
 
368
    abstract_value param_values[] =
 
369
        {
 
370
            { .type = &abstract_type_string,
 
371
              .u.string_val = sr }
 
372
        };
 
373
 
 
374
    abstract_type result_type = abstract_type_string;
 
375
 
 
376
    *result = NULL;
 
377
    XEN_CALL_("SR.get_uuid");
 
378
    return session->ok;
 
379
}