Rev 4537 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4537 | Rev 4668 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | #include <as.h> |
50 | #include <as.h> |
51 | #include <assert.h> |
51 | #include <assert.h> |
52 | #include <atomic.h> |
52 | #include <atomic.h> |
53 | #include "vfs.h" |
53 | #include "vfs.h" |
54 | 54 | ||
- | 55 | FIBRIL_CONDVAR_INITIALIZE(fs_head_cv); |
|
55 | FIBRIL_MUTEX_INITIALIZE(fs_head_lock); |
56 | FIBRIL_MUTEX_INITIALIZE(fs_head_lock); |
56 | link_t fs_head; |
57 | LIST_INITIALIZE(fs_head); |
57 | 58 | ||
58 | atomic_t fs_handle_next = { |
59 | atomic_t fs_handle_next = { |
59 | .count = 1 |
60 | .count = 1 |
60 | }; |
61 | }; |
61 | 62 | ||
Line 266... | Line 267... | ||
266 | * system a global file system handle. |
267 | * system a global file system handle. |
267 | */ |
268 | */ |
268 | fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next); |
269 | fs_info->fs_handle = (fs_handle_t) atomic_postinc(&fs_handle_next); |
269 | ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle); |
270 | ipc_answer_1(rid, EOK, (ipcarg_t) fs_info->fs_handle); |
270 | 271 | ||
- | 272 | fibril_condvar_broadcast(&fs_head_cv); |
|
271 | fibril_mutex_unlock(&fs_head_lock); |
273 | fibril_mutex_unlock(&fs_head_lock); |
272 | 274 | ||
273 | dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n", |
275 | dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n", |
274 | FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle); |
276 | FS_NAME_MAXLEN, fs_info->vfs_info.name, fs_info->fs_handle); |
275 | } |
277 | } |
Line 281... | Line 283... | ||
281 | * @return Phone over which a multi-call request can be safely |
283 | * @return Phone over which a multi-call request can be safely |
282 | * sent. Return 0 if no phone was found. |
284 | * sent. Return 0 if no phone was found. |
283 | */ |
285 | */ |
284 | int vfs_grab_phone(fs_handle_t handle) |
286 | int vfs_grab_phone(fs_handle_t handle) |
285 | { |
287 | { |
- | 288 | int phone; |
|
- | 289 | ||
286 | /* |
290 | /* |
287 | * For now, we don't try to be very clever and very fast. |
291 | * For now, we don't try to be very clever and very fast. We simply |
288 | * We simply lookup the phone in the fs_head list. We currently don't |
292 | * lookup the phone in the fs_head list and duplicate it. The duplicate |
289 | * open any additional phones (even though that itself would be pretty |
293 | * phone will be returned to the client and the client will use it for |
290 | * straightforward; housekeeping multiple open phones to a FS task would |
- | |
291 | * be more demanding). Instead, we simply take the respective |
294 | * communication. In the future, we should cache the connections so |
292 | * phone_futex and keep it until vfs_release_phone(). |
295 | * that they do not have to be reestablished over and over again. |
293 | */ |
296 | */ |
294 | fibril_mutex_lock(&fs_head_lock); |
297 | fibril_mutex_lock(&fs_head_lock); |
295 | link_t *cur; |
298 | link_t *cur; |
296 | fs_info_t *fs; |
299 | fs_info_t *fs; |
297 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
300 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
298 | fs = list_get_instance(cur, fs_info_t, fs_link); |
301 | fs = list_get_instance(cur, fs_info_t, fs_link); |
299 | if (fs->fs_handle == handle) { |
302 | if (fs->fs_handle == handle) { |
300 | fibril_mutex_unlock(&fs_head_lock); |
303 | fibril_mutex_unlock(&fs_head_lock); |
301 | fibril_mutex_lock(&fs->phone_lock); |
304 | fibril_mutex_lock(&fs->phone_lock); |
- | 305 | phone = ipc_connect_me_to(fs->phone, 0, 0, 0); |
|
- | 306 | fibril_mutex_unlock(&fs->phone_lock); |
|
- | 307 | ||
- | 308 | assert(phone > 0); |
|
302 | return fs->phone; |
309 | return phone; |
303 | } |
310 | } |
304 | } |
311 | } |
305 | fibril_mutex_unlock(&fs_head_lock); |
312 | fibril_mutex_unlock(&fs_head_lock); |
306 | return 0; |
313 | return 0; |
307 | } |
314 | } |
308 | 315 | ||
309 | /** Tell VFS that the phone is in use for any request. |
316 | /** Tell VFS that the phone is not needed anymore. |
310 | * |
317 | * |
311 | * @param phone Phone to FS task. |
318 | * @param phone Phone to FS task. |
312 | */ |
319 | */ |
313 | void vfs_release_phone(int phone) |
320 | void vfs_release_phone(int phone) |
314 | { |
321 | { |
315 | bool found = false; |
- | |
316 | - | ||
317 | fibril_mutex_lock(&fs_head_lock); |
- | |
318 | link_t *cur; |
- | |
319 | for (cur = fs_head.next; cur != &fs_head; cur = cur->next) { |
322 | /* TODO: implement connection caching */ |
320 | fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link); |
- | |
321 | if (fs->phone == phone) { |
323 | ipc_hangup(phone); |
322 | found = true; |
- | |
323 | fibril_mutex_unlock(&fs_head_lock); |
- | |
324 | fibril_mutex_unlock(&fs->phone_lock); |
- | |
325 | return; |
- | |
326 | } |
- | |
327 | } |
- | |
328 | fibril_mutex_unlock(&fs_head_lock); |
- | |
329 | - | ||
330 | /* |
- | |
331 | * Not good to get here. |
- | |
332 | */ |
- | |
333 | assert(found == true); |
- | |
334 | } |
324 | } |
335 | 325 | ||
336 | /** Convert file system name to its handle. |
326 | /** Convert file system name to its handle. |
337 | * |
327 | * |
338 | * @param name File system name. |
328 | * @param name File system name. |