|
1 /* |
|
2 * This patch fixes the performance issue observed while retrieving the |
|
3 * hrStorage parameters in systems with large number of mountpoints |
|
4 * parameters using snmpwalk. |
|
5 * |
|
6 * This issue is happening due to the overhead of large number of |
|
7 * ioctl() system calls in getmntent() function called by the |
|
8 * Get_Next_HR_Filesys() function. |
|
9 * We see that in the Get_Next_HR_Filesys() function, inorder to access |
|
10 * the last mountpoint, the /etc/mnttab is opened and we walk through |
|
11 * all the mnttab entries for all filesystems till the end. This is the |
|
12 * reason we find a large number of the MNTIOC_GETMNTENT ioctl() calls. |
|
13 * |
|
14 * To reduce the overhead of the getmntent() calls, we maintain a cache |
|
15 * of all the /etc/mnttab entries and walk through the cache instead of |
|
16 * opening /etc/mnttab and walking all the entries for each mountpoint. |
|
17 */ |
|
18 |
|
19 --- net-snmp-5.4.1.orig/agent/mibgroup/host/hr_filesys.c 2007-05-18 11:08:01.000000000 -0700 |
|
20 +++ net-snmp-5.4.1/agent/mibgroup/host/hr_filesys.c 2012-08-17 01:23:04.781860694 -0700 |
|
21 @@ -31,6 +31,10 @@ |
|
22 #include <sys/mount.h> |
|
23 #endif |
|
24 |
|
25 +#ifdef solaris2 |
|
26 +#include <sys/stat.h> |
|
27 +#endif |
|
28 + |
|
29 #include <ctype.h> |
|
30 #if HAVE_STRING_H |
|
31 #include <string.h> |
|
32 @@ -85,7 +89,11 @@ |
|
33 #ifdef solaris2 |
|
34 |
|
35 struct mnttab HRFS_entry_struct; |
|
36 -struct mnttab *HRFS_entry = &HRFS_entry_struct; |
|
37 +struct mnttab *HRFS_entry; |
|
38 +struct mnttab *HRFS_list; |
|
39 +static int fscount; |
|
40 +static time_t last_access=-1; |
|
41 + |
|
42 #define HRFS_name mnt_special |
|
43 #define HRFS_mount mnt_mountp |
|
44 #define HRFS_type mnt_fstype |
|
45 @@ -563,6 +571,12 @@ |
|
46 void |
|
47 Init_HR_FileSys(void) |
|
48 { |
|
49 +#ifdef solaris2 |
|
50 + char buf[512]={NULL}; |
|
51 + int lines=0, i=0; |
|
52 + struct stat file_stat; |
|
53 +#endif |
|
54 + |
|
55 #if HAVE_GETFSSTAT |
|
56 #if defined(HAVE_STATVFS) && defined(__NetBSD__) |
|
57 fscount = getvfsstat(NULL, 0, ST_NOWAIT); |
|
58 @@ -603,10 +617,62 @@ |
|
59 } |
|
60 } |
|
61 #else |
|
62 - HRFS_index = 1; |
|
63 - if (fp != NULL) |
|
64 - fclose(fp); |
|
65 - fp = fopen(ETC_MNTTAB, "r"); |
|
66 + HRFS_index = 1; |
|
67 + if (fp != NULL) |
|
68 + fclose(fp); |
|
69 +#ifdef solaris2 |
|
70 + HRFS_index = 0; |
|
71 + stat(ETC_MNTTAB, &file_stat); |
|
72 + if (last_access == -1 || last_access != file_stat.st_mtime) { |
|
73 + fp = fopen(ETC_MNTTAB, "r"); |
|
74 + if(fp == NULL) |
|
75 + { |
|
76 + DEBUGMSGTL(("host/hr_filesys", "fopen failed for mnttab.\n")); |
|
77 + return; |
|
78 + } |
|
79 + |
|
80 + while ( (fgets((char *)&buf,sizeof(buf),fp)) != NULL) { |
|
81 + lines++; |
|
82 + } |
|
83 + fclose(fp); |
|
84 + |
|
85 + HRFS_list = (struct mnttab *) malloc (sizeof(struct mnttab) * lines); |
|
86 + |
|
87 + if(HRFS_list == NULL) |
|
88 + { |
|
89 + DEBUGMSGTL(("host/hr_filesys", "Memory allocation for mnttab cache failed.\n")); |
|
90 + return; |
|
91 + } |
|
92 + |
|
93 + fp = fopen(ETC_MNTTAB, "r"); |
|
94 + |
|
95 + if(fp == NULL) |
|
96 + { |
|
97 + DEBUGMSGTL(("host/hr_filesys", "fopen failed for mnttab.\n")); |
|
98 + free(HRFS_list); |
|
99 + return; |
|
100 + } |
|
101 + |
|
102 + fscount = lines; |
|
103 + while (i < fscount) |
|
104 + { |
|
105 + if (getmntent(fp, &HRFS_entry_struct) == 0) |
|
106 + { |
|
107 + HRFS_list[i].mnt_special = strdup(HRFS_entry_struct.mnt_special); |
|
108 + HRFS_list[i].mnt_mountp = strdup(HRFS_entry_struct.mnt_mountp); |
|
109 + HRFS_list[i].mnt_fstype = strdup(HRFS_entry_struct.mnt_fstype); |
|
110 + HRFS_list[i].mnt_mntopts = strdup(HRFS_entry_struct.mnt_mntopts); |
|
111 + i++; |
|
112 + } |
|
113 + } |
|
114 + |
|
115 + HRFS_entry = HRFS_list; |
|
116 + last_access = file_stat.st_mtime; |
|
117 + } |
|
118 +#else |
|
119 + fp = fopen(ETC_MNTTAB, "r"); |
|
120 +#endif |
|
121 + |
|
122 #endif |
|
123 } |
|
124 |
|
125 @@ -699,21 +765,24 @@ |
|
126 #else |
|
127 const char **cpp; |
|
128 |
|
129 - if (fp == NULL) |
|
130 - return -1; |
|
131 |
|
132 #ifdef solaris2 |
|
133 - if (getmntent(fp, HRFS_entry) != 0) |
|
134 - return -1; |
|
135 + |
|
136 + if (HRFS_index >= fscount) |
|
137 + return -1; |
|
138 + HRFS_entry = &HRFS_list[HRFS_index]; |
|
139 + return ++HRFS_index; |
|
140 + |
|
141 #else |
|
142 - HRFS_entry = getmntent(fp); |
|
143 - if (HRFS_entry == NULL) |
|
144 - return -1; |
|
145 -#endif /* solaris2 */ |
|
146 + if (fp == NULL) |
|
147 + return -1; |
|
148 + HRFS_entry = getmntent(fp); |
|
149 + if (HRFS_entry == NULL) |
|
150 + return -1; |
|
151 |
|
152 - for (cpp = HRFS_ignores; *cpp != NULL; ++cpp) |
|
153 - if (!strcmp(HRFS_entry->HRFS_type, *cpp)) |
|
154 - return Get_Next_HR_FileSys(); |
|
155 + for (cpp = HRFS_ignores; *cpp != NULL; ++cpp) |
|
156 + if (!strcmp(HRFS_entry->HRFS_type, *cpp)) |
|
157 + return Get_Next_HR_FileSys(); |
|
158 |
|
159 /* |
|
160 * Try and ensure that index values are persistent |
|
161 @@ -728,6 +797,8 @@ |
|
162 } |
|
163 |
|
164 return HRFS_index++; |
|
165 +#endif |
|
166 + |
|
167 #endif /* HAVE_GETFSSTAT */ |
|
168 } |
|
169 |
|
170 @@ -780,20 +851,34 @@ |
|
171 End_HR_FileSys(void) |
|
172 { |
|
173 #ifdef HAVE_GETFSSTAT |
|
174 - if (fsstats) |
|
175 - free((char *) fsstats); |
|
176 - fsstats = NULL; |
|
177 + if (fsstats) |
|
178 + free((char *) fsstats); |
|
179 + fsstats = NULL; |
|
180 #elif defined(aix4) || defined(aix5) |
|
181 - if(aixmnt != NULL) { |
|
182 - free(aixmnt); |
|
183 - aixmnt = NULL; |
|
184 - aixcurr = NULL; |
|
185 - HRFS_entry = NULL; |
|
186 - } |
|
187 -#else |
|
188 - if (fp != NULL) |
|
189 - fclose(fp); |
|
190 - fp = NULL; |
|
191 + if(aixmnt != NULL) { |
|
192 + free(aixmnt); |
|
193 + aixmnt = NULL; |
|
194 + aixcurr = NULL; |
|
195 + HRFS_entry = NULL; |
|
196 + } |
|
197 +#else |
|
198 + int i=0; |
|
199 + if (fp != NULL) |
|
200 + fclose(fp); |
|
201 + fp = NULL; |
|
202 + |
|
203 +#ifdef solaris2 |
|
204 + while (i < fscount) { |
|
205 + free(HRFS_list[i].mnt_special); |
|
206 + free(HRFS_list[i].mnt_mountp); |
|
207 + free(HRFS_list[i].mnt_fstype); |
|
208 + free(HRFS_list[i].mnt_mntopts); |
|
209 + i++; |
|
210 + } |
|
211 + if (HRFS_list != NULL) |
|
212 + free(HRFS_list); |
|
213 +#endif |
|
214 + |
|
215 #endif |
|
216 } |
|
217 |