Index: sys/kern/kern_proc.c =================================================================== --- sys/kern/kern_proc.c +++ sys/kern/kern_proc.c @@ -2208,43 +2208,11 @@ freepath = NULL; fullpath = ""; if (lobj) { - vp = NULL; - switch (lobj->type) { - case OBJT_DEFAULT: - kve->kve_type = KVME_TYPE_DEFAULT; - break; - case OBJT_VNODE: - kve->kve_type = KVME_TYPE_VNODE; - vp = lobj->handle; - vref(vp); - break; - case OBJT_SWAP: - if ((lobj->flags & OBJ_TMPFS_NODE) != 0) { - kve->kve_type = KVME_TYPE_VNODE; - if ((lobj->flags & OBJ_TMPFS) != 0) { - vp = lobj->un_pager.swp.swp_tmpfs; - vref(vp); - } - } else { - kve->kve_type = KVME_TYPE_SWAP; - } - break; - case OBJT_DEVICE: - kve->kve_type = KVME_TYPE_DEVICE; - break; - case OBJT_PHYS: - kve->kve_type = KVME_TYPE_PHYS; - break; - case OBJT_DEAD: - kve->kve_type = KVME_TYPE_DEAD; - break; - case OBJT_SG: - kve->kve_type = KVME_TYPE_SG; - break; - default: + kve->kve_type = vm_object_kvme_type(lobj, &vp); + if (kve->kve_type == KVME_TYPE_MGTDEVICE) kve->kve_type = KVME_TYPE_UNKNOWN; - break; - } + if (vp != NULL) + vref(vp); if (lobj != obj) VM_OBJECT_RUNLOCK(lobj); @@ -2452,46 +2420,9 @@ freepath = NULL; fullpath = ""; if (lobj != NULL) { - vp = NULL; - switch (lobj->type) { - case OBJT_DEFAULT: - kve->kve_type = KVME_TYPE_DEFAULT; - break; - case OBJT_VNODE: - kve->kve_type = KVME_TYPE_VNODE; - vp = lobj->handle; + kve->kve_type = vm_object_kvme_type(lobj, &vp); + if (vp != NULL) vref(vp); - break; - case OBJT_SWAP: - if ((lobj->flags & OBJ_TMPFS_NODE) != 0) { - kve->kve_type = KVME_TYPE_VNODE; - if ((lobj->flags & OBJ_TMPFS) != 0) { - vp = lobj->un_pager.swp.swp_tmpfs; - vref(vp); - } - } else { - kve->kve_type = KVME_TYPE_SWAP; - } - break; - case OBJT_DEVICE: - kve->kve_type = KVME_TYPE_DEVICE; - break; - case OBJT_PHYS: - kve->kve_type = KVME_TYPE_PHYS; - break; - case OBJT_DEAD: - kve->kve_type = KVME_TYPE_DEAD; - break; - case OBJT_SG: - kve->kve_type = KVME_TYPE_SG; - break; - case OBJT_MGTDEVICE: - kve->kve_type = KVME_TYPE_MGTDEVICE; - break; - default: - kve->kve_type = KVME_TYPE_UNKNOWN; - break; - } if (lobj != obj) VM_OBJECT_RUNLOCK(lobj); Index: sys/vm/vm_object.h =================================================================== --- sys/vm/vm_object.h +++ sys/vm/vm_object.h @@ -263,6 +263,8 @@ #define VM_OBJECT_WUNLOCK(object) \ rw_wunlock(&(object)->lock) +struct vnode; + /* * The object must be locked or thread private. */ @@ -328,6 +330,7 @@ void vm_object_terminate (vm_object_t); void vm_object_set_writeable_dirty (vm_object_t); void vm_object_init (void); +int vm_object_kvme_type(vm_object_t object, struct vnode **vpp); void vm_object_madvise(vm_object_t, vm_pindex_t, vm_pindex_t, int); boolean_t vm_object_page_clean(vm_object_t object, vm_ooffset_t start, vm_ooffset_t end, int flags); Index: sys/vm/vm_object.c =================================================================== --- sys/vm/vm_object.c +++ sys/vm/vm_object.c @@ -2306,16 +2306,63 @@ } } +/* + * Return the vnode for the given object, or NULL if none exists. + * For tmpfs objects, the function may return NULL if there is + * no vnode allocated at the time of the call. + */ struct vnode * vm_object_vnode(vm_object_t object) { + struct vnode *vp; VM_OBJECT_ASSERT_LOCKED(object); - if (object->type == OBJT_VNODE) - return (object->handle); - if (object->type == OBJT_SWAP && (object->flags & OBJ_TMPFS) != 0) - return (object->un_pager.swp.swp_tmpfs); - return (NULL); + 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; + } + return (vp); +} + +/* + * Return the kvme type of the given object. + * If vpp is not NULL, set it to the object's vm_object_vnode() or NULL. + */ +int +vm_object_kvme_type(vm_object_t object, struct vnode **vpp) +{ + + VM_OBJECT_ASSERT_LOCKED(object); + if (vpp != NULL) + *vpp = vm_object_vnode(object); + switch (object->type) { + case OBJT_DEFAULT: + return (KVME_TYPE_DEFAULT); + case OBJT_VNODE: + return (KVME_TYPE_VNODE); + case OBJT_SWAP: + if ((object->flags & OBJ_TMPFS_NODE) != 0) + return (KVME_TYPE_VNODE); + return (KVME_TYPE_SWAP); + case OBJT_DEVICE: + return (KVME_TYPE_DEVICE); + case OBJT_PHYS: + return (KVME_TYPE_PHYS); + case OBJT_DEAD: + return (KVME_TYPE_DEAD); + case OBJT_SG: + return (KVME_TYPE_SG); + case OBJT_MGTDEVICE: + return (KVME_TYPE_MGTDEVICE); + default: + return (KVME_TYPE_UNKNOWN); + } } static int @@ -2392,38 +2439,9 @@ kvo->kvo_vn_fsid_freebsd11 = 0; freepath = NULL; fullpath = ""; - vp = NULL; - switch (obj->type) { - case OBJT_DEFAULT: - kvo->kvo_type = KVME_TYPE_DEFAULT; - break; - case OBJT_VNODE: - kvo->kvo_type = KVME_TYPE_VNODE; - vp = obj->handle; + kvo->kvo_type = vm_object_kvme_type(obj, &vp); + if (vp != NULL) vref(vp); - break; - case OBJT_SWAP: - kvo->kvo_type = KVME_TYPE_SWAP; - break; - case OBJT_DEVICE: - kvo->kvo_type = KVME_TYPE_DEVICE; - break; - case OBJT_PHYS: - kvo->kvo_type = KVME_TYPE_PHYS; - break; - case OBJT_DEAD: - kvo->kvo_type = KVME_TYPE_DEAD; - break; - case OBJT_SG: - kvo->kvo_type = KVME_TYPE_SG; - break; - case OBJT_MGTDEVICE: - kvo->kvo_type = KVME_TYPE_MGTDEVICE; - break; - default: - kvo->kvo_type = KVME_TYPE_UNKNOWN; - break; - } VM_OBJECT_RUNLOCK(obj); if (vp != NULL) { vn_fullpath(curthread, vp, &fullpath, &freepath);