9c2f8b953ed483bab0964eaa03d79b19be84a18d
[openafs.git] / src / vol / salvsync.h
1 /*
2  * Copyright 2006-2007, Sine Nomine Associates and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * demand attach fs
12  * salvage server interface
13  */
14 #ifndef _AFS_VOL_SALVSYNC_H
15 #define _AFS_VOL_SALVSYNC_H
16
17 #define SALSRV_EXIT_VOLGROUP_LINK 10
18
19
20 #ifdef AFS_DEMAND_ATTACH_FS
21 #include "daemon_com.h"
22 #include "voldefs.h"
23
24
25 #define SALVSYNC_PROTO_VERSION_V1     1
26 #define SALVSYNC_PROTO_VERSION_V2     2
27 #define SALVSYNC_PROTO_VERSION        SALVSYNC_PROTO_VERSION_V2
28
29
30 /** 
31  * SALVSYNC protocol command codes.
32  */
33 typedef enum {
34     SALVSYNC_OP_NOP           = SYNC_COM_CODE_DECL(0),     /**< just return stats */
35     SALVSYNC_OP_SALVAGE       = SYNC_COM_CODE_DECL(1),     /**< schedule a salvage */
36     SALVSYNC_OP_CANCEL        = SYNC_COM_CODE_DECL(2),     /**< cancel a salvage */
37     SALVSYNC_OP_RAISEPRIO     = SYNC_COM_CODE_DECL(3),     /**< raise salvage priority */
38     SALVSYNC_OP_QUERY         = SYNC_COM_CODE_DECL(4),     /**< query status of a salvage */
39     SALVSYNC_OP_CANCELALL     = SYNC_COM_CODE_DECL(5),     /**< cancel all pending salvages */
40     SALVSYNC_OP_LINK          = SYNC_COM_CODE_DECL(6),     /**< link a clone to its parent */
41     SALVSYNC_OP_MAX_ID /* must be at end of enum */
42 } SALVSYNC_op_code_t;
43
44 #define SALVSYNC_NOP         SALVSYNC_OP_NOP
45 #define SALVSYNC_SALVAGE     SALVSYNC_OP_SALVAGE
46 #define SALVSYNC_CANCEL      SALVSYNC_OP_CANCEL
47 #define SALVSYNC_RAISEPRIO   SALVSYNC_OP_RAISEPRIO
48 #define SALVSYNC_QUERY       SALVSYNC_OP_QUERY
49 #define SALVSYNC_CANCELALL   SALVSYNC_OP_CANCELALL
50 #define SALVSYNC_LINK        SALVSYNC_OP_LINK
51
52 /**
53  * SALVSYNC protocol reason codes.
54  */
55 typedef enum {
56     SALVSYNC_REASON_WHATEVER   = SYNC_REASON_CODE_DECL(0), /**< XXX */
57     SALVSYNC_REASON_ERROR      = SYNC_REASON_CODE_DECL(1), /**< volume is in error state */
58     SALVSYNC_REASON_OPERATOR   = SYNC_REASON_CODE_DECL(2), /**< operator forced salvage */
59     SALVSYNC_REASON_SHUTDOWN   = SYNC_REASON_CODE_DECL(3), /**< cancel due to shutdown */
60     SALVSYNC_REASON_NEEDED     = SYNC_REASON_CODE_DECL(4), /**< needsSalvaged flag set */
61     SALVSYNC_REASON_MAX_ID /* must be at end of enum */
62 } SALVSYNC_reason_code_t;
63
64 #define SALVSYNC_WHATEVER    SALVSYNC_REASON_WHATEVER
65 #define SALVSYNC_ERROR       SALVSYNC_REASON_ERROR
66 #define SALVSYNC_OPERATOR    SALVSYNC_REASON_OPERATOR
67 #define SALVSYNC_SHUTDOWN    SALVSYNC_REASON_SHUTDOWN
68 #define SALVSYNC_NEEDED      SALVSYNC_REASON_NEEDED
69
70 /* SALVSYNC response codes */
71
72 /* SALVSYNC flags */
73 #define SALVSYNC_FLAG_VOL_STATS_VALID SYNC_FLAG_CODE_DECL(0) /* volume stats in response are valid */
74
75 /** 
76  * SALVSYNC command state.
77  */
78 typedef enum {
79     SALVSYNC_STATE_UNKNOWN = 0,       /**< unknown state */
80     SALVSYNC_STATE_QUEUED  = 1,       /**< salvage request is queued */
81     SALVSYNC_STATE_SALVAGING = 2,     /**< salvage is happening now */
82     SALVSYNC_STATE_ERROR = 3,         /**< salvage ended in an error */
83     SALVSYNC_STATE_DONE = 4           /**< last salvage ended successfully */
84 } SALVSYNC_command_state_t;
85
86
87 /**
88  * on-wire salvsync protocol payload.
89  */
90 typedef struct SALVSYNC_command_hdr {
91     afs_uint32 hdr_version;     /**< salvsync protocol header version */
92     afs_uint32 prio;            /**< salvage priority */
93     afs_uint32 volume;          /**< volume on which to operate */
94     afs_uint32 parent;          /**< parent volume (for vol group linking command) */
95     char partName[16];          /**< partition name, e.g. /vicepa */
96     afs_uint32 reserved[6];
97 } SALVSYNC_command_hdr;
98
99 typedef struct SALVSYNC_response_hdr {
100     afs_int32 state;
101     afs_int32 prio;
102     afs_int32 sq_len;
103     afs_int32 pq_len;
104     afs_uint32 reserved[4];
105 } SALVSYNC_response_hdr;
106
107 typedef struct SALVSYNC_command {
108     SYNC_command_hdr * hdr;
109     SALVSYNC_command_hdr * sop;
110     SYNC_command * com;
111 } SALVSYNC_command;
112
113 typedef struct SALVSYNC_response {
114     SYNC_response_hdr * hdr;
115     SALVSYNC_response_hdr * sop;
116     SYNC_response * res;
117 } SALVSYNC_response;
118
119 typedef struct SALVSYNC_command_info {
120     SYNC_command_hdr com;
121     SALVSYNC_command_hdr sop;
122 } SALVSYNC_command_info;
123
124 typedef enum {
125     SALVSYNC_VOLGROUP_PARENT,
126     SALVSYNC_VOLGROUP_CLONE
127 } SalvageQueueNodeType_t;
128
129 struct SalvageQueueNode {
130     struct rx_queue q;
131     struct rx_queue hash_chain;
132     SalvageQueueNodeType_t type;
133     union {
134         struct SalvageQueueNode * parent;
135         struct SalvageQueueNode * children[VOLMAXTYPES];
136     } volgroup;
137     SALVSYNC_command_state_t state;
138     struct SALVSYNC_command_info command;
139     afs_int32 partition_id;
140     int pid;
141 };
142
143
144 /* Prototypes from salvsync.c */
145
146 /* online salvager client interfaces */
147 extern int SALVSYNC_clientFinis(void);
148 extern int SALVSYNC_clientInit(void);
149 extern int SALVSYNC_clientReconnect(void);
150 extern afs_int32 SALVSYNC_askSalv(SYNC_command * com, SYNC_response * res);
151 extern afs_int32 SALVSYNC_SalvageVolume(VolumeId volume, char *partName, int com, int reason,
152                                         afs_uint32 prio, SYNC_response * res);
153 extern afs_int32 SALVSYNC_LinkVolume(VolumeId parent, VolumeId clone,
154                                      char * partName, SYNC_response * res_in);
155
156 /* salvage server interfaces */
157 extern void SALVSYNC_salvInit(void);
158 extern struct SalvageQueueNode * SALVSYNC_getWork(void);
159 extern void SALVSYNC_doneWork(struct SalvageQueueNode *, int result);
160 extern void SALVSYNC_doneWorkByPid(int pid, int result);
161
162 #endif /* AFS_DEMAND_ATTACH_FS */
163
164 #endif /* _AFS_VOL_SALVSYNC_H */