123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include "internal.h"
- #include <common/kfifo.h>
- #include <debug/bug.h>
- int vfs_dentry_put(struct vfs_dir_entry_t *dentry)
- {
- int retval = 0;
- uint64_t in_value = 0;
- struct kfifo_t fifo = {0};
- const struct vfs_dir_entry_t *start_dentry = dentry;
-
- if (unlikely(dentry->lockref.count > 1))
- {
- BUG_ON(1);
- retval = -EBUSY;
- goto out;
- }
- if (D_ISDIR(dentry))
- {
-
-
-
- retval = kfifo_alloc(&fifo, 1024 * sizeof(uint64_t), 0);
- if (retval != 0)
- goto failed;
-
- in_value = (uint64_t)dentry;
- kfifo_in(&fifo, &in_value, sizeof(uint64_t));
- list_del(&dentry->child_node_list);
- while (!kfifo_empty(&fifo))
- {
-
- kfifo_out(&fifo, &dentry, sizeof(uint64_t));
- BUG_ON(dentry == NULL);
- struct List *list = &dentry->subdirs_list;
- if (!list_empty(list))
- {
-
- do
- {
- list = list_next(list);
- in_value = (uint64_t)container_of(list, struct vfs_dir_entry_t, child_node_list);
- if (in_value != NULL)
- kfifo_in(&fifo, &in_value, sizeof(uint64_t));
- } while (list_next(list) != (&dentry->subdirs_list));
- }
- if (unlikely(dentry != start_dentry))
- spin_lock(&dentry->lockref.lock);
- if (dentry->lockref.count > 1)
- {
- if (unlikely(dentry != start_dentry))
- spin_unlock(&dentry->lockref.lock);
- continue;
- }
-
- spin_lock(&dentry->dir_inode->lockref.lock);
- retval = vfs_free_inode(dentry->dir_inode);
- if (retval > 0)
- {
- spin_unlock(&dentry->dir_inode->lockref.lock);
- retval = 0;
- }
-
- if (is_local_mountpoint(dentry))
- do_umount(dentry);
- if (dentry->dir_ops->release != NULL)
- dentry->dir_ops->release(dentry);
- kfree(dentry);
- }
- kfifo_free_alloc(&fifo);
- retval = 0;
- goto out;
- }
- else
- {
- kdebug("to put dentry: file: %s", dentry->name);
- list_del(&dentry->child_node_list);
-
- spin_lock(&dentry->dir_inode->lockref.lock);
- retval = vfs_free_inode(dentry->dir_inode);
- kdebug("retval=%d", retval);
- if (retval > 0)
- spin_unlock(&dentry->dir_inode->lockref.lock);
- if (dentry->dir_ops->release != NULL)
- dentry->dir_ops->release(dentry);
- kfree(dentry);
- goto out;
- }
- failed:;
- if (fifo.buffer != NULL)
- kfifo_free_alloc(&fifo);
- kerror("dentry_put failed.");
- out:;
-
- return retval;
- }
- int vfs_free_inode(struct vfs_index_node_t *inode)
- {
- --inode->lockref.count;
- BUG_ON(inode->lockref.count < 0);
- if (inode->lockref.count == 0)
- {
- kfree(inode->private_inode_info);
- kfree(inode);
- return 0;
- }
- else
- return inode->lockref.count;
- }
|