From owner-p4-projects@FreeBSD.ORG Sun Jul 31 22:54:32 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A9AA416A421; Sun, 31 Jul 2005 22:54:31 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8100816A41F for ; Sun, 31 Jul 2005 22:54:31 +0000 (GMT) (envelope-from soc-victor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 313A643D48 for ; Sun, 31 Jul 2005 22:54:31 +0000 (GMT) (envelope-from soc-victor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j6VMsVPl018654 for ; Sun, 31 Jul 2005 22:54:31 GMT (envelope-from soc-victor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6VMsUSL018651 for perforce@freebsd.org; Sun, 31 Jul 2005 22:54:30 GMT (envelope-from soc-victor@freebsd.org) Date: Sun, 31 Jul 2005 22:54:30 GMT Message-Id: <200507312254.j6VMsUSL018651@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-victor@freebsd.org using -f From: Victor Cruceru To: Perforce Change Reviews Cc: Subject: PERFORCE change 81259 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jul 2005 22:54:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=81259 Change 81259 by soc-victor@soc-victor_82.76.158.176 on 2005/07/31 22:53:39 hrDiskStorageTable step #3: added the md(4) support. The issue with removable media (CD, DVD, CF) not solved yet. Blocking is bad .... Affected files ... .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#15 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#3 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#14 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#18 edit Differences ... ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#15 (text+ko) ==== @@ -38,7 +38,7 @@ WARNS?= 6 #Not having NDEBUG defined will enable assertions and a lot of output on stderr -#CFLAGS+= -DNDEBUG +CFLAGS+= -DNDEBUG XSYM= host hrStorageOther hrStorageRam hrStorageVirtualMemory \ hrStorageFixedDisk hrStorageRemovableDisk hrStorageFloppyDisk \ hrStorageCompactDisc hrStorageRamDisk hrStorageFlashMemory \ ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#3 (text+ko) ==== @@ -46,6 +46,7 @@ #include #include #include +#include extern struct hrDeviceTblEntry * @@ -246,11 +247,9 @@ struct ata_cmd iocmd; int maxunit, unit, i; if ( hrState_g.ata_fd < 0 ){ - if ((hrState_g.ata_fd = open("/dev/ata", O_RDWR)) < 0) { - syslog(LOG_ERR, "open /dev/ata failed:%m"); - return; - } + return; } + iocmd.cmd = ATAGMAXCHANNEL; if (ioctl(hrState_g.ata_fd, IOCATA, &iocmd) < 0) { syslog(LOG_ERR, "ioctl(ATAGMAXCHANNEL) failed: %m"); @@ -277,7 +276,7 @@ entry = hrDeviceTblEntry_find_by_name(u_iocmd.u.param.name[i]); if (entry == NULL) { HR_DPRINTF((stderr, - "hrDiskStorageTable; disk %s not in hrDeviceTable\n", + "hrDiskStorageTable: ATA disk %s not in hrDeviceTable\n", u_iocmd.u.param.name[i] )); entry = hrDeviceTblEntry_create(u_iocmd.u.param.name[i]); assert(entry != NULL); @@ -297,7 +296,7 @@ }else{ HR_DPRINTF((stderr, - "hrDiskStorageTable; disk %s already in hrDeviceTable\n", + "hrDiskStorageTable; ATA disk %s already in hrDeviceTable\n", u_iocmd.u.param.name[i] )); } entry->flags |= HR_DEVICE_IMMUTABLE; @@ -346,7 +345,102 @@ ATA_DONE: return; } + +static +void +hrDiskStorage_OS_get_MD_disks_v(void) { + struct hrDeviceTblEntry *entry = NULL; + struct hrDiskStorageTblEntry *disk_entry = NULL; + + struct md_ioctl mdio; + int unit = 0; + + + if ( hrState_g.md_fd < 0 ){ + return; + } + memset(&mdio, 0, sizeof(mdio)); + mdio.md_version = MDIOVERSION; + mdio.md_options = MD_AUTOUNIT; + if (ioctl( hrState_g.md_fd, MDIOCLIST, &mdio) < 0) { + syslog(LOG_ERR, "ioctl(/dev/%s) failed: %m", MDCTL_NAME); + return; + } + for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) { + char mddev[64] = ""; + snprintf(mddev, sizeof(mddev) - 1, "%s%d", MD_NAME, mdio.md_pad[unit + 1]); + struct md_ioctl u_mdio; + + memset(&u_mdio, 0, sizeof(u_mdio)); + u_mdio.md_version = MDIOVERSION; + u_mdio.md_unit = mdio.md_pad[unit + 1]; + + if (ioctl( hrState_g.md_fd, MDIOCQUERY, &u_mdio) < 0) { + syslog(LOG_ERR, "ioctl(/dev/%s, MDIOCQUERY) [%s] failed: %m", MDCTL_NAME, mddev); + continue; + } + + + /*first check if this disk is in hrDeiveTable*/ + entry = hrDeviceTblEntry_find_by_name(mddev); + if (entry == NULL) { + HR_DPRINTF((stderr, + "hrDiskStorageTable; MD %s not in hrDeviceTable\n", + mddev )); + entry = hrDeviceTblEntry_create(mddev); + assert(entry != NULL); + if (entry == NULL) { + continue; + } + + entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage; + entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/ + entry->status = DR_RUNNING; + entry->errors = 0; /*FIX ME*/ + snprintf(entry->descr, sizeof(entry->descr) - 1, + "%s: Memory Disk ", + mddev); + + }else{ + HR_DPRINTF((stderr, + "hrDiskStorageTable; MD %s already in hrDeviceTable\n", + mddev )); + } + entry->flags |= HR_DEVICE_IMMUTABLE; + entry->flags |= HR_DEVICE_FOUND; + + /*Then check hrDiskStorage table for this device*/ + disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index); + if (disk_entry == NULL) { + disk_entry = hrDiskStorageEntry_create(entry); + assert(disk_entry != NULL); + if (disk_entry == NULL) { + continue; + } + if ((u_mdio.md_options & MD_READONLY) == MD_READONLY) { + disk_entry->access = DS_READ_ONLY; + } else { + disk_entry->access = DS_READ_WRITE; + } + memset(&disk_entry->dev_name[0], 0, sizeof(disk_entry->dev_name)); + strncpy(disk_entry->dev_name, mddev, sizeof(disk_entry->dev_name)-1); + + disk_entry->media = DSM_RAMDISK; + disk_entry->removable = SNMP_FALSE; + + + } + disk_entry->flags |= HR_DISKSTORAGE_FOUND; + disk_entry->flags |= HR_DISKSTORAGE_MD; + disk_entry->capacity = u_mdio.md_size / 2; + + disk_entry->r_tick = this_tick; + + } +} + + static void hrDiskStorage_OS_get_disks_v(void) { @@ -424,7 +518,8 @@ assert(disk_entry != NULL); disk_entry->flags |= HR_DISKSTORAGE_FOUND; - if ( (disk_entry->flags & HR_DISKSTORAGE_ATA) == HR_DISKSTORAGE_ATA ) { + if ((disk_entry->flags & HR_DISKSTORAGE_ATA) == HR_DISKSTORAGE_ATA || + (disk_entry->flags & HR_DISKSTORAGE_MD) == HR_DISKSTORAGE_MD) { /*ATA detection is running before this one, so don't waste the time here */ continue; } @@ -500,7 +595,7 @@ } hrDiskStorage_OS_get_ATA_disks_v(); /*this must be called first !*/ - + hrDiskStorage_OS_get_MD_disks_v(); hrDiskStorage_OS_get_disks_v(); /* ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#14 (text+ko) ==== @@ -28,6 +28,22 @@ * * Host Resources MIB implementation for SNMPd. */ + +/* This C file contains code developed by Poul-Henning Kamp + * under the following license: + */ + /* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sbin/mdconfig/mdconfig.c,v 1.33.2.1 2004/09/14 03:32:21 jmg Exp $ + * + */ + #include "hostres_snmp.h" #include "hostres_oid.h" #include "hostres_tree.h" @@ -38,6 +54,10 @@ #include #include #include +#include +#include +#include +#include /*internal id got after we'll register this module with the agent */ @@ -54,13 +74,49 @@ struct hostres_state hrState_g; +static +void +mdmaybeload(void) +{ + struct module_stat mstat; + int fileid, modid; + const char *name; + char *cp; + + name = MD_MODNAME; + /* scan files in kernel */ + mstat.version = sizeof(struct module_stat); + for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { + /* scan modules in file */ + for (modid = kldfirstmod(fileid); modid > 0; + modid = modfnext(modid)) { + if (modstat(modid, &mstat) < 0) + continue; + /* strip bus name if present */ + if ((cp = strchr(mstat.name, '/')) != NULL) { + cp++; + } else { + cp = mstat.name; + } + /* already loaded? */ + if (!strcmp(name, cp)) + return; + } + } + /* not present, we should try to load it */ + if (kldload(name) < 0) { + syslog(LOG_ERR,"kldload(%s) failed: %m\n", name); + } +} + + /* * HOST RESOURCES mib module initialization hook. * Returns 0 on success, < 0 on error */ static int hostres_init(struct lmodule * mod, int argc __unused, char *argv[] __unused) { - + char mddev[32] = ""; hostres_module = mod; @@ -91,7 +147,18 @@ return (-1); /*error*/ } hrState_g.ata_fd = -1; - + if ((hrState_g.ata_fd = open("/dev/ata", O_RDWR)) < 0) { + syslog(LOG_ERR, "open /dev/ata failed:%m"); + } + + mdmaybeload(); + + hrState_g.md_fd = -1; + snprintf(mddev, sizeof(mddev) - 1, "/dev/%s", MDCTL_NAME); + if ((hrState_g.md_fd = open(mddev, O_RDWR)) < 0) { + syslog(LOG_ERR, "open %s failed: %m", mddev); + } + hrState_g.dev_root = NULL; hrState_g.hrSWOSIndex = 0; @@ -242,6 +309,13 @@ } hrState_g.ata_fd = -1; } + if (hrState_g.md_fd > 0) { + if (close(hrState_g.md_fd) < 0) { + syslog(LOG_ERR,"close (/dev/mdctl) failed: %m"); + } + hrState_g.md_fd = -1; + } + if( host_registration_id > 0){ or_unregister(host_registration_id); } ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#18 (text+ko) ==== @@ -257,6 +257,7 @@ /*next items are not from the SNMP mib table, only to be used internally*/ #define HR_DISKSTORAGE_FOUND 0x001 #define HR_DISKSTORAGE_ATA 0x002 /*belongs to the ATA subsystem*/ +#define HR_DISKSTORAGE_MD 0x004 /*it is a MD (memory disk) */ uint32_t flags; uint64_t r_tick; u_char dev_name[32]; /*device name, i.e. "ad4" or "acd0"*/ @@ -413,6 +414,7 @@ char* disk_list; /*returned by sysctl("kern.disks")*/ size_t disk_list_len; int ata_fd; /* fd for "/dev/ata"*/ + int md_fd; /* fd for "/dev/mdctl"*/ };