Пример #1
0
mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
			mempool_free_t *free_fn, void *pool_data, int node_id)
{
	mempool_t *pool;
	pool = kmalloc_node(sizeof(*pool), GFP_KERNEL, node_id);
	if (!pool)
		return NULL;
	memset(pool, 0, sizeof(*pool));
	pool->elements = kmalloc_node(min_nr * sizeof(void *),
					GFP_KERNEL, node_id);
	if (!pool->elements) {
		kfree(pool);
		return NULL;
	}
	spin_lock_init(&pool->lock);
	pool->min_nr = min_nr;
	pool->pool_data = pool_data;
	init_waitqueue_head(&pool->wait);
	pool->alloc = alloc_fn;
	pool->free = free_fn;

	/*
	 * First pre-allocate the guaranteed number of buffers.
	 */
	while (pool->curr_nr < pool->min_nr) {
		void *element;

		element = pool->alloc(GFP_KERNEL, pool->pool_data);
		if (unlikely(!element)) {
			free_pool(pool);
			return NULL;
		}
		add_element(pool, element);
	}
	return pool;
}
/**
 * mempool_destroy - deallocate a memory pool
 * @pool:      pointer to the memory pool which was allocated via
 *             mempool_create().
 *
 * this function only sleeps if the free_fn() function sleeps. The caller
 * has to guarantee that all elements have been returned to the pool (ie:
 * freed) prior to calling mempool_destroy().
 */
void mempool_destroy(mempool_t *pool)
{
	if (pool->curr_nr != pool->min_nr)
		BUG();		/* There were outstanding elements */
	free_pool(pool);
}
/**
 * mempool_destroy - deallocate a memory pool
 * @pool:      pointer to the memory pool which was allocated via
 *             mempool_create().
 *
 * this function only sleeps if the free_fn() function sleeps. The caller
 * has to guarantee that all elements have been returned to the pool (ie:
 * freed) prior to calling mempool_destroy().
 */
void mempool_destroy(mempool_t *pool)
{
	/* Check for outstanding elements */
	BUG_ON(pool->curr_nr != pool->min_nr);
	free_pool(pool);
}
Пример #4
0
// process characters at a time for commands
char
command(void)
{
	S16	ret=0;
	IPADDR	t;
	U8		*u;

	readln_from_a_file((FILE*)stdin, command_buffer, CMD_MAX_SIZE);

	yprintf("command in = %s\n",command_buffer);

			if(command_buffer[0]=='?')
			{
				// Attach to service
				printf("Supported Commands:\n");
				printf("	r - restart\n");
				printf("	e - drop next tunnel rx packet\n");
				printf("	m - check status of memory allocator\n");
				printf("	p - change port\n");
				printf("	s - status\n");
				printf("	y - startup proxy\n");
				printf("	c - connect\n");
				printf("	w - send wakup command (ping server and clients)\n");
                printf("    i - send direct message (specify uid and msg)\n");
#if defined(WEB_SSL)
				printf("    ssl on - enable ssl\n");
				printf("    ssl off - disable ssl\n");
#endif
				printf("	f - files from share target (fl - directory list...)\n");
				printf("	d - Get device List (only works if yoicsid client.)\n");

				printf("\n    q to quit bcaster\n");
				printf("\n    x to exit right now without cleanup.\n");

			}
			else
			 if(command_buffer[0]=='r')
			{
				// Attach to service
				printf("Reconnect to Weaved Service...\n");
				Yoics_reconnect();
				//printf("current state %s\n",server_state_string[state]);
			}
			else if(command_buffer[0]=='p')
			{
				printf("Swapping local port to %d\n",Yoics_Change_Port(0));
			}
			else if(command_buffer[0]=='w')
			{
				printf("Wakeup Command\n");
				send_ping(PING_STANDARD);
				Yoics_Session_Force_Ping();
#if defined(TRACE_LOG)
                traceDump();            // Tracedump just for test
#endif
			}
			else if (command_buffer[0]=='c')
			{
				// connect
				printf("sending connect request for ");
				print_uid(Remote_Address);
				printf("\n");
				//Session_create(&Remote_Address, 0);	////+++ remote address right?
#if defined(BCASTER)				
				ret=Yoics_Session_create(Remote_Address);
				if(-1== ret )
				{
					printf("Initiate session create faild\n");
				}
				else if(-2==ret)
				{
					printf("Initiate session create faild, no slots left\n");
				}
				else
					printf("OK ret= %d\n",ret);
#endif
#if defined(BUILD_SHARE)				
				new_share=Share_Connect(Remote_Address,&share_app_callback);
			
				if(0== new_share )
				{
					printf("Initiate session create faild\n");
				}
				else
					printf("OK ret= %d\n",ret);
#endif
				//yoics_connect(Remote_Address);
			}
			else if (command_buffer[0]=='m')
			{
#if ALLOC_DEBUG
				alloc_check();
#else
				alloc_stat();
#endif
				alloc_pool_check(pool);
			}
			else if (command_buffer[0]=='s')
			{

#if defined(WEB_SSL)
				if (!strcmp(command_buffer,"ssl on")) {
					printf("Turn on SSL\n");

					//
					// Set the web port to ssl port
					//
					webPort = WEB_PORT_SSL;

					//
					// Enable SSL module
					Yoics_Set_SSL(SSL_ENABLE);

				}
				else if (!strcmp (command_buffer, "ssl off")) {

					printf("Turn off SSL\n");

					//
					// Set the web port to non SSL port
					//
					webPort = WEB_PORT;

					//
					// Disable SSL module
					//
					Yoics_Set_SSL (SSL_DISABLE);
				}
				else 
#endif
				{
					t=Yoics_Get_Current_Server();
					u=Yoics_Current_UID();
					printf("server state is %d -- 0)Uconn 1)rstart 2)NATchk 3)ReqAuth 4)ID 5)Conn\n",Yoics_Server_Connection_State());
					printf("  server is %d.%d.%d.%d:%d\n",t.ipb1,t.ipb2,t.ipb3,t.ipb4,(U16)Yoics_Get_Current_Server_Port());
					printf("  key hash is %x:%x\n",secret[0],secret[1]);
					printf("  server spi is 0x%X\n",(unsigned int)Yoics_Return_Server_SPI());
					printf("Our UID is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
					u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7]);
					printf("Our Serial Number is %.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
					serial_num[0],serial_num[1],serial_num[2],serial_num[3],serial_num[4],serial_num[5],
					serial_num[6],serial_num[7]);
					t=Yoics_Get_Our_Bound_IP();
					printf("Our bound ip:port is %d.%d.%d.%d:%d\n",t.ipb1,t.ipb2,t.ipb3,t.ipb4,Yoics_Get_Our_Bound_Port());
					t=Yoics_Get_Our_Mapped_IP();
					printf("Our mapped ip:port is %d.%d.%d.%d:%d -  UPNP/NAT-PMP mapped port is %d\n",t.ipb1,t.ipb2,t.ipb3,t.ipb4,Yoics_Get_Our_Mapped_Port(),parameters.upnp_port);
					printf("Last server hearbeat %u seconds ago\n",(U32)((U32)second_count()-(U32)server_hearbeat));					
					printf("Our NAT type is %d\n",Yoics_Return_NAT_Type());
                    printf("Forward Port is %d\n\n",parameters.forward_port);
					alloc_stat();
					printf("\nActive Sessions %d\n",active_sessions);
					printf("\nSession List\n");
					Yoics_session_list();
					printf("\nProxy Status\n");
					proxy_status();
				}
			}
			else if (command_buffer[0]=='e')
			{
				//printf("Drop next tun data packet.\n");
				//tunnel_drop(tun_num);
			}
			else if (command_buffer[0]=='y')
			{
				if(sindex)
				{
					if(proxy_local_port==0)
						proxy_local_port=5959;
					printf("Starting Proxy on port %d.\n",proxy_local_port);

					if(proxy_client_start(proxy_ip,proxy_local_port, restrict_connect_ip, sindex))
					//if(proxy_start(proxy_ip,proxy_local_port))
						printf("Proxy started.\n");
					else
						printf("proxy startup failed.\n");
				}
				else
				{
					printf("must be connected to peer first\n");
				}
			}
			else if (command_buffer[0]=='d')
			{
				printf("Device List:\n");

#if !defined(BCASTER)			
				if(YOICS_SERVER_CONNECTED==Yoics_Server_Connection_State())
				{
					DEVICE devlist[10];
					char	server_name[32];
					int		tt;
					IPADDR	answer;
					// Get current server IP and make it into a string
					answer=Yoics_Get_Current_Server();

					sprintf(server_name,"%d.%d.%d.%d",answer.ipb1,answer.ipb2,answer.ipb3,answer.ipb4);					
					
					tt=Yoics_Get_Device_List(server_name, webPort, 5000, devlist, 10, 1);

					printf("found %d entries\n",tt);
				
				}
				else
					printf("Must be connected to service to issue this command\n");
#endif				

			}
			else if (command_buffer[0]=='z')
			{
                U8* crash;
				yprintf("Force SIG 11:\n");
                crash=0;
                *crash="c";                                         // This is correct, it forces a crash!  Ignore this warning in compile
				//session_list();
			}
			else if (command_buffer[0]=='q')
			{
				ret=EXIT;
			}
			else if (command_buffer[0]=='x')
			{
                DEBUG4("Free Pool x\n");
	            free_pool();
#if defined(TRACE_LOG)
                traceCleanup();
#endif
				exit(0);
				ret=EXIT;
			}
			else if (command_buffer[0]=='i')
			{
                int len;
                U8* tptr;
                char tpack[255];
                U8 tuid[32];
                YOICSPACKET	*pkt;
                pkt=(YOICSPACKET*)tpack;
                 //
                // Create a map peer
                //
                pkt->packet_type	= htons(PING_MSG);		
                pkt->source			= htons(TARGET_FORWARD);				// not done yet
                len					= sizeof(YOICSPACKET);
                pkt->salt			= 0;
                pkt->spi			= 0;
                tptr=pkt->data;	
                //
                // Add our UID
                //
	            tptr=yoics_add_data(tptr,CLIENTUID,my_uid,UID_SIZE);
	            len+=UID_SIZE+sizeof(DATATYPE);

                //
                // Add Null Type to finish the message
                //
                yoics_add_data(tptr,NULLTYPE,0,0);
                len+=sizeof(DATATYPE);
                //
				// send direct message using packet forwarder
                //
                UID_Extract(&tuid[0],"80:00:00:05:46:00:26:e7");
                send_packet_forward(tuid, (U8*)tpack ,len);

			}
			else
			{
			yprintf("unknown command = %s\n",command_buffer);
			}

	return((S8)ret);

}
Пример #5
0
void memcache_destroy(struct memcache *cache)
{
    free_pool(cache);
}
Пример #6
0
/**
 * emalloc - Allocate memory with a strict alignment requirement
 * @size: size in bytes of the requested allocation
 * @align: the required alignment of the allocation
 * @addr: a pointer to the allocated address on success
 * @low: pick up an address in low memory region
 *
 * If we cannot satisfy @align we return 0.
 */
EFI_STATUS emalloc(UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS *addr, BOOLEAN low)
{
        UINTN map_size, map_key, desc_size;
        EFI_MEMORY_DESCRIPTOR *map_buf;
        UINTN d, map_end;
        UINT32 desc_version;
        EFI_STATUS err;
        UINTN nr_pages = EFI_SIZE_TO_PAGES(size);

        err = memory_map(&map_buf, &map_size, &map_key,
                         &desc_size, &desc_version);
        if (err != EFI_SUCCESS)
                goto fail;

        d = (UINTN)map_buf;
        map_end = (UINTN)map_buf + map_size;

        for (; d < map_end; d += desc_size) {
                EFI_MEMORY_DESCRIPTOR *desc;
                EFI_PHYSICAL_ADDRESS start, end, aligned;

                desc = (EFI_MEMORY_DESCRIPTOR *)d;
                if (desc->Type != EfiConventionalMemory)
                        continue;

                if (desc->NumberOfPages < nr_pages)
                        continue;

                start = desc->PhysicalStart;
                end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);

                /* Low-memory is super-precious! */
                if (!low) {
                        if (end <= 1 << 20)
                                continue;
                        if (start < 1 << 20) {
                                size -= (1 << 20) - start;
                                start = (1 << 20);
                        }
                }
                if (start == 0)
                        start += 8;

                aligned = (start + align -1) & ~(align -1);

                if ((aligned + size) <= end) {
                        err = allocate_pages(AllocateAddress, EfiLoaderData,
                                             nr_pages, &aligned);
                        if (err == EFI_SUCCESS) {
                                *addr = aligned;
                                break;
                        }
                }
        }

        if (d == map_end)
                err = EFI_OUT_OF_RESOURCES;

        free_pool(map_buf);
fail:
        return err;
}
mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
			mempool_free_t *free_fn, void *pool_data, int node_id)
{

	mempool_t *pool;

#if defined(__VMKLNX__)
	vmk_ModuleID moduleID;
        vmk_HeapID heapID;

	VMK_ASSERT(vmk_PreemptionIsEnabled() == VMK_FALSE);
        moduleID  = vmk_ModuleStackTop();
        heapID = vmk_ModuleGetHeapID(moduleID);
        VMK_ASSERT(heapID != VMK_INVALID_HEAP_ID);

        pool = vmklnx_kmalloc(heapID,
                              sizeof(*pool),
			      GFP_KERNEL,
                              NULL);
#else /* !defined(__VMKLNX__) */
	pool = kmalloc_node(sizeof(*pool), GFP_KERNEL, node_id);
#endif /* defined(__VMKLNX__) */

	if (!pool)
		return NULL;
	memset(pool, 0, sizeof(*pool));

#if defined(__VMKLNX__)
        pool->elements = vmklnx_kmalloc(heapID,
                                        min_nr * sizeof(void *),
					GFP_KERNEL,
                                        NULL);
#else /* !defined(__VMKLNX__) */
	pool->elements = kmalloc_node(min_nr * sizeof(void *),
					GFP_KERNEL, node_id);
#endif /* defined(__VMKLNX__) */

	if (!pool->elements) {
		kfree(pool);
		return NULL;
	}
	spin_lock_init(&pool->lock);
	pool->min_nr = min_nr;
	pool->pool_data = pool_data;
	init_waitqueue_head(&pool->wait);
	pool->alloc = alloc_fn;
	pool->free = free_fn;
        
#if defined(__VMKLNX__)
        pool->module_id = moduleID;
#endif /* defined(__VMKLNX__) */

	/*
	 * First pre-allocate the guaranteed number of buffers.
	 */
	while (pool->curr_nr < pool->min_nr) {
		void *element;

#if defined(__VMKLNX__)
                VMKAPI_MODULE_CALL(pool->module_id, element, pool->alloc, 
                                   GFP_KERNEL, pool->pool_data);
#else /* !defined(__VMKLNX__) */
		element = pool->alloc(GFP_KERNEL, pool->pool_data);
#endif /* defined(__VMKLNX__) */
		if (unlikely(!element)) {
			free_pool(pool);
			return NULL;
		}
		add_element(pool, element);
	}
	return pool;
}