Subversion Repositories HelenOS

Rev

Rev 4539 | Rev 4566 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4539 Rev 4551
Line 283... Line 283...
283
 * @return      Phone over which a multi-call request can be safely
283
 * @return      Phone over which a multi-call request can be safely
284
 *          sent. Return 0 if no phone was found.
284
 *          sent. Return 0 if no phone was found.
285
 */
285
 */
286
int vfs_grab_phone(fs_handle_t handle)
286
int vfs_grab_phone(fs_handle_t handle)
287
{
287
{
-
 
288
    int phone;
-
 
289
 
288
    /*
290
    /*
289
     * 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
290
     * 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
291
     * 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
292
     * straightforward; housekeeping multiple open phones to a FS task would
-
 
293
     * be more demanding). Instead, we simply take the respective
294
     * communication.  In the future, we should cache the connections so
294
     * phone_futex and keep it until vfs_release_phone().
295
     * that they do not have to be reestablished over and over again.
295
     */
296
     */
296
    fibril_mutex_lock(&fs_head_lock);
297
    fibril_mutex_lock(&fs_head_lock);
297
    link_t *cur;
298
    link_t *cur;
298
    fs_info_t *fs;
299
    fs_info_t *fs;
299
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
300
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
300
        fs = list_get_instance(cur, fs_info_t, fs_link);
301
        fs = list_get_instance(cur, fs_info_t, fs_link);
301
        if (fs->fs_handle == handle) {
302
        if (fs->fs_handle == handle) {
302
            fibril_mutex_unlock(&fs_head_lock);
303
            fibril_mutex_unlock(&fs_head_lock);
303
            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);
304
            return fs->phone;
309
            return phone;
305
        }
310
        }
306
    }
311
    }
307
    fibril_mutex_unlock(&fs_head_lock);
312
    fibril_mutex_unlock(&fs_head_lock);
308
    return 0;
313
    return 0;
309
}
314
}
310
 
315
 
311
/** Tell VFS that the phone is in use for any request.
316
/** Tell VFS that the phone is not needed anymore.
312
 *
317
 *
313
 * @param phone     Phone to FS task.
318
 * @param phone     Phone to FS task.
314
 */
319
 */
315
void vfs_release_phone(int phone)
320
void vfs_release_phone(int phone)
316
{
321
{
317
    bool found = false;
-
 
318
 
-
 
319
    fibril_mutex_lock(&fs_head_lock);
-
 
320
    link_t *cur;
-
 
321
    for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
322
    /* TODO: implement connection caching */
322
        fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
-
 
323
        if (fs->phone == phone) {
323
    ipc_hangup(phone);
324
            found = true;
-
 
325
            fibril_mutex_unlock(&fs_head_lock);
-
 
326
            fibril_mutex_unlock(&fs->phone_lock);
-
 
327
            return;
-
 
328
        }
-
 
329
    }
-
 
330
    fibril_mutex_unlock(&fs_head_lock);
-
 
331
 
-
 
332
    /*
-
 
333
     * Not good to get here.
-
 
334
     */
-
 
335
    assert(found == true);
-
 
336
}
324
}
337
 
325
 
338
/** Convert file system name to its handle.
326
/** Convert file system name to its handle.
339
 *
327
 *
340
 * @param name      File system name.
328
 * @param name      File system name.