Changeset 8d049ee0 in mainline


Ignore:
Timestamp:
2009-04-18T20:14:49Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8c1eb69
Parents:
594303b
Message:

Support multiple TMPFS instances.

Location:
uspace/srv/fs/tmpfs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs.c

    r594303b r8d049ee0  
    128128{
    129129        printf(NAME ": HelenOS TMPFS file system server\n");
    130        
     130
     131        if (!tmpfs_init()) {
     132                printf(NAME ": failed to initialize TMPFS\n");
     133                return -1;
     134        }
     135
    131136        int vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
    132137        if (vfs_phone < EOK) {
     
    141146                return rc;
    142147        }
    143        
     148
    144149        printf(NAME ": Accepting connections\n");
    145150        async_manager();
  • uspace/srv/fs/tmpfs/tmpfs.h

    r594303b r8d049ee0  
    5353typedef struct tmpfs_dentry {
    5454        fs_index_t index;       /**< TMPFS node index. */
     55        dev_handle_t dev_handle;/**< Device handle. */
    5556        link_t dh_link;         /**< Dentries hash table link. */
    5657        struct tmpfs_dentry *sibling;
     
    6667
    6768extern libfs_ops_t tmpfs_libfs_ops;
     69
     70extern bool tmpfs_init(void);
    6871
    6972extern void tmpfs_mounted(ipc_callid_t, ipc_call_t *);
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r594303b r8d049ee0  
    5959#define NAMES_BUCKETS           4
    6060
    61 /*
    62  * For now, we don't distinguish between different dev_handles/instances. All
    63  * requests resolve to the only instance, rooted in the following variable.
    64  */
    65 static tmpfs_dentry_t *root;
    66 
    67 #define TMPFS_DEV               0       /**< Dummy device handle for TMPFS */
     61/** All root nodes have index 0. */
     62#define TMPFS_SOME_ROOT         0
     63/** Global counter for assigning node indices. Shared by all instances. */
     64fs_index_t tmpfs_next_index = 1;
    6865
    6966/*
     
    103100static void *tmpfs_root_get(dev_handle_t dev_handle)
    104101{
    105         return root;
     102        return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT);
    106103}
    107104
     
    143140hash_table_t dentries;
    144141
     142#define DENTRIES_KEY_INDEX      0
     143#define DENTRIES_KEY_DEV        1
     144
    145145/* Implementation of hash table interface for the dentries hash table. */
    146 static hash_index_t dentries_hash(unsigned long *key)
    147 {
    148         return *key % DENTRIES_BUCKETS;
    149 }
    150 
    151 static int dentries_compare(unsigned long *key, hash_count_t keys,
     146static hash_index_t dentries_hash(unsigned long key[])
     147{
     148        return key[DENTRIES_KEY_INDEX] % DENTRIES_BUCKETS;
     149}
     150
     151static int dentries_compare(unsigned long key[], hash_count_t keys,
    152152    link_t *item)
    153153{
    154154        tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t,
    155155            dh_link);
    156         return dentry->index == *key;
     156        return (dentry->index == key[DENTRIES_KEY_INDEX] &&
     157            dentry->dev_handle == key[DENTRIES_KEY_DEV]);
    157158}
    158159
     
    168169};
    169170
    170 fs_index_t tmpfs_next_index = 1;
    171 
    172171typedef struct {
    173172        char *name;
     
    216215{
    217216        dentry->index = 0;
     217        dentry->dev_handle = 0;
    218218        dentry->sibling = NULL;
    219219        dentry->child = NULL;
     
    227227}
    228228
    229 static bool tmpfs_init(void)
    230 {
    231         if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops))
     229bool tmpfs_init(void)
     230{
     231        if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 2, &dentries_ops))
    232232                return false;
    233         root = (tmpfs_dentry_t *) tmpfs_create_node(TMPFS_DEV, L_DIRECTORY);
    234         if (!root) {
    235                 hash_table_destroy(&dentries);
     233       
     234        return true;
     235}
     236
     237static bool tmpfs_instance_init(dev_handle_t dev_handle)
     238{
     239        tmpfs_dentry_t *root;
     240       
     241        root = (tmpfs_dentry_t *) tmpfs_create_node(dev_handle, L_DIRECTORY);
     242        if (!root)
    236243                return false;
    237         }
    238244        root->lnkcnt = 0;       /* FS root is not linked */
    239245        return true;
     
    273279tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
    274280{
    275         unsigned long key = index;
    276         link_t *lnk = hash_table_find(&dentries, &key);
     281        unsigned long key[] = {
     282                [DENTRIES_KEY_INDEX] = index,
     283                [DENTRIES_KEY_DEV] = dev_handle
     284        };
     285        link_t *lnk = hash_table_find(&dentries, key);
    277286        if (!lnk)
    278287                return NULL;
     
    297306                return NULL;
    298307        }
    299         node->index = tmpfs_next_index++;
     308        if (!tmpfs_root_get(dev_handle))
     309                node->index = TMPFS_SOME_ROOT;
     310        else
     311                node->index = tmpfs_next_index++;
     312        node->dev_handle = dev_handle;
    300313        if (lflag & L_DIRECTORY)
    301314                node->type = TMPFS_DIRECTORY;
     
    304317
    305318        /* Insert the new node into the dentry hash table. */
    306         unsigned long key = node->index;
    307         hash_table_insert(&dentries, &key, &node->dh_link);
     319        unsigned long key[] = {
     320                [DENTRIES_KEY_INDEX] = node->index,
     321                [DENTRIES_KEY_DEV] = node->dev_handle
     322        };
     323        hash_table_insert(&dentries, key, &node->dh_link);
    308324        return (void *) node;
    309325}
     
    385401        assert(!dentry->sibling);
    386402
    387         unsigned long key = dentry->index;
    388         hash_table_remove(&dentries, &key, 1);
     403        unsigned long key[] = {
     404                [DENTRIES_KEY_INDEX] = dentry->index,
     405                [DENTRIES_KEY_DEV] = dentry->dev_handle
     406        };
     407        hash_table_remove(&dentries, key, 2);
    389408
    390409        hash_table_destroy(&dentry->names);
     
    422441        opts[size] = '\0';
    423442
    424         /* Initialize TMPFS. */
    425         if (!root && !tmpfs_init()) {
     443        /* Initialize TMPFS instance. */
     444        if (!tmpfs_instance_init(dev_handle)) {
    426445                ipc_answer_0(rid, ENOMEM);
    427446                return;
    428447        }
    429448
     449        tmpfs_dentry_t *root = tmpfs_root_get(dev_handle);
    430450        if (str_cmp(opts, "restore") == 0) {
    431451                if (tmpfs_restore(dev_handle))
     
    464484         */
    465485        link_t *hlp;
    466         unsigned long key = index;
    467         hlp = hash_table_find(&dentries, &key);
     486        unsigned long key[] = {
     487                [DENTRIES_KEY_INDEX] = index,
     488                [DENTRIES_KEY_DEV] = dev_handle,
     489        };
     490        hlp = hash_table_find(&dentries, key);
    468491        if (!hlp) {
    469492                ipc_answer_0(rid, ENOENT);
     
    537560         */
    538561        link_t *hlp;
    539         unsigned long key = index;
    540         hlp = hash_table_find(&dentries, &key);
     562        unsigned long key[] = {
     563                [DENTRIES_KEY_INDEX] = index,
     564                [DENTRIES_KEY_DEV] = dev_handle
     565        };
     566        hlp = hash_table_find(&dentries, key);
    541567        if (!hlp) {
    542568                ipc_answer_0(rid, ENOENT);
     
    598624         */
    599625        link_t *hlp;
    600         unsigned long key = index;
    601         hlp = hash_table_find(&dentries, &key);
     626        unsigned long key[] = {
     627                [DENTRIES_KEY_INDEX] = index,
     628                [DENTRIES_KEY_DEV] = dev_handle
     629        };
     630        hlp = hash_table_find(&dentries, key);
    602631        if (!hlp) {
    603632                ipc_answer_0(rid, ENOENT);
     
    633662
    634663        link_t *hlp;
    635         unsigned long key = index;
    636         hlp = hash_table_find(&dentries, &key);
     664        unsigned long key[] = {
     665                [DENTRIES_KEY_INDEX] = index,
     666                [DENTRIES_KEY_DEV] = dev_handle
     667        };
     668        hlp = hash_table_find(&dentries, key);
    637669        if (!hlp) {
    638670                ipc_answer_0(rid, ENOENT);
Note: See TracChangeset for help on using the changeset viewer.