Imported Upstream version 3.3.1
[debian/amanda] / server-src / driverio.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: James da Silva, Systems Design and Analysis Group
24  *                         Computer Science Department
25  *                         University of Maryland at College Park
26  */
27 /*
28  * $Id: driverio.h,v 1.35 2006/05/25 01:47:19 johnfranks Exp $
29  *
30  * driver-related helper functions
31  */
32 #ifndef DRIVERIO_H
33 #define DRIVERIO_H
34
35 #include "amanda.h"
36 #include "event.h"
37 #include "holding.h"
38 #include "server_util.h"
39
40 #ifndef GLOBAL
41 #define GLOBAL extern
42 #endif
43
44 typedef enum {
45    TAPER_STATE_DEFAULT        = 0,        //   0 Before TAPER-START
46    TAPER_STATE_INIT           = (1 << 0), //   1 Between TAPE-START and TAPE-OK
47    TAPER_STATE_RESERVATION    = (1 << 1), //   2 Have a reservation
48    TAPER_STATE_IDLE           = (1 << 2), //   4 tape started and do nothing
49    TAPER_STATE_DUMP_TO_TAPE   = (1 << 3), //   8 Doing a PORT-WRITE
50    TAPER_STATE_FILE_TO_TAPE   = (1 << 4), //  16 Doing a FILE-WRITE
51    TAPER_STATE_TAPE_REQUESTED = (1 << 5), //  32 REQUEST-NEW-TAPE received
52    TAPER_STATE_WAIT_FOR_TAPE  = (1 << 6), //  64 if taper wait for a tape,
53                                           //     after a START-SCAN send
54    TAPER_STATE_WAIT_NEW_TAPE  = (1 << 7), // 128 AFTER NEW-TAPE sent and before
55                                           //     NEW-TAPE received
56    TAPER_STATE_TAPE_STARTED   = (1 << 8), // 256 taper already started to write
57                                           //     to a tape.
58    TAPER_STATE_DONE           = (1 << 9),
59 } TaperState;
60
61 /* chunker process structure */
62
63 typedef struct chunker_s {
64     char *name;                 /* name of this chunker */
65     pid_t pid;                  /* its pid */
66     int down;                   /* state */
67     int fd;                     /* read/write */
68     int result;
69     event_handle_t *ev_read;    /* read event handle */
70     struct dumper_s *dumper;
71 } chunker_t;
72
73 /* dumper process structure */
74
75 typedef struct dumper_s {
76     char *name;                 /* name of this dumper */
77     pid_t pid;                  /* its pid */
78     int busy, down;             /* state */
79     int fd;                     /* read/write */
80     int result;
81     int output_port;            /* output port */
82     event_handle_t *ev_read;    /* read event handle */
83     disk_t *dp;                 /* disk currently being dumped */
84     chunker_t *chunker;
85 } dumper_t;
86
87 typedef struct taper_s {
88     char       *name;                  /* name of this taper */
89     int         sendresult;
90     char       *input_error;
91     char       *tape_error;
92     int         result;
93     dumper_t   *dumper;
94     disk_t     *disk;
95     char       *first_label;
96     off_t       first_fileno;
97     TaperState  state;
98     off_t       left;
99     off_t       written;               // Number of kb already written to tape
100     int         nb_dle;                /* number of dle on the volume */
101 } taper_t;
102
103 /* holding disk reservation structure; this is built as a list parallel
104  * to the configuration's linked list of holding disks. */
105
106 typedef struct holdalloc_s {
107     struct holdalloc_s *next;
108     holdingdisk_t *hdisk;
109
110     off_t disksize;
111     int allocated_dumpers;
112     off_t allocated_space;
113 } holdalloc_t;
114
115 typedef struct assignedhd_s {
116     holdalloc_t         *disk;
117     off_t               used;
118     off_t               reserved;
119     char                *destname;
120 } assignedhd_t;
121
122 /* schedule structure */
123
124 typedef struct sched_s {
125     int dump_attempted;
126     int taper_attempted;
127     int  priority;
128     int level, degr_level;
129     unsigned long est_time, degr_time;
130     off_t est_nsize, est_csize, est_size;
131     off_t degr_nsize, degr_csize, act_size;
132     off_t origsize, dumpsize;
133     time_t dumptime, tapetime;
134     char *dumpdate, *degr_dumpdate;
135     unsigned long est_kps, degr_kps;
136     char *destname;                             /* file/port name */
137     dumper_t *dumper;
138     taper_t  *taper;
139     assignedhd_t **holdp;
140     time_t timestamp;
141     char *datestamp;
142     int activehd;
143     int no_space;
144     char *degr_mesg;
145 } sched_t;
146
147 #define sched(dp)       ((sched_t *) (dp)->up)
148
149
150 GLOBAL dumper_t dmptable[MAX_DUMPERS];
151 GLOBAL chunker_t chktable[MAX_DUMPERS];
152 GLOBAL taper_t   *tapetable;
153
154 /* command/result tokens */
155
156 GLOBAL int taper_fd;
157 GLOBAL pid_t taper_pid;
158 GLOBAL event_handle_t *taper_ev_read;
159 GLOBAL int taper_nb_wait_reply;
160
161 void init_driverio(void);
162 void startup_tape_process(char *taper_program, int taper_parallel_write, gboolean no_taper);
163 void startup_dump_process(dumper_t *dumper, char *dumper_program);
164 void startup_dump_processes(char *dumper_program, int inparallel, char *timestamp);
165 void startup_chunk_process(chunker_t *chunker, char *chunker_program);
166
167 cmd_t getresult(int fd, int show, int *result_argc, char ***result_argv);
168 disk_t *serial2disk(char *str);
169 void free_serial(char *str);
170 void free_serial_dp(disk_t *dp);
171 void check_unfree_serial(void);
172 char *disk2serial(disk_t *dp);
173 void update_info_dumper(disk_t *dp, off_t origsize, off_t dumpsize, time_t dumptime);
174 void update_info_taper(disk_t *dp, char *label, off_t filenum, int level);
175 void free_assignedhd(assignedhd_t **holdp);
176 #endif  /* !DRIVERIO_H */