no-copy-libafs-builds-20021015
[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 "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 int afs_AddMarinerName(register char *aname, register struct vcache *avc)
40 {
41     register int i;
42     register char *tp;
43
44     AFS_STATCNT(afs_AddMarinerName);
45     i = marinerPtr++;
46     if (i >= NMAR) {
47         i = 0;
48         marinerPtr = 1;
49     }
50     tp = marinerNames[i];
51     strncpy(tp, aname, SMAR);
52     tp[SMAR-1] = 0;
53     marinerVCs[i] = avc;
54     return 0;
55 }
56
57 char *afs_GetMariner(register struct vcache *avc)
58 {
59     register int i;
60     AFS_STATCNT(afs_GetMariner);
61     for(i=0; i<NMAR; i++) {
62         if (marinerVCs[i] == avc) {
63             return marinerNames[i];
64         }
65     }
66     return "a file";
67 }
68
69 void afs_MarinerLogFetch(register struct vcache *avc, register afs_int32 off, 
70         register afs_int32 bytes, register afs_int32 idx)
71 {
72     struct sockaddr_in taddr;
73     register char *tp, *tp1, *tp2;
74     struct iovec dvec;
75     int len;
76
77
78     AFS_STATCNT(afs_MarinerLog);
79     taddr.sin_family = AF_INET;
80     taddr.sin_addr.s_addr = afs_marinerHost;
81     taddr.sin_port = htons(2106);
82 #ifdef  STRUCT_SOCKADDR_HAS_SA_LEN
83     taddr.sin_len = sizeof(taddr);
84 #endif  /* AFS_OSF_ENV */
85     tp = tp1 = (char *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
86     strcpy(tp, "fetch$Fetching ");
87     tp += 15; /* change it if string changes */
88     tp2 = afs_GetMariner(avc);
89     strcpy(tp, tp2);
90     tp += strlen(tp2);
91     *tp++ = '\n';
92     /* note, console doesn't want a terminating null */
93     len = strlen(tp1) - 1;
94     /* I don't care if mariner packets fail to be sent */
95     dvec.iov_base = tp1;
96     dvec.iov_len = len;
97     AFS_GUNLOCK();
98     (void) osi_NetSend(afs_server->socket, &taddr, &dvec, 1, len, 0);
99     AFS_GLOCK();
100     osi_FreeSmallSpace(tp1);
101 } /*afs_MarinerLogFetch*/
102
103 void afs_MarinerLog(register char *astring, register struct vcache *avc)
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 #ifdef  STRUCT_SOCKADDR_HAS_SA_LEN
114     taddr.sin_len = sizeof(taddr);
115 #endif  /* AFS_OSF_ENV */
116     tp = buf = (char *) osi_AllocSmallSpace(AFS_SMALLOCSIZ);
117
118     strcpy(tp, astring);
119     tp += strlen(astring);
120     *tp++ = ' ';
121     tp1 = afs_GetMariner(avc);
122     strcpy(tp, tp1);
123     tp += strlen(tp1);
124     *tp++ = '\n';
125     /* note, console doesn't want a terminating null */
126     /* I don't care if mariner packets fail to be sent */
127     dvec.iov_base = buf;
128     dvec.iov_len = tp-buf;
129     AFS_GUNLOCK();
130     (void) osi_NetSend(afs_server->socket, &taddr, &dvec, 1, tp-buf, 0);
131     AFS_GLOCK();
132     osi_FreeSmallSpace(buf);
133 } /*afs_MarinerLog*/
134
135 void shutdown_mariner(void)
136 {
137     int i;
138
139     marinerPtr = 0;
140     afs_mariner = 0;
141
142     for (i=0; i<NMAR; i++)
143         marinerVCs[i] = 0;
144 }
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170