Debian Codegraph @

agent/mibgroup/hardware/fsys/fsys_mntctl.c

raw
1 #include <net-snmp/net-snmp-config.h>
2 #include <net-snmp/net-snmp-includes.h>
3 #include <net-snmp/agent/net-snmp-agent-includes.h>
4 #include <net-snmp/agent/hardware/fsys.h>
5
6 #include <stdio.h>
7 #ifdef HAVE_SYS_MNTCTL_H
8 #include <sys/mntctl.h>
9 #endif
10 #ifdef HAVE_SYS_VMOUNT_H
11 #include <sys/vmount.h>
12 #endif
13 #ifdef HAVE_SYS_STATFS_H
14 #include <sys/statfs.h>
15 #endif
16 #ifdef HAVE_SYS_STATVFS_H
17 #include <sys/statvfs.h>
18 #endif
19
20
21 static int
22 _fsys_remote( char *device, int type, char *host )
23 {
24 if (( type == NETSNMP_FS_TYPE_NFS) ||
25 ( type == NETSNMP_FS_TYPE_AFS))
26 return 1;
27 else
28 return 0;
29 }
30
31 static int
32 _fsys_type( int type)
33 {
34 DEBUGMSGTL(("fsys:type", "Classifying %d\n", type));
35
36 switch ( type ) {
37 case MNT_AIX:
38 case MNT_JFS:
39 return NETSNMP_FS_TYPE_BERKELEY;
40
41 case MNT_CDROM:
42 return NETSNMP_FS_TYPE_ISO9660;
43
44 case MNT_NFS:
45 case MNT_NFS3:
46 return NETSNMP_FS_TYPE_NFS;
47 case MNT_AUTOFS:
48 return NETSNMP_FS_TYPE_AUTOFS;
49
50 /*
51 * The following code covers selected filesystems
52 * which are not covered by the HR-TYPES enumerations,
53 * but should still be monitored.
54 * These are all mapped into type "other"
55 *
56 */
57 #ifdef MNT_NAMEFS
58 case MNT_NAMEFS:
59 #endif
60 #ifdef MNT_PROCFS
61 case MNT_PROCFS:
62 #endif
63 #ifdef MNT_ACFS
64 case MNT_ACFS:
65 #endif
66 case MNT_SFS:
67 case MNT_CACHEFS:
68 return NETSNMP_FS_TYPE_OTHER;
69
70 /*
71 * All other types are silently skipped
72 */
73 default:
74 return NETSNMP_FS_TYPE_IGNORE;
75 }
76 return NETSNMP_FS_TYPE_IGNORE; /* Not reached */
77 }
78
79 void
80 netsnmp_fsys_arch_init( void )
81 {
82 return;
83 }
84
85 void
86 netsnmp_fsys_arch_load( void )
87 {
88 int ret = 0, i = 0;
89 uint size = 0;
90
91 struct vmount *aixmnt, *aixcurr;
92 char *path;
93 struct statfs stat_buf;
94 netsnmp_fsys_info *entry;
95 char tmpbuf[1024];
96
97 /*
98 * Retrieve information about the currently mounted filesystems...
99 */
100 ret = mntctl(MCTL_QUERY, sizeof(uint), (void *) &size);
101 if ( ret != 0 || size<=0 ) {
102 snmp_log_perror( "initial mntctl failed" );
103 return;
104 }
105
106 aixmnt = (struct vmount *)malloc( size );
107 if ( aixmnt == NULL ) {
108 snmp_log_perror( "cannot allocate memory for mntctl data" );
109 return;
110 }
111
112 ret = mntctl(MCTL_QUERY, size, (void *) aixmnt);
113 if ( ret <= 0 ) {
114 free(aixmnt);
115 snmp_log_perror( "main mntctl failed" );
116 return;
117 }
118 aixcurr = aixmnt;
119
120
121 /*
122 * ... and insert this into the filesystem container.
123 */
124
125 for (i = 0;
126 i < ret;
127 i++, aixcurr = (struct vmount *) ((char*)aixcurr + aixcurr->vmt_length) ) {
128
129 path = vmt2dataptr( aixcurr, VMT_STUB );
130 entry = netsnmp_fsys_by_path( path, NETSNMP_FS_FIND_CREATE );
131 if (!entry) {
132 continue;
133 }
134
135 strlcpy(entry->path, path, sizeof(entry->path));
136 strlcpy(entry->device, vmt2dataptr(aixcurr, VMT_OBJECT),
137 sizeof(entry->device));
138 entry->type = _fsys_type( aixcurr->vmt_gfstype );
139
140 if (!(entry->type & _NETSNMP_FS_TYPE_SKIP_BIT))
141 entry->flags |= NETSNMP_FS_FLAG_ACTIVE;
142
143 if ( _fsys_remote( entry->device, entry->type, vmt2dataptr( aixcurr, VMT_HOST) ))
144 entry->flags |= NETSNMP_FS_FLAG_REMOTE;
145 if ( aixcurr->vmt_flags & MNT_READONLY )
146 entry->flags |= NETSNMP_FS_FLAG_RONLY;
147 /*
148 * The root device is presumably bootable.
149 * Other partitions probably aren't!
150 */
151 if ((entry->path[0] == '/') && (entry->path[1] == '\0'))
152 entry->flags |= NETSNMP_FS_FLAG_BOOTABLE;
153
154 /*
155 * XXX - identify removeable disks
156 */
157
158 /*
159 * Skip retrieving statistics for AUTOFS and optionally for remote
160 * mounts.
161 */
162 if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) &&
163 netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
164 NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES))
165 continue;
166 if (entry->type == NETSNMP_FS_TYPE_AUTOFS)
167 continue;
168
169 if ( statfs( entry->path, &stat_buf ) < 0 ) {
170 snprintf( tmpbuf, sizeof(tmpbuf), "Cannot statfs %s", entry->path );
171 snmp_log_perror( tmpbuf );
172 continue;
173 }
174 entry->units = stat_buf.f_bsize;
175 entry->size = stat_buf.f_blocks;
176 entry->used = (stat_buf.f_blocks - stat_buf.f_bfree);
177 entry->avail = stat_buf.f_bavail;
178 entry->inums_total = stat_buf.f_files;
179 entry->inums_avail = stat_buf.f_ffree;
180 netsnmp_fsys_calculate32(entry);
181 }
182 free(aixmnt);
183 aixmnt = NULL;
184 aixcurr = NULL;
185 }
186