VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/solaris/PerformanceSolaris.cpp@ 43978

Last change on this file since 43978 was 43978, checked in by vboxsync, 12 years ago

Main/Metrics: Host disk size for Solaris (#6345)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.7 KB
Line 
1/* $Id: PerformanceSolaris.cpp 43978 2012-11-28 05:11:51Z vboxsync $ */
2
3/** @file
4 *
5 * VBox Solaris-specific Performance Classes implementation.
6 */
7
8/*
9 * Copyright (C) 2008 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#undef _FILE_OFFSET_BITS
21#include <procfs.h>
22#include <stdio.h>
23#include <errno.h>
24#include <fcntl.h>
25#include <kstat.h>
26#include <unistd.h>
27#include <sys/sysinfo.h>
28#include <sys/time.h>
29#include <sys/types.h>
30#include <sys/statvfs.h>
31
32#include <iprt/ctype.h>
33#include <iprt/err.h>
34#include <iprt/string.h>
35#include <iprt/alloc.h>
36#include <iprt/param.h>
37#include <iprt/path.h>
38#include <VBox/log.h>
39#include "Performance.h"
40
41#include <dlfcn.h>
42
43#include <libzfs.h>
44#include <libnvpair.h>
45
46#include <map>
47
48namespace pm {
49
50 typedef libzfs_handle_t *(*PFNZFSINIT)(void);
51 typedef zfs_handle_t *(*PFNZFSOPEN)(libzfs_handle_t *, const char *, int);
52 typedef void (*PFNZFSCLOSE)(zfs_handle_t *);
53 typedef uint64_t (*PFNZFSPROPGETINT)(zfs_handle_t *, zfs_prop_t);
54 typedef zpool_handle_t *(*PFNZPOOLOPEN)(libzfs_handle_t *, const char *);
55 typedef void (*PFNZPOOLCLOSE)(zpool_handle_t *);
56 typedef nvlist_t *(*PFNZPOOLGETCONFIG)(zpool_handle_t *, nvlist_t **);
57 typedef char *(*PFNZPOOLVDEVNAME)(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, boolean_t);
58
59 typedef std::map<RTCString,RTCString> FsMap;
60
61class CollectorSolaris : public CollectorHAL
62{
63public:
64 CollectorSolaris();
65 virtual ~CollectorSolaris();
66 virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
67 virtual int getHostFilesystemUsage(const char *name, ULONG *total, ULONG *used, ULONG *available);
68 virtual int getHostDiskSize(const char *name, uint64_t *size);
69 virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
70
71 virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
72 virtual int getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx);
73 virtual int getRawHostDiskLoad(const char *name, uint64_t *disk_ms, uint64_t *total_ms);
74 virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
75
76 virtual int getDiskListByFs(const char *name, DiskList& list);
77private:
78 static uint32_t getInstance(const char *pszIfaceName, char *pszDevName);
79 uint64_t getZfsTotal(uint64_t cbTotal, const char *szFsType, const char *szFsName);
80 void updateFilesystemMap(void);
81 RTCString physToInstName(const char *pcszPhysName);
82 RTCString pathToInstName(const char *pcszDevPathName);
83
84 kstat_ctl_t *mKC;
85 kstat_t *mSysPages;
86 kstat_t *mZFSCache;
87
88 void *mZfsSo;
89 libzfs_handle_t *mZfsLib;
90 PFNZFSINIT mZfsInit;
91 PFNZFSOPEN mZfsOpen;
92 PFNZFSCLOSE mZfsClose;
93 PFNZFSPROPGETINT mZfsPropGetInt;
94 PFNZPOOLOPEN mZpoolOpen;
95 PFNZPOOLCLOSE mZpoolClose;
96 PFNZPOOLGETCONFIG mZpoolGetConfig;
97 PFNZPOOLVDEVNAME mZpoolVdevName;
98
99 FsMap mFsMap;
100};
101
102CollectorHAL *createHAL()
103{
104 return new CollectorSolaris();
105}
106
107// Collector HAL for Solaris
108
109
110CollectorSolaris::CollectorSolaris()
111 : mKC(0),
112 mSysPages(0),
113 mZFSCache(0),
114 mZfsLib(0)
115{
116 if ((mKC = kstat_open()) == 0)
117 {
118 Log(("kstat_open() -> %d\n", errno));
119 return;
120 }
121
122 if ((mSysPages = kstat_lookup(mKC, (char *)"unix", 0, (char *)"system_pages")) == 0)
123 {
124 Log(("kstat_lookup(system_pages) -> %d\n", errno));
125 return;
126 }
127
128 if ((mZFSCache = kstat_lookup(mKC, (char *)"zfs", 0, (char *)"arcstats")) == 0)
129 {
130 Log(("kstat_lookup(system_pages) -> %d\n", errno));
131 }
132
133 /* Try to load libzfs dynamically, it may be missing. */
134 mZfsSo = dlopen("libzfs.so", RTLD_LAZY);
135 if (mZfsSo)
136 {
137 mZfsInit = (PFNZFSINIT)dlsym(mZfsSo, "libzfs_init");
138 mZfsOpen = (PFNZFSOPEN)dlsym(mZfsSo, "zfs_open");
139 mZfsClose = (PFNZFSCLOSE)dlsym(mZfsSo, "zfs_close");
140 mZfsPropGetInt = (PFNZFSPROPGETINT)dlsym(mZfsSo, "zfs_prop_get_int");
141 mZpoolOpen = (PFNZPOOLOPEN)dlsym(mZfsSo, "zpool_open");
142 mZpoolClose = (PFNZPOOLCLOSE)dlsym(mZfsSo, "zpool_close");
143 mZpoolGetConfig = (PFNZPOOLGETCONFIG)dlsym(mZfsSo, "zpool_get_config");
144 mZpoolVdevName = (PFNZPOOLVDEVNAME)dlsym(mZfsSo, "zpool_vdev_name");
145
146 if (mZfsInit && mZfsOpen && mZfsClose && mZfsPropGetInt
147 && mZpoolOpen && mZpoolClose && mZpoolGetConfig && mZpoolVdevName)
148 mZfsLib = mZfsInit();
149 else
150 LogRel(("Incompatible libzfs? libzfs_init=%p zfs_open=%p zfs_close=%p zfs_prop_get_int=%p\n",
151 mZfsInit, mZfsOpen, mZfsClose, mZfsPropGetInt));
152 }
153
154 updateFilesystemMap();
155}
156
157CollectorSolaris::~CollectorSolaris()
158{
159 if (mKC)
160 kstat_close(mKC);
161 if (mZfsSo)
162 dlclose(mZfsSo);
163}
164
165int CollectorSolaris::getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle)
166{
167 int rc = VINF_SUCCESS;
168 kstat_t *ksp;
169 uint64_t tmpUser, tmpKernel, tmpIdle;
170 int cpus;
171 cpu_stat_t cpu_stats;
172
173 if (mKC == 0)
174 return VERR_INTERNAL_ERROR;
175
176 tmpUser = tmpKernel = tmpIdle = cpus = 0;
177 for (ksp = mKC->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
178 if (strcmp(ksp->ks_module, "cpu_stat") == 0) {
179 if (kstat_read(mKC, ksp, &cpu_stats) == -1)
180 {
181 Log(("kstat_read() -> %d\n", errno));
182 return VERR_INTERNAL_ERROR;
183 }
184 ++cpus;
185 tmpUser += cpu_stats.cpu_sysinfo.cpu[CPU_USER];
186 tmpKernel += cpu_stats.cpu_sysinfo.cpu[CPU_KERNEL];
187 tmpIdle += cpu_stats.cpu_sysinfo.cpu[CPU_IDLE];
188 }
189 }
190
191 if (cpus == 0)
192 {
193 Log(("no cpu stats found!\n"));
194 return VERR_INTERNAL_ERROR;
195 }
196
197 if (user) *user = tmpUser;
198 if (kernel) *kernel = tmpKernel;
199 if (idle) *idle = tmpIdle;
200
201 return rc;
202}
203
204int CollectorSolaris::getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total)
205{
206 int rc = VINF_SUCCESS;
207 char *pszName;
208 prusage_t prusage;
209
210 RTStrAPrintf(&pszName, "/proc/%d/usage", process);
211 Log(("Opening %s...\n", pszName));
212 int h = open(pszName, O_RDONLY);
213 RTStrFree(pszName);
214
215 if (h != -1)
216 {
217 if (read(h, &prusage, sizeof(prusage)) == sizeof(prusage))
218 {
219 //Assert((pid_t)process == pstatus.pr_pid);
220 //Log(("user=%u kernel=%u total=%u\n", prusage.pr_utime.tv_sec, prusage.pr_stime.tv_sec, prusage.pr_tstamp.tv_sec));
221 *user = (uint64_t)prusage.pr_utime.tv_sec * 1000000000 + prusage.pr_utime.tv_nsec;
222 *kernel = (uint64_t)prusage.pr_stime.tv_sec * 1000000000 + prusage.pr_stime.tv_nsec;
223 *total = (uint64_t)prusage.pr_tstamp.tv_sec * 1000000000 + prusage.pr_tstamp.tv_nsec;
224 //Log(("user=%llu kernel=%llu total=%llu\n", *user, *kernel, *total));
225 }
226 else
227 {
228 Log(("read() -> %d\n", errno));
229 rc = VERR_FILE_IO_ERROR;
230 }
231 close(h);
232 }
233 else
234 {
235 Log(("open() -> %d\n", errno));
236 rc = VERR_ACCESS_DENIED;
237 }
238
239 return rc;
240}
241
242int CollectorSolaris::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
243{
244 int rc = VINF_SUCCESS;
245
246 kstat_named_t *kn;
247
248 if (mKC == 0 || mSysPages == 0)
249 return VERR_INTERNAL_ERROR;
250
251 if (kstat_read(mKC, mSysPages, 0) == -1)
252 {
253 Log(("kstat_read(sys_pages) -> %d\n", errno));
254 return VERR_INTERNAL_ERROR;
255 }
256 if ((kn = (kstat_named_t *)kstat_data_lookup(mSysPages, (char *)"freemem")) == 0)
257 {
258 Log(("kstat_data_lookup(freemem) -> %d\n", errno));
259 return VERR_INTERNAL_ERROR;
260 }
261 *available = kn->value.ul * (PAGE_SIZE/1024);
262
263 if (kstat_read(mKC, mZFSCache, 0) != -1)
264 {
265 if (mZFSCache)
266 {
267 if ((kn = (kstat_named_t *)kstat_data_lookup(mZFSCache, (char *)"size")))
268 {
269 ulong_t ulSize = kn->value.ul;
270
271 if ((kn = (kstat_named_t *)kstat_data_lookup(mZFSCache, (char *)"c_min")))
272 {
273 /*
274 * Account for ZFS minimum arc cache size limit.
275 * "c_min" is the target minimum size of the ZFS cache, and not the hard limit. It's possible
276 * for "size" to shrink below "c_min" (e.g: during boot & high memory consumption).
277 */
278 ulong_t ulMin = kn->value.ul;
279 *available += ulSize > ulMin ? (ulSize - ulMin) / 1024 : 0;
280 }
281 else
282 Log(("kstat_data_lookup(c_min) ->%d\n", errno));
283 }
284 else
285 Log(("kstat_data_lookup(size) -> %d\n", errno));
286 }
287 else
288 Log(("mZFSCache missing.\n"));
289 }
290
291 if ((kn = (kstat_named_t *)kstat_data_lookup(mSysPages, (char *)"physmem")) == 0)
292 {
293 Log(("kstat_data_lookup(physmem) -> %d\n", errno));
294 return VERR_INTERNAL_ERROR;
295 }
296 *total = kn->value.ul * (PAGE_SIZE/1024);
297 *used = *total - *available;
298
299 return rc;
300}
301
302int CollectorSolaris::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
303{
304 int rc = VINF_SUCCESS;
305 char *pszName = NULL;
306 psinfo_t psinfo;
307
308 RTStrAPrintf(&pszName, "/proc/%d/psinfo", process);
309 Log(("Opening %s...\n", pszName));
310 int h = open(pszName, O_RDONLY);
311 RTStrFree(pszName);
312
313 if (h != -1)
314 {
315 if (read(h, &psinfo, sizeof(psinfo)) == sizeof(psinfo))
316 {
317 Assert((pid_t)process == psinfo.pr_pid);
318 *used = psinfo.pr_rssize;
319 }
320 else
321 {
322 Log(("read() -> %d\n", errno));
323 rc = VERR_FILE_IO_ERROR;
324 }
325 close(h);
326 }
327 else
328 {
329 Log(("open() -> %d\n", errno));
330 rc = VERR_ACCESS_DENIED;
331 }
332
333 return rc;
334}
335
336uint32_t CollectorSolaris::getInstance(const char *pszIfaceName, char *pszDevName)
337{
338 /*
339 * Get the instance number from the interface name, then clip it off.
340 */
341 int cbInstance = 0;
342 int cbIface = strlen(pszIfaceName);
343 const char *pszEnd = pszIfaceName + cbIface - 1;
344 for (int i = 0; i < cbIface - 1; i++)
345 {
346 if (!RT_C_IS_DIGIT(*pszEnd))
347 break;
348 cbInstance++;
349 pszEnd--;
350 }
351
352 uint32_t uInstance = RTStrToUInt32(pszEnd + 1);
353 strncpy(pszDevName, pszIfaceName, cbIface - cbInstance);
354 pszDevName[cbIface - cbInstance] = '\0';
355 return uInstance;
356}
357
358int CollectorSolaris::getRawHostNetworkLoad(const char *name, uint64_t *rx, uint64_t *tx)
359{
360 AssertReturn(strlen(name) < KSTAT_STRLEN, VERR_INVALID_PARAMETER);
361 LogFlowThisFunc(("m=%s i=%d n=%s\n", "link", -1, name));
362 kstat_t *ksAdapter = kstat_lookup(mKC, "link", -1, (char *)name);
363 if (ksAdapter == 0)
364 {
365 char szModule[KSTAT_STRLEN];
366 uint32_t uInstance = getInstance(name, szModule);
367 LogFlowThisFunc(("m=%s i=%u n=%s\n", szModule, uInstance, "phys"));
368 ksAdapter = kstat_lookup(mKC, szModule, uInstance, "phys");
369 if (ksAdapter == 0)
370 {
371 LogFlowThisFunc(("m=%s i=%u n=%s\n", szModule, uInstance, name));
372 ksAdapter = kstat_lookup(mKC, szModule, uInstance, (char *)name);
373 if (ksAdapter == 0)
374 {
375 LogRel(("Failed to get network statistics for %s\n", name));
376 return VERR_INTERNAL_ERROR;
377 }
378 }
379 }
380 if (kstat_read(mKC, ksAdapter, 0) == -1)
381 {
382 LogRel(("kstat_read(adapter) -> %d\n", errno));
383 return VERR_INTERNAL_ERROR;
384 }
385 kstat_named_t *kn;
386 if ((kn = (kstat_named_t *)kstat_data_lookup(ksAdapter, (char *)"rbytes")) == 0)
387 {
388 LogRel(("kstat_data_lookup(rbytes) -> %d, name=%s\n", errno, name));
389 return VERR_INTERNAL_ERROR;
390 }
391 *rx = kn->value.ul;
392 if ((kn = (kstat_named_t *)kstat_data_lookup(ksAdapter, (char *)"obytes")) == 0)
393 {
394 LogRel(("kstat_data_lookup(obytes) -> %d\n", errno));
395 return VERR_INTERNAL_ERROR;
396 }
397 *tx = kn->value.ul;
398 return VINF_SUCCESS;
399}
400
401int CollectorSolaris::getRawHostDiskLoad(const char *name, uint64_t *disk_ms, uint64_t *total_ms)
402{
403 int rc = VINF_SUCCESS;
404 AssertReturn(strlen(name) < KSTAT_STRLEN, VERR_INVALID_PARAMETER);
405 LogFlowThisFunc(("n=%s\n", name));
406 kstat_t *ksDisk = kstat_lookup(mKC, NULL, -1, (char *)name);
407 if (ksDisk != 0)
408 {
409 if (kstat_read(mKC, ksDisk, 0) == -1)
410 {
411 LogRel(("kstat_read(%s) -> %d\n", name, errno));
412 rc = VERR_INTERNAL_ERROR;
413 }
414 else
415 {
416 kstat_io_t *ksIo = KSTAT_IO_PTR(ksDisk);
417 /*
418 * We do not care for wrap possibility here, although we may
419 * reconsider in about 300 years (9223372036854775807 ns).
420 */
421 *disk_ms = ksIo->rtime / 1000000;
422 *total_ms = ksDisk->ks_snaptime / 1000000;
423 }
424 }
425 else
426 {
427 LogRel(("kstat_lookup(%s) -> %d\n", name, errno));
428 rc = VERR_INTERNAL_ERROR;
429 }
430
431 return rc;
432}
433
434uint64_t CollectorSolaris::getZfsTotal(uint64_t cbTotal, const char *szFsType, const char *szFsName)
435{
436 if (strcmp(szFsType, "zfs"))
437 return cbTotal;
438 FsMap::iterator it = mFsMap.find(szFsName);
439 if (it == mFsMap.end())
440 return cbTotal;
441
442 char *pszDataset = strdup(it->second.c_str());
443 char *pszEnd = pszDataset + strlen(pszDataset);
444 uint64_t uAvail = 0;
445 while (pszEnd)
446 {
447 zfs_handle_t *hDataset;
448
449 *pszEnd = 0;
450 hDataset = mZfsOpen(mZfsLib, pszDataset, ZFS_TYPE_DATASET);
451 if (!hDataset)
452 break;
453
454 if (uAvail == 0)
455 {
456 uAvail = mZfsPropGetInt(hDataset, ZFS_PROP_REFQUOTA);
457 if (uAvail == 0)
458 uAvail = UINT64_MAX;
459 }
460
461 uint64_t uQuota = mZfsPropGetInt(hDataset, ZFS_PROP_QUOTA);
462 if (uQuota && uAvail > uQuota)
463 uAvail = uQuota;
464
465 pszEnd = strrchr(pszDataset, '/');
466 if (!pszEnd)
467 {
468 uint64_t uPoolSize = mZfsPropGetInt(hDataset, ZFS_PROP_USED) +
469 mZfsPropGetInt(hDataset, ZFS_PROP_AVAILABLE);
470 if (uAvail > uPoolSize)
471 uAvail = uPoolSize;
472 }
473 mZfsClose(hDataset);
474 }
475 free(pszDataset);
476
477 return uAvail ? uAvail : cbTotal;
478}
479
480int CollectorSolaris::getHostFilesystemUsage(const char *path, ULONG *total, ULONG *used, ULONG *available)
481{
482 struct statvfs64 stats;
483 const unsigned _MB = 1024 * 1024;
484
485 if (statvfs64(path, &stats) == -1)
486 {
487 LogRel(("Failed to collect %s filesystem usage: errno=%d.\n", path, errno));
488 return VERR_ACCESS_DENIED;
489 }
490 uint64_t cbBlock = stats.f_frsize ? stats.f_frsize : stats.f_bsize;
491 *total = (ULONG)(getZfsTotal(cbBlock * stats.f_blocks, stats.f_basetype, path) / _MB);
492 LogRel(("f_blocks=%llu.\n", stats.f_blocks));
493 *used = (ULONG)(cbBlock * (stats.f_blocks - stats.f_bfree) / _MB);
494 *available = (ULONG)(cbBlock * stats.f_bavail / _MB);
495
496 return VINF_SUCCESS;
497}
498
499int CollectorSolaris::getHostDiskSize(const char *name, uint64_t *size)
500{
501 int rc = VINF_SUCCESS;
502 AssertReturn(strlen(name) + 5 < KSTAT_STRLEN, VERR_INVALID_PARAMETER);
503 LogFlowThisFunc(("n=%s\n", name));
504 char szName[KSTAT_STRLEN];
505 strcpy(szName, name);
506 strcat(szName, ",err");
507 kstat_t *ksDisk = kstat_lookup(mKC, "sderr", -1, szName);
508 if (ksDisk != 0)
509 {
510 if (kstat_read(mKC, ksDisk, 0) == -1)
511 {
512 LogRel(("kstat_read(%s) -> %d\n", name, errno));
513 rc = VERR_INTERNAL_ERROR;
514 }
515 else
516 {
517 kstat_named_t *kn;
518 if ((kn = (kstat_named_t *)kstat_data_lookup(ksDisk, (char *)"Size")) == 0)
519 {
520 LogRel(("kstat_data_lookup(rbytes) -> %d, name=%s\n", errno, name));
521 return VERR_INTERNAL_ERROR;
522 }
523 *size = kn->value.ull;
524 }
525 }
526
527 return rc;
528}
529
530RTCString CollectorSolaris::physToInstName(const char *pcszPhysName)
531{
532 FILE *fp = fopen("/etc/path_to_inst", "r");
533 if (!fp)
534 return RTCString();
535
536 RTCString strInstName;
537 size_t cbName = strlen(pcszPhysName);
538 char szBuf[RTPATH_MAX];
539 while (fgets(szBuf, sizeof(szBuf), fp))
540 {
541 if (szBuf[0] == '"' && strncmp(szBuf + 1, pcszPhysName, cbName) == 0)
542 {
543 char *pszDriver, *pszInstance;
544 pszDriver = strrchr(szBuf, '"');
545 if (pszDriver)
546 {
547 *pszDriver = '\0';
548 pszDriver = strrchr(szBuf, '"');
549 if (pszDriver)
550 {
551 *pszDriver++ = '\0';
552 pszInstance = strrchr(szBuf, ' ');
553 if (pszInstance)
554 {
555 *pszInstance = '\0';
556 pszInstance = strrchr(szBuf, ' ');
557 if (pszInstance)
558 {
559 *pszInstance++ = '\0';
560 strInstName = pszDriver;
561 strInstName += pszInstance;
562 break;
563 }
564 }
565 }
566 }
567 }
568 }
569 fclose(fp);
570
571 return strInstName;
572}
573
574RTCString CollectorSolaris::pathToInstName(const char *pcszDevPathName)
575{
576 char szLink[RTPATH_MAX];
577 if (readlink(pcszDevPathName, szLink, sizeof(szLink)) != -1)
578 {
579 char *pszStart, *pszEnd;
580 pszStart = strstr(szLink, "/devices/");
581 pszEnd = strrchr(szLink, ':');
582 if (pszStart && pszEnd)
583 {
584 pszStart += 8; // Skip "/devices"
585 *pszEnd = '\0'; // Trim partition
586 return physToInstName(pszStart);
587 }
588 }
589
590 return RTCString(pcszDevPathName);
591}
592
593int CollectorSolaris::getDiskListByFs(const char *name, DiskList& list)
594{
595 FsMap::iterator it = mFsMap.find(name);
596 if (it == mFsMap.end())
597 return VERR_INVALID_PARAMETER;
598
599 RTCString strName = it->second.substr(0, it->second.find("/"));
600 if (mZpoolOpen && mZpoolClose && mZpoolGetConfig && !strName.isEmpty())
601 {
602 zpool_handle_t *zh = mZpoolOpen(mZfsLib, strName.c_str());
603 if (zh)
604 {
605 unsigned int cChildren = 0;
606 nvlist_t **nvChildren = NULL;
607 nvlist_t *nvRoot = NULL;
608 nvlist_t *nvConfig = mZpoolGetConfig(zh, NULL);
609 if ( !nvlist_lookup_nvlist(nvConfig, ZPOOL_CONFIG_VDEV_TREE, &nvRoot)
610 && !nvlist_lookup_nvlist_array(nvRoot, ZPOOL_CONFIG_CHILDREN, &nvChildren, &cChildren))
611 {
612 for (unsigned int i = 0; i < cChildren; ++i)
613 {
614 uint64_t fHole = 0;
615 uint64_t fLog = 0;
616
617 nvlist_lookup_uint64(nvChildren[i], ZPOOL_CONFIG_IS_HOLE, &fHole);
618 nvlist_lookup_uint64(nvChildren[i], ZPOOL_CONFIG_IS_LOG, &fLog);
619
620 if (!fHole && !fLog)
621 {
622 char *pszChildName = mZpoolVdevName(mZfsLib, zh, nvChildren[i], _B_FALSE);
623 Assert(pszChildName);
624 RTCString strDevPath("/dev/dsk/");
625 strDevPath += pszChildName;
626 char szLink[RTPATH_MAX];
627 if (readlink(strDevPath.c_str(), szLink, sizeof(szLink)) != -1)
628 {
629 char *pszStart, *pszEnd;
630 pszStart = strstr(szLink, "/devices/");
631 pszEnd = strrchr(szLink, ':');
632 if (pszStart && pszEnd)
633 {
634 pszStart += 8; // Skip "/devices"
635 *pszEnd = '\0'; // Trim partition
636 list.push_back(physToInstName(pszStart));
637 }
638 }
639 free(pszChildName);
640 }
641 }
642 }
643 mZpoolClose(zh);
644 }
645 }
646 else
647 list.push_back(pathToInstName(it->second.c_str()));
648 return VINF_SUCCESS;
649}
650
651void CollectorSolaris::updateFilesystemMap(void)
652{
653 FILE *fp = fopen("/etc/mnttab", "r");
654 if (fp)
655 {
656 struct mnttab Entry;
657 int rc = 0;
658 resetmnttab(fp);
659 while ((rc = getmntent(fp, &Entry)) == 0)
660 mFsMap[Entry.mnt_mountp] = Entry.mnt_special;
661 fclose(fp);
662 if (rc != -1)
663 LogRel(("Error while reading mnttab: %d\n", rc));
664 }
665}
666
667}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette