Remove the RCSID macro
[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
20 #include "afs/sysincludes.h"    /*Standard vendor system headers */
21 #include "afsincludes.h"        /*AFS-based standard headers */
22 #include "afs/afs_stats.h"      /* statistics */
23
24 /* Exported variables */
25 struct rx_service *afs_server;
26
27
28 #define SMAR        20          /* size of a mariner name */
29 #define NMAR        10          /* number of mariner names */
30 static char marinerNames[NMAR][SMAR];
31 static struct vcache *marinerVCs[NMAR];
32 static int marinerPtr = 0;      /* pointer to next mariner slot to use */
33
34 /* Exported variables */
35 afs_int32 afs_mariner = 0;
36 afs_int32 afs_marinerHost = 0;
37
38 int
39 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 *
58 afs_GetMariner(register struct vcache *avc)
59 {
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
71 afs_MarinerLogFetch(register struct vcache *avc, register afs_int32 off,
72                     register afs_int32 bytes, register afs_int32 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
106 afs_MarinerLog(register char *astring, register struct vcache *avc)
107 {
108     struct sockaddr_in taddr;
109     register char *tp, *tp1, *buf;
110     struct iovec dvec;
111
112     AFS_STATCNT(afs_MarinerLog);
113     taddr.sin_family = AF_INET;
114     taddr.sin_addr.s_addr = afs_marinerHost;
115     taddr.sin_port = htons(2106);
116 #ifdef  STRUCT_SOCKADDR_HAS_SA_LEN
117     taddr.sin_len = sizeof(taddr);
118 #endif /* AFS_OSF_ENV */
119     tp = buf = (char *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
120
121     strcpy(tp, astring);
122     tp += strlen(astring);
123     *tp++ = ' ';
124     tp1 = afs_GetMariner(avc);
125     strcpy(tp, tp1);
126     tp += strlen(tp1);
127     *tp++ = '\n';
128     /* note, console doesn't want a terminating null */
129     /* I don't care if mariner packets fail to be sent */
130     dvec.iov_base = buf;
131     dvec.iov_len = tp - buf;
132     AFS_GUNLOCK();
133     (void)osi_NetSend(afs_server->socket, &taddr, &dvec, 1, tp - buf, 0);
134     AFS_GLOCK();
135     osi_FreeSmallSpace(buf);
136 }                               /*afs_MarinerLog */
137
138 void
139 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 }