void CollectorLinux::addVolumeDependencies(const char *pcszVolume, DiskList& listDisks) { char szVolInfo[RTPATH_MAX]; int rc = RTPathAppPrivateArch(szVolInfo, sizeof(szVolInfo) - sizeof("/" VBOXVOLINFO_NAME " ") - strlen(pcszVolume)); if (RT_FAILURE(rc)) { LogRel(("VolInfo: Failed to get program path, rc=%Rrc\n", rc)); return; } strcat(szVolInfo, "/" VBOXVOLINFO_NAME " "); strcat(szVolInfo, pcszVolume); FILE *fp = popen(szVolInfo, "r"); if (fp) { char szBuf[128]; while (fgets(szBuf, sizeof(szBuf), fp)) if (strncmp(szBuf, RT_STR_TUPLE("dm-"))) listDisks.push_back(RTCString(trimTrailingDigits(szBuf))); else listDisks.push_back(RTCString(trimNewline(szBuf))); pclose(fp); } else listDisks.push_back(RTCString(pcszVolume)); }
int CollectorSolaris::getDiskListByFs(const char *name, DiskList& listUsage, DiskList& listLoad) { FsMap::iterator it = mFsMap.find(name); if (it == mFsMap.end()) return VERR_INVALID_PARAMETER; RTCString strName = it->second.substr(0, it->second.find("/")); if (mZpoolOpen && mZpoolClose && mZpoolGetConfig && !strName.isEmpty()) { zpool_handle_t *zh = mZpoolOpen(mZfsLib, strName.c_str()); if (zh) { unsigned int cChildren = 0; nvlist_t **nvChildren = NULL; nvlist_t *nvRoot = NULL; nvlist_t *nvConfig = mZpoolGetConfig(zh, NULL); if ( !nvlist_lookup_nvlist(nvConfig, ZPOOL_CONFIG_VDEV_TREE, &nvRoot) && !nvlist_lookup_nvlist_array(nvRoot, ZPOOL_CONFIG_CHILDREN, &nvChildren, &cChildren)) { for (unsigned int i = 0; i < cChildren; ++i) { uint64_t fHole = 0; uint64_t fLog = 0; nvlist_lookup_uint64(nvChildren[i], ZPOOL_CONFIG_IS_HOLE, &fHole); nvlist_lookup_uint64(nvChildren[i], ZPOOL_CONFIG_IS_LOG, &fLog); if (!fHole && !fLog) { char *pszChildName = mZpoolVdevName(mZfsLib, zh, nvChildren[i], _B_FALSE); Assert(pszChildName); RTCString strDevPath("/dev/dsk/"); strDevPath += pszChildName; char szLink[RTPATH_MAX]; if (readlink(strDevPath.c_str(), szLink, sizeof(szLink)) != -1) { char *pszStart, *pszEnd; pszStart = strstr(szLink, "/devices/"); pszEnd = strrchr(szLink, ':'); if (pszStart && pszEnd) { pszStart += 8; // Skip "/devices" *pszEnd = '\0'; // Trim partition listUsage.push_back(physToInstName(pszStart)); } } free(pszChildName); } } } mZpoolClose(zh); } } else listUsage.push_back(pathToInstName(it->second.c_str())); listLoad = listUsage; return VINF_SUCCESS; }
int CollectorLinux::getDiskListByFs(const char *pszPath, DiskList& listUsage, DiskList& listLoad) { FILE *mtab = setmntent("/etc/mtab", "r"); if (mtab) { struct mntent *mntent; while ((mntent = getmntent(mtab))) { /* Skip rootfs entry, there must be another root mount. */ if (strcmp(mntent->mnt_fsname, "rootfs") == 0) continue; if (strcmp(pszPath, mntent->mnt_dir) == 0) { char szDevName[128]; char szFsName[1024]; /* Try to resolve symbolic link if necessary. Yes, we access the file system here! */ int rc = RTPathReal(mntent->mnt_fsname, szFsName, sizeof(szFsName)); if (RT_FAILURE(rc)) continue; /* something got wrong, just ignore this path */ /* check against the actual mtab entry, NOT the real path as /dev/mapper/xyz is * often a symlink to something else */ if (!strncmp(mntent->mnt_fsname, RT_STR_TUPLE("/dev/mapper"))) { /* LVM */ getDiskName(szDevName, sizeof(szDevName), mntent->mnt_fsname, false /*=fTrimDigits*/); addVolumeDependencies(szDevName, listUsage); listLoad = listUsage; } else if (!strncmp(szFsName, RT_STR_TUPLE("/dev/md"))) { /* Software RAID */ getDiskName(szDevName, sizeof(szDevName), szFsName, false /*=fTrimDigits*/); listUsage.push_back(RTCString(szDevName)); addRaidDisks(szDevName, listLoad); } else { /* Plain disk partition. Trim the trailing digits to get the drive name */ getDiskName(szDevName, sizeof(szDevName), szFsName, true /*=fTrimDigits*/); listUsage.push_back(RTCString(szDevName)); listLoad.push_back(RTCString(szDevName)); } if (listUsage.empty() || listLoad.empty()) { LogRel(("Failed to retrive disk info: getDiskName(%s) --> %s\n", mntent->mnt_fsname, szDevName)); } break; } } endmntent(mtab); } return VINF_SUCCESS; }
void SummaryWidget::createDiskMaps() { DiskList disks; const Q3CString free = i18n("Free").toLocal8Bit(); const Q3CString used = i18n("Used").toLocal8Bit(); KIconLoader loader; oldScheme = Config::scheme; Config::scheme = (Filelight::MapScheme)2000; for (DiskList::ConstIterator it = disks.begin(), end = disks.end(); it != end; ++it) { Disk const &disk = *it; if (disk.free == 0 && disk.used == 0) continue; QWidget *box = new QWidget(this); box->setLayout(new QVBoxLayout(box)); //box->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum); RadialMap::Widget *map = new MyRadialMap(box); // QString text; QTextOStream(&text) // << "<img src='" << loader.iconPath(disk.icon, KIconLoader::Toolbar) << "'>" // << " " << disk.mount << " " // << "<i>(" << disk.device << ")</i>"; QGridLayout* horizontalLayout = new QGridLayout(box); QLabel *icon = new QLabel(box); icon->setPixmap(KIcon(disk.icon).pixmap(32,32)); horizontalLayout->addWidget(icon); QLabel *label = new QLabel(disk.mount + " (" + disk.device + ")", box); label->setAlignment(Qt::AlignCenter); horizontalLayout->addWidget(label); box->layout()->addWidget(map); box->layout()->addItem(horizontalLayout); layout()->addWidget(box); //box->show(); // will show its children too Directory *tree = new Directory(disk.mount.toLocal8Bit()); tree->append(free, disk.free); tree->append(used, disk.used); map->create(tree); //must be done when visible connect(map, SIGNAL(activated(const KUrl&)), SIGNAL(activated(const KUrl&))); } }
void CollectorLinux::addRaidDisks(const char *pcszDevice, DiskList& listDisks) { FILE *f = fopen("/proc/mdstat", "r"); if (f) { char szBuf[128]; while (fgets(szBuf, sizeof(szBuf), f)) { char *pszBufName = szBuf; char *pszBufData = strchr(pszBufName, ' '); if (!pszBufData) { LogRel(("CollectorLinux::addRaidDisks() failed to parse disk stats: %s\n", szBuf)); continue; } *pszBufData++ = '\0'; if (!strcmp(pcszDevice, pszBufName)) { while (*pszBufData == ':') ++pszBufData; /* Skip delimiter */ while (*pszBufData == ' ') ++pszBufData; /* Skip spaces */ while (RT_C_IS_ALNUM(*pszBufData)) ++pszBufData; /* Skip status */ while (*pszBufData == ' ') ++pszBufData; /* Skip spaces */ while (RT_C_IS_ALNUM(*pszBufData)) ++pszBufData; /* Skip type */ while (*pszBufData != '\0') { while (*pszBufData == ' ') ++pszBufData; /* Skip spaces */ char *pszDisk = pszBufData; while (RT_C_IS_ALPHA(*pszBufData)) ++pszBufData; if (*pszBufData) { *pszBufData++ = '\0'; listDisks.push_back(RTCString(pszDisk)); while (*pszBufData != '\0' && *pszBufData != ' ') ++pszBufData; } else listDisks.push_back(RTCString(pszDisk)); } break; } } fclose(f); } }
void SummaryWidget::createDiskMaps() { DiskList disks; const QCString free = i18n( "Free" ).local8Bit(); const QCString used = i18n( "Used" ).local8Bit(); KIconLoader loader; oldScheme = Config::scheme; Config::scheme = (Filelight::MapScheme)2000; for (DiskList::ConstIterator it = disks.begin(), end = disks.end(); it != end; ++it) { Disk const &disk = *it; if (disk.free == 0 && disk.used == 0) continue; QWidget *box = new QVBox( this ); RadialMap::Widget *map = new MyRadialMap( box ); QString text; QTextOStream( &text ) << "<img src='" << loader.iconPath( disk.icon, KIcon::Toolbar ) << "'>" << " " << disk.mount << " " << "<i>(" << disk.device << ")</i>"; QLabel *label = new QLabel( text, box ); label->setAlignment( Qt::AlignCenter ); label->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Maximum ); box->show(); // will show its children too Directory *tree = new Directory( disk.mount.local8Bit() ); tree->append( free, disk.free ); tree->append( used, disk.used ); map->create( tree ); //must be done when visible connect( map, SIGNAL(activated( const KURL& )), SIGNAL(activated( const KURL& )) ); } }