* @brief Decrease reference count of a virtual node (vnode) and potentially free it * * @param[in,out] vnode Pointer to the vnode to be unreferenced */
| 137 | * @param[in,out] vnode Pointer to the vnode to be unreferenced |
| 138 | */ |
| 139 | void dfs_vnode_unref(struct dfs_vnode *vnode) |
| 140 | { |
| 141 | rt_err_t ret = RT_EOK; |
| 142 | |
| 143 | if (vnode) |
| 144 | { |
| 145 | ret = dfs_file_lock(); |
| 146 | if (ret == RT_EOK) |
| 147 | { |
| 148 | rt_atomic_sub(&(vnode->ref_count), 1); |
| 149 | DLOG(note, "vnode", "vnode ref_count=%d", rt_atomic_load(&(vnode->ref_count))); |
| 150 | #ifdef RT_USING_PAGECACHE |
| 151 | if (vnode->aspace) |
| 152 | { |
| 153 | dfs_aspace_destroy(vnode->aspace); |
| 154 | } |
| 155 | #endif |
| 156 | if (rt_atomic_load(&(vnode->ref_count)) == 0) |
| 157 | { |
| 158 | LOG_I("free a vnode: %p", vnode); |
| 159 | DLOG(msg, "vnode", "vnode", DLOG_MSG, "free vnode, ref_count=0"); |
| 160 | |
| 161 | if (vnode->mnt) |
| 162 | { |
| 163 | DLOG(msg, "vnode", vnode->mnt->fs_ops->name, DLOG_MSG, "fs_ops->free_vnode"); |
| 164 | vnode->mnt->fs_ops->free_vnode(vnode); |
| 165 | } |
| 166 | |
| 167 | dfs_file_unlock(); |
| 168 | |
| 169 | rt_free(vnode); |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | dfs_file_unlock(); |
| 174 | DLOG(note, "vnode", "vnode ref_count=%d", rt_atomic_load(&(vnode->ref_count))); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return; |
| 180 | } |
no test coverage detected