clang-format
This commit is contained in:
176
kern/vfs/vnode.c
176
kern/vfs/vnode.c
@@ -40,50 +40,43 @@
|
||||
/*
|
||||
* Initialize an abstract vnode.
|
||||
*/
|
||||
int
|
||||
vnode_init(struct vnode *vn, const struct vnode_ops *ops,
|
||||
struct fs *fs, void *fsdata)
|
||||
{
|
||||
KASSERT(vn != NULL);
|
||||
KASSERT(ops != NULL);
|
||||
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;
|
||||
spinlock_init(&vn->vn_countlock);
|
||||
vn->vn_fs = fs;
|
||||
vn->vn_data = fsdata;
|
||||
return 0;
|
||||
vn->vn_ops = ops;
|
||||
vn->vn_refcount = 1;
|
||||
spinlock_init(&vn->vn_countlock);
|
||||
vn->vn_fs = fs;
|
||||
vn->vn_data = fsdata;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Destroy an abstract vnode.
|
||||
*/
|
||||
void
|
||||
vnode_cleanup(struct vnode *vn)
|
||||
{
|
||||
KASSERT(vn->vn_refcount == 1);
|
||||
void vnode_cleanup(struct vnode *vn) {
|
||||
KASSERT(vn->vn_refcount == 1);
|
||||
|
||||
spinlock_cleanup(&vn->vn_countlock);
|
||||
spinlock_cleanup(&vn->vn_countlock);
|
||||
|
||||
vn->vn_ops = NULL;
|
||||
vn->vn_refcount = 0;
|
||||
vn->vn_fs = NULL;
|
||||
vn->vn_data = NULL;
|
||||
vn->vn_ops = NULL;
|
||||
vn->vn_refcount = 0;
|
||||
vn->vn_fs = NULL;
|
||||
vn->vn_data = NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Increment refcount.
|
||||
* Called by VOP_INCREF.
|
||||
*/
|
||||
void
|
||||
vnode_incref(struct vnode *vn)
|
||||
{
|
||||
KASSERT(vn != NULL);
|
||||
void vnode_incref(struct vnode *vn) {
|
||||
KASSERT(vn != NULL);
|
||||
|
||||
spinlock_acquire(&vn->vn_countlock);
|
||||
vn->vn_refcount++;
|
||||
spinlock_release(&vn->vn_countlock);
|
||||
spinlock_acquire(&vn->vn_countlock);
|
||||
vn->vn_refcount++;
|
||||
spinlock_release(&vn->vn_countlock);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -91,88 +84,79 @@ vnode_incref(struct vnode *vn)
|
||||
* Called by VOP_DECREF.
|
||||
* Calls VOP_RECLAIM if the refcount hits zero.
|
||||
*/
|
||||
void
|
||||
vnode_decref(struct vnode *vn)
|
||||
{
|
||||
bool destroy;
|
||||
int result;
|
||||
void vnode_decref(struct vnode *vn) {
|
||||
bool destroy;
|
||||
int result;
|
||||
|
||||
KASSERT(vn != NULL);
|
||||
KASSERT(vn != NULL);
|
||||
|
||||
spinlock_acquire(&vn->vn_countlock);
|
||||
spinlock_acquire(&vn->vn_countlock);
|
||||
|
||||
KASSERT(vn->vn_refcount > 0);
|
||||
if (vn->vn_refcount > 1) {
|
||||
vn->vn_refcount--;
|
||||
destroy = false;
|
||||
}
|
||||
else {
|
||||
/* Don't decrement; pass the reference to VOP_RECLAIM. */
|
||||
destroy = true;
|
||||
}
|
||||
spinlock_release(&vn->vn_countlock);
|
||||
KASSERT(vn->vn_refcount > 0);
|
||||
if (vn->vn_refcount > 1) {
|
||||
vn->vn_refcount--;
|
||||
destroy = false;
|
||||
} else {
|
||||
/* Don't decrement; pass the reference to VOP_RECLAIM. */
|
||||
destroy = true;
|
||||
}
|
||||
spinlock_release(&vn->vn_countlock);
|
||||
|
||||
if (destroy) {
|
||||
result = VOP_RECLAIM(vn);
|
||||
if (result != 0 && result != EBUSY) {
|
||||
// XXX: lame.
|
||||
kprintf("vfs: Warning: VOP_RECLAIM: %s\n",
|
||||
strerror(result));
|
||||
}
|
||||
}
|
||||
if (destroy) {
|
||||
result = VOP_RECLAIM(vn);
|
||||
if (result != 0 && result != EBUSY) {
|
||||
// XXX: lame.
|
||||
kprintf("vfs: Warning: VOP_RECLAIM: %s\n", strerror(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for various things being valid.
|
||||
* Called before all VOP_* calls.
|
||||
*/
|
||||
void
|
||||
vnode_check(struct vnode *v, const char *opstr)
|
||||
{
|
||||
/* not safe, and not really needed to check constant fields */
|
||||
/*vfs_biglock_acquire();*/
|
||||
void vnode_check(struct vnode *v, const char *opstr) {
|
||||
/* not safe, and not really needed to check constant fields */
|
||||
/*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 == 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 == 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_ops->vop_magic != VOP_MAGIC) {
|
||||
panic("vnode_check: vop_%s: ops with bad magic number %lx\n", opstr,
|
||||
v->vn_ops->vop_magic);
|
||||
}
|
||||
|
||||
// Device vnodes have null fs pointers.
|
||||
//if (v->vn_fs == NULL) {
|
||||
// panic("vnode_check: vop_%s: null fs pointer\n", opstr);
|
||||
//}
|
||||
if (v->vn_fs == (void *)0xdeadbeef) {
|
||||
panic("vnode_check: vop_%s: deadbeef fs pointer\n", opstr);
|
||||
}
|
||||
// Device vnodes have null fs pointers.
|
||||
// if (v->vn_fs == NULL) {
|
||||
// panic("vnode_check: vop_%s: null fs pointer\n", opstr);
|
||||
//}
|
||||
if (v->vn_fs == (void *)0xdeadbeef) {
|
||||
panic("vnode_check: vop_%s: deadbeef fs pointer\n", opstr);
|
||||
}
|
||||
|
||||
spinlock_acquire(&v->vn_countlock);
|
||||
spinlock_acquire(&v->vn_countlock);
|
||||
|
||||
if (v->vn_refcount < 0) {
|
||||
panic("vnode_check: vop_%s: negative refcount %d\n", opstr,
|
||||
v->vn_refcount);
|
||||
}
|
||||
else if (v->vn_refcount == 0) {
|
||||
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_refcount < 0) {
|
||||
panic("vnode_check: vop_%s: negative refcount %d\n", opstr, v->vn_refcount);
|
||||
} else if (v->vn_refcount == 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
spinlock_release(&v->vn_countlock);
|
||||
/*vfs_biglock_release();*/
|
||||
spinlock_release(&v->vn_countlock);
|
||||
/*vfs_biglock_release();*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user