예제 #1
0
static void __sweep(struct dm_deferred_set *ds, struct list_head *head)
{
	while ((ds->sweeper != ds->current_entry) &&
	       !ds->entries[ds->sweeper].count) {
		list_splice_init(&ds->entries[ds->sweeper].work_items, head);
		ds->sweeper = ds_next(ds->sweeper);
	}

	if ((ds->sweeper == ds->current_entry) && !ds->entries[ds->sweeper].count)
		list_splice_init(&ds->entries[ds->sweeper].work_items, head);
}
예제 #2
0
파일: algorithms.c 프로젝트: meh/datashit
void*
ds_each_ (void* data, DSNexter nexter, void* metadata, DSYielder yielder, void* metadata2)
{
	void* current = data;

	do {
		yielder(current, metadata2);
	} while ((current = ds_next(current, nexter, metadata)));

	return data;
}
예제 #3
0
파일: algorithms.c 프로젝트: meh/datashit
size_t
ds_count_ (void* data, DSNexter nexter, void* metadata, DSCounter counter, void* metadata2)
{
	size_t result = 0;
	void*  current = data;

	do {
		if (counter == NULL || counter(current, metadata2)) {
			result++;
		}
	} while ((current = ds_next(current, nexter, metadata)));

	return result;
}
예제 #4
0
/*
 * Returns 1 if deferred or 0 if no pending items to delay job.
 */
int dm_deferred_set_add_work(struct dm_deferred_set *ds, struct list_head *work)
{
	int r = 1;
	unsigned long flags;
	unsigned next_entry;

	spin_lock_irqsave(&ds->lock, flags);
	if ((ds->sweeper == ds->current_entry) &&
	    !ds->entries[ds->current_entry].count)
		r = 0;
	else {
		list_add(work, &ds->entries[ds->current_entry].work_items);
		next_entry = ds_next(ds->current_entry);
		if (!ds->entries[next_entry].count)
			ds->current_entry = next_entry;
	}
	spin_unlock_irqrestore(&ds->lock, flags);

	return r;
}
예제 #5
0
boolean_t
unpack_package_from_stream(char *a_idsName, char *a_pkginst, char *a_tempDir)
{
	int		dparts;
	char		instdir[PATH_MAX];

	/* entry assertions */

	assert(a_idsName != (char *)NULL);
	assert(a_pkginst != (char *)NULL);
	assert(a_tempDir != (char *)NULL);

	/* entry debug information */

	echoDebug(DBG_UNPACKSTRM_ENTRY);
	echoDebug(DBG_UNPACKSTRM_ARGS, a_pkginst, a_idsName, a_tempDir);

	/* find the specified package in the datastream */

	dparts = ds_findpkg(a_idsName, a_pkginst);
	if (dparts < 1) {
		progerr(gettext(ERR_DSARCH), a_pkginst);
		return (B_FALSE);
		/*NOTREACHED*/
	}

	/*
	 * read in next part from stream, even if we decide
	 * later that we don't need it
	 */

	/* create directory to hold this package instance */

	if (snprintf(instdir, sizeof (instdir), "%s/%s", a_tempDir, a_pkginst)
	    >= PATH_MAX) {
		progerr(ERR_CREATE_PATH_2, a_tempDir, a_pkginst);
		return (B_FALSE);
	}

	switch (fmkdir(instdir, 0755)) {
	case 0:	/* directory created */
		break;
	case 1: /* could not remove existing non-directory node */
		progerr(ERR_REMOVE, instdir, strerror(errno));
		return (B_FALSE);
	case 2: /* could not create specified new directory */
	default:
		progerr(ERR_UNPACK_FMKDIR, instdir, strerror(errno));
		return (B_FALSE);
	}

	/* unpack package instance from stream to dir created */

	echoDebug(DBG_UNPACKSTRM_UNPACKING, a_pkginst, a_idsName, instdir);

	if (chdir(instdir)) {
		progerr(ERR_CHDIR, instdir);
		return (B_FALSE);
	}

	dparts--;
	if (ds_next(a_idsName, instdir)) {
		progerr(ERR_UNPACK_DSREAD, dparts+1, a_idsName, instdir,
			a_pkginst);
		return (B_FALSE);
	}

	if (chdir(get_PKGADM())) {
		progerr(gettext(ERR_CHDIR), get_PKGADM());
		return (B_FALSE);
	}

	return (B_TRUE);
}