Changeset c028b22 in mainline for uspace/srv/vfs/vfs_register.c


Ignore:
Timestamp:
2011-07-08T17:01:01Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc1a727
Parents:
4e36219 (diff), 026793d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r4e36219 rc028b22  
    5252#include "vfs.h"
    5353
    54 FIBRIL_CONDVAR_INITIALIZE(fs_head_cv);
    55 FIBRIL_MUTEX_INITIALIZE(fs_head_lock);
    56 LIST_INITIALIZE(fs_head);
     54FIBRIL_CONDVAR_INITIALIZE(fs_list_cv);
     55FIBRIL_MUTEX_INITIALIZE(fs_list_lock);
     56LIST_INITIALIZE(fs_list);
    5757
    5858atomic_t fs_handle_next = {
     
    6262/** Verify the VFS info structure.
    6363 *
    64  * @param info          Info structure to be verified.
    65  *
    66  * @return              Non-zero if the info structure is sane, zero otherwise.
     64 * @param info Info structure to be verified.
     65 *
     66 * @return Non-zero if the info structure is sane, zero otherwise.
     67 *
    6768 */
    6869static bool vfs_info_sane(vfs_info_t *info)
    6970{
    7071        int i;
    71 
     72       
    7273        /*
    7374         * Check if the name is non-empty and is composed solely of ASCII
     
    7879                return false;
    7980        }
     81       
    8082        for (i = 1; i < FS_NAME_MAXLEN; i++) {
    8183                if (!(islower(info->name[i]) || isdigit(info->name[i])) &&
     
    9092                }
    9193        }
     94       
    9295        /*
    9396         * This check is not redundant. It ensures that the name is
     
    104107/** VFS_REGISTER protocol function.
    105108 *
    106  * @param rid           Hash of the call with the request.
    107  * @param request       Call structure with the request.
     109 * @param rid     Hash of the call with the request.
     110 * @param request Call structure with the request.
     111 *
    108112 */
    109113void vfs_register(ipc_callid_t rid, ipc_call_t *request)
    110114{
    111         int phone;
    112        
    113115        dprintf("Processing VFS_REGISTER request received from %p.\n",
    114116            request->in_phone_hash);
     
    147149        }
    148150       
    149         fibril_mutex_lock(&fs_head_lock);
     151        fibril_mutex_lock(&fs_list_lock);
    150152       
    151153        /*
     
    157159                 */
    158160                dprintf("FS is already registered.\n");
    159                 fibril_mutex_unlock(&fs_head_lock);
     161                fibril_mutex_unlock(&fs_list_lock);
    160162                free(fs_info);
    161163                async_answer_0(rid, EEXISTS);
     
    167169         */
    168170        dprintf("Inserting FS into the list of registered file systems.\n");
    169         list_append(&fs_info->fs_link, &fs_head);
     171        list_append(&fs_info->fs_link, &fs_list);
    170172       
    171173        /*
     
    174176         * which to forward VFS requests to it.
    175177         */
    176         ipc_call_t call;
    177         ipc_callid_t callid = async_get_call(&call);
    178         if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
    179                 dprintf("Unexpected call, method = %d\n", IPC_GET_IMETHOD(call));
     178        fs_info->sess = async_callback_receive(EXCHANGE_PARALLEL);
     179        if (!fs_info->sess) {
     180                dprintf("Callback connection expected\n");
    180181                list_remove(&fs_info->fs_link);
    181                 fibril_mutex_unlock(&fs_head_lock);
    182                 free(fs_info);
    183                 async_answer_0(callid, EINVAL);
     182                fibril_mutex_unlock(&fs_list_lock);
     183                free(fs_info);
    184184                async_answer_0(rid, EINVAL);
    185185                return;
    186186        }
    187187       
    188         phone = IPC_GET_ARG5(call);
    189         async_session_create(&fs_info->session, phone, 0);
    190         async_answer_0(callid, EOK);
    191        
    192188        dprintf("Callback connection to FS created.\n");
    193189       
     
    197193       
    198194        size_t size;
     195        ipc_callid_t callid;
    199196        if (!async_share_in_receive(&callid, &size)) {
    200197                dprintf("Unexpected call, method = %d\n", IPC_GET_IMETHOD(call));
    201198                list_remove(&fs_info->fs_link);
    202                 fibril_mutex_unlock(&fs_head_lock);
    203                 async_session_destroy(&fs_info->session);
    204                 async_hangup(phone);
     199                fibril_mutex_unlock(&fs_list_lock);
     200                async_hangup(fs_info->sess);
    205201                free(fs_info);
    206202                async_answer_0(callid, EINVAL);
     
    215211                dprintf("Client suggests wrong size of PFB, size = %d\n", size);
    216212                list_remove(&fs_info->fs_link);
    217                 fibril_mutex_unlock(&fs_head_lock);
    218                 async_session_destroy(&fs_info->session);
    219                 async_hangup(phone);
     213                fibril_mutex_unlock(&fs_list_lock);
     214                async_hangup(fs_info->sess);
    220215                free(fs_info);
    221216                async_answer_0(callid, EINVAL);
     
    240235        async_answer_1(rid, EOK, (sysarg_t) fs_info->fs_handle);
    241236       
    242         fibril_condvar_broadcast(&fs_head_cv);
    243         fibril_mutex_unlock(&fs_head_lock);
     237        fibril_condvar_broadcast(&fs_list_cv);
     238        fibril_mutex_unlock(&fs_list_lock);
    244239       
    245240        dprintf("\"%.*s\" filesystem successfully registered, handle=%d.\n",
     
    247242}
    248243
    249 /** For a given file system handle, implement policy for allocating a phone.
    250  *
    251  * @param handle        File system handle.
    252  *
    253  * @return              Phone over which a multi-call request can be safely
    254  *                      sent. Return 0 if no phone was found.
    255  */
    256 int vfs_grab_phone(fs_handle_t handle)
    257 {
    258         link_t *cur;
    259         fs_info_t *fs;
    260         int phone;
    261 
    262         /*
    263          * For now, we don't try to be very clever and very fast.  We simply
    264          * lookup the phone in the fs_head list and duplicate it.  The duplicate
    265          * phone will be returned to the client and the client will use it for
    266          * communication.  In the future, we should cache the connections so
    267          * that they do not have to be reestablished over and over again.
    268          */
    269         fibril_mutex_lock(&fs_head_lock);
    270         for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
    271                 fs = list_get_instance(cur, fs_info_t, fs_link);
     244/** Begin an exchange for a given file system handle
     245 *
     246 * @param handle File system handle.
     247 *
     248 * @return Exchange for a multi-call request.
     249 * @return NULL if no such file exists.
     250 *
     251 */
     252async_exch_t *vfs_exchange_grab(fs_handle_t handle)
     253{
     254        /*
     255         * For now, we don't try to be very clever and very fast.
     256         * We simply lookup the session in fs_list and
     257         * begin an exchange.
     258         */
     259        fibril_mutex_lock(&fs_list_lock);
     260       
     261        list_foreach(fs_list, cur) {
     262                fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
     263               
    272264                if (fs->fs_handle == handle) {
    273                         fibril_mutex_unlock(&fs_head_lock);
    274                         phone = async_exchange_begin(&fs->session);
    275 
    276                         assert(phone > 0);
    277                         return phone;
     265                        fibril_mutex_unlock(&fs_list_lock);
     266                       
     267                        assert(fs->sess);
     268                        async_exch_t *exch = async_exchange_begin(fs->sess);
     269                       
     270                        assert(exch);
     271                        return exch;
    278272                }
    279273        }
    280         fibril_mutex_unlock(&fs_head_lock);
    281         return 0;
    282 }
    283 
    284 /** Tell VFS that the phone is not needed anymore.
    285  *
    286  * @param phone         Phone to FS task.
    287  */
    288 void vfs_release_phone(fs_handle_t handle, int phone)
    289 {
    290         link_t *cur;
    291         fs_info_t *fs;
    292 
    293         fibril_mutex_lock(&fs_head_lock);
    294         for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
    295                 fs = list_get_instance(cur, fs_info_t, fs_link);
    296                 if (fs->fs_handle == handle) {
    297                         fibril_mutex_unlock(&fs_head_lock);
    298                         async_exchange_end(&fs->session, phone);
    299                         return;
    300                 }
    301         }
    302         /* should not really get here */
    303         abort();
    304         fibril_mutex_unlock(&fs_head_lock);
     274       
     275        fibril_mutex_unlock(&fs_list_lock);
     276       
     277        return NULL;
     278}
     279
     280/** End VFS server exchange.
     281 *
     282 * @param exch   VFS server exchange.
     283 *
     284 */
     285void vfs_exchange_release(async_exch_t *exch)
     286{
     287        async_exchange_end(exch);
    305288}
    306289
    307290/** Convert file system name to its handle.
    308291 *
    309  * @param name          File system name.
    310  * @param lock          If true, the function will lock and unlock the
    311  *                      fs_head_lock.
    312  *
    313  * @return              File system handle or zero if file system not found.
     292 * @param name File system name.
     293 * @param lock If true, the function will lock and unlock the
     294 *             fs_list_lock.
     295 *
     296 * @return File system handle or zero if file system not found.
     297 *
    314298 */
    315299fs_handle_t fs_name_to_handle(char *name, bool lock)
     
    318302       
    319303        if (lock)
    320                 fibril_mutex_lock(&fs_head_lock);
    321         link_t *cur;
    322         for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     304                fibril_mutex_lock(&fs_list_lock);
     305       
     306        list_foreach(fs_list, cur) {
    323307                fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
    324308                if (str_cmp(fs->vfs_info.name, name) == 0) {
     
    327311                }
    328312        }
     313       
    329314        if (lock)
    330                 fibril_mutex_unlock(&fs_head_lock);
     315                fibril_mutex_unlock(&fs_list_lock);
     316       
    331317        return handle;
    332318}
     
    334320/** Find the VFS info structure.
    335321 *
    336  * @param handle        FS handle for which the VFS info structure is sought.
    337  * @return              VFS info structure on success or NULL otherwise.
     322 * @param handle FS handle for which the VFS info structure is sought.
     323 *
     324 * @return VFS info structure on success or NULL otherwise.
     325 *
    338326 */
    339327vfs_info_t *fs_handle_to_info(fs_handle_t handle)
    340328{
    341329        vfs_info_t *info = NULL;
    342         link_t *cur;
    343 
    344         fibril_mutex_lock(&fs_head_lock);
    345         for (cur = fs_head.next; cur != &fs_head; cur = cur->next) {
     330       
     331        fibril_mutex_lock(&fs_list_lock);
     332        list_foreach(fs_list, cur) {
    346333                fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
    347334                if (fs->fs_handle == handle) {
     
    350337                }
    351338        }
    352         fibril_mutex_unlock(&fs_head_lock);
    353 
     339        fibril_mutex_unlock(&fs_list_lock);
     340       
    354341        return info;
    355342}
     
    357344/**
    358345 * @}
    359  */ 
     346 */
Note: See TracChangeset for help on using the changeset viewer.