Browse Source

Add ./tarball_archive/symon-2.86.tar.gz

Wictor Lund 3 years ago
parent
commit
a26e6bf12a

+ 10 - 0
symon/CHANGELOG

@@ -1,3 +1,13 @@
+05/02/2013 - 2.86
+
+   - platform/OpenBSD/sm_proc.c updated to new kinfo_proc interface
+
+   - platform/OpenBSD/sm_io.c hw.disknames was parsed wrong for devices with
+     no uuid (Raphaël Berbain)
+
+   - platform/FreeBSD/sm_smart.c updated to also support atacam (Alexander
+     Sheiko)
+
 18/02/2012 - 2.85
 
    - lib/diskname rewrite -- return possible disknames for Linux and FreeBSD

+ 2 - 2
symon/Makefile.inc

@@ -1,8 +1,8 @@
-V=2.85
+V=2.86
 
 AR?=	ar
 CC?=	cc
-CFLAGS+=-Wall
+CFLAGS+=-Wall -g
 INSTALL?=install
 LORDER?=lorder
 TSORT?=tsort

+ 1 - 1
symon/platform/FreeBSD/Makefile.inc

@@ -1,4 +1,4 @@
-SYMON_LIBS?=-lkvm -ldevstat
+SYMON_LIBS?=-lkvm -ldevstat -lcam
 SYMUX_LIBS?=-lm
 
 SYSCONFDIR?=${PREFIX}/etc

+ 104 - 28
symon/platform/FreeBSD/sm_smart.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 Willem Dijkstra
+ * Copyright (c) 2009-2013 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,6 +38,9 @@
 #include <strings.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <camlib.h>
+#include <cam/cam_ccb.h>
 
 #include "conf.h"
 #include "data.h"
@@ -50,14 +53,19 @@
 #ifndef HAS_ATA_SMART_CMD
 #define ATA_SMART_CMD 0xb0
 #endif
+
+#define MSG_SIMPLE_Q_TAG 0x20
+
 /* per drive storage structure */
 struct smart_device {
+    struct smart_values data;
+    struct ata_ioc_request cmd;
+    struct cam_device *cd;
+    struct ccb_ataio ccb;
     char name[MAX_PATH_LEN];
     int fd;
     int type;
     int failed;
-    struct ata_ioc_request cmd;
-    struct smart_values data;
 };
 
 static struct smart_device *smart_devs = NULL;
@@ -70,7 +78,9 @@ init_smart(struct stream *st)
     int fd;
     int i;
     char drivename[MAX_PATH_LEN];
-    struct ata_ioc_request *p;
+    struct ata_ioc_request *pa;
+    struct cam_device *cd;
+    struct ccb_ataio *pc;
 
     if (sizeof(struct smart_values) != DISK_BLOCK_LEN) {
         fatal("smart: internal error: smart values structure is broken");
@@ -81,13 +91,18 @@ init_smart(struct stream *st)
     }
 
     initdisknamectx(&c, st->arg, drivename, sizeof(drivename));
+
     fd = -1;
+    cd = NULL;
 
-    while (nextdiskname(&c))
+    while (nextdiskname(&c)) {
+        if ((cd = cam_open_device(drivename, O_RDWR)) != NULL)
+            break;
         if ((fd = open(drivename, O_RDONLY, O_NONBLOCK)) != -1)
             break;
+    }
 
-    if (fd < 0)
+    if ((fd < 0) && (cd == NULL))
         fatal("smart: cannot open '%.200s'", st->arg);
 
     /* look for drive in our global table */
@@ -111,26 +126,57 @@ init_smart(struct stream *st)
     /* rewire all bufferlocations, as our addresses may have changed */
     for (i = 0; i <= smart_cur; i++) {
         smart_devs[i].cmd.data = (caddr_t)&smart_devs[i].data;
+        smart_devs[i].ccb.data_ptr = (u_int8_t *)&smart_devs[i].data;
     }
 
     /* store drivename in new block */
     snprintf(smart_devs[smart_cur].name, MAX_PATH_LEN, "%s", drivename);
 
-    /* populate ata command header */
-    p = &smart_devs[smart_cur].cmd;
-    p->u.ata.command = ATA_SMART_CMD;
-    p->timeout = SMART_TIMEOUT;
-    p->u.ata.feature = ATA_SMART_READ_VALUES;
-    p->u.ata.lba = SMART_CYLINDER << 8;
-    p->flags = ATA_CMD_READ;
-    p->count = DISK_BLOCK_LEN;
-
     /* store filedescriptor to device */
-    smart_devs[smart_cur].fd = fd;
+    if (fd > 0) {
+        smart_devs[smart_cur].fd = fd;
+
+        /* populate ata command header */
+        pa = &smart_devs[smart_cur].cmd;
+        pa->u.ata.command = ATA_SMART_CMD;
+        pa->timeout = SMART_TIMEOUT;
+        pa->u.ata.feature = ATA_SMART_READ_VALUES;
+        pa->u.ata.lba = SMART_CYLINDER << 8;
+        pa->flags = ATA_CMD_READ;
+        pa->count = DISK_BLOCK_LEN;
+    } else if (cd) {
+        smart_devs[smart_cur].cd = cd;
+
+        /* populate cam control block */
+        pc = &smart_devs[smart_cur].ccb;
+        cam_fill_ataio(pc,
+                       0,                            /* retries */
+                       NULL,                         /* completion callback */
+                       CAM_DIR_IN,                   /* flags */
+                       MSG_SIMPLE_Q_TAG,             /* tag_action */
+                       (u_int8_t *)&smart_devs[smart_cur].data,
+                       DISK_BLOCK_LEN,
+                       SMART_TIMEOUT);               /* timeout (s) */
+
+        /* disable queue freeze on error */
+        pc->ccb_h.flags |= CAM_DEV_QFRZDIS;
+
+        /* populate ata command header */
+        pc->cmd.flags = CAM_ATAIO_NEEDRESULT;
+        pc->cmd.command = ATA_SMART_CMD;
+        pc->cmd.features = ATA_SMART_READ_VALUES;
+        pc->cmd.lba_low = 0;
+        pc->cmd.lba_mid = SMART_CYLINDER & 0xff;
+        pc->cmd.lba_high = (SMART_CYLINDER >> 8) & 0xff;
+        pc->cmd.lba_low_exp = 0;
+        pc->cmd.lba_mid_exp = 0;
+        pc->cmd.lba_high_exp = 0;
+        pc->cmd.sector_count = 1;
+        pc->cmd.sector_count_exp = 0;
+    }
 
     /* store smart dev entry in stream to facilitate quick get */
     st->parg.smart = smart_cur;
-
     smart_cur++;
 
     info("started module smart(%.200s)", st->arg);
@@ -142,20 +188,36 @@ gets_smart()
     int i;
 
     for (i = 0; i < smart_cur; i++) {
-        if (ioctl(smart_devs[i].fd, IOCATAREQUEST, &smart_devs[i].cmd) || smart_devs[i].cmd.error) {
-            warning("smart: ioctl for drive '%s' failed: %d",
-                    &smart_devs[i].name, errno);
-            smart_devs[i].failed = 1;
-        }
+        if (smart_devs[i].fd > 0) {
+            if (ioctl(smart_devs[i].fd, IOCATAREQUEST, &smart_devs[i].cmd) || smart_devs[i].cmd.error) {
+                warning("smart: ioctl for drive '%s' failed: %s",
+                        &smart_devs[i].name, strerror(errno));
+                smart_devs[i].failed = 1;
+                continue;
+            }
 
-        /* Some drives do not calculate the smart checksum correctly;
-         * additional code that identifies these drives would increase our
-         * footprint and the amount of datajuggling we need to do; we would
-         * rather ignore the checksums.
-         */
+            /* Some drives do not calculate the smart checksum correctly;
+             * additional code that identifies these drives would increase our
+             * footprint and the amount of datajuggling we need to do; we would
+             * rather ignore the checksums.
+             */
 
-        smart_devs[i].failed = 0;
+            smart_devs[i].failed = 0;
+        } else if (smart_devs[i].cd != NULL) {
+            if ((cam_send_ccb(smart_devs[i].cd, (union ccb *)&smart_devs[i].ccb) < 0) || smart_devs[i].ccb.res.error) {
+                warning("smart: ccb for drive '%s' failed: %s",
+                        &smart_devs[i].name,
+                        cam_error_string(smart_devs[i].cd, (union ccb *)&smart_devs[i].ccb,
+                                         (char *)&smart_devs[i].data, DISK_BLOCK_LEN,
+                                         CAM_ESF_ALL, CAM_EPF_ALL));
+                smart_devs[i].failed = 1;
+                continue;
+            }
+
+            smart_devs[i].failed = 0;
+        }
     }
+
     return;
 }
 
@@ -168,6 +230,20 @@ get_smart(char *symon_buf, int maxlen, struct stream *st)
         (!smart_devs[st->parg.smart].failed))
     {
         smart_parse(&smart_devs[st->parg.smart].data, &sr);
+        debug("%x %x %x %x %x %x %x %x %x %x %x %x",
+                      sr.read_error_rate,
+                      sr.reallocated_sectors,
+                      sr.spin_retries,
+                      sr.air_flow_temp,
+                      sr.temperature,
+                      sr.reallocations,
+                      sr.current_pending,
+                      sr.uncorrectables,
+                      sr.soft_read_error_rate,
+                      sr.g_sense_error_rate,
+                      sr.temperature2,
+                      sr.free_fall_protection);
+
         return snpack(symon_buf, maxlen, st->arg, MT_SMART,
                       sr.read_error_rate,
                       sr.reallocated_sectors,

+ 4 - 0
symon/platform/OpenBSD/conf.sh

@@ -10,6 +10,10 @@ case `grep -csq KERN_PROC2 /usr/include/sys/sysctl.h` in
 1)	echo "#define HAS_KERN_PROC2	1" ;;
 0)	echo "#undef HAS_KERN_PROC2" ;;
 esac;
+case `grep -csq kp_proc /usr/include/sys/sysctl.h` in
+1)	echo "#define HAS_KERN_KPPROC	1" ;;
+0)	echo "#undef HAS_KERN_KPPROC" ;;
+esac;
 case `grep -csq "struct sensordev" /usr/include/sys/sensors.h` in
 1)	echo "#define HAS_SENSORDEV	1" ;;
 0)	echo "#undef HAS_SENSORDEV" ;;

+ 2 - 3
symon/platform/OpenBSD/sm_io.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001-2004 Willem Dijkstra
+ * Copyright (c) 2001-2012 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -134,8 +134,7 @@ gets_io()
         }
         if ((*p == ':') && (*p+1 != '\0')) {
             *p = '\0';
-            p++;
-            io_dkuids[io_dks] = p;
+            io_dkuids[io_dks] = p+1;
 	}
         p++;
     }

+ 28 - 20
symon/platform/OpenBSD/sm_proc.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001-2010 Willem Dijkstra
+ * Copyright (c) 2001-2012 Willem Dijkstra
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,12 +51,23 @@
 
 #define pagetob(size) (((u_int32_t)size) << proc_pageshift)
 
-/* Globals for this module start with proc_ */
 #ifdef HAS_KERN_PROC2
-static struct kinfo_proc2 *proc_ps = NULL;
+#define KINFO_NEWAPI
+#define KINFO_MIB KERN_PROC2
+#define KINFO_STRUCT kinfo_proc2
+#else
+#ifndef HAS_KERN_KPPROC
+#define KINFO_NEWAPI
+#define KINFO_MIB KERN_PROC
+#define KINFO_STRUCT kinfo_proc
 #else
-static struct kinfo_proc *proc_ps = NULL;
+#undef KINFO_NEWAPI
+#define KINFO_STRUCT kinfo_proc
 #endif
+#endif
+
+/* Globals for this module start with proc_ */
+static struct KINFO_STRUCT *proc_ps = NULL;
 static int proc_max = 0;
 static int proc_cur = 0;
 static int proc_stathz = 0;
@@ -68,6 +79,7 @@ static int proc_pagesize;
 typedef long pctcpu;
 #define pctdouble(p) ((double)(p) / FIXED_PCTCPU)
 
+
 void
 gets_proc()
 {
@@ -84,39 +96,39 @@ gets_proc()
               __FILE__, __LINE__);
     }
 
-#ifdef HAS_KERN_PROC2
+#ifdef KINFO_NEWAPI
     /* increase buffers if necessary */
     if (procs > proc_max) {
         proc_max = (procs * 5) / 4;
 
         if (proc_max > SYMON_MAX_DOBJECTS) {
-            fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc2 structures",
+            fatal("%s:%d: dynamic object limit (%d) exceeded for kinfo_proc structures",
                   __FILE__, __LINE__, SYMON_MAX_DOBJECTS);
         }
 
-        proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct kinfo_proc2));
+        proc_ps = xrealloc(proc_ps, proc_max * sizeof(struct KINFO_STRUCT));
     }
 
     /* read data in anger */
     mib[0] = CTL_KERN;
-    mib[1] = KERN_PROC2;
+    mib[1] = KINFO_MIB;
     mib[2] = KERN_PROC_KTHREAD;
     mib[3] = 0;
-    mib[4] = sizeof(struct kinfo_proc2);
+    mib[4] = sizeof(struct KINFO_STRUCT);
     mib[5] = proc_max;
-    size = proc_max * sizeof(struct kinfo_proc2);
+    size = proc_max * sizeof(struct KINFO_STRUCT);
     if (sysctl(mib, 6, proc_ps, &size, NULL, 0) < 0) {
         warning("proc probe cannot get processes");
         proc_cur = 0;
         return;
     }
 
-    if (size % sizeof(struct kinfo_proc2) != 0) {
-        warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc2) %d",
-                size, sizeof(struct kinfo_proc2));
+    if (size % sizeof(struct KINFO_STRUCT) != 0) {
+        warning("proc size mismatch: got %d bytes, not dividable by sizeof(kinfo_proc) %d",
+                size, sizeof(struct KINFO_STRUCT));
         proc_cur = 0;
     } else {
-        proc_cur = size / sizeof(struct kinfo_proc2);
+        proc_cur = size / sizeof(struct KINFO_STRUCT);
     }
 #else
     /* increase buffers if necessary */
@@ -187,11 +199,7 @@ int
 get_proc(char *symon_buf, int maxlen, struct stream *st)
 {
     int i;
-#ifdef HAS_KERN_PROC2
-    struct kinfo_proc2 *pp;
-#else
-    struct kinfo_proc *pp;
-#endif
+    struct KINFO_STRUCT *pp;
     u_quad_t  cpu_ticks = 0;
     u_quad_t  cpu_uticks = 0;
     u_quad_t  cpu_iticks = 0;
@@ -204,7 +212,7 @@ get_proc(char *symon_buf, int maxlen, struct stream *st)
     int n = 0;
 
     for (pp = proc_ps, i = 0; i < proc_cur; pp++, i++) {
-#ifdef HAS_KERN_PROC2
+#ifdef KINFO_NEWAPI
          if (strncmp(st->arg, pp->p_comm, strlen(st->arg)) == 0) {
              /* cpu time - accumulated */
              cpu_uticks += pp->p_uticks;  /* user */