c16d04186a3c8dd1c95a510c958ef63828209102
[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 /* chunker process structure */
45
46 typedef struct chunker_s {
47     char *name;                 /* name of this chunker */
48     pid_t pid;                  /* its pid */
49     int down;                   /* state */
50     int fd;                     /* read/write */
51     int result;
52     event_handle_t *ev_read;    /* read event handle */
53     struct dumper_s *dumper;
54 } chunker_t;
55
56 /* dumper process structure */
57
58 typedef struct dumper_s {
59     char *name;                 /* name of this dumper */
60     pid_t pid;                  /* its pid */
61     int busy, down;             /* state */
62     int fd;                     /* read/write */
63     int result;
64     int output_port;            /* output port */
65     event_handle_t *ev_read;    /* read event handle */
66     disk_t *dp;                 /* disk currently being dumped */
67     chunker_t *chunker;
68 } dumper_t;
69
70 /* holding disk reservation structure; this is built as a list parallel
71  * to the configuration's linked list of holding disks. */
72
73 typedef struct holdalloc_s {
74     struct holdalloc_s *next;
75     holdingdisk_t *hdisk;
76
77     off_t disksize;
78     int allocated_dumpers;
79     off_t allocated_space;
80 } holdalloc_t;
81
82 typedef struct assignedhd_s {
83     holdalloc_t         *disk;
84     off_t               used;
85     off_t               reserved;
86     char                *destname;
87 } assignedhd_t;
88
89 /* schedule structure */
90
91 typedef struct sched_s {
92     int dump_attempted;
93     int taper_attempted;
94     int  priority;
95     int level, degr_level;
96     unsigned long est_time, degr_time;
97     off_t est_nsize, est_csize, est_size;
98     off_t degr_nsize, degr_csize, act_size;
99     off_t origsize, dumpsize;
100     time_t dumptime, tapetime;
101     char *dumpdate, *degr_dumpdate;
102     unsigned long est_kps, degr_kps;
103     char *destname;                             /* file/port name */
104     dumper_t *dumper;
105     assignedhd_t **holdp;
106     time_t timestamp;
107     char *datestamp;
108     int activehd;
109     int no_space;
110     char *degr_mesg;
111 } sched_t;
112
113 #define sched(dp)       ((sched_t *) (dp)->up)
114
115
116 GLOBAL dumper_t dmptable[MAX_DUMPERS];
117 GLOBAL chunker_t chktable[MAX_DUMPERS];
118
119 /* command/result tokens */
120
121 typedef enum {
122    TAPER_STATE_DEFAULT       = 0,
123    TAPER_STATE_DUMP_TO_TAPE  = (1 << 0), // if taper is doing a dump to tape
124    TAPER_STATE_WAIT_FOR_TAPE = (1 << 1), // if taper wait for a tape, after a
125                                          //   REQUEST-NEW-TAPE
126    TAPER_STATE_TAPE_STARTED  = (1 << 2)  // taper already started to write to
127                                          //   a tape.
128 } TaperState;
129
130 GLOBAL int taper, taper_busy;
131 GLOBAL int taper_sendresult;
132 GLOBAL char *taper_input_error;
133 GLOBAL char *taper_tape_error;
134 GLOBAL pid_t taper_pid;
135 GLOBAL int taper_result;
136 GLOBAL dumper_t *taper_dumper;
137 GLOBAL event_handle_t *taper_ev_read;
138 GLOBAL char *taper_first_label;
139 GLOBAL off_t taper_first_fileno;
140 GLOBAL TaperState taper_state;
141 GLOBAL off_t taper_written;             // Number of kb already written to tape
142                                         //   for the DLE.
143
144 void init_driverio(void);
145 void startup_tape_process(char *taper_program);
146 void startup_dump_process(dumper_t *dumper, char *dumper_program);
147 void startup_dump_processes(char *dumper_program, int inparallel, char *timestamp);
148 void startup_chunk_process(chunker_t *chunker, char *chunker_program);
149
150 cmd_t getresult(int fd, int show, int *result_argc, char ***result_argv);
151 disk_t *serial2disk(char *str);
152 void free_serial(char *str);
153 void free_serial_dp(disk_t *dp);
154 void check_unfree_serial(void);
155 char *disk2serial(disk_t *dp);
156 void update_info_dumper(disk_t *dp, off_t origsize, off_t dumpsize, time_t dumptime);
157 void update_info_taper(disk_t *dp, char *label, off_t filenum, int level);
158 void free_assignedhd(assignedhd_t **holdp);
159 #endif  /* !DRIVERIO_H */