Remove the RCSID macro
[openafs.git] / src / vol / fssync-client.c
1 /*
2  * Copyright 2000, International Business Machines Corporation 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  * Portions Copyright (c) 2006,2008 Sine Nomine Associates
10  */
11
12 /*
13         System:         VICE-TWO
14         Module:         fssync.c
15         Institution:    The Information Technology Center, Carnegie-Mellon University
16
17  */
18 #ifdef notdef
19
20 /* All this is going away in early 1989 */
21 int newVLDB;                    /* Compatibility flag */
22
23 #endif
24 static int newVLDB = 1;
25
26
27 #ifndef AFS_PTHREAD_ENV
28 #define USUAL_PRIORITY (LWP_MAX_PRIORITY - 2)
29
30 /*
31  * stack size increased from 8K because the HP machine seemed to have trouble
32  * with the smaller stack
33  */
34 #define USUAL_STACK_SIZE        (24 * 1024)
35 #endif /* !AFS_PTHREAD_ENV */
36
37 /*
38    fssync-client.c
39    File server synchronization with external volume utilities.
40    client-side implementation
41  */
42
43 #include <afsconfig.h>
44 #include <afs/param.h>
45
46
47 #include <sys/types.h>
48 #include <stdio.h>
49 #ifdef AFS_NT40_ENV
50 #include <winsock2.h>
51 #include <time.h>
52 #else
53 #include <sys/param.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
56 #include <netdb.h>
57 #include <sys/time.h>
58 #endif
59 #include <errno.h>
60 #ifdef AFS_PTHREAD_ENV
61 #include <assert.h>
62 #else /* AFS_PTHREAD_ENV */
63 #include <afs/assert.h>
64 #endif /* AFS_PTHREAD_ENV */
65 #include <signal.h>
66 #include <string.h>
67
68 #include <rx/xdr.h>
69 #include <afs/afsint.h>
70 #include "nfs.h"
71 #include <afs/errors.h>
72 #include "daemon_com.h"
73 #include "fssync.h"
74 #include "lwp.h"
75 #include "lock.h"
76 #include <afs/afssyscalls.h>
77 #include "ihandle.h"
78 #include "vnode.h"
79 #include "volume.h"
80 #include "partition.h"
81
82 #ifdef FSSYNC_BUILD_CLIENT
83
84 /*@printflike@*/ extern void Log(const char *format, ...);
85
86 extern int LogLevel;
87
88 static SYNC_client_state fssync_state = 
89     { -1,                    /* file descriptor */
90       FSSYNC_ENDPOINT_DECL,  /* server endpoint */
91       FSYNC_PROTO_VERSION,   /* protocol version */
92       5,                     /* connect retry limit */
93       120,                   /* hard timeout */
94       "FSSYNC",              /* protocol name string */
95     };
96
97 #ifdef AFS_PTHREAD_ENV
98 static pthread_mutex_t vol_fsync_mutex;
99 static volatile vol_fsync_mutex_init = 0;
100 #define VFSYNC_LOCK \
101     assert(pthread_mutex_lock(&vol_fsync_mutex) == 0)
102 #define VFSYNC_UNLOCK \
103     assert(pthread_mutex_unlock(&vol_fsync_mutex) == 0)
104 #else
105 #define VFSYNC_LOCK
106 #define VFSYNC_UNLOCK
107 #endif
108
109 int
110 FSYNC_clientInit(void)
111 {
112 #ifdef AFS_PTHREAD_ENV
113     /* this is safe since it gets called with VOL_LOCK held, or before we go multithreaded */
114     if (!vol_fsync_mutex_init) {
115         assert(pthread_mutex_init(&vol_fsync_mutex, NULL) == 0);
116         vol_fsync_mutex_init = 1;
117     }
118 #endif
119     return SYNC_connect(&fssync_state);
120 }
121
122 void
123 FSYNC_clientFinis(void)
124 {
125     SYNC_closeChannel(&fssync_state);
126 }
127
128 int
129 FSYNC_clientChildProcReconnect(void)
130 {
131     return SYNC_reconnect(&fssync_state);
132 }
133
134 /* fsync client interface */
135 afs_int32
136 FSYNC_askfs(SYNC_command * com, SYNC_response * res)
137 {
138     afs_int32 code;
139
140     VFSYNC_LOCK;
141     code = SYNC_ask(&fssync_state, com, res);
142     VFSYNC_UNLOCK;
143
144     switch (code) {
145     case SYNC_OK:
146     case SYNC_FAILED:
147         break;
148     case SYNC_COM_ERROR:
149     case SYNC_BAD_COMMAND:
150         Log("FSYNC_askfs: fatal FSSYNC protocol error; volume management functionality disabled until next fileserver restart\n");
151         break;
152     case SYNC_DENIED:
153         Log("FSYNC_askfs: FSSYNC request denied for reason=%d\n", res->hdr.reason);
154         break;
155     default:
156         Log("FSYNC_askfs: unknown protocol response %d\n", code);
157         break;
158     }
159     return code;
160 }
161
162 afs_int32
163 FSYNC_GenericOp(void * ext_hdr, size_t ext_len,
164               int command, int reason,
165               SYNC_response * res_in)
166 {
167     SYNC_response res_l, *res;
168     SYNC_command com;
169
170     if (res_in) {
171         res = res_in;
172     } else {
173         res = &res_l;
174         res_l.payload.buf = NULL;
175         res_l.payload.len = 0;
176     }
177
178     memset(&com, 0, sizeof(com));
179
180     com.hdr.programType = programType;
181     com.hdr.command = command;
182     com.hdr.reason = reason;
183     com.hdr.command_len = sizeof(com.hdr) + ext_len;
184     com.payload.buf = ext_hdr;
185     com.payload.len = ext_len;
186
187     return FSYNC_askfs(&com, res);
188 }
189
190 afs_int32
191 FSYNC_VolOp(VolumeId volume, char * partition, 
192             int command, int reason,
193             SYNC_response * res)
194 {
195     FSSYNC_VolOp_hdr vcom;
196
197     memset(&vcom, 0, sizeof(vcom));
198
199     vcom.volume = volume;
200     if (partition)
201         strlcpy(vcom.partName, partition, sizeof(vcom.partName));
202
203     return FSYNC_GenericOp(&vcom, sizeof(vcom), command, reason, res);
204 }
205
206 afs_int32
207 FSYNC_StatsOp(FSSYNC_StatsOp_hdr * scom, int command, int reason,
208               SYNC_response * res)
209 {
210     return FSYNC_GenericOp(scom, sizeof(*scom), command, reason, res);
211 }
212
213
214 #endif /* FSSYNC_BUILD_CLIENT */