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