1 | /*
|
---|
2 | * Copyright (c) 2015 Jiri Svoboda
|
---|
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
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file Virtual Block Device client API
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <errno.h>
|
---|
36 | #include <ipc/services.h>
|
---|
37 | #include <ipc/vbd.h>
|
---|
38 | #include <loc.h>
|
---|
39 | #include <stdlib.h>
|
---|
40 | #include <types/label.h>
|
---|
41 | #include <vbd.h>
|
---|
42 |
|
---|
43 | int vbd_create(vbd_t **rvbd)
|
---|
44 | {
|
---|
45 | vbd_t *vbd;
|
---|
46 | service_id_t vbd_svcid;
|
---|
47 | int rc;
|
---|
48 |
|
---|
49 | vbd = calloc(1, sizeof(vbd_t));
|
---|
50 | if (vbd == NULL) {
|
---|
51 | rc = ENOMEM;
|
---|
52 | goto error;
|
---|
53 | }
|
---|
54 |
|
---|
55 | rc = loc_service_get_id(SERVICE_NAME_VBD, &vbd_svcid,
|
---|
56 | IPC_FLAG_BLOCKING);
|
---|
57 | if (rc != EOK) {
|
---|
58 | rc = EIO;
|
---|
59 | goto error;
|
---|
60 | }
|
---|
61 |
|
---|
62 | vbd->sess = loc_service_connect(EXCHANGE_SERIALIZE, vbd_svcid,
|
---|
63 | IPC_FLAG_BLOCKING);
|
---|
64 | if (vbd->sess == NULL) {
|
---|
65 | rc = EIO;
|
---|
66 | goto error;
|
---|
67 | }
|
---|
68 |
|
---|
69 | *rvbd = vbd;
|
---|
70 | return EOK;
|
---|
71 | error:
|
---|
72 | free(vbd);
|
---|
73 | return rc;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void vbd_destroy(vbd_t *vbd)
|
---|
77 | {
|
---|
78 | if (vbd == NULL)
|
---|
79 | return;
|
---|
80 |
|
---|
81 | async_hangup(vbd->sess);
|
---|
82 | free(vbd);
|
---|
83 | }
|
---|
84 |
|
---|
85 | int vbd_disk_add(vbd_t *vbd, service_id_t disk_sid)
|
---|
86 | {
|
---|
87 | async_exch_t *exch;
|
---|
88 |
|
---|
89 | exch = async_exchange_begin(vbd->sess);
|
---|
90 | sysarg_t rc = async_req_1_0(exch, VBD_DISK_ADD, disk_sid);
|
---|
91 | async_exchange_end(exch);
|
---|
92 |
|
---|
93 | return (int)rc;
|
---|
94 | }
|
---|
95 |
|
---|
96 | int vbd_disk_remove(vbd_t *vbd, service_id_t disk_sid)
|
---|
97 | {
|
---|
98 | async_exch_t *exch;
|
---|
99 |
|
---|
100 | exch = async_exchange_begin(vbd->sess);
|
---|
101 | sysarg_t rc = async_req_1_0(exch, VBD_DISK_REMOVE, disk_sid);
|
---|
102 | async_exchange_end(exch);
|
---|
103 |
|
---|
104 | return (int)rc;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /** Get disk information. */
|
---|
108 | int vbd_disk_info(vbd_t *vbd, service_id_t sid, vbd_disk_info_t *vinfo)
|
---|
109 | {
|
---|
110 | async_exch_t *exch;
|
---|
111 | sysarg_t ltype;
|
---|
112 | int retval;
|
---|
113 |
|
---|
114 | exch = async_exchange_begin(vbd->sess);
|
---|
115 | retval = async_req_1_1(exch, VBD_DISK_INFO, sid, <ype);
|
---|
116 | async_exchange_end(exch);
|
---|
117 |
|
---|
118 | if (retval != EOK)
|
---|
119 | return EIO;
|
---|
120 |
|
---|
121 | vinfo->ltype = (label_type_t)ltype;
|
---|
122 | return EOK;
|
---|
123 | }
|
---|
124 |
|
---|
125 | int vbd_label_create(vbd_t *vbd, service_id_t sid, label_type_t ltype)
|
---|
126 | {
|
---|
127 | async_exch_t *exch;
|
---|
128 | int retval;
|
---|
129 |
|
---|
130 | exch = async_exchange_begin(vbd->sess);
|
---|
131 | retval = async_req_2_0(exch, VBD_LABEL_CREATE, sid, ltype);
|
---|
132 | async_exchange_end(exch);
|
---|
133 |
|
---|
134 | if (retval != EOK)
|
---|
135 | return EIO;
|
---|
136 |
|
---|
137 | return EOK;
|
---|
138 | }
|
---|
139 |
|
---|
140 | int vbd_label_delete(vbd_t *vbd, service_id_t sid)
|
---|
141 | {
|
---|
142 | async_exch_t *exch;
|
---|
143 | int retval;
|
---|
144 |
|
---|
145 | exch = async_exchange_begin(vbd->sess);
|
---|
146 | retval = async_req_1_0(exch, VBD_LABEL_DELETE, sid);
|
---|
147 | async_exchange_end(exch);
|
---|
148 |
|
---|
149 | if (retval != EOK)
|
---|
150 | return EIO;
|
---|
151 |
|
---|
152 | return EOK;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /** @}
|
---|
156 | */
|
---|