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