X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnfs.c;h=4285d765e6ebfe9ddbb42854d8808328e08c6503;hb=01701c370a45f979a7562897a375a5822d10cf75;hp=5c6f620781c59b4c9b284a2f3808a858fa8d4b1f;hpb=99d7118d9ec6fd9b2907cef30bfa91c72b3a5826;p=collectd.git diff --git a/src/nfs.c b/src/nfs.c index 5c6f6207..4285d765 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -1,6 +1,7 @@ /** * collectd - src/nfs.c * Copyright (C) 2005,2006 Jason Pepas + * Copyright (C) 2012,2013 Florian Forster * * 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 @@ -17,7 +18,7 @@ * * Authors: * Jason Pepas - * Florian octo Forster + * Florian octo Forster * Cosmin Ioiart **/ @@ -170,6 +171,160 @@ static const char *nfs4_procedures_names[] = static size_t nfs4_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_procedures_names); #endif +#if KERNEL_LINUX +static const char *nfs4_server40_procedures_names[] = +{ + "null", + "compound", + "reserved", + "access", + "close", + "commit", + "create", + "delegpurge", + "delegreturn", + "getattr", + "getfh", + "link", + "lock", + "lockt", + "locku", + "lookup", + "lookupp", + "nverify", + "open", + "openattr", + "open_confirm", + "open_downgrade", + "putfh", + "putpubfh", + "putrootfh", + "read", + "readdir", + "readlink", + "remove", + "rename", + "renew", + "restorefh", + "savefh", + "secinfo", + "setattr", + "setclientid", + "setcltid_confirm", + "verify", + "write", + "release_lockowner" +}; + +static size_t nfs4_server40_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_server40_procedures_names); + +static const char *nfs4_server41_procedures_names[] = +{ + "backchannel_ctl", + "bind_conn_to_session", + "exchange_id", + "create_session", + "destroy_session", + "free_stateid", + "get_dir_delegation", + "getdeviceinfo", + "getdevicelist", + "layoutcommit", + "layoutget", + "layoutreturn", + "secinfo_no_name", + "sequence", + "set_ssv", + "test_stateid", + "want_delegation", + "destroy_clientid", + "reclaim_complete", +}; + +static size_t nfs4_server41_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_server41_procedures_names); + +#define NFS4_SERVER40_NUM_PROC ( \ + STATIC_ARRAY_SIZE (nfs4_server40_procedures_names) ) + +#define NFS4_SERVER41_NUM_PROC ( \ + STATIC_ARRAY_SIZE (nfs4_server40_procedures_names) + \ + STATIC_ARRAY_SIZE (nfs4_server41_procedures_names) ) + +#define NFS4_SERVER_MAX_PROC (NFS4_SERVER41_NUM_PROC) + +static const char *nfs4_client40_procedures_names[] = +{ + "null", + "read", + "write", + "commit", + "open", + "open_confirm", + "open_noattr", + "open_downgrade", + "close", + "setattr", + "fsinfo", + "renew", + "setclientid", + "setclientid_confirm", + "lock", + "lockt", + "locku", + "access", + "getattr", + "lookup", + "lookupp", + "remove", + "rename", + "link", + "symlink", + "create", + "pathconf", + "statfs", + "readlink", + "readdir", + "server_caps", + "delegreturn", + "getacl", + "setacl", + "fs_locations", /* |35| 2.6.18 */ + "release_lockowner", /* |42| 2.6.36 */ + "secinfo", /* |46| 2.6.39 */ + "fsid_present" /* |54| 3.13 */ +}; + +static const char *nfs4_client41_procedures_names[] = +{ + "exchange_id", /* |40| 2.6.30 */ + "create_session", /* |40| 2.6.30 */ + "destroy_session", /* |40| 2.6.30 */ + "sequence", /* |40| 2.6.30 */ + "get_lease_time", /* |40| 2.6.30 */ + "reclaim_complete", /* |41| 2.6.33 */ + "layoutget", /* |44| 2.6.37 */ + "getdeviceinfo", /* |44| 2.6.37 */ + "layoutcommit", /* |46| 2.6.39 */ + "layoutreturn", /* |47| 3.0 */ + "secinfo_no_name", /* |51| 3.1 */ + "test_stateid", /* |51| 3.1 */ + "free_stateid", /* |51| 3.1 */ + "getdevicelist", /* |51| 3.1 */ + "bind_conn_to_session", /* |53| 3.5 */ + "destroy_clientid" /* |53| 3.5 */ +}; + +#define NFS4_CLIENT40_NUM_PROC ( \ + STATIC_ARRAY_SIZE (nfs4_client40_procedures_names) ) + +#define NFS4_CLIENT41_NUM_PROC ( \ + STATIC_ARRAY_SIZE (nfs4_client40_procedures_names) + \ + STATIC_ARRAY_SIZE (nfs4_client41_procedures_names) ) + +#define NFS4_CLIENT_MAX_PROC (NFS4_CLIENT41_NUM_PROC) + +#endif + #if HAVE_LIBKSTAT extern kstat_ctl_t *kc; static kstat_t *nfs2_ksp_client; @@ -180,8 +335,6 @@ static kstat_t *nfs4_ksp_client; static kstat_t *nfs4_ksp_server; #endif -/* Possibly TODO: NFSv4 statistics */ - #if KERNEL_LINUX static int nfs_init (void) { @@ -251,14 +404,27 @@ static void nfs_procedures_submit (const char *plugin_instance, } /* void nfs_procedures_submit */ #if KERNEL_LINUX -static int nfs_submit_fields (int nfs_version, const char *instance, - char **fields, size_t fields_num, - const char **proc_names, size_t proc_names_num) +static void nfs_submit_fields (int nfs_version, const char *instance, + char **fields, size_t fields_num, const char **proc_names) { char plugin_instance[DATA_MAX_NAME_LEN]; value_t values[fields_num]; size_t i; + ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s", + nfs_version, instance); + + for (i = 0; i < fields_num; i++) + (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE); + + nfs_procedures_submit (plugin_instance, proc_names, values, + fields_num); +} + +static int nfs_submit_fields_safe (int nfs_version, const char *instance, + char **fields, size_t fields_num, + const char **proc_names, size_t proc_names_num) +{ if (fields_num != proc_names_num) { WARNING ("nfs plugin: Wrong number of fields for " @@ -268,14 +434,121 @@ static int nfs_submit_fields (int nfs_version, const char *instance, return (EINVAL); } - ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s", - nfs_version, instance); + nfs_submit_fields (nfs_version, instance, fields, fields_num, + proc_names); - for (i = 0; i < proc_names_num; i++) - (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE); + return (0); +} - nfs_procedures_submit (plugin_instance, proc_names, values, - proc_names_num); +static int nfs_submit_nfs4_server (const char *instance, char **fields, + size_t fields_num) +{ + static int suppress_warning = 0; + + if (fields_num != NFS4_SERVER40_NUM_PROC && + fields_num != NFS4_SERVER41_NUM_PROC) + { + if (!suppress_warning) + { + WARNING ("nfs plugin: Unexpected number of fields for " + "NFSv4 %s statistics: %zu. ", + instance, fields_num); + } + + if (fields_num > NFS4_SERVER_MAX_PROC) + { + fields_num = NFS4_SERVER_MAX_PROC; + suppress_warning = 1; + } + else + { + return (EINVAL); + } + } + + nfs_submit_fields (4, instance, fields, + nfs4_server40_procedures_names_num, + nfs4_server40_procedures_names); + + if (fields_num >= NFS4_SERVER41_NUM_PROC) + { + fields += nfs4_server40_procedures_names_num; + + nfs_submit_fields (4, instance, fields, + nfs4_server41_procedures_names_num, + nfs4_server41_procedures_names); + } + + return (0); +} + +static int nfs_submit_nfs4_client (const char *instance, char **fields, + size_t fields_num) +{ + size_t proc40_names_num, proc41_names_num; + + static int suppress_warning = 0; + + switch (fields_num) + { + case 34: + case 35: + case 36: + case 37: + case 38: + /* 4.0-only configuration */ + proc40_names_num = fields_num; + break; + case 40: + case 41: + proc40_names_num = 35; + break; + case 42: + case 44: + proc40_names_num = 36; + case 46: + case 47: + case 51: + case 53: + proc40_names_num = 37; + break; + case 54: + proc40_names_num = 38; + break; + default: + if (!suppress_warning) + { + WARNING ("nfs plugin: Unexpected number of " + "fields for NFSv4 %s " + "statistics: %zu. ", + instance, fields_num); + } + + if (fields_num > 34) + { + /* safe fallback to basic nfs40 procedures */ + fields_num = 34; + proc40_names_num = 34; + + suppress_warning = 1; + } + else + { + return (EINVAL); + } + } + + nfs_submit_fields (4, instance, fields, proc40_names_num, + nfs4_client40_procedures_names); + + if (fields_num > proc40_names_num) + { + proc41_names_num = fields_num - proc40_names_num; + fields += proc40_names_num; + + nfs_submit_fields (4, instance, fields,proc41_names_num, + nfs4_client41_procedures_names); + } return (0); } @@ -284,7 +557,7 @@ static void nfs_read_linux (FILE *fh, char *inst) { char buffer[1024]; - char *fields[48]; + char *fields[64]; int fields_num = 0; if (fh == NULL) @@ -300,25 +573,37 @@ static void nfs_read_linux (FILE *fh, char *inst) if (strcmp (fields[0], "proc2") == 0) { - nfs_submit_fields (/* version = */ 2, inst, + nfs_submit_fields_safe (/* version = */ 2, inst, fields + 2, (size_t) (fields_num - 2), nfs2_procedures_names, nfs2_procedures_names_num); } else if (strncmp (fields[0], "proc3", 5) == 0) { - nfs_submit_fields (/* version = */ 3, inst, + nfs_submit_fields_safe (/* version = */ 3, inst, fields + 2, (size_t) (fields_num - 2), nfs3_procedures_names, nfs3_procedures_names_num); } + else if (strcmp (fields[0], "proc4ops") == 0) + { + if (inst[0] == 's') + nfs_submit_nfs4_server (inst, fields + 2, + (size_t) (fields_num - 2)); + } + else if (strcmp (fields[0], "proc4") == 0) + { + if (inst[0] == 'c') + nfs_submit_nfs4_client (inst, fields + 2, + (size_t) (fields_num - 2)); + } } /* while (fgets) */ } /* void nfs_read_linux */ #endif /* KERNEL_LINUX */ #if HAVE_LIBKSTAT static int nfs_read_kstat (kstat_t *ksp, int nfs_version, char *inst, - const char **proc_names, size_t proc_names_num) + char const **proc_names, size_t proc_names_num) { char plugin_instance[DATA_MAX_NAME_LEN]; value_t values[proc_names_num]; @@ -332,8 +617,14 @@ static int nfs_read_kstat (kstat_t *ksp, int nfs_version, char *inst, kstat_read(kc, ksp, NULL); for (i = 0; i < proc_names_num; i++) - values[i].counter = (derive_t) get_kstat_value (ksp, - (char *)proc_names[i]); + { + /* The name passed to kstat_data_lookup() doesn't have the + * "const" modifier, so we need to copy the name here. */ + char name[32]; + sstrncpy (name, proc_names[i], sizeof (name)); + + values[i].counter = (derive_t) get_kstat_value (ksp, name); + } nfs_procedures_submit (plugin_instance, proc_names, values, proc_names_num);