Whamcloud - gitweb
b=21379 Fix orphans proceeding in osc_create
[fs/lustre-release.git] / lustre / mds / lproc_mds.c
index 3069500..5504ea1 100644 (file)
@@ -1,96 +1,48 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (C) 2002 Cluster File Systems, Inc.
+ * GPL HEADER START
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   Lustre is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   Lustre is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 #define DEBUG_SUBSYSTEM S_CLASS
 
 #include <linux/version.h>
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
 #include <asm/statfs.h>
-#endif
-#include <linux/obd.h>
-#include <linux/obd_class.h>
-#include <linux/lprocfs_status.h>
+#include <obd.h>
+#include <obd_class.h>
+#include <lprocfs_status.h>
 #include "mds_internal.h"
 
-#ifndef LPROCFS
-struct lprocfs_vars lprocfs_mds_obd_vars[]  = { {0} };
-struct lprocfs_vars lprocfs_mds_module_vars[] = { {0} };
-struct lprocfs_vars lprocfs_mdt_obd_vars[] = { {0} };
-struct lprocfs_vars lprocfs_mdt_module_vars[] = { {0} };
-
-atomic_t * lprocfs_alloc_mds_counters()
-{
-        return NULL;
-}
-void lprocfs_free_mds_counters(atomic_t *ptr)
-{
-        return;
-}
-
-#else
-
-struct ll_mdscounters_opcode {
-     __u32       opcode;
-     const char *opname;
-} ll_mdscounters_opcode_table[MDS_LAST_OPC_COUNT] = {
-       { MDS_OPEN_COUNT,          "mds_open" },
-       { MDS_CREATE_COUNT,        "mds_create" },
-       { MDS_CLOSE_COUNT,         "mds_close" },
-       { MDS_LINK_COUNT,          "mds_link" },
-       { MDS_UNLINK_COUNT,        "mds_unlink" },
-       { MDS_GETATTR_COUNT,       "mds_getattr" },
-       { MDS_GETATTR_LOCK_COUNT,  "mds_getattr_lock" },
-       { MDS_SETATTR_COUNT,       "mds_setattr" },
-       { MDS_RENAME_COUNT,        "mds_rename" },
-       { MDS_STATFS_COUNT,        "mds_statfs" },
-};
-
-const char* ll_mds_count_opcode2str(__u32 opcode)
-{
-        __u32 offset = opcode;
-
-        LASSERT(offset < MDS_LAST_OPC_COUNT);
-        LASSERT(ll_mdscounters_opcode_table[offset].opcode == opcode);
-        return ll_mdscounters_opcode_table[offset].opname;
-}
-
-struct lprocfs_stats * lprocfs_alloc_mds_counters()
-{
-        struct lprocfs_stats *counters;
-        int i;
-
-        counters = lprocfs_alloc_stats(MDS_LAST_OPC_COUNT);
-
-        for (i = 0; i < MDS_LAST_OPC_COUNT; i ++) {         
-            lprocfs_counter_init(counters, i, 0, 
-                                 (char *)ll_mds_count_opcode2str(i), "reqs");
-        }
-        return counters;
-}
-
-void lprocfs_free_mds_counters(struct lprocfs_stats *ptr)
-{
-        lprocfs_free_stats(ptr);
-}
-
+#ifdef LPROCFS
 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
                                  int *eof, void *data)
 {
@@ -103,263 +55,137 @@ static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
 }
 
-static int lprocfs_rd_mds_counters(char *page, char **start, off_t off,
-                                          int count, int *eof, void *data)
+static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
+                                       int count, int *eof, void *data)
 {
         struct obd_device* obd = (struct obd_device *)data;
-        int len = 0, n, i, j;
-        struct lprocfs_counter  t, ret = { .lc_min = ~(__u64)0 };
-        struct lprocfs_stats *stats;
-        struct timeval now;
 
         LASSERT(obd != NULL);
-        if (obd->u.mds.mds_counters == NULL)
-                return 0;
 
-        do_gettimeofday(&now);
+        return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
+}
 
-        n = snprintf(page, count, "%-25s %lu.%lu secs.usecs\n",
-                               "snapshot_time", now.tv_sec, now.tv_usec);
-        page += n; len +=n; count -=n;
+static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
+                                       unsigned long count, void *data)
+{
+        struct obd_device *obd = data;
+        int val, rc;
 
-        stats = obd->u.mds.mds_counters;
+        rc = lprocfs_write_helper(buffer, count, &val);
+        if (rc)
+                return rc;
 
-        *eof = 1;
-        for (i = 0; i < MDS_LAST_OPC_COUNT; i ++) {
-                ret.lc_count = 0; 
-                for (j = 0; j < num_online_cpus(); j++) {
-                        struct lprocfs_counter *percpu_cntr =
-                                &(stats->ls_percpu[j])->lp_cntr[i];
-                        int centry;
-                        do {
-                                centry = 
-                                   atomic_read(&percpu_cntr->lc_cntl.la_entry); 
-                                t.lc_count = percpu_cntr->lc_count;
-                        } while (centry != 
-                                 atomic_read(&percpu_cntr->lc_cntl.la_entry) &&
-                                 centry != 
-                                 atomic_read(&percpu_cntr->lc_cntl.la_exit));
-                        ret.lc_count += t.lc_count;
-               } 
-                n = snprintf(page, count, "%-25s "LPU64" \n", 
-                                   ll_mds_count_opcode2str(i), ret.lc_count);
-                page += n; len +=n; count -=n;
-        }
-        return (len);
+        obd->u.mds.mds_evict_ost_nids = !!val;
+
+        return count;
 }
 
 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
                                        unsigned long count, void *data)
 {
         struct obd_device *obd = data;
-        struct obd_export *doomed_exp = NULL;
-        struct obd_uuid doomed;
-        struct list_head *p;
-        char tmpbuf[sizeof(doomed)];
+        struct mds_obd *mds = &obd->u.mds;
+        char tmpbuf[sizeof(struct obd_uuid)];
+        struct ptlrpc_request_set *set;
+        int rc;
 
         sscanf(buffer, "%40s", tmpbuf);
-        obd_str2uuid(&doomed, tmpbuf);
-
-        spin_lock(&obd->obd_dev_lock);
-        list_for_each(p, &obd->obd_exports) {
-                doomed_exp = list_entry(p, struct obd_export, exp_obd_chain);
-                if (obd_uuid_equals(&doomed, &doomed_exp->exp_client_uuid)) {
-                        class_export_get(doomed_exp);
-                        break;
-                }
-                doomed_exp = NULL;
-        }
-        spin_unlock(&obd->obd_dev_lock);
-
-        if (doomed_exp == NULL) {
-                CERROR("can't disconnect %s: no export found\n",
-                       doomed.uuid);
-        } else {
-                CERROR("evicting %s at adminstrative request\n",
-                       doomed.uuid);
-                ptlrpc_fail_export(doomed_exp);
-                class_export_put(doomed_exp);
-        }
-        return count;
-}
 
-static int lprocfs_mds_wr_config_update(struct file *file, const char *buffer,
-                                        unsigned long count, void *data)
-{
-        struct obd_device *obd = data;
-        ENTRY;
+        if (strncmp(tmpbuf, "nid:", 4) != 0)
+                return lprocfs_wr_evict_client(file, buffer, count, data);
 
-        RETURN(mds_lov_update_config(obd, 0));
-}
+        set = ptlrpc_prep_set();
+        if (!set)
+                return -ENOMEM;
 
-struct lprocfs_vars lprocfs_mds_obd_vars[] = {
-        { "uuid",         lprocfs_rd_uuid,        0, 0 },
-        { "blocksize",    lprocfs_rd_blksize,     0, 0 },
-        { "kbytestotal",  lprocfs_rd_kbytestotal, 0, 0 },
-        { "kbytesfree",   lprocfs_rd_kbytesfree,  0, 0 },
-        { "kbytesavail",  lprocfs_rd_kbytesavail, 0, 0 },
-        { "fstype",       lprocfs_rd_fstype,      0, 0 },
-        { "filestotal",   lprocfs_rd_filestotal,  0, 0 },
-        { "filesfree",    lprocfs_rd_filesfree,   0, 0 },
-        { "mntdev",       lprocfs_mds_rd_mntdev,  0, 0 },
-        { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
-        { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
-        { "config_update", 0, lprocfs_mds_wr_config_update, 0 },
-        { "num_exports",  lprocfs_rd_num_exports, 0, 0 },
-        { "counters", lprocfs_rd_mds_counters, 0, 0 },
-        { 0 }
-};
+        if (obd->u.mds.mds_evict_ost_nids) {
+                rc = obd_set_info_async(mds->mds_lov_exp,
+                                        sizeof(KEY_EVICT_BY_NID),
+                                        KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
+                                        tmpbuf + 4, set);
+                if (rc)
+                        CERROR("Failed to evict nid %s from OSTs: rc %d\n",
+                               tmpbuf + 4, rc);
 
-/*
- * group hash proc entries handler
- */
-static int lprocfs_wr_group_info(struct file *file, const char *buffer,
-                                 unsigned long count, void *data)
-{
-        struct {
-                int             err;
-                uid_t           uid;
-                uint32_t        ngroups;
-                gid_t          *groups;
-        } param;
-        gid_t   gids_local[NGROUPS_SMALL];
-        gid_t  *gids = NULL;
-
-        if (count != sizeof(param)) {
-                CERROR("invalid data size %lu\n", count);
-                return count;
-        }
-        if (copy_from_user(&param, buffer, count)) {
-                CERROR("broken downcall\n");
-                return count;
-        }
-        if (param.ngroups > NGROUPS_MAX) {
-                CERROR("%d groups?\n", param.ngroups);
-                return count;
+                ptlrpc_check_set(NULL, set);
         }
 
-        if (param.ngroups <= NGROUPS_SMALL)
-                gids = gids_local;
-        else {
-                OBD_ALLOC(gids, param.ngroups * sizeof(gid_t));
-                if (!gids) {
-                        CERROR("fail to alloc memory for %d gids\n",
-                                param.ngroups);
-                        return count;
-                }
-        }
-        if (copy_from_user(gids, param.groups,
-                           param.ngroups * sizeof(gid_t))) {
-                CERROR("broken downcall\n");
-                goto out;
-        }
+        /* See the comments in function lprocfs_wr_evict_client()
+         * in ptlrpc/lproc_ptlrpc.c for details. - jay */
+        class_incref(obd, __FUNCTION__, cfs_current());
+        LPROCFS_EXIT();
 
-        mds_handle_group_downcall(param.err, param.uid,
-                                  param.ngroups, gids);
+        obd_export_evict_by_nid(obd, tmpbuf+4);
 
-out:
-        if (gids && gids != gids_local)
-                OBD_FREE(gids, param.ngroups * sizeof(gid_t));
-        return count;
-}
-static int lprocfs_rd_expire(char *page, char **start, off_t off, int count,
-                             int *eof, void *data)
-{
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
 
-        *eof = 1;
-        return snprintf(page, count, "%d\n", hash->gh_entry_expire);
-}
-static int lprocfs_wr_expire(struct file *file, const char *buffer,
-                             unsigned long count, void *data)
-{
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
-        char buf[32];
+        rc = ptlrpc_set_wait(set);
+        if (rc)
+                CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
+                       rc);
+
+        LPROCFS_ENTRY();
+        class_decref(obd,  __FUNCTION__, cfs_current());
 
-        if (copy_from_user(buf, buffer, min(count, 32UL)))
-                return count;
-        buf[31] = 0;
-        sscanf(buf, "%d", &hash->gh_entry_expire);
+        ptlrpc_set_destroy(set);
         return count;
 }
-static int lprocfs_rd_ac_expire(char *page, char **start, off_t off, int count,
-                                int *eof, void *data)
-{
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
 
-        *eof = 1;
-        return snprintf(page, count, "%d\n", hash->gh_acquire_expire);
-}
-static int lprocfs_wr_ac_expire(struct file *file, const char *buffer,
-                                unsigned long count, void *data)
+static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
+                                 unsigned long count, void *data)
 {
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
-        char buf[32];
+        struct obd_device *obd = data;
+        struct mds_obd *mds = &obd->u.mds;
+        char kernbuf[20], *end;
+        unsigned long diff = 0;
 
-        if (copy_from_user(buf, buffer, min(count, 32UL)))
-                return count;
-        buf[31] = 0;
-        sscanf(buf, "%d", &hash->gh_acquire_expire);
-        return count;
-}
-static int lprocfs_rd_hash_upcall(char *page, char **start, off_t off, int count,
-                                int *eof, void *data)
-{
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
+        if (count > (sizeof(kernbuf) - 1))
+                return -EINVAL;
 
-        *eof = 1;
-        return snprintf(page, count, "%s\n", hash->gh_upcall);
-}
-static int lprocfs_wr_hash_upcall(struct file *file, const char *buffer,
-                                  unsigned long count, void *data)
-{
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
+        if (cfs_copy_from_user(kernbuf, buffer, count))
+                return -EFAULT;
 
-        if (count < MDSGRP_UPCALL_MAXPATH) {
-                sscanf(buffer, "%1024s", hash->gh_upcall);
-                hash->gh_upcall[MDSGRP_UPCALL_MAXPATH-1] = 0;
-        }
-        return count;
-}
-static int lprocfs_wr_hash_flush(struct file *file, const char *buffer,
-                                  unsigned long count, void *data)
-{
-        mds_group_hash_flush_idle();
+        kernbuf[count] = '\0';
+
+        diff = simple_strtoul(kernbuf, &end, 0);
+        if (kernbuf == end)
+                return -EINVAL;
+
+        mds->mds_atime_diff = diff;
         return count;
 }
-static int lprocfs_rd_allow_setgroups(char *page, char **start, off_t off,
-                                      int count, int *eof, void *data)
+
+static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data)
 {
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
+        struct obd_device *obd = data;
+        struct mds_obd *mds = &obd->u.mds;
 
         *eof = 1;
-        return snprintf(page, count, "%d\n", hash->gh_allow_setgroups);
-}
-static int lprocfs_wr_allow_setgroups(struct file *file, const char *buffer,
-                                      unsigned long count, void *data)
-{
-        struct mds_grp_hash *hash = __mds_get_global_group_hash();
-        char buf[8];
-        int val;
-
-        if (copy_from_user(buf, buffer, min(count, 8UL)))
-                return count;
-        buf[7] = 0;
-        sscanf(buf, "%d", &val);
-        hash->gh_allow_setgroups = (val != 0);
-        return count;
+        return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
 }
 
+struct lprocfs_vars lprocfs_mds_obd_vars[] = {
+        { "uuid",            lprocfs_rd_uuid,        0, 0 },
+        { "blocksize",       lprocfs_rd_blksize,     0, 0 },
+        { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
+        { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
+        { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
+        { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
+        { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
+        { "fstype",          lprocfs_rd_fstype,      0, 0 },
+        { "mntdev",          lprocfs_mds_rd_mntdev,  0, 0 },
+        { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
+        { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
+        { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
+        { "evict_ost_nids",  lprocfs_mds_rd_evictostnids,
+                                               lprocfs_mds_wr_evictostnids, 0 },
+        { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
+        { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
+        { 0 }
+};
+
 struct lprocfs_vars lprocfs_mds_module_vars[] = {
         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
-        { "grp_hash_expire_interval", lprocfs_rd_expire, lprocfs_wr_expire, 0},
-        { "grp_hash_acquire_expire", lprocfs_rd_ac_expire,
-                                     lprocfs_wr_ac_expire, 0},
-        { "grp_hash_upcall", lprocfs_rd_hash_upcall, lprocfs_wr_hash_upcall, 0},
-        { "grp_hash_flush", 0, lprocfs_wr_hash_flush, 0},
-        { "group_info", 0,  lprocfs_wr_group_info,   0 },
-        { "allow_setgroups", lprocfs_rd_allow_setgroups,
-                             lprocfs_wr_allow_setgroups, 0},
         { 0 }
 };
 
@@ -373,13 +199,38 @@ struct lprocfs_vars lprocfs_mdt_module_vars[] = {
         { 0 }
 };
 
-#endif /* LPROCFS */
+void mds_counter_incr(struct obd_export *exp, int opcode)
+{
+        if (exp->exp_obd && exp->exp_obd->obd_stats)
+                lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
+        if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
+                lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
+
+}
+
+void mds_stats_counter_init(struct lprocfs_stats *stats)
+{
+        lprocfs_counter_init(stats, LPROC_MDS_OPEN, 0, "open", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_CLOSE, 0, "close", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_MKNOD, 0, "mknod", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_LINK, 0, "link", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_UNLINK, 0, "unlink", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_MKDIR, 0, "mkdir", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_RMDIR, 0, "rmdir", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_RENAME, 0, "rename", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_GETXATTR, 0, "getxattr", "reqs");
+        lprocfs_counter_init(stats, LPROC_MDS_SETXATTR, 0, "setxattr", "reqs");
+}
 
-struct lprocfs_static_vars lprocfs_array_vars[] = { {lprocfs_mds_module_vars,
-                                                     lprocfs_mds_obd_vars},
-                                                    {lprocfs_mdt_module_vars,
-                                                     lprocfs_mdt_obd_vars}};
+void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
+{
+    lvars->module_vars = lprocfs_mds_module_vars;
+    lvars->obd_vars = lprocfs_mds_obd_vars;
+}
 
-LPROCFS_INIT_MULTI_VARS(lprocfs_array_vars,
-                        (sizeof(lprocfs_array_vars) /
-                         sizeof(struct lprocfs_static_vars)))
+void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
+{
+    lvars->module_vars = lprocfs_mdt_module_vars;
+    lvars->obd_vars = lprocfs_mdt_obd_vars;
+}
+#endif