示例#1
0
int efx_vi_alloc(struct efx_vi_state **vih_out, int ifindex)
{
	struct efx_vi_state *efx_state;
	int rc;

	efx_state = kmalloc(sizeof(struct efx_vi_state), GFP_KERNEL);

	if (!efx_state) {
		EFRM_ERR("%s: failed to allocate memory for efx_vi_state",
			 __func__);
		rc = -ENOMEM;
		goto fail;
	}

	efx_state->ifindex = ifindex;
	rc = efrm_client_get(ifindex, NULL, NULL, &efx_state->efrm_client);
	if (rc < 0) {
		EFRM_ERR("%s: efrm_client_get(%d) failed: %d", __func__,
			 ifindex, rc);
		rc = -ENODEV;
		goto fail_no_ifindex;
	}
	efx_state->nic = efrm_client_get_nic(efx_state->efrm_client);

	init_completion(&efx_state->flush_completion);

	/* basically allocate_pt_endpoint() */
	rc = alloc_ep(efx_state);
	if (rc) {
		EFRM_ERR("%s: alloc_ep failed: %d", __func__, rc);
		goto fail_no_pt;
	}
#if EFX_VI_STATIC_FILTERS
	/* Statically allocate a set of filter resources - removes the
	   restriction on not being able to use efx_vi_filter() from
	   in_atomic() */
	rc = efx_vi_alloc_static_filters(efx_state);
	if (rc)
		goto fail_no_filters;
#endif

	*vih_out = efx_state;

	return 0;
#if EFX_VI_STATIC_FILTERS
fail_no_filters:
	free_ep(efx_state);
#endif
fail_no_pt:
	efrm_client_put(efx_state->efrm_client);
fail_no_ifindex:
	kfree(efx_state);
fail:
	return rc;
}
示例#2
0
External_Process*
spawn_external (char* cmd)
{
    External_Process* ep;
    int rc;

    ep = alloc_ep ();
    if (!ep) return 0;

    /* Create the pipes */
    rc = pipe (ep->mypipe);
    if (rc) {
	fprintf (stderr, "Can't open pipes\n");
	free (ep);
	return 0;
    }
    /* Create the child process. */
    ep->pid = fork ();
    if (ep->pid == (pid_t) 0) {
	/* This is the child process. */
	int i = 0;
	char** argv;

	close (ep->mypipe[0]);
	dup2 (ep->mypipe[1],1);
	close (ep->mypipe[1]);

	argv = buildargv (cmd);
	while (argv[i]) {
	    debug_printf ("argv[%d] = %s\n", i, argv[i]);
	    i++;
	}

	execvp (argv[0],&argv[0]);
	/* Doesn't return */
	fprintf (stderr, "Error, returned from execlp\n");
	exit (-1);
    } else if (ep->pid < (pid_t) 0) {
	/* The fork failed. */
	close (ep->mypipe[0]);
	close (ep->mypipe[1]);
	fprintf (stderr, "Fork failed.\n");
	free (ep);
	return 0;
    } else {
	/* This is the parent process. */
	close (ep->mypipe[1]);
	rc = fcntl (ep->mypipe[0], F_SETFL, O_NONBLOCK);
	return ep;
    }
}
示例#3
0
static int init_fabric(void)
{
	int ret;

	ret = ft_getinfo(hints, &fi);
	if (ret)
		return ret;

	ret = get_dupinfo();
	if (ret)
		return ret;

	ret = ft_open_fabric_res();
	if (ret)
		return ret;

	av_attr.count = ep_cnt;

	ret = alloc_ep_res(fi);
	if (ret)
		return ret;

	ret = alloc_ep();
	if (ret)
		return ret;

	ret = bind_ep_array_res();
	if (ret)
		return ret;

	/* Post recv */
	if (rx_shared_ctx)
		ret = ft_post_rx(srx_ctx, MAX(rx_size, FT_MAX_CTRL_MSG), &rx_ctx);
	else
		ret = ft_post_rx(ep_array[0], MAX(rx_size, FT_MAX_CTRL_MSG), &rx_ctx);
	if (ret)
		return ret;

	ret = init_av();
	return ret;
}
示例#4
0
static int client_connect(void)
{
	struct fi_eq_cm_entry entry;
	uint32_t event;
	ssize_t rd;
	int i, ret;

	ret = ft_getinfo(hints, &fi);
	if (ret)
		return ret;

	ret = get_dupinfo();
	if (ret)
		return ret;

	ret = ft_open_fabric_res();
	if (ret)
		return ret;

	ret = alloc_ep_res(fi);
	if (ret)
		return ret;

	ret = alloc_ep();
	if (ret)
		return ret;

	ret = bind_ep_array_res();
	if (ret)
		return ret;

	for (i = 0; i < ep_cnt; i++) {
		ret = fi_connect(ep_array[i], fi->dest_addr, NULL, 0);
		if (ret) {
			FT_PRINTERR("fi_connect", ret);
			return ret;
		}

		rd = fi_eq_sread(eq, &event, &entry, sizeof entry, -1, 0);
		if (rd != sizeof entry) {
			FT_PROCESS_EQ_ERR(rd, eq, "fi_eq_sread", "connect");
			ret = (int) rd;
			return ret;
		}

		if (event != FI_CONNECTED || entry.fid != &ep_array[i]->fid) {
			fprintf(stderr, "Unexpected CM event %d fid %p (ep %p)\n",
				event, entry.fid, ep);
			ret = -FI_EOTHER;
			return ret;
		}
	}

	/* Post recv */
	if (rx_shared_ctx)
		ret = ft_post_rx(srx_ctx, MAX(rx_size, FT_MAX_CTRL_MSG), &rx_ctx);
	else
		ret = ft_post_rx(ep_array[0], MAX(rx_size, FT_MAX_CTRL_MSG), &rx_ctx);
	if (ret)
		return ret;

	return 0;
}
示例#5
0
External_Process*
spawn_external (char* cmd)
{
    External_Process* ep;
    HANDLE hChildStdinRd;
    HANDLE hChildStdinWr;
    HANDLE hChildStdoutWr;

    SECURITY_ATTRIBUTES saAttr; 
    PROCESS_INFORMATION piProcInfo; 
    STARTUPINFO startup_info;
    BOOL rc;
    DWORD creation_flags;

    ep = alloc_ep ();
    if (!ep) return 0;

    /* Set the bInheritHandle flag so pipe handles are inherited. */
    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
    saAttr.bInheritHandle = TRUE; 
    saAttr.lpSecurityDescriptor = NULL; 

    /* Create a pipe for the child process's STDOUT. */
    if (!CreatePipe (&ep->mypipe, &hChildStdoutWr, &saAttr, 0)) {
        debug_printf ("Stdout pipe creation failed\n");
	free (ep);
	return 0;
    }

    /* Ensure the read handle to the pipe for STDOUT is not inherited.*/
    SetHandleInformation (ep->mypipe, HANDLE_FLAG_INHERIT, 0);

    /* Create a pipe for the child process's STDIN. */
    if (!CreatePipe (&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) {
        debug_printf ("Stdin pipe creation failed\n");
	free (ep);
	return 0;
    }

    /* Ensure the write handle to the pipe for STDIN is not inherited. */
    SetHandleInformation (hChildStdinWr, HANDLE_FLAG_INHERIT, 0);

    /* create the child process */
    ZeroMemory (&piProcInfo, sizeof(PROCESS_INFORMATION));
    ZeroMemory (&startup_info, sizeof(STARTUPINFO));
    startup_info.cb = sizeof(STARTUPINFO); 
    startup_info.hStdError = hChildStdoutWr;
    startup_info.hStdOutput = hChildStdoutWr;
    startup_info.hStdInput = hChildStdinRd;
    startup_info.dwFlags |= STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    //startup_info.wShowWindow = SW_SHOW;
    startup_info.wShowWindow = SW_HIDE;

    creation_flags = 0;
    creation_flags |= CREATE_NEW_PROCESS_GROUP;
    //creation_flags |= CREATE_NEW_CONSOLE;

    rc = CreateProcess (
		NULL,           // executable name
		cmd,	        // command line 
		NULL,           // process security attributes 
		NULL,           // primary thread security attributes 
		TRUE,           // handles are inherited 
		creation_flags, // creation flags 
		NULL,           // use parent's environment 
		NULL,           // use parent's current directory 
		&startup_info,  // STARTUPINFO pointer
		&piProcInfo);   // receives PROCESS_INFORMATION 
    if (rc == 0) {
        debug_printf ("CreateProcess() failed\n");
	free (ep);
	return 0;
    }
    ep->hproc = piProcInfo.hProcess;
    ep->pid = piProcInfo.dwProcessId;
    //CloseHandle (piProcInfo.hProcess);
    CloseHandle (piProcInfo.hThread);

    Sleep (0);
    return ep;
}