ubd_user.c 1.3 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 "kern_util.h"
  19. #include "user.h"
  20. #include "ubd_user.h"
  21. #include "os.h"
  22. #include "cow.h"
  23. #include <endian.h>
  24. #include <byteswap.h>
  25. void ignore_sigwinch_sig(void)
  26. {
  27. signal(SIGWINCH, SIG_IGN);
  28. }
  29. int start_io_thread(unsigned long sp, int *fd_out)
  30. {
  31. int pid, fds[2], err;
  32. err = os_pipe(fds, 1, 1);
  33. if(err < 0){
  34. printk("start_io_thread - os_pipe failed, err = %d\n", -err);
  35. goto out;
  36. }
  37. kernel_fd = fds[0];
  38. *fd_out = fds[1];
  39. err = os_set_fd_block(*fd_out, 0);
  40. if (err) {
  41. printk("start_io_thread - failed to set nonblocking I/O.\n");
  42. goto out_close;
  43. }
  44. pid = clone(io_thread, (void *) sp, CLONE_FILES | CLONE_VM, NULL);
  45. if(pid < 0){
  46. err = -errno;
  47. printk("start_io_thread - clone failed : errno = %d\n", errno);
  48. goto out_close;
  49. }
  50. return(pid);
  51. out_close:
  52. os_close_file(fds[0]);
  53. os_close_file(fds[1]);
  54. kernel_fd = -1;
  55. *fd_out = -1;
  56. out:
  57. return err;
  58. }