git: a7c198a24b12 - main - Implement vm_object_vnode() using vm_pager_getvp()
Konstantin Belousov
kib at FreeBSD.org
Fri May 7 14:08:25 UTC 2021
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=a7c198a24b12b9e6d83d7718d8d16a5cef48d35f
commit a7c198a24b12b9e6d83d7718d8d16a5cef48d35f
Author: Konstantin Belousov <kib at FreeBSD.org>
AuthorDate: 2021-05-01 01:08:28 +0000
Commit: Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-05-07 14:08:03 +0000
Implement vm_object_vnode() using vm_pager_getvp()
Allow vp_heldp argument to be NULL, in which case the returned vnode
is not held for tmpfs swap objects.
Reviewed by: markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D30070
---
sys/vm/swap_pager.c | 14 ++++++++++----
sys/vm/vm_object.c | 11 +----------
sys/vm/vm_pager.h | 9 +++------
3 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index f09a6ffc80dc..ec37a26d523d 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -3160,14 +3160,20 @@ swap_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp)
* OBJ_TMPFS_NODE flag set, but not OBJ_TMPFS. In
* this case there is no v_writecount to adjust.
*/
- VM_OBJECT_RLOCK(object);
+ if (vp_heldp != NULL)
+ VM_OBJECT_RLOCK(object);
+ else
+ VM_OBJECT_ASSERT_LOCKED(object);
if ((object->flags & OBJ_TMPFS) != 0) {
vp = object->un_pager.swp.swp_tmpfs;
if (vp != NULL) {
- vhold(vp);
*vpp = vp;
- *vp_heldp = true;
+ if (vp_heldp != NULL) {
+ vhold(vp);
+ *vp_heldp = true;
+ }
}
}
- VM_OBJECT_RUNLOCK(object);
+ if (vp_heldp != NULL)
+ VM_OBJECT_RUNLOCK(object);
}
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index 7b380608cdf4..bbcbad41f10c 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -2429,16 +2429,7 @@ vm_object_vnode(vm_object_t object)
struct vnode *vp;
VM_OBJECT_ASSERT_LOCKED(object);
- if (object->type == OBJT_VNODE) {
- vp = object->handle;
- KASSERT(vp != NULL, ("%s: OBJT_VNODE has no vnode", __func__));
- } else if (object->type == OBJT_SWAP &&
- (object->flags & OBJ_TMPFS) != 0) {
- vp = object->un_pager.swp.swp_tmpfs;
- KASSERT(vp != NULL, ("%s: OBJT_TMPFS has no vnode", __func__));
- } else {
- vp = NULL;
- }
+ vm_pager_getvp(object, &vp, NULL);
return (vp);
}
diff --git a/sys/vm/vm_pager.h b/sys/vm/vm_pager.h
index 6a35c066bea6..507123adb454 100644
--- a/sys/vm/vm_pager.h
+++ b/sys/vm/vm_pager.h
@@ -229,14 +229,11 @@ vm_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp)
pgo_getvp_t *method;
*vpp = NULL;
- *vp_heldp = false;
+ if (vp_heldp != NULL)
+ *vp_heldp = false;
method = pagertab[object->type]->pgo_getvp;
- if (method != NULL) {
+ if (method != NULL)
method(object, vpp, vp_heldp);
- } else {
- KASSERT(0,
- ("vm_pager_getvp: wrong object type obj %p", object));
- }
}
static __inline void
More information about the dev-commits-src-main
mailing list