if (result == 0) { if (flags & PGO_PDFREECLUST && !async) {
if (result == VM_PAGER_PEND || result == VM_PAGER_OK) { if (result == VM_PAGER_OK && (flags & PGO_PDFREECLUST)) {
uvm_pager_put(uobj, pg, ppsp_ptr, npages, flags, start, stop)	struct uvm_object *uobj;	/* IN */	struct vm_page *pg, ***ppsp_ptr;/* IN, IN/OUT */	int *npages;			/* IN/OUT */	int flags;			/* IN */	voff_t start, stop;		/* IN, IN */{	int result;	daddr_t swblk;	boolean_t async = (flags & PGO_SYNCIO) == 0;	struct vm_page **ppsp = *ppsp_ptr;	UVMHIST_FUNC("uvm_pager_put"); UVMHIST_CALLED(ubchist);	/*	 * note that uobj is null  if we are doing a swap-backed pageout.	 * note that uobj is !null if we are doing normal object pageout.	 * note that the page queues must be locked to cluster.	 */	if (uobj) {	/* if !swap-backed */		/*		 * attempt to build a cluster for pageout using its		 * make-put-cluster function (if it has one).		 */		if (uobj->pgops->pgo_mk_pcluster) {			ppsp = uobj->pgops->pgo_mk_pcluster(uobj, ppsp,			    npages, pg, flags, start, stop);			*ppsp_ptr = ppsp;  /* update caller's pointer */		} else {			ppsp[0] = pg;			*npages = 1;		}		swblk = 0;		/* XXX: keep gcc happy */	} else {		/*		 * for swap-backed pageout, the caller (the pagedaemon) has		 * already built the cluster for us.   the starting swap		 * block we are writing to has been passed in as "start."		 * "pg" could be NULL if there is no page we are especially		 * interested in (in which case the whole cluster gets dropped		 * in the event of an error or a sync "done").		 */		swblk = (daddr_t) start;		/* ppsp and npages should be ok */	}	/* now that we've clustered we can unlock the page queues */	uvm_unlock_pageq();	/*	 * now attempt the I/O.   if we have a failure and we are	 * clustered, we will drop the cluster and try again.	 */ReTry:	if (uobj) {		/* object is locked */		result = uobj->pgops->pgo_put(uobj, ppsp, *npages, flags);		UVMHIST_LOG(ubchist, "put -> %d", result, 0,0,0);		/* object is now unlocked */	} else {		/* nothing locked */		result = uvm_swap_put(swblk, ppsp, *npages, flags);		/* nothing locked */	}	/*	 * we have attempted the I/O.	 *	 * if the I/O was a success then:	 * 	if !PGO_PDFREECLUST, we return the cluster to the	 *		caller (who must un-busy all pages)	 *	else we un-busy cluster pages for the pagedaemon	 *	 * if I/O is pending (async i/o) then we return the pending code.	 * [in this case the async i/o done function must clean up when	 *  i/o is done...]	 */	if (result == 0) {		if (flags & PGO_PDFREECLUST && !async) {			/*			 * drop cluster and relock object for sync i/o.			 */			if (uobj)				/* required for dropcluster */				simple_lock(&uobj->vmobjlock);			if (*npages > 1 || pg == NULL)				uvm_pager_dropcluster(uobj, pg, ppsp, npages,				    PGO_PDFREECLUST);			/* if (uobj): object still locked, as per #3 */		}		return (result);	}	/*	 * a pager error occured (even after dropping the cluster, if there	 * was one).  give up! the caller only has one page ("pg")	 * to worry about.	 */	if (*npages > 1 || pg == NULL) {		if (uobj) {			simple_lock(&uobj->vmobjlock);		}		uvm_pager_dropcluster(uobj, pg, ppsp, npages, PGO_REALLOCSWAP);		/*		 * for hard failures on swap-backed pageouts with a "pg"		 * we need to clear pg's swslot since uvm_pager_dropcluster()		 * didn't do it and we aren't going to retry.		 */		if (uobj == NULL && pg != NULL && result != EAGAIN) {			if (pg->pqflags & PQ_ANON) {				simple_lock(&pg->uanon->an_lock);				pg->uanon->an_swslot = 0;				simple_unlock(&pg->uanon->an_lock);			} else {				simple_lock(&pg->uobject->vmobjlock);				uao_set_swslot(pg->uobject,				    pg->offset >> PAGE_SHIFT, 0);				simple_unlock(&pg->uobject->vmobjlock);			}		}		if (result == EAGAIN) {			/*			 * for transient failures, free all the swslots that			 * we're not going to retry with.			 */			if (uobj == NULL) {				if (pg) {					uvm_swap_free(swblk + 1, *npages - 1);				} else {					uvm_swap_free(swblk, *npages);				}			}			if (pg) {				ppsp[0] = pg;				*npages = 1;				goto ReTry;			}		} else if (uobj == NULL) {			/*			 * for hard errors on swap-backed pageouts,			 * mark the swslots as bad.  note that we do not			 * free swslots that we mark bad.			 */			uvm_swap_markbad(swblk, *npages);		}	}	/*	 * a pager error occurred (even after dropping the cluster, if there	 * was one).    give up!   the caller only has one page ("pg")	 * to worry about.	 */	if (uobj && (flags & PGO_PDFREECLUST) != 0)		simple_lock(&uobj->vmobjlock);	return(result);}