123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #include <types.h>
- #include <kern/errno.h>
- #include <lib.h>
- #include <synch.h>
- #include <vfs.h>
- #include <vnode.h>
- int
- vnode_init(struct vnode *vn, const struct vnode_ops *ops,
- struct fs *fs, void *fsdata)
- {
- KASSERT(vn!=NULL);
- KASSERT(ops!=NULL);
- vn->vn_ops = ops;
- vn->vn_refcount = 1;
- vn->vn_opencount = 0;
- vn->vn_fs = fs;
- vn->vn_data = fsdata;
- return 0;
- }
- void
- vnode_cleanup(struct vnode *vn)
- {
- KASSERT(vn->vn_refcount==1);
- KASSERT(vn->vn_opencount==0);
- vn->vn_ops = NULL;
- vn->vn_refcount = 0;
- vn->vn_opencount = 0;
- vn->vn_fs = NULL;
- vn->vn_data = NULL;
- }
- void
- vnode_incref(struct vnode *vn)
- {
- KASSERT(vn != NULL);
- vfs_biglock_acquire();
- vn->vn_refcount++;
- vfs_biglock_release();
- }
- void
- vnode_decref(struct vnode *vn)
- {
- int result;
- KASSERT(vn != NULL);
- vfs_biglock_acquire();
- KASSERT(vn->vn_refcount>0);
- if (vn->vn_refcount>1) {
- vn->vn_refcount--;
- }
- else {
- result = VOP_RECLAIM(vn);
- if (result != 0 && result != EBUSY) {
-
- kprintf("vfs: Warning: VOP_RECLAIM: %s\n",
- strerror(result));
- }
- }
- vfs_biglock_release();
- }
- void
- vnode_incopen(struct vnode *vn)
- {
- KASSERT(vn != NULL);
- vfs_biglock_acquire();
- vn->vn_opencount++;
- vfs_biglock_release();
- }
- void
- vnode_decopen(struct vnode *vn)
- {
- int result;
- KASSERT(vn != NULL);
- vfs_biglock_acquire();
- KASSERT(vn->vn_opencount>0);
- vn->vn_opencount--;
- if (vn->vn_opencount > 0) {
- vfs_biglock_release();
- return;
- }
- result = VOP_CLOSE(vn);
- if (result) {
-
-
-
- kprintf("vfs: Warning: VOP_CLOSE: %s\n", strerror(result));
- }
- vfs_biglock_release();
- }
- void
- vnode_check(struct vnode *v, const char *opstr)
- {
- vfs_biglock_acquire();
- if (v == NULL) {
- panic("vnode_check: vop_%s: null vnode\n", opstr);
- }
- if (v == (void *)0xdeadbeef) {
- panic("vnode_check: vop_%s: deadbeef vnode\n", opstr);
- }
- if (v->vn_ops == NULL) {
- panic("vnode_check: vop_%s: null ops pointer\n", opstr);
- }
- if (v->vn_ops == (void *)0xdeadbeef) {
- panic("vnode_check: vop_%s: deadbeef ops pointer\n", opstr);
- }
- if (v->vn_ops->vop_magic != VOP_MAGIC) {
- panic("vnode_check: vop_%s: ops with bad magic number %lx\n",
- opstr, v->vn_ops->vop_magic);
- }
-
-
-
-
- if (v->vn_fs == (void *)0xdeadbeef) {
- panic("vnode_check: vop_%s: deadbeef fs pointer\n", opstr);
- }
- if (v->vn_refcount < 0) {
- panic("vnode_check: vop_%s: negative refcount %d\n", opstr,
- v->vn_refcount);
- }
- else if (v->vn_refcount == 0 && strcmp(opstr, "reclaim")) {
- panic("vnode_check: vop_%s: zero refcount\n", opstr);
- }
- else if (v->vn_refcount > 0x100000) {
- kprintf("vnode_check: vop_%s: warning: large refcount %d\n",
- opstr, v->vn_refcount);
- }
- if (v->vn_opencount < 0) {
- panic("vnode_check: vop_%s: negative opencount %d\n", opstr,
- v->vn_opencount);
- }
- else if (v->vn_opencount > 0x100000) {
- kprintf("vnode_check: vop_%s: warning: large opencount %d\n",
- opstr, v->vn_opencount);
- }
- vfs_biglock_release();
- }
|