From ee0a0729298b8bc5a30f36bbaf17e6d0e92cb93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 26 Feb 2008 10:41:43 +0000 Subject: [PATCH] * While it was broken before, having the devices_used counter updated in {get|put}_node() is not really what we want either; moved the maintenance into the open() and free_cookie() hooks. * This should fix driver reloading on change for drivers that have been used before. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24135 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/fs/devfs.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/system/kernel/fs/devfs.cpp b/src/system/kernel/fs/devfs.cpp index 6257f2f9f8..65c4e809a7 100644 --- a/src/system/kernel/fs/devfs.cpp +++ b/src/system/kernel/fs/devfs.cpp @@ -1510,9 +1510,6 @@ devfs_get_vnode(fs_volume _fs, ino_t id, fs_vnode *_vnode, bool reenter) if (vnode == NULL) return B_ENTRY_NOT_FOUND; - if (S_ISCHR(vnode->stream.type) && vnode->stream.u.dev.driver != NULL) - vnode->stream.u.dev.driver->devices_used++; - TRACE(("devfs_get_vnode: looked it up at %p\n", *_vnode)); *_vnode = vnode; @@ -1523,15 +1520,12 @@ devfs_get_vnode(fs_volume _fs, ino_t id, fs_vnode *_vnode, bool reenter) static status_t devfs_put_vnode(fs_volume _fs, fs_vnode _v, bool reenter) { - struct devfs *fs = (struct devfs *)_fs; +#ifdef TRACE_DEVFS struct devfs_vnode *vnode = (struct devfs_vnode *)_v; - TRACE(("devfs_put_vnode: entry on vnode %p, id = %Ld, reenter %d\n", vnode, vnode->id, reenter)); - - RecursiveLocker _(fs->lock); - - if (S_ISCHR(vnode->stream.type) && vnode->stream.u.dev.driver != NULL) - vnode->stream.u.dev.driver->devices_used++; + TRACE(("devfs_put_vnode: entry on vnode %p, id = %Ld, reenter %d\n", + vnode, vnode->id, reenter)); +#endif return B_OK; } @@ -1626,6 +1620,7 @@ static status_t devfs_open(fs_volume _fs, fs_vnode _vnode, int openMode, fs_cookie *_cookie) { struct devfs_vnode *vnode = (struct devfs_vnode *)_vnode; + struct devfs *fs = (struct devfs *)_fs; struct devfs_cookie *cookie; status_t status = B_OK; @@ -1647,6 +1642,11 @@ devfs_open(fs_volume _fs, fs_vnode _vnode, int openMode, fs_cookie *_cookie) status = vnode->stream.u.dev.ops->open(buffer, openMode, &cookie->device_cookie); } + + RecursiveLocker _(fs->lock); + + if (status == B_OK && vnode->stream.u.dev.driver != NULL) + vnode->stream.u.dev.driver->devices_used++; } if (status < B_OK) free(cookie); @@ -1679,12 +1679,18 @@ devfs_free_cookie(fs_volume _fs, fs_vnode _vnode, fs_cookie _cookie) { struct devfs_vnode *vnode = (struct devfs_vnode *)_vnode; struct devfs_cookie *cookie = (struct devfs_cookie *)_cookie; + struct devfs *fs = (struct devfs *)_fs; TRACE(("devfs_freecookie: entry vnode %p, cookie %p\n", vnode, cookie)); if (S_ISCHR(vnode->stream.type)) { // pass the call through to the underlying device vnode->stream.u.dev.info->free(cookie->device_cookie); + + RecursiveLocker _(fs->lock); + + if (vnode->stream.u.dev.driver != NULL) + vnode->stream.u.dev.driver->devices_used--; } free(cookie);