Merge branch 'collectd-5.4' into collectd-5.5
[collectd.git] / src / zfs_arc.c
index fb61dcc..86e7d4c 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (C) 2012  Aurelien Rougemont
  * Copyright (C) 2013  Xin Li
  * Copyright (C) 2014  Marc Fournier
+ * Copyright (C) 2014  Wilfried Goesgens
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -23,6 +24,7 @@
  *   Aurelien Rougemont <beorn at gandi.net>
  *   Xin Li <delphij at FreeBSD.org>
  *   Marc Fournier <marc.fournier at camptocamp.com>
+ *   Wilfried Goesgens <dothebart at citadel.org>
  **/
 
 #include "collectd.h"
@@ -51,7 +53,7 @@ static long long get_zfs_value(kstat_t *zfs_stats  __attribute__((unused)),
                return (-1);
        }
 
-       return ((long long int)e->value);
+       return (*(long long int*)e->value);
 }
 
 #elif !defined(__FreeBSD__) // Solaris
@@ -184,7 +186,7 @@ static int za_read (void)
                return (-1);
        }
 
-       len = read_file_contents (ZOL_ARCSTATS_FILE, file_contents, sizeof(file_contents));
+       len = read_file_contents (ZOL_ARCSTATS_FILE, file_contents, sizeof(file_contents) - 1);
        if (len > 1)
        {
 
@@ -206,7 +208,12 @@ static int za_read (void)
                {
                        llentry_t *e;
                        llvalues = malloc(sizeof(long long int) * i);
-                       i = 0;
+                       if (llvalues == NULL)
+                       {
+                               ERROR ("zfs_arc plugin: `malloc' failed.");
+                               return (-1);
+                       }
+                       int j = 0;
 
                        pnl = file_contents;
                        while (pnl != NULL)
@@ -218,9 +225,9 @@ static int za_read (void)
                                numfields = strsplit (pnl, fields, 4);
                                if (numfields == 3)
                                {
-                                       llvalues[i] = atoll (fields[2]);
+                                       llvalues[j] = atoll (fields[2]);
 
-                                       e = llentry_create (fields[0], (void *)llvalues[i]);
+                                       e = llentry_create (fields[0], &llvalues[j]);
                                        if (e == NULL)
                                        {
                                                ERROR ("zfs_arc plugin: `llentry_create' failed.");
@@ -229,6 +236,7 @@ static int za_read (void)
                                        {
                                                llist_append (ksp, e);
                                        }
+                                       j++;
                                }
                                pnl = pnnl;
                                if (pnl != NULL)
@@ -248,7 +256,14 @@ static int za_read (void)
 
        /* Sizes */
        za_read_gauge (ksp, "size",    "cache_size", "arc");
-       za_read_gauge (ksp, "l2_size", "cache_size", "L2");
+
+       /* The "l2_size" value has disappeared from Solaris some time in
+        * early 2013, and has only reappeared recently in Solaris 11.2.
+        * Stop trying if we ever fail to read it, so we don't spam the log.
+        */
+       static int l2_size_avail = 1;
+       if (l2_size_avail && za_read_gauge (ksp, "l2_size", "cache_size", "L2") != 0)
+               l2_size_avail = 0;
 
        /* Operations */
        za_read_derive (ksp, "deleted",  "cache_operation", "deleted");