FreeBSD/sbin/hastd/activemap.c
/*
 * Return next offset of where we should synchronize.
 */
Return next offset of where we should synchronize.
Return next offset of where we should synchronize .
off_t
activemap_sync_offset(struct activemap *amp, off_t *lengthp, int *syncextp)
{
	off_t syncoff, left;
	int ext;
	PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC);
	PJDLOG_ASSERT(lengthp != NULL);
	PJDLOG_ASSERT(syncextp != NULL);
	*syncextp = -1;
	if (amp->am_syncoff == -2)
		return (-1);
	if (amp->am_syncoff >= 0 &&
	    (amp->am_syncoff + MAXPHYS >= amp->am_mediasize ||
	     off2ext(amp, amp->am_syncoff) !=
	     off2ext(amp, amp->am_syncoff + MAXPHYS))) {
		ext = off2ext(amp, amp->am_syncoff);
		bit_clear(amp->am_syncmap, ext);
		*syncextp = ext;
		amp->am_syncoff = -1;
	}
	if (amp->am_syncoff == -1) {
		bit_ffs(amp->am_syncmap, amp->am_nextents, &ext);
		if (ext == -1) {
			amp->am_syncoff = -2;
			return (-1);
		}
		amp->am_syncoff = ext2off(amp, ext);
	} else {
		amp->am_syncoff += MAXPHYS;
		if (amp->am_syncoff >= amp->am_mediasize) {
			amp->am_syncoff = -2;
			return (-1);
		}
	}
	syncoff = amp->am_syncoff;
	left = ext2off(amp, off2ext(amp, syncoff)) +
	    amp->am_extentsize - syncoff;
	if (syncoff + left > amp->am_mediasize)
		left = amp->am_mediasize - syncoff;
	if (left > MAXPHYS)
		left = MAXPHYS;
	PJDLOG_ASSERT(left >= 0 && left <= MAXPHYS);
	PJDLOG_ASSERT(syncoff >= 0 && syncoff < amp->am_mediasize);
	PJDLOG_ASSERT(syncoff + left >= 0 &&
	    syncoff + left <= amp->am_mediasize);
	*lengthp = left;
	return (syncoff);
}
off_t activemap_sync_offset ( struct activemap * amp , off_t * lengthp , int * syncextp ) { off_t syncoff , left ; int ext ; PJDLOG_ASSERT ( amp -> am_magic == ACTIVEMAP_MAGIC ) ; PJDLOG_ASSERT ( lengthp != NULL ) ; PJDLOG_ASSERT ( syncextp != NULL ) ; * syncextp = -1 ; if ( amp -> am_syncoff == -2 ) return ( -1 ) ; if ( amp -> am_syncoff >= 0 && ( amp -> am_syncoff + MAXPHYS >= amp -> am_mediasize || off2ext ( amp , amp -> am_syncoff ) != off2ext ( amp , amp -> am_syncoff + MAXPHYS ) ) ) { ext = off2ext ( amp , amp -> am_syncoff ) ; bit_clear ( amp -> am_syncmap , ext ) ; * syncextp = ext ; amp -> am_syncoff = -1 ; } if ( amp -> am_syncoff == -1 ) { bit_ffs ( amp -> am_syncmap , amp -> am_nextents , & ext ) ; if ( ext == -1 ) { amp -> am_syncoff = -2 ; return ( -1 ) ; } amp -> am_syncoff = ext2off ( amp , ext ) ; } else { amp -> am_syncoff += MAXPHYS ; if ( amp -> am_syncoff >= amp -> am_mediasize ) { amp -> am_syncoff = -2 ; return ( -1 ) ; } } syncoff = amp -> am_syncoff ; left = ext2off ( amp , off2ext ( amp , syncoff ) ) + amp -> am_extentsize - syncoff ; if ( syncoff + left > amp -> am_mediasize ) left = amp -> am_mediasize - syncoff ; if ( left > MAXPHYS ) left = MAXPHYS ; PJDLOG_ASSERT ( left >= 0 && left <= MAXPHYS ) ; PJDLOG_ASSERT ( syncoff >= 0 && syncoff < amp -> am_mediasize ) ; PJDLOG_ASSERT ( syncoff + left >= 0 && syncoff + left <= amp -> am_mediasize ) ; * lengthp = left ; return ( syncoff ) ; }
Return next offset of where we should synchronize.
Return next offset of where we should synchronize .
/*
		 * We are about to change extent, so mark previous one as clean.
		 */ /*
		 * Let's find first extent to synchronize.
		 */ /*
		 * We don't change extent, so just increase offset.
		 */