Changeset 5f4cfb1e in mainline for uspace/srv/vfs/vfs_register.c


Ignore:
Timestamp:
2007-09-28T10:36:31Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
13125d3
Parents:
566d798d
Message:

VFS work.
Upon FS registration via VFS_REGISTER, the client is assigned a unique file
system handle. When generating the VFS_LOOKUP request in VFS, we also need to
pass the device handle. Add function to transform file system handle to phone.
Implement basic multi-call VFS request serialization on VFS side.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_register.c

    r566d798d r5f4cfb1e  
    4848#include <as.h>
    4949#include <libadt/list.h>
     50#include <assert.h>
    5051#include "vfs.h"
    5152
    5253atomic_t fs_head_futex = FUTEX_INITIALIZER;
    5354link_t fs_head;
     55
     56atomic_t fs_handle_next = {
     57        .count = 1
     58};
    5459
    5560/** Verify the VFS info structure.
     
    306311        /*
    307312         * That was it. The FS has been registered.
    308          */
    309         ipc_answer_fast(rid, EOK, 0, 0);
    310         dprintf("\"%s\" filesystem successfully registered.\n",
    311             fs_info->vfs_info.name);
    312 
     313         * In reply to the VFS_REGISTER request, we assign the client file
     314         * system a global file system handle.
     315         */
     316        fs_info->fs_handle = (int) atomic_postinc(&fs_handle_next);
     317        ipc_answer_fast(rid, EOK, (ipcarg_t) fs_info->fs_handle, 0);
     318        dprintf("\"%s\" filesystem successfully registered, handle=%d.\n",
     319            fs_info->vfs_info.name, fs_info->fs_handle);
     320
     321}
     322
     323/** For a given file system handle, implement policy for allocating a phone.
     324 *
     325 * @param handle        File system handle.
     326 *
     327 * @return              Phone over which a multi-call request can be safely
     328 *                      sent. Return 0 if no phone was found.
     329 */
     330int vfs_grab_phone(int handle)
     331{
     332        /*
     333         * For now, we don't try to be very clever and very fast.
     334         * We simply lookup the phone in the fs_head list. We currently don't
     335         * open any additional phones (even though that itself would be pretty
     336         * straightforward; housekeeping multiple open phones to a FS task would
     337         * be more demanding). Instead, we simply take the respective
     338         * phone_futex and keep it until vfs_release_phone().
     339         */
     340        futex_down(&fs_head_futex);
     341        link_t *cur;
     342        fs_info_t *fs;
     343        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     344                fs = list_get_instance(cur, fs_info_t, fs_link);
     345                if (fs->fs_handle == handle) {
     346                        futex_up(&fs_head_futex);
     347                        /*
     348                         * For now, take the futex unconditionally.
     349                         * Oh yeah, serialization rocks.
     350                         * It will be up'ed in vfs_release_phone().
     351                         */
     352                        futex_down(&fs->phone_futex);
     353                        return fs->phone;
     354                }
     355        }
     356        futex_up(&fs_head_futex);
     357        return 0;
     358}
     359
     360/** Tell VFS that the phone is in use for any request.
     361 *
     362 * @param phone         Phone to FS task.
     363 */
     364void vfs_release_phone(int phone)
     365{
     366        bool found = false;
     367
     368        futex_down(&fs_head_futex);
     369        link_t *cur;
     370        for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     371                fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
     372                if (fs->phone == phone) {
     373                        found = true;
     374                        futex_up(&fs_head_futex);
     375                        futex_up(&fs->phone_futex);
     376                        return;
     377                }
     378        }
     379        futex_up(&fs_head_futex);
     380
     381        /*
     382         * Not good to get here.
     383         */
     384        assert(found == true);
    313385}
    314386
Note: See TracChangeset for help on using the changeset viewer.