static void rx_loop()
{
    int ret;
	
	while (!the_working_paras.need_exit)
	{
	    ret=fd_readable(the_working_paras.sockfd, 0, 10000);
	    if (ret<=0)
    	{
    	    if (ret<0 && !the_working_paras.no_verbose)
    	        ERR_DBG_PRINT("test fd failed");

			continue;
    	}

        ret=read(the_working_paras.sockfd
			,the_working_paras.buf
			,sizeof(the_working_paras.buf));
		INC_STAT(the_stat_data.rx_times_total);

		if (ret>0)
		{
			INC_STAT(the_stat_data.rx_times_succ);
			INC_STAT_VALUE(the_stat_data.rx_bytes, ret);

			if (!the_working_paras.no_verbose)
			{
			    printf("[%"PRIu64"]got %d bytes\n"
					,the_stat_data.rx_times_succ
					,ret);

                if (!the_working_paras.no_prt_pkt)
            	{
					printf("the data contents is:\n");
					print_mem(the_working_paras.buf, ret);
            	}
			}

		}
		else
		{
			INC_STAT(the_stat_data.rx_times_fail);

			if (!the_working_paras.no_verbose)
			    ERR_DBG_PRINT("rx failed");

			break;
		}
		
		printf("\n\n");
		continue;

	}
}
static void sig_handler(int sig_no, siginfo_t *pt_siginfo, void *p_ucontext)
{
    int ret;
    if (SIGINT==sig_no)
	{
		the_working_paras.need_exit = 1;
		alarm(0);
	}
	else if (SIGALRM==sig_no)
	{
	    alarm(the_working_paras.snd_interval);
		
		INC_STAT(the_stat_data.tx_pkts_total);
		INC_STAT_VALUE(the_stat_data.tx_bytes_total, the_working_paras.snd_data_len);

		if (!the_working_paras.no_verbose)
		{
			printf("[%"PRIu64"]try send %d bytes to %s:%d\n"
				,the_stat_data.tx_pkts_total
				,the_working_paras.snd_data_len
				,the_working_paras.dst_ip
				,(int)the_working_paras.dst_port);

		}
		ret=write_certain_bytes(the_working_paras.sockfd
			, the_working_paras.snd_buf
			, the_working_paras.snd_data_len
			, NULL);

		if (0==ret)
		{
			INC_STAT(the_stat_data.tx_pkts_succ);
			INC_STAT_VALUE(the_stat_data.tx_bytes_succ, the_working_paras.snd_data_len);
		}
		else
		{
			INC_STAT(the_stat_data.tx_pkts_fail);
			INC_STAT_VALUE(the_stat_data.tx_bytes_fail, the_working_paras.snd_data_len);

			if (!the_working_paras.no_verbose)
				ERR_DBG_PRINT("tx failed");
			
			the_working_paras.need_exit = 1;
			alarm(0);

		}

	}
}
int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap,
			       __u64 arg)
{
	if (!bitmap)
		return 0;

	if (EXT2FS_IS_32_BITMAP(bitmap)) {
		if (arg & ~0xffffffffULL) {
			ext2fs_warn_bitmap2(bitmap, EXT2FS_UNMARK_ERROR,
					    0xffffffff);
			return 0;
		}
		return ext2fs_unmark_generic_bitmap(bitmap, arg);
	}

	if (!EXT2FS_IS_64_BITMAP(bitmap))
		return 0;

	arg >>= bitmap->cluster_bits;

	INC_STAT(bitmap, unmark_count);

	if ((arg < bitmap->start) || (arg > bitmap->end)) {
		warn_bitmap(bitmap, EXT2FS_UNMARK_ERROR, arg);
		return 0;
	}

	return bitmap->bitmap_ops->unmark_bmap(bitmap, arg);
}
Example #4
0
static void *
alloc_large(struct mempool *pool,
            unsigned int size
            MT_ARG
)
{
    if (pool->large_index+1 >= pool->large_num) {
        pool->large_num *= 2;
        pool->large = (unsigned char**)realloc(pool->large, pool->large_num * sizeof(char*));
    }

    void *ret = malloc(size);
    pool->large[pool->large_index] = (unsigned char*)ret;
    pool->large_index++;

    INC_STAT(alloc_total, size);
    INC_STAT(size_each_type[mt], size);

    return ret;
}
errcode_t ext2fs_resize_generic_bmap(ext2fs_generic_bitmap bmap,
				     __u64 new_end,
				     __u64 new_real_end)
{
	if (!bmap)
		return EINVAL;

	if (EXT2FS_IS_32_BITMAP(bmap))
		return ext2fs_resize_generic_bitmap(bmap->magic, new_end,
						    new_real_end, bmap);

	if (!EXT2FS_IS_64_BITMAP(bmap))
		return EINVAL;

	INC_STAT(bmap, resize_count);

	return bmap->bitmap_ops->resize_bmap(bmap, new_end, new_real_end);
}
int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap,
				    blk64_t block, unsigned int num)
{
	__u64	end = block + num;

	if (!bmap)
		return EINVAL;

	if (num == 1)
		return !ext2fs_test_generic_bmap((ext2fs_generic_bitmap)
						 bmap, block);

	if (EXT2FS_IS_32_BITMAP(bmap)) {
		if ((block+num-1) & ~0xffffffffULL) {
			ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap,
					    EXT2FS_UNMARK_ERROR, 0xffffffff);
			return EINVAL;
		}
		return ext2fs_test_block_bitmap_range(
			(ext2fs_generic_bitmap) bmap, block, num);
	}

	if (!EXT2FS_IS_64_BITMAP(bmap))
		return EINVAL;

	INC_STAT(bmap, test_ext_count);

	/* convert to clusters if necessary */
	block >>= bmap->cluster_bits;
	end += (1 << bmap->cluster_bits) - 1;
	end >>= bmap->cluster_bits;
	num = end - block;

	if ((block < bmap->start) || (block+num-1 > bmap->end)) {
		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, block,
				   bmap->description);
//change return value to none to 0, build error fix
		return 0;
	}

	return bmap->bitmap_ops->test_clear_bmap_extent(bmap, block, num);
}
Example #7
0
void queue_cachemiss (tux_req_t *req)
{
	iothread_t *iot = req->ti->iot;

	Dprintk("queueing_cachemiss(req:%p) (req->cwd_dentry: %p) at %p:%p.\n",
		req, req->cwd_dentry, __builtin_return_address(0), __builtin_return_address(1));
	if (req->idle_input || req->wait_output_space)
		TUX_BUG();
	req->had_cachemiss = 1;
	if (!list_empty(&req->work))
		TUX_BUG();
	spin_lock(&iot->async_lock);
	if (connection_too_fast(req))
		list_add_tail(&req->work, &iot->async_queue);
	else
		list_add(&req->work, &iot->async_queue);
	iot->nr_async_pending++;
	INC_STAT(nr_cachemiss_pending);
	spin_unlock(&iot->async_lock);

	wake_up(&iot->async_sleep);
}
void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap,
				       blk64_t block, unsigned int num)
{
	__u64	end = block + num;

	if (!bmap)
		return;

	if (EXT2FS_IS_32_BITMAP(bmap)) {
		if ((block+num-1) & ~0xffffffffULL) {
			ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap,
					    EXT2FS_UNMARK_ERROR, 0xffffffff);
			return;
		}
		ext2fs_unmark_block_bitmap_range((ext2fs_generic_bitmap) bmap,
						 block, num);
	}

	if (!EXT2FS_IS_64_BITMAP(bmap))
		return;

	INC_STAT(bmap, unmark_ext_count);

	/* convert to clusters if necessary */
	block >>= bmap->cluster_bits;
	end += (1 << bmap->cluster_bits) - 1;
	end >>= bmap->cluster_bits;
	num = end - block;

	if ((block < bmap->start) || (block+num-1 > bmap->end)) {
		ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
				   bmap->description);
		return;
	}

	bmap->bitmap_ops->unmark_bmap_extent(bmap, block, num);
}
errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap,
					__u64 start, unsigned int num,
					void *out)
{
	if (!bmap)
		return EINVAL;

	if (EXT2FS_IS_32_BITMAP(bmap)) {
		if ((start+num-1) & ~0xffffffffULL) {
			ext2fs_warn_bitmap2(bmap,
					    EXT2FS_UNMARK_ERROR, 0xffffffff);
			return EINVAL;
		}
		return ext2fs_get_generic_bitmap_range(bmap, bmap->magic,
						       start, num, out);
	}

	if (!EXT2FS_IS_64_BITMAP(bmap))
		return EINVAL;

	INC_STAT(bmap, get_range_count);

	return bmap->bitmap_ops->get_bmap_range(bmap, start, num, out);
}
Example #10
0
/*
 * Return 1 if the output space condition went away
 * before adding the handler.
 */
int add_output_space_event (tux_req_t *req, struct socket *sock)
{
	struct sock *sk = sock->sk;
	/*
	 * blocked due to socket IO?
	 */
	spin_lock_irq(&req->ti->work_lock);
	add_keepalive_timer(req);
	if (test_and_set_bit(0,&req->wait_output_space))
		TUX_BUG();
	INC_STAT(nr_output_space_pending);

	if ((sk->sk_state == TCP_ESTABLISHED) && enough_wspace(sk)) {
		if (test_and_clear_bit(0, &req->wait_output_space)) {
			DEC_STAT(nr_output_space_pending);
			del_keepalive_timer(req);
			spin_unlock_irq(&req->ti->work_lock);
			return 1;
		}
	}
	spin_unlock_irq(&req->ti->work_lock);

	return 0;
}
Example #11
0
void *
npr_mempool_alloc_align_stat(struct npr_mempool *pool,
                             unsigned int align_shift, unsigned int size
                             MT_ARG
)
{
    uintptr_t ptr, ptr_aligned;
    int ptr_diff, remain;
    unsigned char *alloc_ptr;
    unsigned int alloc_size;
    unsigned int align;
    uintptr_t align_mask;
    unsigned int aligned_size;


    if (size >= 1024) {
        return alloc_large(pool, size PASS_MT);
    }

    align = 1<<align_shift;
    align_mask = ~((uintptr_t)(1<<align_shift) - 1);
    aligned_size = (size + (align-1))&align_mask;

retry:
    ptr = (uintptr_t)(pool->data_entry[pool->entry_index] + pool->entry_byte_pos);
    ptr_aligned = (ptr+(align-1))&align_mask;
    ptr_diff = ptr_aligned - ptr;
    remain = pool->entry_byte_remain - ptr_diff;
    alloc_ptr = (unsigned char*)ptr_aligned;

    if ((int)size > remain) {
        unsigned int next_entry_index;
        INC_STAT(unused_mem, pool->entry_byte_remain);

        /* realloc entry */
        next_entry_index = pool->entry_index + 1;
        alloc_size = pool->entry_byte_size*2;

        if ((size+align) > alloc_size)
            alloc_size = (size+align)*2;

        if (next_entry_index >= pool->entry_num) {
            /* realloc entry pointer */
            int next_entry_num = pool->entry_num * 2;
            pool->data_entry = (unsigned char**)realloc(pool->data_entry, next_entry_num * sizeof(unsigned char*));
            pool->entry_num = next_entry_num;
        }

        pool->entry_byte_remain = pool->entry_byte_size = alloc_size;
        pool->entry_index = next_entry_index;
        pool->entry_byte_pos = 0;

        pool->data_entry[next_entry_index] = (unsigned char*)malloc(alloc_size);

        goto retry;
    }
    INC_STAT(align_padding, ptr_diff);

    alloc_size = (ptr_diff + aligned_size);

    remain -= alloc_size;
    pool->entry_byte_remain = remain;
    pool->entry_byte_pos += alloc_size;

    pool->alloc_small += alloc_size;
    INC_STAT(alloc_total, alloc_size);
    INC_STAT(size_each_type[mt], alloc_size);

    /* memset(alloc_ptr, 0x33, size); */

    return alloc_ptr;
}
static void rxtx_loop()
{
    int ret, send_ret;
	struct sockaddr_in  peer_addr;
    char peer_ip[32];
	uint16_t peer_port;
	while (!the_working_paras.need_exit)
	{
	    ret=fd_readable(the_working_paras.sockfd, 0, 10000);
	    if (ret<=0)
    	{
    	    if (ret<0 && !the_working_paras.no_verbose)
    	        ERR_DBG_PRINT("test fd failed");

			continue;
    	}

        ret=udp_socket_recvfrom(the_working_paras.sockfd
			,the_working_paras.buf
			,sizeof(the_working_paras.buf)
			,&peer_addr);
		INC_STAT(the_stat_data.rx_times_total);

		if (ret>0)
		{
			INC_STAT(the_stat_data.rx_pkts);
			INC_STAT_VALUE(the_stat_data.rx_bytes, ret);

			if (!the_working_paras.no_verbose)
			{
			    resolve_sockaddr(&peer_addr, peer_ip, sizeof(peer_ip), &peer_port);
			    printf("[%"PRIu64"]got %d bytes from %s:%d\n"
					,the_stat_data.rx_pkts
					,ret
					,peer_ip
					,(int)peer_port);

                if (!the_working_paras.no_prt_pkt)
            	{
					printf("the data contents is:\n");
					print_mem(the_working_paras.buf, ret);
            	}
			}
			
			if (!the_working_paras.only_recv)
			{
				if (!the_working_paras.no_verbose)
				{
				    printf("try send back %d bytes to %s:%d\n"
						,ret
						,peer_ip
						,(int)peer_port);

				}
			    send_ret=udp_socket_sendto(the_working_paras.sockfd, the_working_paras.buf, ret, &peer_addr);
				INC_STAT(the_stat_data.tx_pkts_total);
				INC_STAT_VALUE(the_stat_data.tx_bytes_total, ret);

				if (send_ret==ret)
				{
				    INC_STAT(the_stat_data.tx_pkts_succ);
			        INC_STAT_VALUE(the_stat_data.tx_bytes_succ, ret);
				}
				else if (send_ret<=0)
				{
				    INC_STAT(the_stat_data.tx_pkts_fail);
			        INC_STAT_VALUE(the_stat_data.tx_bytes_fail, ret);

					if (!the_working_paras.no_verbose)
					    ERR_DBG_PRINT("tx failed");

				}
				else
					DBG_PRINT_QUIT("abnormal event: udp packet was partly sent!");
			}

		}
		else
		{
			INC_STAT(the_stat_data.rx_times_fail);

			if (!the_working_paras.no_verbose)
			    ERR_DBG_PRINT("rx failed");
		}

		printf("\n\n");
		continue;

	}
}