Ejemplo n.º 1
0
void
slmbmaptimeothr_begin(struct psc_thread *thr)
{
	struct bmap_mds_lease *bml;
	int rc, nsecs = 0;

	while (pscthr_run(thr)) {
		spinlock(&mdsBmapTimeoTbl.btt_lock);
		bml = pll_peekhead(&mdsBmapTimeoTbl.btt_leases);
		if (!bml) {
			freelock(&mdsBmapTimeoTbl.btt_lock);
			nsecs = BMAP_TIMEO_MAX;
			goto sleep;
		}

		if (!BML_TRYLOCK(bml)) {
			freelock(&mdsBmapTimeoTbl.btt_lock);
			nsecs = 1;
			goto sleep;
		}
		if (bml->bml_refcnt) {
			BML_ULOCK(bml);
			freelock(&mdsBmapTimeoTbl.btt_lock);
			nsecs = 1;
			goto sleep;
		}

		if (!(bml->bml_flags & BML_FREEING)) {
			nsecs = bml->bml_expire - time(NULL);
			if (nsecs > 0) {
				BML_ULOCK(bml);
				freelock(&mdsBmapTimeoTbl.btt_lock);
				goto sleep;
			}
			bml->bml_flags |= BML_FREEING;
		}

		BML_ULOCK(bml);
		freelock(&mdsBmapTimeoTbl.btt_lock);

		rc = mds_bmap_bml_release(bml);
		if (rc) {
			DEBUG_BMAP(PLL_WARN, bml_2_bmap(bml),
			    "rc=%d bml=%p fl=%d seq=%"PRId64,
			    rc, bml, bml->bml_flags, bml->bml_seq);
			nsecs = 1;
		} else
			nsecs = 0;
 sleep:
		psclog_debug("nsecs=%d", nsecs);

		if (nsecs > 0)
			sleep((uint32_t)nsecs);
	}
}
Ejemplo n.º 2
0
void
mds_bmap_timeotbl_remove(struct bmap_mds_lease *bml)
{
	struct bmap_mds_lease *tmp;
	int update = 0;

	spinlock(&mdsBmapTimeoTbl.btt_lock);
	if (pll_peekhead(&mdsBmapTimeoTbl.btt_leases) == bml)
		update = 1;
	pll_remove(&mdsBmapTimeoTbl.btt_leases, bml);
	if (update) {
		tmp = pll_peekhead(&mdsBmapTimeoTbl.btt_leases);
		if (tmp)
			mdsBmapTimeoTbl.btt_minseq = tmp->bml_seq;
		else
			mdsBmapTimeoTbl.btt_minseq =
			    mdsBmapTimeoTbl.btt_maxseq;
		mds_bmap_timeotbl_journal_seqno();
	}
	freelock(&mdsBmapTimeoTbl.btt_lock);
}
Ejemplo n.º 3
0
void *
_lc_get(struct psc_listcache *plc, const struct timespec *abstime,
    int flags)
{
	int locked, rc;
	void *p;

	locked = LIST_CACHE_RLOCK(plc);
//	if (plc->plc_flags & PLCF_DYING)
//		pfl_assert(flags & PLCF_DYINGOK)
	while (lc_empty(plc)) {
		if ((plc->plc_flags & PLCF_DYING) ||
		    (flags & PLCBF_NOBLOCK)) {
			LIST_CACHE_URLOCK(plc, locked);
			return (NULL);
		}

		/* Alert listeners who want to know about exhaustion. */
		pfl_waitq_wakeall(&plc->plc_wq_want);
		if (abstime)
			psclog_debug("lc@%p <%s> timed wait "PSCPRI_TIMESPEC,
			    plc, plc->plc_name, PSCPRI_TIMESPEC_ARGS(abstime));
		else
			psclog_debug("lc@%p <%s> blocking wait", plc,
			    plc->plc_name);
		if (abstime) {
			rc = pfl_waitq_waitabs(&plc->plc_wq_empty,
			    LIST_CACHE_GETLOCK(plc), abstime);
			if (rc) {
				pfl_assert(rc == ETIMEDOUT);
				errno = rc;
				return (NULL);
			}
		} else
			pfl_waitq_wait(&plc->plc_wq_empty,
			    LIST_CACHE_GETLOCK(plc));
		LIST_CACHE_LOCK(plc);
	}
	if (flags & PLCBF_TAIL)
		p = pll_peektail(&plc->plc_pll);
	else
		p = pll_peekhead(&plc->plc_pll);
	if ((flags & PLCBF_PEEK) == 0)
		lc_remove(plc, p);
	LIST_CACHE_URLOCK(plc, locked);
	return (p);
}