Move contents of afs_osi_gcpags to per-OS files
[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     afs_MarinerLog("fetch$Fetching", avc);
75 }                               /*afs_MarinerLogFetch */
76
77 void
78 afs_MarinerLog(register char *astring, register struct vcache *avc)
79 {
80     struct sockaddr_in taddr;
81     register char *tp, *tp1, *buf;
82     struct iovec dvec;
83
84     AFS_STATCNT(afs_MarinerLog);
85     taddr.sin_family = AF_INET;
86     taddr.sin_addr.s_addr = afs_marinerHost;
87     taddr.sin_port = htons(2106);
88 #ifdef  STRUCT_SOCKADDR_HAS_SA_LEN
89     taddr.sin_len = sizeof(taddr);
90 #endif
91     tp = buf = (char *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
92
93     strcpy(tp, astring);
94     tp += strlen(astring);
95     if (avc) {
96         *tp++ = ' ';
97         tp1 = afs_GetMariner(avc);
98         strcpy(tp, tp1);
99         tp += strlen(tp1);
100     }
101     *tp++ = '\n';
102     /* note, console doesn't want a terminating null */
103     /* I don't care if mariner packets fail to be sent */
104     dvec.iov_base = buf;
105     dvec.iov_len = tp - buf;
106     AFS_GUNLOCK();
107     (void)osi_NetSend(afs_server->socket, &taddr, &dvec, 1, tp - buf, 0);
108     AFS_GLOCK();
109     osi_FreeSmallSpace(buf);
110 }                               /*afs_MarinerLog */
111
112 void
113 shutdown_mariner(void)
114 {
115     int i;
116
117     marinerPtr = 0;
118     afs_mariner = 0;
119
120     for (i = 0; i < NMAR; i++)
121         marinerVCs[i] = 0;
122 }