freebsd-almost-working-client-20020216
[openafs.git] / src / afs / afs_mariner.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
10 /*
11  * afs_mariner.c - fetch/store monitoring facility.
12  */
13 /*
14  * Implements:
15  */
16 #include <afsconfig.h>
17 #include "../afs/param.h"
18
19 RCSID("$Header$");
20
21 #include "../afs/sysincludes.h" /*Standard vendor system headers*/
22 #include "../afs/afsincludes.h" /*AFS-based standard headers*/
23 #include "../afs/afs_stats.h"  /* statistics */
24
25 /* Exported variables */
26 struct rx_service *afs_server;
27
28
29 #define SMAR        20                  /* size of a mariner name */
30 #define NMAR        10                  /* number of mariner names */
31 static char marinerNames[NMAR][SMAR];
32 static struct vcache *marinerVCs[NMAR];
33 static int marinerPtr = 0;      /* pointer to next mariner slot to use */
34
35 /* Exported variables */
36 afs_int32 afs_mariner = 0;
37 afs_int32 afs_marinerHost = 0;
38
39 afs_AddMarinerName(aname, avc)
40     register char *aname;
41     register struct vcache *avc; {
42     register int i;
43     register char *tp;
44
45     AFS_STATCNT(afs_AddMarinerName);
46     i = marinerPtr++;
47     if (i >= NMAR) {
48         i = 0;
49         marinerPtr = 1;
50     }
51     tp = marinerNames[i];
52     strncpy(tp, aname, SMAR);
53     tp[SMAR-1] = 0;
54     marinerVCs[i] = avc;
55     return 0;
56 }
57
58 char *afs_GetMariner(avc)
59     register struct vcache *avc; {
60     register int i;
61     AFS_STATCNT(afs_GetMariner);
62     for(i=0; i<NMAR; i++) {
63         if (marinerVCs[i] == avc) {
64             return marinerNames[i];
65         }
66     }
67     return "a file";
68 }
69
70 void afs_MarinerLogFetch(avc, off, bytes, idx)
71     register struct vcache *avc;
72     register afs_int32 off, bytes, idx;
73 {
74     struct sockaddr_in taddr;
75     register char *tp, *tp1, *tp2;
76     struct iovec dvec;
77     int len;
78
79
80     AFS_STATCNT(afs_MarinerLog);
81     taddr.sin_family = AF_INET;
82     taddr.sin_addr.s_addr = afs_marinerHost;
83     taddr.sin_port = htons(2106);
84 #ifdef  STRUCT_SOCKADDR_HAS_SA_LEN
85     taddr.sin_len = sizeof(taddr);
86 #endif  /* AFS_OSF_ENV */
87     tp = tp1 = (char *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
88     strcpy(tp, "fetch$Fetching ");
89     tp += 15; /* change it if string changes */
90     tp2 = afs_GetMariner(avc);
91     strcpy(tp, tp2);
92     tp += strlen(tp2);
93     *tp++ = '\n';
94     /* note, console doesn't want a terminating null */
95     len = strlen(tp1) - 1;
96     /* I don't care if mariner packets fail to be sent */
97     dvec.iov_base = tp1;
98     dvec.iov_len = len;
99     AFS_GUNLOCK();
100     (void) osi_NetSend(afs_server->socket, &taddr, &dvec, 1, len, 0);
101     AFS_GLOCK();
102     osi_FreeSmallSpace(tp1);
103 } /*afs_MarinerLogFetch*/
104
105 void afs_MarinerLog(astring, avc)
106     register struct vcache *avc;
107     register char *astring;
108 {
109     struct sockaddr_in taddr;
110     register char *tp, *tp1, *buf;
111     struct iovec dvec;
112
113     AFS_STATCNT(afs_MarinerLog);
114     taddr.sin_family = AF_INET;
115     taddr.sin_addr.s_addr = afs_marinerHost;
116     taddr.sin_port = htons(2106);
117 #ifdef  STRUCT_SOCKADDR_HAS_SA_LEN
118     taddr.sin_len = sizeof(taddr);
119 #endif  /* AFS_OSF_ENV */
120     tp = buf = (char *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
121
122     strcpy(tp, astring);
123     tp += strlen(astring);
124     *tp++ = ' ';
125     tp1 = afs_GetMariner(avc);
126     strcpy(tp, tp1);
127     tp += strlen(tp1);
128     *tp++ = '\n';
129     /* note, console doesn't want a terminating null */
130     /* I don't care if mariner packets fail to be sent */
131     dvec.iov_base = buf;
132     dvec.iov_len = tp-buf;
133     AFS_GUNLOCK();
134     (void) osi_NetSend(afs_server->socket, &taddr, &dvec, 1, tp-buf, 0);
135     AFS_GLOCK();
136     osi_FreeSmallSpace(buf);
137 } /*afs_MarinerLog*/
138
139 void shutdown_mariner(void)
140 {
141     int i;
142
143     marinerPtr = 0;
144     afs_mariner = 0;
145
146     for (i=0; i<NMAR; i++)
147         marinerVCs[i] = 0;
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174