2016-11-09 23:43:25 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Anton Ivanov (aivanov@brocade.com)
|
2005-10-11 07:10:32 +04:00
|
|
|
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
|
|
|
|
* Copyright (C) 2001 Ridgerun,Inc (glonnon@ridgerun.com)
|
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <endian.h>
|
|
|
|
#include <byteswap.h>
|
|
|
|
|
2011-08-19 02:04:41 +04:00
|
|
|
#include "ubd.h"
|
2012-10-08 06:27:32 +04:00
|
|
|
#include <os.h>
|
2016-11-09 23:43:25 +03:00
|
|
|
#include <poll.h>
|
|
|
|
|
|
|
|
struct pollfd kernel_pollfd;
|
2011-08-19 02:04:41 +04:00
|
|
|
|
2005-10-11 07:10:32 +04:00
|
|
|
int start_io_thread(unsigned long sp, int *fd_out)
|
|
|
|
{
|
|
|
|
int pid, fds[2], err;
|
|
|
|
|
|
|
|
err = os_pipe(fds, 1, 1);
|
|
|
|
if(err < 0){
|
|
|
|
printk("start_io_thread - os_pipe failed, err = %d\n", -err);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_fd = fds[0];
|
2016-11-09 23:43:25 +03:00
|
|
|
kernel_pollfd.fd = kernel_fd;
|
|
|
|
kernel_pollfd.events = POLLIN;
|
2005-10-11 07:10:32 +04:00
|
|
|
*fd_out = fds[1];
|
|
|
|
|
2007-07-16 10:38:51 +04:00
|
|
|
err = os_set_fd_block(*fd_out, 0);
|
2016-11-09 23:43:25 +03:00
|
|
|
err = os_set_fd_block(kernel_fd, 0);
|
2007-07-16 10:38:51 +04:00
|
|
|
if (err) {
|
|
|
|
printk("start_io_thread - failed to set nonblocking I/O.\n");
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
2007-12-18 03:19:46 +03:00
|
|
|
pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL);
|
2005-10-11 07:10:32 +04:00
|
|
|
if(pid < 0){
|
|
|
|
err = -errno;
|
2007-05-07 01:51:02 +04:00
|
|
|
printk("start_io_thread - clone failed : errno = %d\n", errno);
|
2005-10-11 07:10:32 +04:00
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(pid);
|
|
|
|
|
|
|
|
out_close:
|
|
|
|
os_close_file(fds[0]);
|
|
|
|
os_close_file(fds[1]);
|
|
|
|
kernel_fd = -1;
|
|
|
|
*fd_out = -1;
|
|
|
|
out:
|
2007-05-07 01:51:02 +04:00
|
|
|
return err;
|
2005-10-11 07:10:32 +04:00
|
|
|
}
|
2016-11-09 23:43:25 +03:00
|
|
|
|
|
|
|
int ubd_read_poll(int timeout)
|
|
|
|
{
|
|
|
|
kernel_pollfd.events = POLLIN;
|
|
|
|
return poll(&kernel_pollfd, 1, timeout);
|
|
|
|
}
|
|
|
|
int ubd_write_poll(int timeout)
|
|
|
|
{
|
|
|
|
kernel_pollfd.events = POLLOUT;
|
|
|
|
return poll(&kernel_pollfd, 1, timeout);
|
|
|
|
}
|
|
|
|
|