2N/A/*
2N/A * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * BSD 3 Clause License
2N/A *
2N/A * Copyright (c) 2007, The Storage Networking Industry Association.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A * - Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A *
2N/A * - Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in
2N/A * the documentation and/or other materials provided with the
2N/A * distribution.
2N/A *
2N/A * - Neither the name of The Storage Networking Industry Association (SNIA)
2N/A * nor the names of its contributors may be used to endorse or promote
2N/A * products derived from this software without specific prior written
2N/A * permission.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2N/A * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2N/A * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2N/A * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2N/A * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2N/A * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2N/A * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2N/A * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2N/A * POSSIBILITY OF SUCH DAMAGE.
2N/A */
2N/A/* Copyright (c) 2007, The Storage Networking Industry Association. */
2N/A/* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
2N/A#ifndef _LIBNDMP_H
2N/A#define _LIBNDMP_H
2N/A
2N/A#include <rpc/types.h>
2N/A#include <libscf.h>
2N/A#include <libnvpair.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/* NDMP supported versions */
2N/A#define NDMP_V2 2
2N/A#define NDMP_V3 3
2N/A#define NDMP_V4 4
2N/A
2N/A/* Device type */
2N/A#define NDMP_SINQ_SEQ_ACCESS_DEVICE 0x01
2N/A#define NDMP_SINQ_TAPE_ROBOT 0x08
2N/A
2N/A/*
2N/A * Check for delimiters: space, tab or comma
2N/A */
2N/A#define IS_DELIM(c) ((c) == ' ' || (c) == ',' || (c) == '\t')
2N/A
2N/A
2N/Aextern int ndmp_errno;
2N/A
2N/A/* NDMP plugin module API */
2N/A#define NDMP_PLUGIN_VERSION 1
2N/A
2N/A/*
2N/A * The basename for creating snapshot name.
2N/A */
2N/A#define NDMP_BASENAME ".ndmp"
2N/A
2N/Atypedef struct ndmp_context {
2N/A char *nc_plname;
2N/A uint_t nc_plversion;
2N/A void *nc_pldata; /* data private to the plugin */
2N/A void *nc_cmds;
2N/A void *nc_params;
2N/A void *nc_ddata; /* data private to the daemon */
2N/A} ndmp_context_t;
2N/A
2N/Atypedef struct ndmp_plugin {
2N/A const char *np_plid; /* plugin identifier */
2N/A uint_t np_plversion; /* plugin version */
2N/A void *np_pldata; /* for private use by the plugin */
2N/A
2N/A /* Plugin entry points */
2N/A int (*np_pre_backup)(struct ndmp_plugin *, ndmp_context_t *,
2N/A const char *);
2N/A int (*np_post_backup)(struct ndmp_plugin *, ndmp_context_t *,
2N/A int);
2N/A int (*np_pre_restore)(struct ndmp_plugin *, ndmp_context_t *,
2N/A const char *, const char *);
2N/A int (*np_post_restore)(struct ndmp_plugin *, ndmp_context_t *,
2N/A int);
2N/A} ndmp_plugin_t;
2N/A
2N/Atypedef enum ndmp_log_dma_type {
2N/A NDMP_LOGD_NORMAL = 0,
2N/A NDMP_LOGD_DEBUG = 1,
2N/A NDMP_LOGD_ERROR = 2,
2N/A NDMP_LOGD_WARNING = 3
2N/A} ndmp_log_dma_type_t;
2N/A
2N/A/*
2N/A * enum of available backup types. Note that the entries here should match
2N/A * their name strings defined in ndmpd.h, and that they should further match the
2N/A * definition of ndmpd_backup_type_name in ndmpd_util.c
2N/A */
2N/Atypedef enum {
2N/A NDMP_BUTYPE_TAR = 0,
2N/A NDMP_BUTYPE_DUMP,
2N/A NDMP_BUTYPE_ZFS,
2N/A NDMP_BUTYPE_NUMBER /* not a type, number of butypes, must be last */
2N/A} ndmpd_backup_type_t;
2N/A
2N/Aextern ndmpd_backup_type_t ndmp_get_backup_type(ndmp_context_t *);
2N/A
2N/A/* libndmp door call related data */
2N/A#define MAX_ALLOWED_DOOR_RETRY 5
2N/A#define NDMP_DOOR_SESSION_INFO 1024
2N/A#define NDMP_DOOR_DEVICE_INFO 400
2N/A
2N/A/* libndmp error codes */
2N/A#define ENDMP_BASE 2000
2N/A#define ENDMP_INTERNAL_ERROR ENDMP_BASE
2N/A#define ENDMP_INVALID ENDMP_BASE + 500
2N/A
2N/Aenum {
2N/A ENDMP_DOOR_SRV_TIMEOUT = ENDMP_BASE,
2N/A ENDMP_DOOR_SRV_OPERATION,
2N/A ENDMP_DOOR_OPEN,
2N/A ENDMP_MEM_ALLOC,
2N/A ENDMP_DOOR_ENCODE_START,
2N/A ENDMP_DOOR_ENCODE_FINISH,
2N/A ENDMP_DOOR_DECODE_FINISH,
2N/A ENDMP_SMF_PERM,
2N/A ENDMP_SMF_INTERNAL,
2N/A ENDMP_SMF_PROP,
2N/A ENDMP_SMF_PROP_GRP,
2N/A /* The following are error codes indicating invalid args */
2N/A ENDMP_INVALID_ARG = ENDMP_INVALID,
2N/A ENDMP_ENOENT,
2N/A ENDMP_INVALID_PROPVAL,
2N/A ENDMP_INVALID_DTYPE
2N/A};
2N/A
2N/A/* Tape device open mode */
2N/Atypedef enum ndmp_tp_open_mode {
2N/A NDMP_TP_READ_MODE,
2N/A NDMP_TP_WRITE_MODE,
2N/A NDMP_TP_RAW_MODE,
2N/A NDMP_TP_RAW1_MODE = 0x7fffffff,
2N/A NDMP_TP_RAW2_MODE = NDMP_TP_RAW_MODE
2N/A} ndmp_tp_open_mode_t;
2N/A
2N/A/* Mover state */
2N/Atypedef enum ndmp_mv_state {
2N/A NDMP_MV_STATE_IDLE,
2N/A NDMP_MV_STATE_LISTEN,
2N/A NDMP_MV_STATE_ACTIVE,
2N/A NDMP_MV_STATE_PAUSED,
2N/A NDMP_MV_STATE_HALTED
2N/A} ndmp_mv_state_t;
2N/A
2N/A/* Mover mode */
2N/Atypedef enum ndmp_mv_mode {
2N/A NDMP_MV_MODE_READ,
2N/A NDMP_MV_MODE_WRITE,
2N/A NDMP_MV_MODE_NOACTION
2N/A} ndmp_mv_mode_t;
2N/A
2N/A/* Mover pause reson */
2N/Atypedef enum ndmp_mv_pause_reason {
2N/A NDMP_MV_PAUSE_NA,
2N/A NDMP_MV_PAUSE_EOM,
2N/A NDMP_MV_PAUSE_EOF,
2N/A NDMP_MV_PAUSE_SEEK,
2N/A NDMP_MV_PAUSE_MEDIA_ERROR,
2N/A NDMP_MV_PAUSE_EOW
2N/A} ndmp_mv_pause_reason_t;
2N/A
2N/A/* Mover halt reason */
2N/Atypedef enum ndmp_mv_halt_reason {
2N/A NDMP_MV_HALT_NA,
2N/A NDMP_MV_HALT_CONNECT_CLOSED,
2N/A NDMP_MV_HALT_ABORTED,
2N/A NDMP_MV_HALT_INTERNAL_ERROR,
2N/A NDMP_MV_HALT_CONNECT_ERROR,
2N/A NDMP_MV_HALT_MEDIA_ERROR
2N/A} ndmp_mv_halt_reason_t;
2N/A
2N/A/* Address type */
2N/Atypedef enum ndmp_ad_type {
2N/A NDMP_AD_LOCAL,
2N/A NDMP_AD_TCP,
2N/A NDMP_AD_FC,
2N/A NDMP_AD_IPC
2N/A} ndmp_ad_type_t;
2N/A
2N/A/* NDMP data operation */
2N/Atypedef enum ndmp_dt_operation {
2N/A NDMP_DT_OP_NOACTION,
2N/A NDMP_DT_OP_BACKUP,
2N/A NDMP_DT_OP_RECOVER,
2N/A NDMP_DT_OP_RECOVER_FILEHIST
2N/A} ndmp_dt_operation_t;
2N/A
2N/A/* NDMP data state */
2N/Atypedef enum ndmp_dt_state {
2N/A NDMP_DT_STATE_IDLE,
2N/A NDMP_DT_STATE_ACTIVE,
2N/A NDMP_DT_STATE_HALTED,
2N/A NDMP_DT_STATE_LISTEN,
2N/A NDMP_DT_STATE_CONNECTED
2N/A} ndmp_dt_state_t;
2N/A
2N/A/* NDMP data halt reason */
2N/Atypedef enum ndmp_dt_halt_reason {
2N/A NDMP_DT_HALT_NA,
2N/A NDMP_DT_HALT_SUCCESSFUL,
2N/A NDMP_DT_HALT_ABORTED,
2N/A NDMP_DT_HALT_INTERNAL_ERROR,
2N/A NDMP_DT_HALT_CONNECT_ERROR
2N/A} ndmp_dt_halt_reason_t;
2N/A
2N/A/* Device information structure */
2N/Atypedef struct ndmp_devinfo {
2N/A uint_t nd_dev_type; /* SCSI device type */
2N/A char *nd_name; /* Device name */
2N/A uint_t nd_lun; /* Lun number */
2N/A uint_t nd_sid; /* Scsi id */
2N/A char *nd_vendor; /* Vendor name */
2N/A char *nd_product; /* Product name */
2N/A char *nd_revision; /* Revision */
2N/A char *nd_serial; /* Serial */
2N/A char *nd_wwn; /* World wide name */
2N/A} ndmp_devinfo_t;
2N/A
2N/A/* Scsi device info sturcture */
2N/Atypedef struct ndmp_scsi {
2N/A int ns_scsi_open; /* Scsi device open */
2N/A /* -1 if not open */
2N/A char *ns_adapter_name; /* Scsi adapter name */
2N/A int ns_valid_target_set; /* Scsi valid target */
2N/A /* scsi_id and lun are set only if valid_target_set is set */
2N/A int ns_scsi_id; /* Scsi id */
2N/A int ns_lun; /* Scsi lun */
2N/A} ndmp_scsi_t;
2N/A
2N/Atypedef struct ndmp_tape {
2N/A int nt_fd; /* Tape device file descriptor */
2N/A /* The data below is set only if "fd" is not -1 */
2N/A ulong_t nt_rec_count; /* Number of records written */
2N/A ndmp_tp_open_mode_t nt_mode; /* Tape device open mode */
2N/A char *nt_dev_name; /* Device name */
2N/A int nt_sid; /* Scsi id */
2N/A int nt_lun; /* Lun number */
2N/A} ndmp_tape_t;
2N/A
2N/A/* NDMP mover info structure */
2N/Atypedef struct ndmp_mover {
2N/A ndmp_mv_state_t nm_state; /* Current state */
2N/A ndmp_mv_mode_t nm_mode; /* Current mode */
2N/A ndmp_mv_pause_reason_t nm_pause_reason; /* Current reason */
2N/A ndmp_mv_halt_reason_t nm_halt_reason; /* Current reason */
2N/A ulong_t nm_rec_size; /* Tape I/O record size */
2N/A ulong_t nm_rec_num; /* Current record num */
2N/A u_longlong_t nm_mov_pos; /* Current data stream pos */
2N/A u_longlong_t nm_window_offset; /* Valid data window begin */
2N/A u_longlong_t nm_window_length; /* Valid data window length */
2N/A int nm_sock; /* Data conn socket */
2N/A
2N/A /* Filled in V3 and V4 only */
2N/A int nm_listen_sock; /* Data conn listen socket */
2N/A ndmp_ad_type_t nm_addr_type; /* Current address type */
2N/A char *nm_tcp_addr; /* Only if addr_type is tcp */
2N/A} ndmp_mover_t;
2N/A
2N/Atypedef struct ndmp_dt_name {
2N/A char *nn_name;
2N/A char *nn_dest;
2N/A} ndmp_dt_name_t;
2N/A
2N/A/* NDMP name/value pair structure */
2N/Atypedef struct ndmp_dt_pval {
2N/A char *np_name;
2N/A char *np_value;
2N/A} ndmp_dt_pval_t;
2N/A
2N/Atypedef struct ndmp_dt_name_v3 {
2N/A char *nn3_opath;
2N/A char *nn3_dpath;
2N/A u_longlong_t nn3_node;
2N/A u_longlong_t nn3_fh_info;
2N/A} ndmp_dt_name_v3_t;
2N/A
2N/Atypedef struct ndmp_dt_v3 {
2N/A int dv3_listen_sock;
2N/A u_longlong_t dv3_bytes_processed;
2N/A ndmp_dt_name_v3_t *dv3_nlist; /* V3 recover file list */
2N/A} ndmp_dt_v3_t;
2N/A
2N/A/* NDMP data structure */
2N/Atypedef struct ndmp_data {
2N/A ndmp_dt_operation_t nd_oper; /* Current operation */
2N/A ndmp_dt_state_t nd_state; /* Current state */
2N/A ndmp_dt_halt_reason_t nd_halt_reason; /* Current reason */
2N/A int nd_sock; /* Listen and data socket */
2N/A ndmp_ad_type_t nd_addr_type; /* Current address type */
2N/A char *nd_tcp_addr; /* Only if addr_type is tcp */
2N/A int nd_abort; /* Abort operation flag */
2N/A /* 0 = No, otherwise Yes */
2N/A u_longlong_t nd_read_offset; /* Data read seek offset */
2N/A u_longlong_t nd_read_length; /* Data read length */
2N/A u_longlong_t nd_total_size; /* Backup data size */
2N/A ulong_t nd_env_len; /* Environment length */
2N/A ndmp_dt_pval_t *nd_env; /* Environment from backup */
2N/A /* or recover request */
2N/A ulong_t nld_nlist_len; /* Recover file list length */
2N/A union {
2N/A /* Filled in V2 */
2N/A ndmp_dt_name_t *nld_nlist; /* Recover file list */
2N/A /* Filled in V3 */
2N/A ndmp_dt_v3_t nld_dt_v3; /* V3 data */
2N/A } nd_nlist;
2N/A} ndmp_data_t;
2N/A
2N/A/* NDMP session information */
2N/Atypedef struct ndmp_session_info {
2N/A int nsi_sid; /* Session id */
2N/A int nsi_pver; /* NDMP protocol version */
2N/A int nsi_auth; /* Authorized ? 0="no", else "yes" */
2N/A int nsi_eof; /* Connection EOF flag */
2N/A /* 0="no", else "yes" */
2N/A char *nsi_cl_addr; /* Client address */
2N/A ndmp_scsi_t nsi_scsi; /* Scsi device information */
2N/A ndmp_tape_t nsi_tape; /* Tape device information */
2N/A ndmp_mover_t nsi_mover; /* Mover information */
2N/A ndmp_data_t nsi_data; /* Data information */
2N/A} ndmp_session_info_t;
2N/A
2N/A/* Stats data */
2N/Atypedef struct ndmp_stat {
2N/A int ns_trun; /* Number of worker threads running */
2N/A int ns_twait; /* Number of blocked worker threads */
2N/A int ns_nbk; /* Number of backups operations running */
2N/A int ns_nrs; /* Number of restores operations running */
2N/A int ns_rfile; /* Number of files being read */
2N/A int ns_wfile; /* Number of files being written */
2N/A uint64_t ns_rdisk; /* Number of disk blocks being read */
2N/A uint64_t ns_wdisk; /* Number of disk blocks being written */
2N/A uint64_t ns_rtape; /* Number of tape blocks being read */
2N/A uint64_t ns_wtape; /* Number of tape blocks being written */
2N/A} ndmp_stat_t;
2N/A
2N/A/* Common encode/decode functions used by door clients/servers. */
2N/Atypedef struct ndmp_door_ctx {
2N/A char *ptr;
2N/A char *start_ptr;
2N/A char *end_ptr;
2N/A int status;
2N/A} ndmp_door_ctx_t;
2N/A
2N/A/* Status indicator for door call returns */
2N/Atypedef struct ndmp_door_err {
2N/A int door_err;
2N/A int door_extended_err;
2N/A} ndmp_door_err_t;
2N/A
2N/Aextern int ndmp_get_devinfo(ndmp_devinfo_t **, size_t *);
2N/Aextern void ndmp_get_devinfo_free(ndmp_devinfo_t **, size_t *);
2N/Aextern int ndmp_get_dbglevel(void);
2N/Aextern int ndmp_get_session_info(ndmp_session_info_t **, size_t *);
2N/Aextern void ndmp_get_session_info_free(ndmp_session_info_t **, size_t *);
2N/Aextern int ndmp_get_stats(ndmp_stat_t *);
2N/Aextern int ndmp_terminate_session(int);
2N/Aextern int ndmp_set_dbglevel(int);
2N/Aextern const char *ndmp_strerror(int);
2N/Aextern int ndmp_door_status(void);
2N/Aextern int ndmp_get_prop(char *, char **);
2N/Aextern int ndmp_set_prop(char *, char *);
2N/Aextern int ndmp_service_refresh(void);
2N/Aextern char *ndmp_base64_encode(char *);
2N/Aextern char *ndmp_base64_decode(char *);
2N/Aextern ndmp_door_ctx_t *ndmp_door_decode_start(char *, int);
2N/Aextern int ndmp_door_decode_finish(ndmp_door_ctx_t *);
2N/Aextern ndmp_door_ctx_t *ndmp_door_encode_start(char *, int);
2N/Aextern int ndmp_door_encode_finish(ndmp_door_ctx_t *, unsigned int *);
2N/Aextern int32_t ndmp_door_get_int32(ndmp_door_ctx_t *);
2N/Aextern uint32_t ndmp_door_get_uint32(ndmp_door_ctx_t *);
2N/Aextern char *ndmp_door_get_string(ndmp_door_ctx_t *);
2N/Aextern void ndmp_door_put_int32(ndmp_door_ctx_t *, int32_t);
2N/Aextern void ndmp_door_put_uint32(ndmp_door_ctx_t *, uint32_t);
2N/Aextern void ndmp_door_put_string(ndmp_door_ctx_t *, char *);
2N/Aextern void ndmp_door_free_string(char *);
2N/Aextern int64_t ndmp_door_get_int64(ndmp_door_ctx_t *);
2N/Aextern uint64_t ndmp_door_get_uint64(ndmp_door_ctx_t *);
2N/Aextern void ndmp_door_put_uint64(ndmp_door_ctx_t *, uint64_t);
2N/Aextern void ndmp_door_put_short(ndmp_door_ctx_t *, short);
2N/Aextern short ndmp_door_get_short(ndmp_door_ctx_t *);
2N/Aextern void ndmp_door_put_ushort(ndmp_door_ctx_t *, unsigned short);
2N/Aextern unsigned short ndmp_door_get_ushort(ndmp_door_ctx_t *);
2N/Aextern void ndmp_door_put_buf(ndmp_door_ctx_t *, unsigned char *, int);
2N/Aextern int ndmp_door_get_buf(ndmp_door_ctx_t *, unsigned char *, int);
2N/A
2N/Aextern int ndmp_include_zfs(ndmp_context_t *, const char *);
2N/Aextern int ndmp_iter_zfs(ndmp_context_t *, int (*)(nvlist_t *, void *), void *);
2N/Aextern uint_t ndmp_context_get_version(ndmp_context_t *);
2N/Aextern void ndmp_context_set_specific(ndmp_context_t *, void *);
2N/Aextern void *ndmp_context_get_specific(ndmp_context_t *);
2N/Avoid ndmp_log_dma(ndmp_context_t *, ndmp_log_dma_type_t, const char *, ...);
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _LIBNDMP_H */