ubd_user.c 1.2 KB

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