ksmbd_work.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2019 Samsung Electronics Co., Ltd.
  4. */
  5. #ifndef __KSMBD_WORK_H__
  6. #define __KSMBD_WORK_H__
  7. #include <linux/ctype.h>
  8. #include <linux/workqueue.h>
  9. struct ksmbd_conn;
  10. struct ksmbd_session;
  11. struct ksmbd_tree_connect;
  12. enum {
  13. KSMBD_WORK_ACTIVE = 0,
  14. KSMBD_WORK_CANCELLED,
  15. KSMBD_WORK_CLOSED,
  16. };
  17. struct aux_read {
  18. void *buf;
  19. struct list_head entry;
  20. };
  21. /* one of these for every pending CIFS request at the connection */
  22. struct ksmbd_work {
  23. /* Server corresponding to this mid */
  24. struct ksmbd_conn *conn;
  25. struct ksmbd_session *sess;
  26. struct ksmbd_tree_connect *tcon;
  27. /* Pointer to received SMB header */
  28. void *request_buf;
  29. /* Response buffer */
  30. void *response_buf;
  31. struct list_head aux_read_list;
  32. struct kvec *iov;
  33. int iov_alloc_cnt;
  34. int iov_cnt;
  35. int iov_idx;
  36. /* Next cmd hdr in compound req buf*/
  37. int next_smb2_rcv_hdr_off;
  38. /* Next cmd hdr in compound rsp buf*/
  39. int next_smb2_rsp_hdr_off;
  40. /* Current cmd hdr in compound rsp buf*/
  41. int curr_smb2_rsp_hdr_off;
  42. /*
  43. * Current Local FID assigned compound response if SMB2 CREATE
  44. * command is present in compound request
  45. */
  46. u64 compound_fid;
  47. u64 compound_pfid;
  48. u64 compound_sid;
  49. const struct cred *saved_cred;
  50. /* Number of granted credits */
  51. unsigned int credits_granted;
  52. /* response smb header size */
  53. unsigned int response_sz;
  54. void *tr_buf;
  55. unsigned char state;
  56. /* No response for cancelled request */
  57. bool send_no_response:1;
  58. /* Request is encrypted */
  59. bool encrypted:1;
  60. /* Is this SYNC or ASYNC ksmbd_work */
  61. bool asynchronous:1;
  62. bool need_invalidate_rkey:1;
  63. unsigned int remote_key;
  64. /* cancel works */
  65. int async_id;
  66. void **cancel_argv;
  67. void (*cancel_fn)(void **argv);
  68. struct work_struct work;
  69. /* List head at conn->requests */
  70. struct list_head request_entry;
  71. /* List head at conn->async_requests */
  72. struct list_head async_request_entry;
  73. struct list_head fp_entry;
  74. };
  75. /**
  76. * ksmbd_resp_buf_next - Get next buffer on compound response.
  77. * @work: smb work containing response buffer
  78. */
  79. static inline void *ksmbd_resp_buf_next(struct ksmbd_work *work)
  80. {
  81. return work->response_buf + work->next_smb2_rsp_hdr_off + 4;
  82. }
  83. /**
  84. * ksmbd_resp_buf_curr - Get current buffer on compound response.
  85. * @work: smb work containing response buffer
  86. */
  87. static inline void *ksmbd_resp_buf_curr(struct ksmbd_work *work)
  88. {
  89. return work->response_buf + work->curr_smb2_rsp_hdr_off + 4;
  90. }
  91. /**
  92. * ksmbd_req_buf_next - Get next buffer on compound request.
  93. * @work: smb work containing response buffer
  94. */
  95. static inline void *ksmbd_req_buf_next(struct ksmbd_work *work)
  96. {
  97. return work->request_buf + work->next_smb2_rcv_hdr_off + 4;
  98. }
  99. struct ksmbd_work *ksmbd_alloc_work_struct(void);
  100. void ksmbd_free_work_struct(struct ksmbd_work *work);
  101. void ksmbd_work_pool_destroy(void);
  102. int ksmbd_work_pool_init(void);
  103. int ksmbd_workqueue_init(void);
  104. void ksmbd_workqueue_destroy(void);
  105. bool ksmbd_queue_work(struct ksmbd_work *work);
  106. int ksmbd_iov_pin_rsp_read(struct ksmbd_work *work, void *ib, int len,
  107. void *aux_buf, unsigned int aux_size);
  108. int ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len);
  109. int allocate_interim_rsp_buf(struct ksmbd_work *work);
  110. #endif /* __KSMBD_WORK_H__ */