d2a18bfa8cb531c3efc6b60245e059e7a53ac980
[openafs.git] / src / afs / IRIX / osi_misc.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  * Implementation of miscellaneous Irix routines.
12  */
13 #include <afsconfig.h>
14 #include "afs/param.h"
15
16
17 #ifdef  AFS_SGI62_ENV
18 #include "afs/sysincludes.h"    /* Standard vendor system headers */
19 #include "afsincludes.h"        /* Afs-based standard headers */
20 #include "afs/afs_stats.h"      /* statistics */
21
22
23
24
25 /*
26  * various special purpose routines
27  */
28 void
29 afs_mpservice(void *a)
30 {
31 }
32
33 /*!
34  * make a semaphore name for use in <sys/sema.h>-type routines on
35  * IRIX
36  *
37  * \param[out]  sname           will contain the semaphore name and
38  *                              should point to an allocated string
39  *                              buffer of size METER_NAMSZ
40  * \param[in]   prefix          string with which to start the name
41  * \param[in]   v_number        vnode number to complete the name
42  *
43  * \post sname will point to the beginning of a NULL-terminated
44  *       string to be used as a semaphore name with a maximum of
45  *       (METER_NAMSZ-1) characters plus the NULL.  The name is a
46  *       concatenation of the string at 'prefix' and the ASCII
47  *       representation of the number in 'v_number'.  sname is
48  *       returned.
49  *
50  * \note Due to IRIX's use of uint64_t to represent vnumber_t and a
51  *       maximum semaphore name length of 15 (METER_NAMSZ-1), this
52  *       function cannot be guaranteed to produce a name which
53  *       uniquely describes a vnode.
54  *
55  */
56 char *
57 makesname(char *sname, const char *prefix, vnumber_t v_number)
58 {
59     char vnbuf[21]; /* max number of uint64 decimal digits + 1 */
60     size_t prlen, vnlen;
61
62     if (sname) {
63         /*
64          * Note: IRIX doesn't have realloc() available in the
65          * kernel, so the openafs util implementation of snprintf is
66          * not usable.  What follows is intended to reproduce the
67          * behavior of:
68          *      snprintf(sname, METER_NAMSZ, "%s%llu", prefix,
69          *               (unsigned long long)v_number);
70          * Additionally, the kernel only provides a void sprintf(),
71          * making length checking slightly more difficult.
72          */
73         prlen = strlen(prefix);
74         if (prlen > METER_NAMSZ-1)
75             prlen = METER_NAMSZ-1;
76         strncpy(sname, prefix, prlen);
77
78         memset(vnbuf, 0, sizeof(vnbuf));
79         sprintf(vnbuf, "%llu", (unsigned long long)v_number);
80         vnlen = strlen(vnbuf);
81         if (vnlen+prlen > METER_NAMSZ-1)
82             vnlen = METER_NAMSZ-1-prlen;
83         if (vnlen > 0)
84             strncpy(&(sname[prlen]), vnbuf, vnlen);
85         sname[vnlen+prlen] = '\0';
86     }
87     return sname;
88 }
89
90 #ifdef AFS_SGI_VNODE_GLUE
91 #include <sys/invent.h>
92 extern mutex_t afs_init_kern_lock;
93
94 /* afs_init_kernel_config
95  *
96  * initialize vnode glue layer by testing for NUMA.
97  * Argument: flag
98  * 0 = no numa, 1 = has numa, -1 = test for numa.
99  */
100 int
101 afs_init_kernel_config(int flag)
102 {
103     static int afs_kern_inited = 0;
104     int code = 0;
105
106     mutex_enter(&afs_init_kern_lock);
107     if (!afs_kern_inited) {
108         afs_kern_inited = 1;
109
110         if (flag == -1) {
111             inventory_t *pinv;
112             /* test for numa arch. */
113             /* Determine if thisis a NUMA platform. Currently, this is true
114              * only if it's an IP27 or IP35.
115              */
116             pinv =
117                 find_inventory(NULL, INV_PROCESSOR,
118                                INV_CPUBOARD, -1, -1, -1);
119             if (!pinv)
120                 code = ENODEV;
121             else
122                 afs_is_numa_arch = ((pinv->inv_state == INV_IP27BOARD)
123                                     || (pinv->inv_state == INV_IP35BOARD))
124                     ? 1 : 0;
125         } else
126             afs_is_numa_arch = flag;
127     }
128     mutex_exit(&afs_init_kern_lock);
129     return code;
130 }
131 #endif /* AFS_SGI_VNODE_GLUE */
132
133 /* And just so we know what someone is _really_ running */
134 #ifdef IP19
135 int afs_ipno = 19;
136 #elif defined(IP20)
137 int afs_ipno = 20;
138 #elif defined(IP21)
139 int afs_ipno = 21;
140 #elif defined(IP25)
141 int afs_ipno = 25;
142 #elif defined(IP26)
143 int afs_ipno = 26;
144 #elif defined(IP27)
145 int afs_ipno = 27;
146 #elif defined(IP28)
147 int afs_ipno = 28;
148 #elif defined(IP30)
149 int afs_ipno = 30;
150 #elif defined(IP35)
151 int afs_ipno = 35;
152 #else
153 int afs_ipno = -1;
154 #endif
155
156
157 #endif /* AFS_SGI62_ENV */