ndmpd.h revision 416eec611c764c2e9dc8dc28133302a7fc551fac
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 2007, The Storage Networking Industry Association. */
/* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
#ifndef _NDMPD_H
#define _NDMPD_H
#include <libzfs.h>
#include <ndmpd_door.h>
#include <libndmp.h>
#include "ndmpd_common.h"
#include "tlm_buffers.h"
#include <dirent.h>
#include "ndmpd_prop.h"
#include "traverse.h"
#include <pthread.h>
#include <libndmp.h>
#include <atomic.h>
#define SCSI_MAX_NAME 32
#define MD5_CHALLENGE_SIZE 64
#define MD5_PASS_LIMIT 32
/* Test unit ready */
#define TUR_WAIT 3000000
#define TUR_MAX_TRY 3
/* File handler classes */
#define HC_CLIENT 1
#define HC_MOVER 2
#define HC_MODULE 4
#define HC_ALL 0xffffffff
#define IN_ADDR(x) \
(*(struct in_addr *)&x)
typedef void *(*funct_t)(void *); /* function pointer */
#define HOSTNAMELEN 256
#define VENDOR_NAME "Sun Microsystems"
#define PRODUCT_NAME "Solaris 5.11"
/*
* Calculate array length based on its size and size of
* its elements.
*/
#define ARRAY_LEN(a, t) (sizeof (a) / sizeof (t))
/*
* Default maximum permitted sequence number for the token-based backup.
*/
#define NDMP_MAX_TOKSEQ 9
/*
* Hard-limit for the sequence number in the token-based backup.
* It's one less than the ASCII value of 'A'. The 'A' letter
* can be used as level in the lbr-type backups.
*/
/*
* Soft-limit for the sequence number in the token-based backup.
*/
/*
* Root inode number of dump format in V2.
*/
#define ROOT_INODE 2
/*
* NDMP backup image signature.
*/
#define NDMPUTF8MAGIC "NDMPUTF8MAGIC"
/*
* Supported BU types
*/
#define NDMP_DUMP_TYPE "dump"
#define NDMP_TAR_TYPE "tar"
/* All 1's binary maximum mover window */
#define MAX_WINDOW_SIZE 0xffffffffffffffffULL
{ \
env++; \
}
#define NDMP_CL_ADDR_LEN 24
#define NDMP_TCP_ADDR_SIZE 32
#define NDMP_TAPE_DEV_NAME 256
typedef struct {
char *bk_path;
int bk_llevel; /* last backup level */
int bk_clevel; /* current backup level */
int bk_map;
int bk_dirino;
char *bk_dmpnm;
char **bk_exl; /* exlude list */
char **bk_inc; /* include list */
typedef struct {
char *rs_path;
char *rs_bkpath;
int *rs_restored;
int rs_bm;
int rs_lastidx;
/*
* Tar format archiving ops table
*/
extern tm_ops_t tm_tar_ops;
/*
* IS_LBR_BKTYPE shows if the backup type is one of these
* 'F' of 'f': 'Full' backup type.
* 'A' of 'a': 'Archive' backup type.
* 'I' of 'i': 'Incremental' backup type.
* 'D' of 'd': 'Differntial' backup type.
*/
/*
* NLP flags.
*/
#define NLPF_CHKPNTED_PATH (1 << 0)
/*
* Macros on NLP flags.
*/
/*
* NDMP statistics
*/
(uint64_t)d))
#define NS_UPD(s, t) { \
}
#define NLP_READY 1
typedef struct ndmp_lbr_params {
struct ndmpd_session *nlp_session;
int nlp_flags;
#define nlp_tokseq nlp_clevel
#define nlp_tokdate nlp_ldate
struct {
/*
* nw: shows the number of threads waiting for a request
* to be processed.
* rv: if error occurred when processing a request.
*/
int ev_nw;
int ev_rv;
} nlp_event;
int nlp_flag;
typedef struct mem_ndmp_name_v3 {
char *nm3_opath;
char *nm3_dpath;
char *nm3_newnm;
typedef struct ndmpd_file_handler {
int fh_fd;
void *fh_cookie;
struct ndmpd_file_handler *fh_next;
typedef struct ndmpd_session_scsi_desc {
int sd_is_open;
int sd_devid;
int sd_sid;
int sd_lun;
char sd_adapter_name[SCSI_MAX_NAME];
typedef struct ndmpd_session_tape_desc {
int td_fd; /* tape device file descriptor */
int td_sid;
int td_lun;
char td_adapter_name[SCSI_MAX_NAME];
td_io_err:1,
td_write:1;
typedef struct ndmpd_session_mover_desc {
int md_listen_sock; /* data conn listen socket */
int md_sock; /* data conn socket */
char *md_buf; /* data buffer */
/*
* V2 fields.
*/
/*
* V3 fields.
*/
/*
* V4 fields.
*/
typedef struct ndmpd_session_data_module {
void *dm_module_cookie; /* sent as abort_func param */
typedef struct ndmpd_session_data_desc {
/*
* Common fields.
*/
int dd_sock; /* listen and data socket */
/*
* V2 fields.
*/
/*
* V3 fields.
*/
int dd_listen_sock; /* socket for listening for remote */
/* mover connections */
/*
* V4 fields.
*/
typedef struct ndmpd_session_file_history {
char *fh_path_name_buf;
char *fh_dir_name_buf;
typedef struct ndmpd_session_file_history_v3 {
char *fh_file_name_buf;
char *fh_dir_name_buf;
typedef struct ndmpd_session {
int ns_nref;
/*
* NDMP V3
* Tape, SCSI, mover, data and file handlers will
* be shared between V2 and V3.
*/
/*
* NDMP V4 related data
*/
/* handling of hardlink, hardlink queue head */
struct hardlink_q *hardlink_q;
/*
* NDMP request handler functions.
*/
/* Config */
/* Scsi */
/* Tape */
/* Data */
/* Connect */
/* Mover */
/*
*/
/*
* NDMP V3
*/
/*
* NDMP V4
*/
#ifndef NO_NDMP_API_LOG_PROTOTYPES
#endif /* NO_NDMP_API_LOG_PROTOTYPES */
typedef void ndmpd_func_t(ndmp_connection_t *, void *);
/*
* pthread call arg parameters
*/
typedef struct {
int nw_sock;
long nw_ipaddr;
typedef struct {
char *br_jname;
typedef struct {
typedef struct {
char *bs_jname;
char *bs_path;
/*
* Variables from ndmpd_comm.c
*/
extern int ndmp_ver;
extern int ndmp_full_restore_path;
extern int ndmp_dar_support;
extern int ndmp_port;
extern ndmp_stat_t ndstat;
extern void ndmpd_main(void);
extern void connection_handler(ndmp_connection_t *);
int result);
/* Variables from ndmpd_main.c */
extern libzfs_handle_t *zlibh;
/*
* Utility from ndmpd_connect.c.
*/
extern int ndmp_connect_list_add(ndmp_connection_t *, int *);
extern int ndmp_connect_list_del(ndmp_connection_t *);
extern int ndmpd_connect_kill_id(int);
extern void ndmp_connect_list_get(ndmp_door_ctx_t *);
extern void ndmpd_get_devs(ndmp_door_ctx_t *);
/*
* Utility functions form ndmpd_data.c.
*/
extern void ndmpd_data_cleanup(ndmpd_session_t *);
extern int ndmpd_data_init(ndmpd_session_t *);
extern char *ndmp_data_get_mover_mode(ndmpd_session_t *);
/*
* Utility functions from ndmpd_mover.c.
*/
extern int ndmpd_mover_init(ndmpd_session_t *);
extern void ndmpd_mover_cleanup(ndmpd_session_t *);
extern void ndmpd_mover_error(ndmpd_session_t *,
extern int ndmpd_mover_seek(ndmpd_session_t *,
extern int ndmpd_local_write(ndmpd_session_t *,
char *,
ulong_t);
extern int ndmpd_remote_write(ndmpd_session_t *,
char *,
ulong_t);
extern int ndmpd_local_read(ndmpd_session_t *,
char *,
ulong_t);
extern int ndmpd_remote_read(ndmpd_session_t *,
char *,
ulong_t);
extern void ndmpd_mover_shut_down(ndmpd_session_t *);
extern void ndmpd_mover_error(ndmpd_session_t *,
extern int ndmpd_local_write_v3(ndmpd_session_t *,
char *,
ulong_t);
extern int ndmpd_local_read_v3(ndmpd_session_t *,
char *,
ulong_t);
extern int ndmpd_remote_read_v3(ndmpd_session_t *,
char *,
ulong_t);
extern int ndmpd_mover_wait_v3(ndmpd_session_t *);
extern void ndmpd_write_eom(int);
/*
* Utility functions from ndmpd_file_history.c
*/
extern void ndmpd_file_history_init(ndmpd_session_t *);
extern void ndmpd_file_history_cleanup(ndmpd_session_t *,
extern int ndmpd_file_history_path(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *,
extern int ndmpd_file_history_dir(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *);
extern int ndmpd_file_history_node(lbr_fhlog_call_backs_t *,
char *,
char *,
struct stat64 *,
extern int
char *,
struct stat64 *,
extern int ndmpd_fhpath_v3_cb(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *,
extern int ndmpd_fhdir_v3_cb(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *);
extern int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *,
char *,
char *,
struct stat64 *,
extern int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *,
char *,
struct stat64 *,
extern int ndmp_send_recovery_stat_v3(ndmpd_module_params_t *,
int,
int);
/*
* Utility functions from ndmpd_dtime.c
*/
extern int ndmpd_put_dumptime(char *, int, time_t);
extern int ndmpd_get_dumptime(char *, int *, time_t *);
extern int ndmpd_append_dumptime(char *, char *, int, time_t);
/*
* Global variables from ndmpd_tar3.c
*/
extern char **ndmp_excl_list;
/*
* Global variables from ndmpd_util.c
*/
extern int ndmp_force_bk_dirs;
extern int ndmp_rbs;
extern int ndmp_sbs;
extern boolean_t ndmp_dump_path_node;
extern boolean_t ndmp_tar_path_node;
extern boolean_t ndmp_ignore_ctime;
extern boolean_t ndmp_include_lmtime;
/*
* Utility functions from ndmpd_util.c.
*/
extern int ndmpd_select(ndmpd_session_t *,
ulong_t);
ndmp_pval *,
ulong_t);
extern void ndmpd_free_env(ndmpd_session_t *);
ndmp_name *,
ulong_t);
extern void ndmpd_free_nlist(ndmpd_session_t *);
extern int ndmpd_add_file_handler(ndmpd_session_t *,
void *,
int,
extern int ndmpd_remove_file_handler(ndmpd_session_t *,
int);
extern void ndmp_send_reply(ndmp_connection_t *,
void *,
char *);
extern int ndmp_mtioctl(int, int, int);
extern void ndmp_set_socket_nodelay(int);
extern void ndmp_set_socket_snd_buf(int, int);
extern void ndmp_set_socket_rcv_buf(int, int);
extern long ndmp_buffer_get_size(ndmpd_session_t *);
extern int ndmp_lbr_init(ndmpd_session_t *);
extern void ndmp_lbr_cleanup(ndmpd_session_t *);
extern void nlp_ref_nw(ndmpd_session_t *);
extern void nlp_unref_nw(ndmpd_session_t *);
extern void nlp_wait_nw(ndmpd_session_t *);
extern void nlp_event_nw(ndmpd_session_t *);
extern int nlp_event_rv_get(ndmpd_session_t *);
extern void nlp_event_rv_set(ndmpd_session_t *, int);
extern void ndmp_execute_cdb(ndmpd_session_t *,
char *,
int,
int,
extern scsi_adapter_t *scsi_get_adapter(int);
extern boolean_t is_tape_unit_ready(char *, int);
extern int ndmp_open_list_add(ndmp_connection_t *, char *, int, int, int);
extern int ndmp_open_list_del(char *, int, int);
extern void ndmp_open_list_release(ndmp_connection_t *);
extern void ndmp_stop_buffer_worker(ndmpd_session_t *);
extern void ndmp_stop_reader_thread(ndmpd_session_t *);
extern void ndmp_stop_writer_thread(ndmpd_session_t *);
extern void ndmp_free_reader_writer_ipc(ndmpd_session_t *);
extern void ndmp_waitfor_op(ndmpd_session_t *);
extern char *ndmp_new_job_name(char *);
extern char *ndmpd_mk_temp(char *);
extern char *ndmpd_make_bk_dir_path(char *, char *);
extern boolean_t ndmp_is_chkpnt_root(char *);
extern char **ndmpd_make_exc_list(void);
extern void ndmp_sort_nlist_v3(ndmpd_session_t *);
extern int ndmp_get_bk_dir_ino(ndmp_lbr_params_t *);
extern int ndmp_write_utf8magic(tlm_cmd_t *);
extern int ndmp_tar_writer(ndmpd_session_t *,
tlm_commands_t *);
extern void ndmp_wait_for_reader(tlm_commands_t *);
ndmp_name_v3 *,
ulong_t);
extern void ndmpd_free_nlist_v3(ndmpd_session_t *);
extern char *ndmp_addr2str_v3(ndmp_addr_type);
extern int ndmp_get_cur_bk_time(ndmp_lbr_params_t *,
time_t *, char *);
extern char *ndmp_get_relative_path(char *, char *);
extern boolean_t ndmp_fhinode;
extern void ndmp_load_params(void);
extern void randomize(unsigned char *, int);
/*
* Utility functions from ndmpd_tar3.c.
*/
extern char *get_bk_path_v3(ndmpd_module_params_t *);
/*
* door init and fini function from ndmpd_door_serv.c
*/
extern int ndmp_door_init(void);
extern void ndmp_door_fini(void);
extern boolean_t ndmp_door_check(void);
extern int ndmp_get_max_tok_seq(void);
extern boolean_t get_debug_level(void);
typedef struct ndmp_chkpnt_vol {
char cv_vol_name[64];
unsigned int cv_count;
void *cv_next;
extern int get_zfsvolname(char *, int, char *);
extern int ndmp_start_check_point(char *, char *);
extern int ndmp_release_check_point(char *, char *);
extern void ndmpd_abort_marking_v2(ndmpd_session_t *);
extern ndmp_lbr_params_t *ndmp_get_nlp(void *);
extern int ndmp_backup_extract_params(ndmpd_session_t *,
extern int ndmp_restore_extract_params(ndmpd_session_t *,
extern int ndmp_tar_reader(ndmp_tar_reader_arg_t *);
extern int tape_open(char *, int);
extern void ndmp_session_ref(ndmpd_session_t *);
extern void ndmp_session_unref(ndmpd_session_t *);
void ndmpd_get_file_entry_type(int, ndmp_file_type *);
extern int tcp_accept(int, unsigned int *);
extern int tcp_get_peer(int, unsigned int *, int *);
extern char *gethostaddr(void);
extern int tlm_init(void);
extern int chkpnt_backup_successful(char *, char *);
extern int chkpnt_backup_prepare(char *, char *);
extern boolean_t fs_is_chkpntvol(char *);
extern boolean_t fs_is_chkpnt_enabled(char *);
extern boolean_t fs_is_rdonly(char *);
extern boolean_t fs_volexist(char *);
extern boolean_t fs_is_valid_logvol(char *);
extern boolean_t rootfs_dot_or_dotdot(char *);
extern int dp_readdir(DIR *, unsigned long *, char *,
int *, unsigned long *);
extern void scsi_find_sid_lun();
extern char *sasd_slink_name();
extern int scsi_dev_exists(char *, int, int);
extern int scsi_get_devtype(char *, int, int);
extern struct open_list *ndmp_open_list_find(char *, int, int);
extern int filecopy(char *, char *);
extern void ndmp_stop_local_reader();
extern void ndmp_stop_remote_reader();
extern char *trim_whitespace(char *);
extern int fs_readdir(struct fs_fhandle *, char *, long *,
char *, int *, struct fs_fhandle *, struct stat64 *);
time_t t);
extern int sasd_dev_count(void);
extern struct scsi_link *sasd_dev_slink(int);
extern struct sasd_drive *sasd_drive(int);
extern ndmp_plugin_t *ndmp_pl;
#endif /* _NDMPD_H */