12654012fSReza Sabdar /* 2*e461e790SRandall Ralphs * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 32654012fSReza Sabdar */ 42654012fSReza Sabdar 52654012fSReza Sabdar /* 62654012fSReza Sabdar * BSD 3 Clause License 72654012fSReza Sabdar * 82654012fSReza Sabdar * Copyright (c) 2007, The Storage Networking Industry Association. 92654012fSReza Sabdar * 102654012fSReza Sabdar * Redistribution and use in source and binary forms, with or without 112654012fSReza Sabdar * modification, are permitted provided that the following conditions 122654012fSReza Sabdar * are met: 132654012fSReza Sabdar * - Redistributions of source code must retain the above copyright 142654012fSReza Sabdar * notice, this list of conditions and the following disclaimer. 152654012fSReza Sabdar * 162654012fSReza Sabdar * - Redistributions in binary form must reproduce the above copyright 172654012fSReza Sabdar * notice, this list of conditions and the following disclaimer in 182654012fSReza Sabdar * the documentation and/or other materials provided with the 192654012fSReza Sabdar * distribution. 202654012fSReza Sabdar * 212654012fSReza Sabdar * - Neither the name of The Storage Networking Industry Association (SNIA) 222654012fSReza Sabdar * nor the names of its contributors may be used to endorse or promote 232654012fSReza Sabdar * products derived from this software without specific prior written 242654012fSReza Sabdar * permission. 252654012fSReza Sabdar * 262654012fSReza Sabdar * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 272654012fSReza Sabdar * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 282654012fSReza Sabdar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 292654012fSReza Sabdar * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 302654012fSReza Sabdar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 312654012fSReza Sabdar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 322654012fSReza Sabdar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 332654012fSReza Sabdar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 342654012fSReza Sabdar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 352654012fSReza Sabdar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 362654012fSReza Sabdar * POSSIBILITY OF SUCH DAMAGE. 372654012fSReza Sabdar */ 382654012fSReza Sabdar #ifndef _TLM_H_ 392654012fSReza Sabdar #define _TLM_H_ 402654012fSReza Sabdar 412654012fSReza Sabdar #include <sys/types.h> 422654012fSReza Sabdar #include <synch.h> 432654012fSReza Sabdar #include <limits.h> 442654012fSReza Sabdar #include <cstack.h> 452654012fSReza Sabdar #include <sys/acl.h> 462654012fSReza Sabdar #include <stdio.h> 472654012fSReza Sabdar #include <errno.h> 482654012fSReza Sabdar #include <fcntl.h> 492654012fSReza Sabdar #include <strings.h> 502654012fSReza Sabdar #include <sys/stat.h> 512654012fSReza Sabdar #include <time.h> 522654012fSReza Sabdar #include <sys/queue.h> 5342ed7838SReza Sabdar #include <sys/fs/zfs.h> 5442ed7838SReza Sabdar #include <libzfs.h> 552654012fSReza Sabdar 562654012fSReza Sabdar #define IS_SET(f, m) (((f) & (m)) != 0) 572654012fSReza Sabdar 582654012fSReza Sabdar #define TLM_MAX_BACKUP_JOB_NAME 32 /* max size of a job's name */ 592654012fSReza Sabdar #define TLM_TAPE_BUFFERS 10 /* number of rotating tape buffers */ 602654012fSReza Sabdar #define TLM_LINE_SIZE 128 /* size of text messages */ 612654012fSReza Sabdar 622654012fSReza Sabdar 632654012fSReza Sabdar #define TLM_BACKUP_RUN 0x00000001 642654012fSReza Sabdar #define TLM_RESTORE_RUN 0x00000002 652654012fSReza Sabdar #define TLM_STOP 0x00000009 /* graceful stop */ 662654012fSReza Sabdar #define TLM_ABORT 0x99999999 /* abandon the run */ 672654012fSReza Sabdar 682654012fSReza Sabdar #define TLM_EXTRA_SPACE 64 692654012fSReza Sabdar #define TLM_MAX_PATH_NAME (PATH_MAX + TLM_EXTRA_SPACE) 702654012fSReza Sabdar 712654012fSReza Sabdar #define ENTRYTYPELEN 14 722654012fSReza Sabdar #define PERMS 4 732654012fSReza Sabdar #define ID_STR_MAX 20 742654012fSReza Sabdar #define APPENDED_ID_MAX (ID_STR_MAX + 1) 752654012fSReza Sabdar #define ACL_ENTRY_SIZE (ENTRYTYPELEN + ID_STR_MAX + PERMS + APPENDED_ID_MAX) 762654012fSReza Sabdar #define TLM_MAX_ACL_TXT MAX_ACL_ENTRIES * ACL_ENTRY_SIZE 772654012fSReza Sabdar 782654012fSReza Sabdar 792654012fSReza Sabdar /* operation flags */ 802654012fSReza Sabdar #define TLM_OP_CHOOSE_ARCHIVE 0x00000001 /* look for archive bit */ 812654012fSReza Sabdar 822654012fSReza Sabdar /* 832654012fSReza Sabdar * Synchronization flags used when launching the TLM threads. 842654012fSReza Sabdar */ 852654012fSReza Sabdar #define TLM_TAPE_READER 0x00000001 862654012fSReza Sabdar #define TLM_TAPE_WRITER 0x00000002 872654012fSReza Sabdar #define TLM_SOCK_READER 0x00000004 882654012fSReza Sabdar #define TLM_SOCK_WRITER 0x00000008 892654012fSReza Sabdar #define TLM_BUF_READER 0x00000010 902654012fSReza Sabdar #define TLM_BUF_WRITER 0x00000020 912654012fSReza Sabdar #define TLM_TAR_READER 0x00000040 922654012fSReza Sabdar #define TLM_TAR_WRITER 0x00000080 932654012fSReza Sabdar 947bc22e45SReza Sabdar #define SCSI_SERIAL_PAGE 0x80 957bc22e45SReza Sabdar #define SCSI_DEVICE_IDENT_PAGE 0x83 962654012fSReza Sabdar #define SCMD_READ_ELEMENT_STATUS 0xB8 972654012fSReza Sabdar 98b6b15642SReza Sabdar #define OCTAL7CHAR 07777777 99b6b15642SReza Sabdar #define SYSATTR_RDONLY "SUNWattr_ro" 100b6b15642SReza Sabdar #define SYSATTR_RW "SUNWattr_rw" 101b6b15642SReza Sabdar 1022654012fSReza Sabdar typedef int (*func_t)(); 1032654012fSReza Sabdar 1047bc22e45SReza Sabdar typedef struct scsi_serial { 1057bc22e45SReza Sabdar int sr_flags; 1067bc22e45SReza Sabdar char sr_num[16]; 1077bc22e45SReza Sabdar } scsi_serial_t; 1087bc22e45SReza Sabdar 1092654012fSReza Sabdar typedef struct fs_fhandle { 1102654012fSReza Sabdar int fh_fid; 1112654012fSReza Sabdar char *fh_fpath; 1122654012fSReza Sabdar } fs_fhandle_t; 1132654012fSReza Sabdar 1142654012fSReza Sabdar typedef struct scsi_link { 1152654012fSReza Sabdar struct scsi_link *sl_next; 1162654012fSReza Sabdar struct scsi_link *sl_prev; 1172654012fSReza Sabdar struct scsi_adapter *sl_sa; 1182654012fSReza Sabdar unsigned int sl_sid; 1192654012fSReza Sabdar unsigned int sl_lun; 1202654012fSReza Sabdar unsigned int sl_requested_max_active; 1212654012fSReza Sabdar unsigned int sl_granted_max_active; 1222654012fSReza Sabdar unsigned int sl_n_active; 1232654012fSReza Sabdar unsigned int sl_type; /* SCSI device type */ 1242654012fSReza Sabdar } scsi_link_t; 1252654012fSReza Sabdar 1262654012fSReza Sabdar typedef struct scsi_adapter { 1272654012fSReza Sabdar struct scsi_adapter *sa_next; 1282654012fSReza Sabdar char sa_name[16]; 1292654012fSReza Sabdar struct scsi_link sa_link_head; 1302654012fSReza Sabdar } scsi_adapter_t; 1312654012fSReza Sabdar 1322654012fSReza Sabdar typedef struct sasd_drive { 1332654012fSReza Sabdar char sd_name[256]; 1342654012fSReza Sabdar char sd_vendor[8 + 1]; 1352654012fSReza Sabdar char sd_id[16 + 1]; 1362654012fSReza Sabdar char sd_rev[4 + 1]; 1377bc22e45SReza Sabdar char sd_serial[16 + 1]; 1387bc22e45SReza Sabdar char sd_wwn[32 + 1]; 1392654012fSReza Sabdar } sasd_drive_t; 1402654012fSReza Sabdar 1412654012fSReza Sabdar typedef struct scsi_sasd_drive { 1422654012fSReza Sabdar sasd_drive_t ss_sd; 1432654012fSReza Sabdar scsi_link_t ss_slink; 1442654012fSReza Sabdar } scsi_sasd_drive_t; 1452654012fSReza Sabdar 1462654012fSReza Sabdar 1472654012fSReza Sabdar #define DEFAULT_SLINK_MAX_XFER (64*1024) 1482654012fSReza Sabdar 1492654012fSReza Sabdar typedef struct tlm_info { 1502654012fSReza Sabdar int ti_init_done; /* initialization done ? */ 1512654012fSReza Sabdar int ti_library_count; /* number of libraries */ 1522654012fSReza Sabdar struct tlm_library *ti_library; /* first in chain */ 1532654012fSReza Sabdar struct tlm_chain_link *ti_job_stats; /* chain of job statistics */ 1542654012fSReza Sabdar } tlm_info_t; 1552654012fSReza Sabdar 1562654012fSReza Sabdar typedef struct tlm_chain_link { 1572654012fSReza Sabdar struct tlm_chain_link *tc_next; /* next blob of statistics */ 1582654012fSReza Sabdar struct tlm_chain_link *tc_prev; /* previous blob in the chain */ 1592654012fSReza Sabdar int tc_ref_count; /* number of routines */ 1602654012fSReza Sabdar void *tc_data; /* the data blob */ 1612654012fSReza Sabdar } tlm_chain_link_t; 1622654012fSReza Sabdar 1632654012fSReza Sabdar typedef struct tlm_robot { 1642654012fSReza Sabdar struct tlm_robot *tr_next; 1652654012fSReza Sabdar struct tlm_library *tr_library; 1662654012fSReza Sabdar int tr_number; 1672654012fSReza Sabdar } tlm_robot_t; 1682654012fSReza Sabdar 1692654012fSReza Sabdar typedef struct tlm_drive { 1702654012fSReza Sabdar struct tlm_drive *td_next; 1712654012fSReza Sabdar struct tlm_library *td_library; 1722654012fSReza Sabdar char td_job_name[TLM_MAX_BACKUP_JOB_NAME]; 1732654012fSReza Sabdar int td_number; /* number of this tape drive */ 1742654012fSReza Sabdar int td_element; /* the library's number for the drive */ 1752654012fSReza Sabdar struct scsi_link *td_slink; /* because the drive may be connected */ 1762654012fSReza Sabdar /* to a different SCSI card than the */ 1772654012fSReza Sabdar /* library */ 1782654012fSReza Sabdar short td_scsi_id; 1792654012fSReza Sabdar short td_lun; 1802654012fSReza Sabdar short td_volume_number; /* for current job */ 1812654012fSReza Sabdar /* an index into the tape set */ 1822654012fSReza Sabdar int td_fd; /* I/O file descriptor */ 1832654012fSReza Sabdar int td_errno; /* system error number */ 1842654012fSReza Sabdar long td_exists : 1; 1852654012fSReza Sabdar 1862654012fSReza Sabdar } tlm_drive_t; 1872654012fSReza Sabdar 1882654012fSReza Sabdar typedef struct tlm_slot { 1892654012fSReza Sabdar struct tlm_slot *ts_next; 1902654012fSReza Sabdar struct tlm_library *ts_library; 1912654012fSReza Sabdar int ts_number; /* number of this slot */ 1922654012fSReza Sabdar int ts_element; 1932654012fSReza Sabdar short ts_use_count; /* number of times used since loaded */ 1942654012fSReza Sabdar long ts_status_full : 1; 1952654012fSReza Sabdar } tlm_slot_t; 1962654012fSReza Sabdar 1972654012fSReza Sabdar typedef struct tlm_library { 1982654012fSReza Sabdar struct tlm_library *tl_next; 1992654012fSReza Sabdar int tl_number; /* number of this tape library */ 2002654012fSReza Sabdar long tl_capability_robot : 1, 2012654012fSReza Sabdar tl_capability_door : 1, 2022654012fSReza Sabdar tl_capability_lock : 1, 2032654012fSReza Sabdar tl_capability_slots : 1, 2042654012fSReza Sabdar tl_capability_export : 1, 2052654012fSReza Sabdar tl_capability_drives : 1, 2062654012fSReza Sabdar tl_capability_barcodes : 1, 2072654012fSReza Sabdar tl_ghost_drives : 1; 2082654012fSReza Sabdar /* 2092654012fSReza Sabdar * "ghost_drives" is used to make sure that 2102654012fSReza Sabdar * all drives claimed by the library really 2112654012fSReza Sabdar * exist ... libraries have been known to lie. 2122654012fSReza Sabdar */ 2132654012fSReza Sabdar struct scsi_link *tl_slink; 2142654012fSReza Sabdar 2152654012fSReza Sabdar int tl_robot_count; 2162654012fSReza Sabdar tlm_robot_t *tl_robot; 2172654012fSReza Sabdar int tl_drive_count; 2182654012fSReza Sabdar tlm_drive_t *tl_drive; 2192654012fSReza Sabdar int tl_slot_count; 2202654012fSReza Sabdar tlm_slot_t *tl_slot; 2212654012fSReza Sabdar } tlm_library_t; 2222654012fSReza Sabdar 2237bc22e45SReza Sabdar typedef struct { 2247bc22e45SReza Sabdar #ifdef _BIG_ENDIAN 2257bc22e45SReza Sabdar uint8_t di_peripheral_qual : 3, 2267bc22e45SReza Sabdar di_peripheral_dev_type : 5; 2277bc22e45SReza Sabdar uint8_t di_page_code; 2287bc22e45SReza Sabdar uint16_t di_page_length; 2297bc22e45SReza Sabdar #else 2307bc22e45SReza Sabdar uint8_t di_peripheral_dev_type : 5, 2317bc22e45SReza Sabdar di_peripheral_qual : 3; 2327bc22e45SReza Sabdar uint8_t di_page_code; 2337bc22e45SReza Sabdar uint16_t di_page_length; 2347bc22e45SReza Sabdar #endif 2357bc22e45SReza Sabdar } device_ident_header_t; 2367bc22e45SReza Sabdar 2377bc22e45SReza Sabdar typedef struct { 2387bc22e45SReza Sabdar #ifdef _BIG_ENDIAN 2397bc22e45SReza Sabdar uint8_t ni_proto_ident : 4, 2407bc22e45SReza Sabdar ni_code_set : 4; 2417bc22e45SReza Sabdar 2427bc22e45SReza Sabdar uint8_t ni_PIV : 1, 2437bc22e45SReza Sabdar : 1, 2447bc22e45SReza Sabdar ni_asso : 2, 2457bc22e45SReza Sabdar ni_ident_type : 4; 2467bc22e45SReza Sabdar 2477bc22e45SReza Sabdar uint8_t ni_reserved; 2487bc22e45SReza Sabdar uint8_t ni_ident_length; 2497bc22e45SReza Sabdar #else 2507bc22e45SReza Sabdar uint8_t ni_code_set : 4, 2517bc22e45SReza Sabdar ni_proto_ident : 4; 2527bc22e45SReza Sabdar 2537bc22e45SReza Sabdar uint8_t ni_ident_type : 4, 2547bc22e45SReza Sabdar ni_asso : 2, 2557bc22e45SReza Sabdar : 1, 2567bc22e45SReza Sabdar ni_PIV : 1; 2577bc22e45SReza Sabdar uint8_t ni_reserved; 2587bc22e45SReza Sabdar uint8_t ni_ident_length; 2597bc22e45SReza Sabdar #endif 2607bc22e45SReza Sabdar } name_ident_t; 2617bc22e45SReza Sabdar 2622654012fSReza Sabdar #define TLM_NO_ERRORS 0x00000000 2632654012fSReza Sabdar #define TLM_ERROR_BUSY 0x00000001 2642654012fSReza Sabdar #define TLM_ERROR_INTERNAL 0x00000002 2652654012fSReza Sabdar #define TLM_ERROR_NO_ROBOTS 0x00000003 2662654012fSReza Sabdar #define TLM_TIMEOUT 0x00000004 2672654012fSReza Sabdar #define TLM_ERROR_RANGE 0x00000005 2682654012fSReza Sabdar #define TLM_EMPTY 0x00000006 2692654012fSReza Sabdar #define TLM_DRIVE_NOT_ASSIGNED 0x00000007 2702654012fSReza Sabdar #define TLM_NO_TAPE_NAME 0x00000008 2712654012fSReza Sabdar #define TLM_NO_BACKUP_DIR 0x00000009 2722654012fSReza Sabdar #define TLM_NO_BACKUP_HARDWARE 0x0000000a 2732654012fSReza Sabdar #define TLM_NO_SOURCE_FILE 0x0000000b 2742654012fSReza Sabdar #define TLM_NO_FREE_TAPES 0x0000000c 2752654012fSReza Sabdar #define TLM_EOT 0x0000000d 2762654012fSReza Sabdar #define TLM_SERIAL_NOT_FOUND 0x0000000e 2772654012fSReza Sabdar #define TLM_SMALL_READ 0x0000000f 2782654012fSReza Sabdar #define TLM_NO_RESTORE_FILE 0x00000010 2792654012fSReza Sabdar #define TLM_EOF 0x00000011 2802654012fSReza Sabdar #define TLM_NO_DIRECTORY 0x00000012 2812654012fSReza Sabdar #define TLM_NO_MEMORY 0x00000013 2822654012fSReza Sabdar #define TLM_WRITE_ERROR 0x00000014 2832654012fSReza Sabdar #define TLM_NO_SCRATCH_SPACE 0x00000015 2842654012fSReza Sabdar #define TLM_INVALID 0x00000016 2852654012fSReza Sabdar #define TLM_MOVE 0x00000017 2862654012fSReza Sabdar #define TLM_SKIP 0x00000018 2872654012fSReza Sabdar #define TLM_OPEN_ERR 0x00000019 2882654012fSReza Sabdar 2892654012fSReza Sabdar 2902654012fSReza Sabdar #define TLM_MAX_TAPE_DRIVES 16 2912654012fSReza Sabdar #define TLM_NAME_SIZE 100 2922654012fSReza Sabdar #define TLM_MAX_TAR_IMAGE 017777777770 2932654012fSReza Sabdar 2942654012fSReza Sabdar #define TLM_VOLNAME_MAX_LENGTH 255 2952654012fSReza Sabdar #define NAME_MAX 255 2962654012fSReza Sabdar 2972654012fSReza Sabdar #define TLM_MAGIC "ustar " 2982654012fSReza Sabdar #define TLM_SNAPSHOT_PREFIX ".zfs" 2992654012fSReza Sabdar #define TLM_SNAPSHOT_DIR ".zfs/snapshot" 3002654012fSReza Sabdar 3012654012fSReza Sabdar #define RECORDSIZE 512 3022654012fSReza Sabdar #define NAMSIZ 100 3032654012fSReza Sabdar 3042654012fSReza Sabdar typedef struct tlm_tar_hdr { 3052654012fSReza Sabdar char th_name[TLM_NAME_SIZE]; 3062654012fSReza Sabdar char th_mode[8]; 3072654012fSReza Sabdar char th_uid[8]; 3082654012fSReza Sabdar char th_gid[8]; 3092654012fSReza Sabdar char th_size[12]; 3102654012fSReza Sabdar char th_mtime[12]; 3112654012fSReza Sabdar char th_chksum[8]; 3122654012fSReza Sabdar char th_linkflag; 3132654012fSReza Sabdar char th_linkname[TLM_NAME_SIZE]; 3142654012fSReza Sabdar char th_magic[8]; 315b6b15642SReza Sabdar char th_uname[32]; 316b6b15642SReza Sabdar char th_gname[32]; 3172654012fSReza Sabdar union { 3182654012fSReza Sabdar struct { 3192654012fSReza Sabdar char th_devmajor[8]; 3202654012fSReza Sabdar char th_devminor[8]; 3212654012fSReza Sabdar } th_dev; 3222654012fSReza Sabdar char th_hlink_ino[12]; 3232654012fSReza Sabdar } th_shared; 3242654012fSReza Sabdar } tlm_tar_hdr_t; 3252654012fSReza Sabdar 3262654012fSReza Sabdar 3272654012fSReza Sabdar 3282654012fSReza Sabdar /* 3292654012fSReza Sabdar * The linkflag defines the type of file 3302654012fSReza Sabdar */ 3312654012fSReza Sabdar #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */ 3322654012fSReza Sabdar #define LF_NORMAL '0' /* Normal disk file */ 3332654012fSReza Sabdar #define LF_LINK '1' /* Link to previously dumped file */ 3342654012fSReza Sabdar #define LF_SYMLINK '2' /* Symbolic link */ 3352654012fSReza Sabdar #define LF_CHR '3' /* Character special file */ 3362654012fSReza Sabdar #define LF_BLK '4' /* Block special file */ 3372654012fSReza Sabdar #define LF_DIR '5' /* Directory */ 3382654012fSReza Sabdar #define LF_FIFO '6' /* FIFO special file */ 3392654012fSReza Sabdar #define LF_CONTIG '7' /* Contiguous file */ 3402654012fSReza Sabdar /* Further link types may be defined later. */ 3412654012fSReza Sabdar 3422654012fSReza Sabdar #define LF_DUMPDIR 'D' 3432654012fSReza Sabdar /* 3442654012fSReza Sabdar * This is a dir entry that contains 3452654012fSReza Sabdar * the names of files that were in 3462654012fSReza Sabdar * the dir at the time the dump 3472654012fSReza Sabdar * was made 3482654012fSReza Sabdar */ 3492654012fSReza Sabdar #define LF_HUMONGUS 'H' 3502654012fSReza Sabdar /* 3512654012fSReza Sabdar * Identifies the NEXT file on the tape 3522654012fSReza Sabdar * as a HUGE file 3532654012fSReza Sabdar */ 3542654012fSReza Sabdar #define LF_LONGLINK 'K' 3552654012fSReza Sabdar /* 3562654012fSReza Sabdar * Identifies the NEXT file on the tape 3572654012fSReza Sabdar * as having a long linkname 3582654012fSReza Sabdar */ 3592654012fSReza Sabdar #define LF_LONGNAME 'L' 3602654012fSReza Sabdar /* 3612654012fSReza Sabdar * Identifies the NEXT file on the tape 3622654012fSReza Sabdar * as having a long name. 3632654012fSReza Sabdar */ 3642654012fSReza Sabdar #define LF_MULTIVOL 'M' 3652654012fSReza Sabdar /* 3662654012fSReza Sabdar * This is the continuation 3672654012fSReza Sabdar * of a file that began on another 3682654012fSReza Sabdar * volume 3692654012fSReza Sabdar */ 3702654012fSReza Sabdar 3712654012fSReza Sabdar #define LF_VOLHDR 'V' /* This file is a tape/volume header */ 3722654012fSReza Sabdar /* Ignore it on extraction */ 3732654012fSReza Sabdar 3742654012fSReza Sabdar #define LF_ACL 'A' /* Access Control List */ 3752654012fSReza Sabdar 3762654012fSReza Sabdar #define LF_XATTR 'E' /* Extended attribute */ 3772654012fSReza Sabdar 3782654012fSReza Sabdar #define KILOBYTE 1024 3792654012fSReza Sabdar 3802654012fSReza Sabdar 3812654012fSReza Sabdar /* 3822654012fSReza Sabdar * ACL support structure 3832654012fSReza Sabdar */ 3842654012fSReza Sabdar typedef struct sec_attr { 3852654012fSReza Sabdar char attr_type; 3862654012fSReza Sabdar char attr_len[7]; 3872654012fSReza Sabdar char attr_info[TLM_MAX_ACL_TXT]; 3882654012fSReza Sabdar } sec_attr_t; 3892654012fSReza Sabdar 3902654012fSReza Sabdar typedef struct tlm_acls { 3912654012fSReza Sabdar int acl_checkpointed : 1, /* are checkpoints active ? */ 3922654012fSReza Sabdar acl_clear_archive : 1, /* clear archive bit ? */ 3932654012fSReza Sabdar acl_overwrite : 1, /* always overwrite ? */ 3942654012fSReza Sabdar acl_update : 1, /* only update ? */ 3952654012fSReza Sabdar acl_non_trivial : 1; /* real ACLs? */ 3962654012fSReza Sabdar /* 3972654012fSReza Sabdar * The following fields are here to allow 3982654012fSReza Sabdar * the backup reader to open a file one time 3992654012fSReza Sabdar * and keep the information for ACL, ATTRs, 4002654012fSReza Sabdar * and reading the file. 4012654012fSReza Sabdar */ 4022654012fSReza Sabdar sec_attr_t acl_info; 4032654012fSReza Sabdar 4042654012fSReza Sabdar char acl_root_dir[TLM_VOLNAME_MAX_LENGTH]; /* name of root filesystem */ 4052654012fSReza Sabdar fs_fhandle_t acl_dir_fh; /* parent dir's info */ 4062654012fSReza Sabdar fs_fhandle_t acl_fil_fh; /* file's info */ 4072654012fSReza Sabdar struct stat64 acl_attr; /* file system attributes */ 408b6b15642SReza Sabdar char uname[32]; 409b6b15642SReza Sabdar char gname[32]; 4102654012fSReza Sabdar } tlm_acls_t; 4112654012fSReza Sabdar 4122654012fSReza Sabdar 4132654012fSReza Sabdar /* 4142654012fSReza Sabdar * Tape manager's data archiving ops vector 4152654012fSReza Sabdar * 4162654012fSReza Sabdar * This vector represents the granular operations for 4172654012fSReza Sabdar * performing backup/restore. Each backend should provide 4182654012fSReza Sabdar * such a vector interface in order to be invoked by NDMP 4192654012fSReza Sabdar * server. 4202654012fSReza Sabdar * The reserved callbacks are kept for different backup 4212654012fSReza Sabdar * types which are volume-based rather than file-based 4222654012fSReza Sabdar * e.g. zfs send. 4232654012fSReza Sabdar */ 4242654012fSReza Sabdar typedef struct tm_ops { 4252654012fSReza Sabdar char *tm_name; 4262654012fSReza Sabdar int (*tm_putfile)(); 4272654012fSReza Sabdar int (*tm_putdir)(); 4282654012fSReza Sabdar int (*tm_putvol)(); /* Reserved */ 4292654012fSReza Sabdar int (*tm_getfile)(); 4302654012fSReza Sabdar int (*tm_getdir)(); 4312654012fSReza Sabdar int (*tm_getvol)(); /* Reserved */ 4322654012fSReza Sabdar } tm_ops_t; 4332654012fSReza Sabdar 4342654012fSReza Sabdar /* The checksum field is filled with this while the checksum is computed. */ 4352654012fSReza Sabdar #define CHKBLANKS " " /* 8 blanks, no null */ 4362654012fSReza Sabdar 4372654012fSReza Sabdar #define LONGNAME_PREFIX "././_LoNg_NaMe_" 4382654012fSReza Sabdar extern void ndmp_log(ulong_t, char *, char *, ...); 4392654012fSReza Sabdar char ndmp_log_info[256]; 4402654012fSReza Sabdar #define NDMP_LOG(p, ...) { \ 4412654012fSReza Sabdar (void) snprintf(ndmp_log_info, \ 4422654012fSReza Sabdar sizeof (ndmp_log_info), \ 4432654012fSReza Sabdar "[%d][%s:%d]", \ 4442654012fSReza Sabdar (int)pthread_self(), __func__, __LINE__); \ 4452654012fSReza Sabdar ndmp_log(p, ndmp_log_info, __VA_ARGS__); \ 4462654012fSReza Sabdar } 4472654012fSReza Sabdar extern void *ndmp_malloc(size_t size); 4482654012fSReza Sabdar 4492654012fSReza Sabdar /* 4502654012fSReza Sabdar * ZFS metadata plug-in module structures 4512654012fSReza Sabdar */ 4522654012fSReza Sabdar #define ZFS_MAX_PROPS 100 4532654012fSReza Sabdar #define ZFS_META_MAGIC "ZFSMETA" 45442ed7838SReza Sabdar #define ZFS_META_MAGIC_EXT "ZFSMETA2" 4552654012fSReza Sabdar 45642ed7838SReza Sabdar /* Add new major/minor for header changes */ 45742ed7838SReza Sabdar typedef enum { 45842ed7838SReza Sabdar META_HDR_MAJOR_0, /* Original format */ 45942ed7838SReza Sabdar META_HDR_MAJOR_1, /* Extended format */ 46042ed7838SReza Sabdar } ndmp_metadata_header_major_t; 46142ed7838SReza Sabdar 46242ed7838SReza Sabdar #define META_HDR_MAJOR_VERSION META_HDR_MAJOR_1 46342ed7838SReza Sabdar 46442ed7838SReza Sabdar typedef enum { 46542ed7838SReza Sabdar META_HDR_MINOR_0, 46642ed7838SReza Sabdar } ndmp_metadata_header_minor_t; 46742ed7838SReza Sabdar 46842ed7838SReza Sabdar #define META_HDR_MINOR_VERSION META_HDR_MINOR_0 46942ed7838SReza Sabdar 47042ed7838SReza Sabdar /* To support older backups */ 4712654012fSReza Sabdar typedef struct ndmp_metadata_property { 4722654012fSReza Sabdar char mp_name[NAME_MAX]; 4732654012fSReza Sabdar char mp_value[NAME_MAX]; 4742654012fSReza Sabdar char mp_source[NAME_MAX]; 4752654012fSReza Sabdar } ndmp_metadata_property_t; 4762654012fSReza Sabdar 47742ed7838SReza Sabdar typedef struct ndmp_metadata_property_ext { 47842ed7838SReza Sabdar char mp_name[ZFS_MAXNAMELEN]; 47942ed7838SReza Sabdar char mp_value[ZFS_MAXPROPLEN]; 48042ed7838SReza Sabdar char mp_source[ZFS_MAXPROPLEN]; 48142ed7838SReza Sabdar } ndmp_metadata_property_ext_t; 48242ed7838SReza Sabdar 48342ed7838SReza Sabdar typedef struct ndmp_metadata_top_header { 48442ed7838SReza Sabdar char th_plname[100]; 48542ed7838SReza Sabdar uint_t th_plversion; 48642ed7838SReza Sabdar char th_magic[10]; 48742ed7838SReza Sabdar void *th_reserved_1; 48842ed7838SReza Sabdar int th_count; 48942ed7838SReza Sabdar } ndmp_metadata_top_header_t; 49042ed7838SReza Sabdar 49142ed7838SReza Sabdar /* Original metadata format */ 4922654012fSReza Sabdar typedef struct ndmp_metadata_header { 49342ed7838SReza Sabdar ndmp_metadata_top_header_t nh_hdr; 4942654012fSReza Sabdar char nh_dataset[NAME_MAX]; 4952654012fSReza Sabdar ndmp_metadata_property_t nh_property[1]; 4962654012fSReza Sabdar } ndmp_metadata_header_t; 4972654012fSReza Sabdar 49842ed7838SReza Sabdar /* Extended metadata format */ 49942ed7838SReza Sabdar typedef struct ndmp_metadata_header_ext { 50042ed7838SReza Sabdar ndmp_metadata_top_header_t nh_hdr; 50142ed7838SReza Sabdar char nh_dataset[ZFS_MAXNAMELEN]; 50242ed7838SReza Sabdar int32_t nh_total_bytes; 50342ed7838SReza Sabdar int32_t nh_major; 50442ed7838SReza Sabdar int32_t nh_minor; 50542ed7838SReza Sabdar ndmp_metadata_property_ext_t nh_property[1]; 50642ed7838SReza Sabdar } ndmp_metadata_header_ext_t; 50742ed7838SReza Sabdar 50842ed7838SReza Sabdar #define nh_plname nh_hdr.th_plname 50942ed7838SReza Sabdar #define nh_plversion nh_hdr.th_plversion 51042ed7838SReza Sabdar #define nh_magic nh_hdr.th_magic 51142ed7838SReza Sabdar #define nh_count nh_hdr.th_count 51242ed7838SReza Sabdar 51342ed7838SReza Sabdar typedef struct ndmp_metadata_handle { 51442ed7838SReza Sabdar void *ml_handle; 51542ed7838SReza Sabdar int32_t ml_quota_prop; 51642ed7838SReza Sabdar union { 51742ed7838SReza Sabdar ndmp_metadata_header_t *u_hdr; 51842ed7838SReza Sabdar ndmp_metadata_header_ext_t *u_xhdr; 51942ed7838SReza Sabdar } ml_hdr_u; 52042ed7838SReza Sabdar } ndmp_metadata_handle_t; 52142ed7838SReza Sabdar 52242ed7838SReza Sabdar #define ml_hdr ml_hdr_u.u_hdr 52342ed7838SReza Sabdar #define ml_xhdr ml_hdr_u.u_xhdr 52442ed7838SReza Sabdar 5252654012fSReza Sabdar /* 5262654012fSReza Sabdar * Node in struct hardlink_q 5272654012fSReza Sabdar * 5282654012fSReza Sabdar * inode: the inode of the hardlink 5292654012fSReza Sabdar * path: the name of the hardlink, used during restore 5302654012fSReza Sabdar * offset: tape offset of the data records for the hardlink, used during backup 5312654012fSReza Sabdar * is_tmp: indicate whether the file was created temporarily for restoring 5322654012fSReza Sabdar * other links during a non-DAR partial restore 5332654012fSReza Sabdar */ 5342654012fSReza Sabdar struct hardlink_node { 5352654012fSReza Sabdar unsigned long inode; 5362654012fSReza Sabdar char *path; 5372654012fSReza Sabdar unsigned long long offset; 5382654012fSReza Sabdar int is_tmp; 5392654012fSReza Sabdar SLIST_ENTRY(hardlink_node) next_hardlink; 5402654012fSReza Sabdar }; 5412654012fSReza Sabdar 5422654012fSReza Sabdar /* 5432654012fSReza Sabdar * Hardlinks that have been backed up or restored. 5442654012fSReza Sabdar * 5452654012fSReza Sabdar * During backup, each node represents a file whose 5462654012fSReza Sabdar * (1) inode has multiple links 5472654012fSReza Sabdar * (2) data has been backed up 5482654012fSReza Sabdar * 5492654012fSReza Sabdar * When we run into a file with multiple links during backup, 5502654012fSReza Sabdar * we first check the list to see whether a file with the same inode 5512654012fSReza Sabdar * has been backed up. If yes, we backup an empty record, while 5522654012fSReza Sabdar * making the file history of this file contain the data offset 5532654012fSReza Sabdar * of the offset of the file that has been backed up. If no, 5542654012fSReza Sabdar * we backup this file, and add an entry to the list. 5552654012fSReza Sabdar * 5562654012fSReza Sabdar * During restore, each node represents an LF_LINK type record whose 5572654012fSReza Sabdar * data has been restored (v.s. a hard link has been created). 5582654012fSReza Sabdar * 5592654012fSReza Sabdar * During restore, when we run into a record of LF_LINK type, we 5602654012fSReza Sabdar * first check the queue to see whether a file with the same inode 5612654012fSReza Sabdar * has been restored. If yes, we create a hardlink to it. 5622654012fSReza Sabdar * If no, we restore the data, and add an entry to the list. 5632654012fSReza Sabdar */ 5642654012fSReza Sabdar struct hardlink_q { 5652654012fSReza Sabdar struct hardlink_node *slh_first; 5662654012fSReza Sabdar }; 5672654012fSReza Sabdar 5682654012fSReza Sabdar /* Utility functions from handling hardlink */ 5692654012fSReza Sabdar extern struct hardlink_q *hardlink_q_init(); 5702654012fSReza Sabdar extern void hardlink_q_cleanup(struct hardlink_q *qhead); 5712654012fSReza Sabdar extern int hardlink_q_get(struct hardlink_q *qhead, unsigned long inode, 5722654012fSReza Sabdar unsigned long long *offset, char **path); 5732654012fSReza Sabdar extern int hardlink_q_add(struct hardlink_q *qhead, unsigned long inode, 5742654012fSReza Sabdar unsigned long long offset, char *path, int is_tmp); 5752654012fSReza Sabdar 5762654012fSReza Sabdar #endif /* !_TLM_H_ */ 577