Changeset 44358c1 in mainline


Ignore:
Timestamp:
2007-11-07T18:46:43Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f3e3e7
Parents:
b818cff
Message:

VFS work.
Increment reference counters for the VFS nodes representing the mount point and
the root of the mounted filesystem, respectively, during VFS_MOUNT. Take the
unlink_futex when transforming the triplet into a VFS node.

Location:
uspace/srv/vfs
Files:
2 edited

Legend:

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

    rb818cff r44358c1  
    6666{
    6767        int dev_handle;
     68        vfs_node_t *mp_node = NULL;
    6869
    6970        /*
     
    137138        /*
    138139         * Lookup the root node of the filesystem being mounted.
     140         * In this case, we don't need to take the unlink_futex as the root node
     141         * cannot be removed. However, we do take a reference to it so that
     142         * we can track how many times it has been mounted.
    139143         */
    140144        int rc;
     
    146150                return;
    147151        }
     152        vfs_node_t *mr_node = vfs_node_get(&mounted_root);
     153        if (!mr_node) {
     154                free(buf);
     155                ipc_answer_fast_0(rid, ENOMEM);
     156                return;
     157        }
    148158
    149159        /*
     
    156166                 * We already have the root FS.
    157167                 */
     168                futex_down(&unlink_futex);
    158169                rc = vfs_lookup_internal((char *) (buf + FS_NAME_MAXLEN),
    159170                    size - FS_NAME_MAXLEN, &mp, NULL);
     
    162173                         * The lookup failed for some reason.
    163174                         */
    164                         futex_up(&rootfs_futex);
     175                        futex_up(&unlink_futex);
     176                        futex_up(&rootfs_futex);
     177                        vfs_node_put(mr_node);  /* failed -> drop reference */
    165178                        free(buf);
    166179                        ipc_answer_fast_0(rid, rc);
    167180                        return;
    168181                }
     182                mp_node = vfs_node_get(&mp);
     183                if (!mp_node) {
     184                        futex_up(&unlink_futex);
     185                        futex_up(&rootfs_futex);
     186                        vfs_node_put(mr_node);  /* failed -> drop reference */
     187                        free(buf);
     188                        ipc_answer_fast_0(rid, ENOMEM);
     189                        return;
     190                }
     191                /*
     192                 * Now we hold a reference to mp_node.
     193                 * It will be dropped upon the corresponding VFS_UNMOUNT.
     194                 * This prevents the mount point from being deleted.
     195                 */
     196                futex_up(&unlink_futex);
    169197        } else {
    170198                /*
     
    188216                        futex_up(&rootfs_futex);
    189217                        free(buf);
     218                        vfs_node_put(mr_node);  /* failed -> drop reference */
    190219                        ipc_answer_fast_0(rid, ENOENT);
    191220                        return;
     
    218247        vfs_release_phone(phone);
    219248
     249        if ((rc1 != EOK) || (rc2 != EOK)) {
     250                /* Mount failed, drop references to mr_node and mp_node. */
     251                vfs_node_put(mr_node);
     252                if (mp_node)
     253                        vfs_node_put(mp_node);
     254        }
     255       
    220256        if (rc2 == EOK)
    221257                ipc_answer_fast_0(rid, rc1);
  • uspace/srv/vfs/vfs_unlink.c

    rb818cff r44358c1  
    4040
    4141/**
    42  * This futex serializes concurrent VFS_CREATE, VFS_OPEN and VFS_UNLINK
    43  * operations.
     42 * This futex prevents the race between a triplet-to-VFS-node resolution and a
     43 * concurrent VFS_UNLINK or VFS_RMDIR operation.
    4444 */
    4545atomic_t unlink_futex = FUTEX_INITIALIZER;
Note: See TracChangeset for help on using the changeset viewer.