1*2654012fSReza Sabdar /* 2*2654012fSReza Sabdar * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 3*2654012fSReza Sabdar * Use is subject to license terms. 4*2654012fSReza Sabdar */ 5*2654012fSReza Sabdar 6*2654012fSReza Sabdar /* 7*2654012fSReza Sabdar * BSD 3 Clause License 8*2654012fSReza Sabdar * 9*2654012fSReza Sabdar * Copyright (c) 2007, The Storage Networking Industry Association. 10*2654012fSReza Sabdar * 11*2654012fSReza Sabdar * Redistribution and use in source and binary forms, with or without 12*2654012fSReza Sabdar * modification, are permitted provided that the following conditions 13*2654012fSReza Sabdar * are met: 14*2654012fSReza Sabdar * - Redistributions of source code must retain the above copyright 15*2654012fSReza Sabdar * notice, this list of conditions and the following disclaimer. 16*2654012fSReza Sabdar * 17*2654012fSReza Sabdar * - Redistributions in binary form must reproduce the above copyright 18*2654012fSReza Sabdar * notice, this list of conditions and the following disclaimer in 19*2654012fSReza Sabdar * the documentation and/or other materials provided with the 20*2654012fSReza Sabdar * distribution. 21*2654012fSReza Sabdar * 22*2654012fSReza Sabdar * - Neither the name of The Storage Networking Industry Association (SNIA) 23*2654012fSReza Sabdar * nor the names of its contributors may be used to endorse or promote 24*2654012fSReza Sabdar * products derived from this software without specific prior written 25*2654012fSReza Sabdar * permission. 26*2654012fSReza Sabdar * 27*2654012fSReza Sabdar * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 28*2654012fSReza Sabdar * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29*2654012fSReza Sabdar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30*2654012fSReza Sabdar * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 31*2654012fSReza Sabdar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32*2654012fSReza Sabdar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33*2654012fSReza Sabdar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34*2654012fSReza Sabdar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35*2654012fSReza Sabdar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36*2654012fSReza Sabdar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37*2654012fSReza Sabdar * POSSIBILITY OF SUCH DAMAGE. 38*2654012fSReza Sabdar */ 39*2654012fSReza Sabdar #ifndef _TLM_H_ 40*2654012fSReza Sabdar #define _TLM_H_ 41*2654012fSReza Sabdar 42*2654012fSReza Sabdar #include <sys/types.h> 43*2654012fSReza Sabdar #include <synch.h> 44*2654012fSReza Sabdar #include <limits.h> 45*2654012fSReza Sabdar #include <cstack.h> 46*2654012fSReza Sabdar #include <sys/acl.h> 47*2654012fSReza Sabdar #include <stdio.h> 48*2654012fSReza Sabdar #include <errno.h> 49*2654012fSReza Sabdar #include <fcntl.h> 50*2654012fSReza Sabdar #include <strings.h> 51*2654012fSReza Sabdar #include <sys/stat.h> 52*2654012fSReza Sabdar #include <time.h> 53*2654012fSReza Sabdar #include <sys/queue.h> 54*2654012fSReza Sabdar 55*2654012fSReza Sabdar #define IS_SET(f, m) (((f) & (m)) != 0) 56*2654012fSReza Sabdar 57*2654012fSReza Sabdar #define TLM_MAX_BACKUP_JOB_NAME 32 /* max size of a job's name */ 58*2654012fSReza Sabdar #define TLM_TAPE_BUFFERS 10 /* number of rotating tape buffers */ 59*2654012fSReza Sabdar #define TLM_LINE_SIZE 128 /* size of text messages */ 60*2654012fSReza Sabdar 61*2654012fSReza Sabdar 62*2654012fSReza Sabdar #define TLM_BACKUP_RUN 0x00000001 63*2654012fSReza Sabdar #define TLM_RESTORE_RUN 0x00000002 64*2654012fSReza Sabdar #define TLM_STOP 0x00000009 /* graceful stop */ 65*2654012fSReza Sabdar #define TLM_ABORT 0x99999999 /* abandon the run */ 66*2654012fSReza Sabdar 67*2654012fSReza Sabdar #define TLM_EXTRA_SPACE 64 68*2654012fSReza Sabdar #define TLM_MAX_PATH_NAME (PATH_MAX + TLM_EXTRA_SPACE) 69*2654012fSReza Sabdar 70*2654012fSReza Sabdar #define ENTRYTYPELEN 14 71*2654012fSReza Sabdar #define PERMS 4 72*2654012fSReza Sabdar #define ID_STR_MAX 20 73*2654012fSReza Sabdar #define APPENDED_ID_MAX (ID_STR_MAX + 1) 74*2654012fSReza Sabdar #define ACL_ENTRY_SIZE (ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX) 75*2654012fSReza Sabdar #define TLM_MAX_ACL_TXT MAX_ACL_ENTRIES * ACL_ENTRY_SIZE 76*2654012fSReza Sabdar 77*2654012fSReza Sabdar 78*2654012fSReza Sabdar /* operation flags */ 79*2654012fSReza Sabdar #define TLM_OP_CHOOSE_ARCHIVE 0x00000001 /* look for archive bit */ 80*2654012fSReza Sabdar 81*2654012fSReza Sabdar /* 82*2654012fSReza Sabdar * Synchronization flags used when launching the TLM threads. 83*2654012fSReza Sabdar */ 84*2654012fSReza Sabdar #define TLM_TAPE_READER 0x00000001 85*2654012fSReza Sabdar #define TLM_TAPE_WRITER 0x00000002 86*2654012fSReza Sabdar #define TLM_SOCK_READER 0x00000004 87*2654012fSReza Sabdar #define TLM_SOCK_WRITER 0x00000008 88*2654012fSReza Sabdar #define TLM_BUF_READER 0x00000010 89*2654012fSReza Sabdar #define TLM_BUF_WRITER 0x00000020 90*2654012fSReza Sabdar #define TLM_TAR_READER 0x00000040 91*2654012fSReza Sabdar #define TLM_TAR_WRITER 0x00000080 92*2654012fSReza Sabdar 93*2654012fSReza Sabdar #define SCMD_READ_ELEMENT_STATUS 0xB8 94*2654012fSReza Sabdar 95*2654012fSReza Sabdar typedef int (*func_t)(); 96*2654012fSReza Sabdar 97*2654012fSReza Sabdar typedef struct fs_fhandle { 98*2654012fSReza Sabdar int fh_fid; 99*2654012fSReza Sabdar char *fh_fpath; 100*2654012fSReza Sabdar } fs_fhandle_t; 101*2654012fSReza Sabdar 102*2654012fSReza Sabdar typedef struct scsi_link { 103*2654012fSReza Sabdar struct scsi_link *sl_next; 104*2654012fSReza Sabdar struct scsi_link *sl_prev; 105*2654012fSReza Sabdar struct scsi_adapter *sl_sa; 106*2654012fSReza Sabdar unsigned int sl_sid; 107*2654012fSReza Sabdar unsigned int sl_lun; 108*2654012fSReza Sabdar unsigned int sl_requested_max_active; 109*2654012fSReza Sabdar unsigned int sl_granted_max_active; 110*2654012fSReza Sabdar unsigned int sl_n_active; 111*2654012fSReza Sabdar unsigned int sl_type; /* SCSI device type */ 112*2654012fSReza Sabdar } scsi_link_t; 113*2654012fSReza Sabdar 114*2654012fSReza Sabdar typedef struct scsi_adapter { 115*2654012fSReza Sabdar struct scsi_adapter *sa_next; 116*2654012fSReza Sabdar char sa_name[16]; 117*2654012fSReza Sabdar struct scsi_link sa_link_head; 118*2654012fSReza Sabdar } scsi_adapter_t; 119*2654012fSReza Sabdar 120*2654012fSReza Sabdar typedef struct sasd_drive { 121*2654012fSReza Sabdar char sd_name[256]; 122*2654012fSReza Sabdar char sd_vendor[8 + 1]; 123*2654012fSReza Sabdar char sd_id[16 + 1]; 124*2654012fSReza Sabdar char sd_rev[4 + 1]; 125*2654012fSReza Sabdar } sasd_drive_t; 126*2654012fSReza Sabdar 127*2654012fSReza Sabdar typedef struct scsi_sasd_drive { 128*2654012fSReza Sabdar sasd_drive_t ss_sd; 129*2654012fSReza Sabdar scsi_link_t ss_slink; 130*2654012fSReza Sabdar } scsi_sasd_drive_t; 131*2654012fSReza Sabdar 132*2654012fSReza Sabdar 133*2654012fSReza Sabdar #define DEFAULT_SLINK_MAX_XFER (64*1024) 134*2654012fSReza Sabdar 135*2654012fSReza Sabdar typedef struct tlm_info { 136*2654012fSReza Sabdar int ti_init_done; /* initialization done ? */ 137*2654012fSReza Sabdar int ti_library_count; /* number of libraries */ 138*2654012fSReza Sabdar struct tlm_library *ti_library; /* first in chain */ 139*2654012fSReza Sabdar struct tlm_chain_link *ti_job_stats; /* chain of job statistics */ 140*2654012fSReza Sabdar } tlm_info_t; 141*2654012fSReza Sabdar 142*2654012fSReza Sabdar typedef struct tlm_chain_link { 143*2654012fSReza Sabdar struct tlm_chain_link *tc_next; /* next blob of statistics */ 144*2654012fSReza Sabdar struct tlm_chain_link *tc_prev; /* previous blob in the chain */ 145*2654012fSReza Sabdar int tc_ref_count; /* number of routines */ 146*2654012fSReza Sabdar void *tc_data; /* the data blob */ 147*2654012fSReza Sabdar } tlm_chain_link_t; 148*2654012fSReza Sabdar 149*2654012fSReza Sabdar typedef struct tlm_robot { 150*2654012fSReza Sabdar struct tlm_robot *tr_next; 151*2654012fSReza Sabdar struct tlm_library *tr_library; 152*2654012fSReza Sabdar int tr_number; 153*2654012fSReza Sabdar } tlm_robot_t; 154*2654012fSReza Sabdar 155*2654012fSReza Sabdar typedef struct tlm_drive { 156*2654012fSReza Sabdar struct tlm_drive *td_next; 157*2654012fSReza Sabdar struct tlm_library *td_library; 158*2654012fSReza Sabdar char td_job_name[TLM_MAX_BACKUP_JOB_NAME]; 159*2654012fSReza Sabdar int td_number; /* number of this tape drive */ 160*2654012fSReza Sabdar int td_element; /* the library's number for the drive */ 161*2654012fSReza Sabdar struct scsi_link *td_slink; /* because the drive may be connected */ 162*2654012fSReza Sabdar /* to a different SCSI card than the */ 163*2654012fSReza Sabdar /* library */ 164*2654012fSReza Sabdar short td_scsi_id; 165*2654012fSReza Sabdar short td_lun; 166*2654012fSReza Sabdar short td_volume_number; /* for current job */ 167*2654012fSReza Sabdar /* an index into the tape set */ 168*2654012fSReza Sabdar int td_fd; /* I/O file descriptor */ 169*2654012fSReza Sabdar int td_errno; /* system error number */ 170*2654012fSReza Sabdar long td_exists : 1; 171*2654012fSReza Sabdar 172*2654012fSReza Sabdar } tlm_drive_t; 173*2654012fSReza Sabdar 174*2654012fSReza Sabdar typedef struct tlm_slot { 175*2654012fSReza Sabdar struct tlm_slot *ts_next; 176*2654012fSReza Sabdar struct tlm_library *ts_library; 177*2654012fSReza Sabdar int ts_number; /* number of this slot */ 178*2654012fSReza Sabdar int ts_element; 179*2654012fSReza Sabdar short ts_use_count; /* number of times used since loaded */ 180*2654012fSReza Sabdar long ts_status_full : 1; 181*2654012fSReza Sabdar } tlm_slot_t; 182*2654012fSReza Sabdar 183*2654012fSReza Sabdar typedef struct tlm_library { 184*2654012fSReza Sabdar struct tlm_library *tl_next; 185*2654012fSReza Sabdar int tl_number; /* number of this tape library */ 186*2654012fSReza Sabdar long tl_capability_robot : 1, 187*2654012fSReza Sabdar tl_capability_door : 1, 188*2654012fSReza Sabdar tl_capability_lock : 1, 189*2654012fSReza Sabdar tl_capability_slots : 1, 190*2654012fSReza Sabdar tl_capability_export : 1, 191*2654012fSReza Sabdar tl_capability_drives : 1, 192*2654012fSReza Sabdar tl_capability_barcodes : 1, 193*2654012fSReza Sabdar tl_ghost_drives : 1; 194*2654012fSReza Sabdar /* 195*2654012fSReza Sabdar * "ghost_drives" is used to make sure that 196*2654012fSReza Sabdar * all drives claimed by the library really 197*2654012fSReza Sabdar * exist ... libraries have been known to lie. 198*2654012fSReza Sabdar */ 199*2654012fSReza Sabdar struct scsi_link *tl_slink; 200*2654012fSReza Sabdar 201*2654012fSReza Sabdar int tl_robot_count; 202*2654012fSReza Sabdar tlm_robot_t *tl_robot; 203*2654012fSReza Sabdar int tl_drive_count; 204*2654012fSReza Sabdar tlm_drive_t *tl_drive; 205*2654012fSReza Sabdar int tl_slot_count; 206*2654012fSReza Sabdar tlm_slot_t *tl_slot; 207*2654012fSReza Sabdar } tlm_library_t; 208*2654012fSReza Sabdar 209*2654012fSReza Sabdar #define TLM_NO_ERRORS 0x00000000 210*2654012fSReza Sabdar #define TLM_ERROR_BUSY 0x00000001 211*2654012fSReza Sabdar #define TLM_ERROR_INTERNAL 0x00000002 212*2654012fSReza Sabdar #define TLM_ERROR_NO_ROBOTS 0x00000003 213*2654012fSReza Sabdar #define TLM_TIMEOUT 0x00000004 214*2654012fSReza Sabdar #define TLM_ERROR_RANGE 0x00000005 215*2654012fSReza Sabdar #define TLM_EMPTY 0x00000006 216*2654012fSReza Sabdar #define TLM_DRIVE_NOT_ASSIGNED 0x00000007 217*2654012fSReza Sabdar #define TLM_NO_TAPE_NAME 0x00000008 218*2654012fSReza Sabdar #define TLM_NO_BACKUP_DIR 0x00000009 219*2654012fSReza Sabdar #define TLM_NO_BACKUP_HARDWARE 0x0000000a 220*2654012fSReza Sabdar #define TLM_NO_SOURCE_FILE 0x0000000b 221*2654012fSReza Sabdar #define TLM_NO_FREE_TAPES 0x0000000c 222*2654012fSReza Sabdar #define TLM_EOT 0x0000000d 223*2654012fSReza Sabdar #define TLM_SERIAL_NOT_FOUND 0x0000000e 224*2654012fSReza Sabdar #define TLM_SMALL_READ 0x0000000f 225*2654012fSReza Sabdar #define TLM_NO_RESTORE_FILE 0x00000010 226*2654012fSReza Sabdar #define TLM_EOF 0x00000011 227*2654012fSReza Sabdar #define TLM_NO_DIRECTORY 0x00000012 228*2654012fSReza Sabdar #define TLM_NO_MEMORY 0x00000013 229*2654012fSReza Sabdar #define TLM_WRITE_ERROR 0x00000014 230*2654012fSReza Sabdar #define TLM_NO_SCRATCH_SPACE 0x00000015 231*2654012fSReza Sabdar #define TLM_INVALID 0x00000016 232*2654012fSReza Sabdar #define TLM_MOVE 0x00000017 233*2654012fSReza Sabdar #define TLM_SKIP 0x00000018 234*2654012fSReza Sabdar #define TLM_OPEN_ERR 0x00000019 235*2654012fSReza Sabdar 236*2654012fSReza Sabdar 237*2654012fSReza Sabdar #define TLM_MAX_TAPE_DRIVES 16 238*2654012fSReza Sabdar #define TLM_NAME_SIZE 100 239*2654012fSReza Sabdar #define TLM_MAX_TAR_IMAGE 017777777770 240*2654012fSReza Sabdar 241*2654012fSReza Sabdar #define TLM_VOLNAME_MAX_LENGTH 255 242*2654012fSReza Sabdar #define NAME_MAX 255 243*2654012fSReza Sabdar 244*2654012fSReza Sabdar #define TLM_MAGIC "ustar " 245*2654012fSReza Sabdar #define TLM_SNAPSHOT_PREFIX ".zfs" 246*2654012fSReza Sabdar #define TLM_SNAPSHOT_DIR ".zfs/snapshot" 247*2654012fSReza Sabdar 248*2654012fSReza Sabdar #define RECORDSIZE 512 249*2654012fSReza Sabdar #define NAMSIZ 100 250*2654012fSReza Sabdar #define TUNMLEN 32 251*2654012fSReza Sabdar #define TGNMLEN 32 252*2654012fSReza Sabdar 253*2654012fSReza Sabdar typedef struct tlm_tar_hdr { 254*2654012fSReza Sabdar char th_name[TLM_NAME_SIZE]; 255*2654012fSReza Sabdar char th_mode[8]; 256*2654012fSReza Sabdar char th_uid[8]; 257*2654012fSReza Sabdar char th_gid[8]; 258*2654012fSReza Sabdar char th_size[12]; 259*2654012fSReza Sabdar char th_mtime[12]; 260*2654012fSReza Sabdar char th_chksum[8]; 261*2654012fSReza Sabdar char th_linkflag; 262*2654012fSReza Sabdar char th_linkname[TLM_NAME_SIZE]; 263*2654012fSReza Sabdar char th_magic[8]; 264*2654012fSReza Sabdar char th_uname[TUNMLEN]; 265*2654012fSReza Sabdar char th_gname[TGNMLEN]; 266*2654012fSReza Sabdar union { 267*2654012fSReza Sabdar struct { 268*2654012fSReza Sabdar char th_devmajor[8]; 269*2654012fSReza Sabdar char th_devminor[8]; 270*2654012fSReza Sabdar } th_dev; 271*2654012fSReza Sabdar char th_hlink_ino[12]; 272*2654012fSReza Sabdar } th_shared; 273*2654012fSReza Sabdar } tlm_tar_hdr_t; 274*2654012fSReza Sabdar 275*2654012fSReza Sabdar 276*2654012fSReza Sabdar 277*2654012fSReza Sabdar /* 278*2654012fSReza Sabdar * The linkflag defines the type of file 279*2654012fSReza Sabdar */ 280*2654012fSReza Sabdar #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */ 281*2654012fSReza Sabdar #define LF_NORMAL '0' /* Normal disk file */ 282*2654012fSReza Sabdar #define LF_LINK '1' /* Link to previously dumped file */ 283*2654012fSReza Sabdar #define LF_SYMLINK '2' /* Symbolic link */ 284*2654012fSReza Sabdar #define LF_CHR '3' /* Character special file */ 285*2654012fSReza Sabdar #define LF_BLK '4' /* Block special file */ 286*2654012fSReza Sabdar #define LF_DIR '5' /* Directory */ 287*2654012fSReza Sabdar #define LF_FIFO '6' /* FIFO special file */ 288*2654012fSReza Sabdar #define LF_CONTIG '7' /* Contiguous file */ 289*2654012fSReza Sabdar /* Further link types may be defined later. */ 290*2654012fSReza Sabdar 291*2654012fSReza Sabdar #define LF_DUMPDIR 'D' 292*2654012fSReza Sabdar /* 293*2654012fSReza Sabdar * This is a dir entry that contains 294*2654012fSReza Sabdar * the names of files that were in 295*2654012fSReza Sabdar * the dir at the time the dump 296*2654012fSReza Sabdar * was made 297*2654012fSReza Sabdar */ 298*2654012fSReza Sabdar #define LF_HUMONGUS 'H' 299*2654012fSReza Sabdar /* 300*2654012fSReza Sabdar * Identifies the NEXT file on the tape 301*2654012fSReza Sabdar * as a HUGE file 302*2654012fSReza Sabdar */ 303*2654012fSReza Sabdar #define LF_LONGLINK 'K' 304*2654012fSReza Sabdar /* 305*2654012fSReza Sabdar * Identifies the NEXT file on the tape 306*2654012fSReza Sabdar * as having a long linkname 307*2654012fSReza Sabdar */ 308*2654012fSReza Sabdar #define LF_LONGNAME 'L' 309*2654012fSReza Sabdar /* 310*2654012fSReza Sabdar * Identifies the NEXT file on the tape 311*2654012fSReza Sabdar * as having a long name. 312*2654012fSReza Sabdar */ 313*2654012fSReza Sabdar #define LF_MULTIVOL 'M' 314*2654012fSReza Sabdar /* 315*2654012fSReza Sabdar * This is the continuation 316*2654012fSReza Sabdar * of a file that began on another 317*2654012fSReza Sabdar * volume 318*2654012fSReza Sabdar */ 319*2654012fSReza Sabdar 320*2654012fSReza Sabdar #define LF_VOLHDR 'V' /* This file is a tape/volume header */ 321*2654012fSReza Sabdar /* Ignore it on extraction */ 322*2654012fSReza Sabdar 323*2654012fSReza Sabdar #define LF_ACL 'A' /* Access Control List */ 324*2654012fSReza Sabdar 325*2654012fSReza Sabdar #define LF_XATTR 'E' /* Extended attribute */ 326*2654012fSReza Sabdar 327*2654012fSReza Sabdar #define KILOBYTE 1024 328*2654012fSReza Sabdar 329*2654012fSReza Sabdar 330*2654012fSReza Sabdar /* 331*2654012fSReza Sabdar * ACL support structure 332*2654012fSReza Sabdar */ 333*2654012fSReza Sabdar typedef struct sec_attr { 334*2654012fSReza Sabdar char attr_type; 335*2654012fSReza Sabdar char attr_len[7]; 336*2654012fSReza Sabdar char attr_info[TLM_MAX_ACL_TXT]; 337*2654012fSReza Sabdar } sec_attr_t; 338*2654012fSReza Sabdar 339*2654012fSReza Sabdar typedef struct tlm_acls { 340*2654012fSReza Sabdar int acl_checkpointed : 1, /* are checkpoints active ? */ 341*2654012fSReza Sabdar acl_clear_archive : 1, /* clear archive bit ? */ 342*2654012fSReza Sabdar acl_overwrite : 1, /* always overwrite ? */ 343*2654012fSReza Sabdar acl_update : 1, /* only update ? */ 344*2654012fSReza Sabdar acl_non_trivial : 1; /* real ACLs? */ 345*2654012fSReza Sabdar /* 346*2654012fSReza Sabdar * The following fields are here to allow 347*2654012fSReza Sabdar * the backup reader to open a file one time 348*2654012fSReza Sabdar * and keep the information for ACL, ATTRs, 349*2654012fSReza Sabdar * and reading the file. 350*2654012fSReza Sabdar */ 351*2654012fSReza Sabdar sec_attr_t acl_info; 352*2654012fSReza Sabdar 353*2654012fSReza Sabdar char acl_root_dir[TLM_VOLNAME_MAX_LENGTH]; /* name of root filesystem */ 354*2654012fSReza Sabdar fs_fhandle_t acl_dir_fh; /* parent dir's info */ 355*2654012fSReza Sabdar fs_fhandle_t acl_fil_fh; /* file's info */ 356*2654012fSReza Sabdar struct stat64 acl_attr; /* file system attributes */ 357*2654012fSReza Sabdar } tlm_acls_t; 358*2654012fSReza Sabdar 359*2654012fSReza Sabdar 360*2654012fSReza Sabdar /* 361*2654012fSReza Sabdar * Tape manager's data archiving ops vector 362*2654012fSReza Sabdar * 363*2654012fSReza Sabdar * This vector represents the granular operations for 364*2654012fSReza Sabdar * performing backup/restore. Each backend should provide 365*2654012fSReza Sabdar * such a vector interface in order to be invoked by NDMP 366*2654012fSReza Sabdar * server. 367*2654012fSReza Sabdar * The reserved callbacks are kept for different backup 368*2654012fSReza Sabdar * types which are volume-based rather than file-based 369*2654012fSReza Sabdar * e.g. zfs send. 370*2654012fSReza Sabdar */ 371*2654012fSReza Sabdar typedef struct tm_ops { 372*2654012fSReza Sabdar char *tm_name; 373*2654012fSReza Sabdar int (*tm_putfile)(); 374*2654012fSReza Sabdar int (*tm_putdir)(); 375*2654012fSReza Sabdar int (*tm_putvol)(); /* Reserved */ 376*2654012fSReza Sabdar int (*tm_getfile)(); 377*2654012fSReza Sabdar int (*tm_getdir)(); 378*2654012fSReza Sabdar int (*tm_getvol)(); /* Reserved */ 379*2654012fSReza Sabdar } tm_ops_t; 380*2654012fSReza Sabdar 381*2654012fSReza Sabdar /* The checksum field is filled with this while the checksum is computed. */ 382*2654012fSReza Sabdar #define CHKBLANKS " " /* 8 blanks, no null */ 383*2654012fSReza Sabdar 384*2654012fSReza Sabdar #define LONGNAME_PREFIX "././_LoNg_NaMe_" 385*2654012fSReza Sabdar extern void ndmp_log(ulong_t, char *, char *, ...); 386*2654012fSReza Sabdar char ndmp_log_info[256]; 387*2654012fSReza Sabdar #define NDMP_LOG(p, ...) { \ 388*2654012fSReza Sabdar (void) snprintf(ndmp_log_info, \ 389*2654012fSReza Sabdar sizeof (ndmp_log_info), \ 390*2654012fSReza Sabdar "[%d][%s:%d]", \ 391*2654012fSReza Sabdar (int)pthread_self(), __func__, __LINE__); \ 392*2654012fSReza Sabdar ndmp_log(p, ndmp_log_info, __VA_ARGS__); \ 393*2654012fSReza Sabdar } 394*2654012fSReza Sabdar extern void *ndmp_malloc(size_t size); 395*2654012fSReza Sabdar 396*2654012fSReza Sabdar /* 397*2654012fSReza Sabdar * ZFS metadata plug-in module structures 398*2654012fSReza Sabdar */ 399*2654012fSReza Sabdar #define ZFS_MAX_PROPS 100 400*2654012fSReza Sabdar #define ZFS_META_MAGIC "ZFSMETA" 401*2654012fSReza Sabdar 402*2654012fSReza Sabdar typedef struct ndmp_metadata_property { 403*2654012fSReza Sabdar char mp_name[NAME_MAX]; 404*2654012fSReza Sabdar char mp_value[NAME_MAX]; 405*2654012fSReza Sabdar char mp_source[NAME_MAX]; 406*2654012fSReza Sabdar } ndmp_metadata_property_t; 407*2654012fSReza Sabdar 408*2654012fSReza Sabdar typedef struct ndmp_metadata_header { 409*2654012fSReza Sabdar char nh_plname[100]; 410*2654012fSReza Sabdar uint_t nh_plversion; 411*2654012fSReza Sabdar char nh_magic[10]; 412*2654012fSReza Sabdar void *nh_handle; 413*2654012fSReza Sabdar int nh_count; 414*2654012fSReza Sabdar char nh_dataset[NAME_MAX]; 415*2654012fSReza Sabdar ndmp_metadata_property_t nh_property[1]; 416*2654012fSReza Sabdar } ndmp_metadata_header_t; 417*2654012fSReza Sabdar 418*2654012fSReza Sabdar /* 419*2654012fSReza Sabdar * Node in struct hardlink_q 420*2654012fSReza Sabdar * 421*2654012fSReza Sabdar * inode: the inode of the hardlink 422*2654012fSReza Sabdar * path: the name of the hardlink, used during restore 423*2654012fSReza Sabdar * offset: tape offset of the data records for the hardlink, used during backup 424*2654012fSReza Sabdar * is_tmp: indicate whether the file was created temporarily for restoring 425*2654012fSReza Sabdar * other links during a non-DAR partial restore 426*2654012fSReza Sabdar */ 427*2654012fSReza Sabdar struct hardlink_node { 428*2654012fSReza Sabdar unsigned long inode; 429*2654012fSReza Sabdar char *path; 430*2654012fSReza Sabdar unsigned long long offset; 431*2654012fSReza Sabdar int is_tmp; 432*2654012fSReza Sabdar SLIST_ENTRY(hardlink_node) next_hardlink; 433*2654012fSReza Sabdar }; 434*2654012fSReza Sabdar 435*2654012fSReza Sabdar /* 436*2654012fSReza Sabdar * Hardlinks that have been backed up or restored. 437*2654012fSReza Sabdar * 438*2654012fSReza Sabdar * During backup, each node represents a file whose 439*2654012fSReza Sabdar * (1) inode has multiple links 440*2654012fSReza Sabdar * (2) data has been backed up 441*2654012fSReza Sabdar * 442*2654012fSReza Sabdar * When we run into a file with multiple links during backup, 443*2654012fSReza Sabdar * we first check the list to see whether a file with the same inode 444*2654012fSReza Sabdar * has been backed up. If yes, we backup an empty record, while 445*2654012fSReza Sabdar * making the file history of this file contain the data offset 446*2654012fSReza Sabdar * of the offset of the file that has been backed up. If no, 447*2654012fSReza Sabdar * we backup this file, and add an entry to the list. 448*2654012fSReza Sabdar * 449*2654012fSReza Sabdar * During restore, each node represents an LF_LINK type record whose 450*2654012fSReza Sabdar * data has been restored (v.s. a hard link has been created). 451*2654012fSReza Sabdar * 452*2654012fSReza Sabdar * During restore, when we run into a record of LF_LINK type, we 453*2654012fSReza Sabdar * first check the queue to see whether a file with the same inode 454*2654012fSReza Sabdar * has been restored. If yes, we create a hardlink to it. 455*2654012fSReza Sabdar * If no, we restore the data, and add an entry to the list. 456*2654012fSReza Sabdar */ 457*2654012fSReza Sabdar struct hardlink_q { 458*2654012fSReza Sabdar struct hardlink_node *slh_first; 459*2654012fSReza Sabdar }; 460*2654012fSReza Sabdar 461*2654012fSReza Sabdar /* Utility functions from handling hardlink */ 462*2654012fSReza Sabdar extern struct hardlink_q *hardlink_q_init(); 463*2654012fSReza Sabdar extern void hardlink_q_cleanup(struct hardlink_q *qhead); 464*2654012fSReza Sabdar extern int hardlink_q_get(struct hardlink_q *qhead, unsigned long inode, 465*2654012fSReza Sabdar unsigned long long *offset, char **path); 466*2654012fSReza Sabdar extern int hardlink_q_add(struct hardlink_q *qhead, unsigned long inode, 467*2654012fSReza Sabdar unsigned long long offset, char *path, int is_tmp); 468*2654012fSReza Sabdar 469*2654012fSReza Sabdar #endif /* !_TLM_H_ */ 470