1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
  14  */
  15 #ifndef _DMU_KRRP_H
  16 #define _DMU_KRRP_H
  17 
  18 #ifdef  __cplusplus
  19 extern "C" {
  20 #endif
  21 
  22 typedef enum {
  23         SBS_UNAVAIL,
  24         SBS_AVAIL,
  25         SBS_USED,
  26         SBS_DONE,
  27         SBS_DESTROYED,
  28         SBS_NUMTYPES
  29 } dmu_krrp_state_t;
  30 
  31 typedef struct dmu_krrp_task dmu_krrp_task_t;
  32 
  33 typedef struct dmu_krrp_stream {
  34         kmutex_t mtx;
  35         kcondvar_t cv;
  36         boolean_t running;
  37         kthread_t *work_thread;
  38         void (*task_executor)(void *);
  39         dmu_krrp_task_t *task;
  40 } dmu_krrp_stream_t;
  41 
  42 struct dmu_krrp_task {
  43         kmutex_t buffer_state_lock;
  44         kcondvar_t buffer_state_cv;
  45         kcondvar_t buffer_destroy_cv;
  46         kreplication_buffer_t *buffer;
  47         size_t buffer_bytes_read;
  48         boolean_t is_read;
  49         boolean_t is_full;
  50         dmu_krrp_state_t buffer_state;
  51         int buffer_error;
  52         dmu_krrp_stream_t *stream_handler;
  53         kreplication_zfs_args_t buffer_args;
  54         char cookie[ZFS_MAX_DATASET_NAME_LEN];
  55 };
  56 
  57 
  58 int dmu_krrp_buffer_write(void *buf, int len,
  59     dmu_krrp_task_t *krrp_task);
  60 int dmu_krrp_buffer_read(void *buf, int len,
  61     dmu_krrp_task_t *krrp_task);
  62 int dmu_krrp_arc_bypass(void *buf, int len, void *arg);
  63 int dmu_krrp_direct_arc_read(spa_t *spa, dmu_krrp_task_t *krrp_task,
  64     zio_cksum_t *zc, const blkptr_t *bp);
  65 
  66 typedef int (*dmu_krrp_arc_bypass_cb)(void *, int, dmu_krrp_task_t *);
  67 typedef struct {
  68         dmu_krrp_task_t *krrp_task;
  69         zio_cksum_t *zc;
  70         dmu_krrp_arc_bypass_cb cb;
  71 } dmu_krrp_arc_bypass_t;
  72 
  73 #ifdef  __cplusplus
  74 }
  75 #endif
  76 
  77 #endif /* _DMU_KRRP_H */