ubd_user.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
  3. * Copyright (C) 2001 Ridgerun,Inc (glonnon@ridgerun.com)
  4. * Licensed under the GPL
  5. */
  6. #include <stddef.h>
  7. #include <unistd.h>
  8. #include <errno.h>
  9. #include <sched.h>
  10. #include <signal.h>
  11. #include <string.h>
  12. #include <netinet/in.h>
  13. #include <sys/time.h>
  14. #include <sys/socket.h>
  15. #include <sys/mman.h>
  16. #include <sys/param.h>
  17. #include "asm/types.h"
  18. #include "user.h"
  19. #include "ubd_user.h"
  20. #include "os.h"
  21. #include "cow.h"
  22. #include <endian.h>
  23. #include <byteswap.h>
  24. void ignore_sigwinch_sig(void)
  25. {
  26. signal(SIGWINCH, SIG_IGN);
  27. }
  28. int start_io_thread(unsigned long sp, int *fd_out)
  29. {
  30. int pid, fds[2], err;
  31. err = os_pipe(fds, 1, 1);
  32. if(err < 0){
  33. printk("start_io_thread - os_pipe failed, err = %d\n", -err);
  34. goto out;
  35. }
  36. kernel_fd = fds[0];
  37. *fd_out = fds[1];
  38. err = os_set_fd_block(*fd_out, 0);
  39. if (err) {
  40. printk("start_io_thread - failed to set nonblocking I/O.\n");
  41. goto out_close;
  42. }
  43. pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL);
  44. if(pid < 0){
  45. err = -errno;
  46. printk("start_io_thread - clone failed : errno = %d\n", errno);
  47. goto out_close;
  48. }
  49. return(pid);
  50. out_close:
  51. os_close_file(fds[0]);
  52. os_close_file(fds[1]);
  53. kernel_fd = -1;
  54. *fd_out = -1;
  55. out:
  56. return err;
  57. }