Beispiel #1
0
void	sm_list_unwedge(PsmPartition partition, PsmAddress list, int interval)
{
	SmList	*listBuffer;

	CHKVOID(partition);
	listBuffer = (SmList *) psp(partition, list);
	CHKVOID(listBuffer);
	sm_SemUnwedge(listBuffer->lock, interval);
}
Beispiel #2
0
void	sm_rbt_unwedge(PsmPartition partition, PsmAddress rbt, int interval)
{
	SmRbt	*rbtPtr;

	CHKVOID(partition);
	CHKVOID(rbt);
	rbtPtr = (SmRbt *) psp(partition, rbt);
	CHKVOID(rbtPtr);
	sm_SemUnwedge(rbtPtr->lock, interval);
}
Beispiel #3
0
static int	checkNodeListParms(IonParms *parms, char *wdName, uvast nodeNbr)
{
	char		*nodeListDir;
	sm_SemId	nodeListMutex;
	char		nodeListFileName[265];
	int		nodeListFile;
	int		lineNbr = 0;
	int		lineLen;
	char		lineBuf[256];
	uvast		lineNodeNbr;
	int		lineWmKey;
	char		lineSdrName[MAX_SDR_NAME + 1];
	char		lineWdName[256];
	int		result;

	nodeListDir = getenv("ION_NODE_LIST_DIR");
	if (nodeListDir == NULL)	/*	Single node on machine.	*/
	{
		if (parms->wmKey == 0)
		{
			parms->wmKey = ION_DEFAULT_SM_KEY;
		}

		if (parms->wmKey != ION_DEFAULT_SM_KEY)
		{
			putErrmsg("Config parms wmKey != default.",
					itoa(ION_DEFAULT_SM_KEY));
			return -1;
		}

		if (parms->sdrName[0] == '\0')
		{
			istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME,
					sizeof parms->sdrName);
		}

		if (strcmp(parms->sdrName, ION_DEFAULT_SDR_NAME) != 0)
		{
			putErrmsg("Config parms sdrName != default.",
					ION_DEFAULT_SDR_NAME);
			return -1;
		}

		return 0;
	}

	/*	Configured for multi-node operation.			*/

	nodeListMutex = sm_SemCreate(NODE_LIST_SEMKEY, SM_SEM_FIFO);
	if (nodeListMutex == SM_SEM_NONE
	|| sm_SemUnwedge(nodeListMutex, 3) < 0 || sm_SemTake(nodeListMutex) < 0)
	{
		putErrmsg("Can't lock node list file.", NULL);
		return -1;
	}

	isprintf(nodeListFileName, sizeof nodeListFileName, "%.255s%cion_nodes",
			nodeListDir, ION_PATH_DELIMITER);
	if (nodeNbr == 0)	/*	Just attaching.			*/
	{
		nodeListFile = iopen(nodeListFileName, O_RDONLY, 0);
	}
	else			/*	Initializing the node.		*/
	{
		nodeListFile = iopen(nodeListFileName, O_RDWR | O_CREAT, 0666);
	}

	if (nodeListFile < 0)
	{
		sm_SemGive(nodeListMutex);
		putSysErrmsg("Can't open ion_nodes file", nodeListFileName);
		writeMemo("[?] Remove ION_NODE_LIST_DIR from env?");
		return -1;
	}

	while (1)
	{
		if (igets(nodeListFile, lineBuf, sizeof lineBuf, &lineLen)
				== NULL)
		{
			if (lineLen < 0)
			{
				close(nodeListFile);
				sm_SemGive(nodeListMutex);
				putErrmsg("Failed reading ion_nodes file.",
						nodeListFileName);
				return -1;
			}

			break;		/*	End of file.		*/
		}

		lineNbr++;
		if (sscanf(lineBuf, UVAST_FIELDSPEC " %d %31s %255s",
			&lineNodeNbr, &lineWmKey, lineSdrName, lineWdName) < 4)
		{
			close(nodeListFile);
			sm_SemGive(nodeListMutex);
			putErrmsg("Syntax error at line#", itoa(lineNbr));
			writeMemoNote("[?] Repair ion_nodes file.",
					nodeListFileName);
			return -1;
		}

		if (lineNodeNbr == nodeNbr)		/*	Match.	*/
		{
			/*	lineNodeNbr can't be zero (we never
			 *	write such lines to the file), so this
			 *	must be matching non-zero node numbers.
			 *	So we are re-initializing this node.	*/

			close(nodeListFile);
			if (strcmp(lineWdName, wdName) != 0)
			{
				sm_SemGive(nodeListMutex);
				putErrmsg("CWD conflict at line#",
						itoa(lineNbr));
				writeMemoNote("[?] Repair ion_nodes file.",
						nodeListFileName);
				return -1;
			}

			if (parms->wmKey == 0)
			{
				parms->wmKey = lineWmKey;
			}

			if (parms->wmKey != lineWmKey)
			{
				sm_SemGive(nodeListMutex);
				putErrmsg("WmKey conflict at line#",
						itoa(lineNbr));
				writeMemoNote("[?] Repair ion_nodes file.",
						nodeListFileName);
				return -1;
			}

			if (parms->sdrName[0] == '\0')
			{
				istrcpy(parms->sdrName, lineSdrName,
						sizeof parms->sdrName);
			}

			if (strcmp(parms->sdrName, lineSdrName) != 0)
			{
				sm_SemGive(nodeListMutex);
				putErrmsg("SdrName conflict at line#",
						itoa(lineNbr));
				writeMemoNote("[?] Repair ion_nodes file.",
						nodeListFileName);
				return -1;
			}

			return 0;
		}

		/*	lineNodeNbr does not match nodeNbr (which may
		 *	be zero).					*/

		if (strcmp(lineWdName, wdName) == 0)	/*	Match.	*/
		{
			close(nodeListFile);
			sm_SemGive(nodeListMutex);
			if (nodeNbr == 0)	/*	Attaching.	*/
			{
				parms->wmKey = lineWmKey;
				istrcpy(parms->sdrName, lineSdrName,
						MAX_SDR_NAME + 1);
				return 0;
			}

			/*	Reinitialization conflict.		*/

			putErrmsg("NodeNbr conflict at line#", itoa(lineNbr));
			writeMemoNote("[?] Repair ion_nodes file.",
					nodeListFileName);
			return -1;
		}

		/*	Haven't found matching line yet.  Continue.	*/
	}

	/*	No matching lines in file.				*/

	if (nodeNbr == 0)	/*	Attaching to existing node.	*/
	{
		close(nodeListFile);
		sm_SemGive(nodeListMutex);
		putErrmsg("No node has been initialized in this directory.",
				wdName);
		return -1;
	}

	/*	Initializing, so append line to the nodes list file.	*/

	if (parms->wmKey == 0)
	{
		parms->wmKey = ION_DEFAULT_SM_KEY;
	}

	if (parms->sdrName[0] == '\0')
	{
		istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME,
				sizeof parms->sdrName);
	}

	isprintf(lineBuf, sizeof lineBuf, UVAST_FIELDSPEC " %d %.31s %.255s\n",
			nodeNbr, parms->wmKey, parms->sdrName, wdName);
	result = iputs(nodeListFile, lineBuf);
	close(nodeListFile);
	sm_SemGive(nodeListMutex);
	if (result < 0)
	{
		putErrmsg("Failed writing to ion_nodes file.", NULL);
		return -1;
	}

	return 0;
}
Beispiel #4
0
int	psm_manage(char *start, u_long length, char *name, PsmPartition *psmp,
		PsmMgtOutcome *outcome)
{
	PsmPartition	partition;
	PartitionMap	*map;

	CHKERR(outcome);
	*outcome = Refused;
	CHKERR(start != NULL);
	if ((((unsigned long) start) % LG_OHD_SIZE) != 0)
	{
		putErrmsg("Starting address not double-word-aligned.",
				utoa((unsigned long) start));
		return -1;	/*	Start address misaligned.	*/
	}

	/*	Acquire handle to space management structure.		*/

	partition = *psmp;

	/*	Dynamically allocate space management structure as
	 *	necessary.						*/

	if (partition == NULL)
	{
		partition = (PsmPartition) acquireSystemMemory(sizeof(PsmView));
		CHKERR(partition != NULL);
		partition->freeNeeded = 1;
	}
	else
	{
		partition->freeNeeded = 0;
	}

	partition->space = start;
	partition->trace = NULL;
	map = (PartitionMap *) (partition->space);
	if (map->status == MANAGED)
	{
		*psmp = partition;
		sm_SemUnwedge(map->semaphore, 3);
		*outcome = Redundant;
		return 0;
	}

	/*	Need to manage and possibly initialize the partition.	*/

	if (length % LG_OHD_SIZE)
	{
		if (partition->freeNeeded) free(partition);
		putErrmsg("Partition length is not an integral number of \
double words.", utoa(length));
		return -1;
	}

	if (length < sizeof(PartitionMap))
	{
		if (partition->freeNeeded) free(partition);
		putErrmsg("Partition length is less than partition map size.",
utoa(length));
		return -1;	/*	Partition can't contain map.	*/
	}

	if (name == NULL)
	{
		if (partition->freeNeeded) free(partition);
		putErrmsg("Partition name is NULL.", NULL);
		return -1;
	}

	if (strlen(name) > 31)
	{
		if (partition->freeNeeded) free(partition);
		putErrmsg("Partition name length exceeds 31.", name);
		return -1;
	}

	switch (map->status)
	{
	case INITIALIZED:
		if (map->partitionSize != length)
		{
			if (partition->freeNeeded) free(partition);
			putErrmsg("Asserted partition length doesn't match \
actual length.", itoa(map->partitionSize));
			return -1;	/*	Size mismatch.		*/
		}

		if (strcmp(map->name, name) != 0)
		{
			if (partition->freeNeeded) free(partition);
			putErrmsg("Asserted partition name doesn't match \
actual name.", map->name);
			return -1;	/*	Name mismatch.		*/
		}

		break;	/*	Proceed with managing the partition.	*/

	default:	/*	Must initialize the partition.		*/
		map->directory = 0;
		map->desperate = 0;
		map->partitionSize = length;
		istrcpy(map->name, name, sizeof map->name);
		map->startOfSmallPool = sizeof(PartitionMap);
		map->endOfSmallPool = map->startOfSmallPool;
		memset((char *) (map->firstSmallFree), 0,
				sizeof map->firstSmallFree);
		map->endOfLargePool = length;
		map->startOfLargePool = map->endOfLargePool;
		memset((char *) (map->firstLargeFree), 0,
				sizeof map->firstLargeFree);
		map->unassignedSpace = map->startOfLargePool -
				map->endOfSmallPool;
		map->traceKey = sm_GetUniqueKey();
		map->traceSize = 0;
	}

	map->semaphore = sm_SemCreate(SM_NO_KEY, SM_SEM_FIFO);
	if (map->semaphore < 0)
	{
		if (partition->freeNeeded) free(partition);
		putErrmsg("Can't create semaphore for partition map.", NULL);
		return -1;
	}

	map->ownerTask = -1;
	map->depth = 0;
	map->status = MANAGED;
	*psmp = partition;
	*outcome = Okay;
	return 0;
}