Whamcloud - gitweb
LU-1303 lod: introduce lod device
[fs/lustre-release.git] / lustre / mdt / mdt_lproc.c
index 3417cae..26d4692 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -29,8 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011 Whamcloud, Inc.
- *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -42,9 +39,6 @@
  * Author: Fan Yong <fanyong@clusterfs.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <linux/version.h>
@@ -187,10 +181,10 @@ static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
 }
 
 void mdt_rename_counter_tally(struct mdt_thread_info *info,
-                              struct mdt_device *mdt,
-                              struct obd_export *exp,
-                              struct mdt_object *src,
-                              struct mdt_object *tgt)
+                             struct mdt_device *mdt,
+                             struct ptlrpc_request *req,
+                             struct mdt_object *src,
+                             struct mdt_object *tgt)
 {
         struct md_attr *ma = &info->mti_attr;
         struct rename_stats *rstats = &mdt->mdt_rename_stats;
@@ -201,18 +195,19 @@ void mdt_rename_counter_tally(struct mdt_thread_info *info,
         rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
         if (rc) {
                 CERROR("%s: "DFID" attr_get, rc = %d\n",
-                       exp->exp_obd->obd_name, PFID(mdt_object_fid(src)), rc);
+                      req->rq_export->exp_obd->obd_name,
+                      PFID(mdt_object_fid(src)), rc);
                 return;
         }
 
         if (src == tgt) {
-                mdt_counter_incr(exp, LPROC_MDT_SAMEDIR_RENAME);
+               mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
                 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
                                       (unsigned int)ma->ma_attr.la_size);
                 return;
         }
 
-        mdt_counter_incr(exp, LPROC_MDT_CROSSDIR_RENAME);
+       mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
         lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
                               (unsigned int)ma->ma_attr.la_size);
 
@@ -221,7 +216,8 @@ void mdt_rename_counter_tally(struct mdt_thread_info *info,
         rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
         if (rc) {
                 CERROR("%s: "DFID" attr_get, rc = %d\n",
-                       exp->exp_obd->obd_name, PFID(mdt_object_fid(tgt)), rc);
+                      req->rq_export->exp_obd->obd_name,
+                      PFID(mdt_object_fid(tgt)), rc);
                 return;
         }
 
@@ -267,8 +263,12 @@ int mdt_procfs_init(struct mdt_device *mdt, const char *name)
                                    "clear", lprocfs_nid_stats_clear_read,
                                    lprocfs_nid_stats_clear_write, obd, NULL);
         rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
-        if (rc == 0)
-                mdt_stats_counter_init(obd->md_stats);
+       if (rc)
+               return rc;
+       mdt_stats_counter_init(obd->md_stats);
+
+       rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
+                                   mdt_stats_counter_init);
 
         rc = lproc_mdt_attach_rename_seqstat(mdt);
         if (rc)
@@ -283,6 +283,8 @@ int mdt_procfs_fini(struct mdt_device *mdt)
         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
         struct obd_device *obd = ld->ld_obd;
 
+       lprocfs_job_stats_fini(obd);
+
         if (obd->obd_proc_exports_entry) {
                 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
                 obd->obd_proc_exports_entry = NULL;
@@ -619,21 +621,44 @@ static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
         return count;
 }
 
+#define BUFLEN (UUID_MAX + 4)
+
 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
                                        unsigned long count, void *data)
 {
-        char tmpbuf[sizeof(struct obd_uuid)];
+        char *kbuf;
+        char *tmpbuf;
 
-        sscanf(buffer, "%40s", tmpbuf);
+        OBD_ALLOC(kbuf, BUFLEN);
+        if (kbuf == NULL)
+                return -ENOMEM;
+
+        /*
+         * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
+         * bytes into kbuf, to ensure that the string is NUL-terminated.
+         * UUID_MAX should include a trailing NUL already.
+         */
+        if (cfs_copy_from_user(kbuf, buffer,
+                               min_t(unsigned long, BUFLEN - 1, count))) {
+                count = -EFAULT;
+                goto out;
+        }
+        tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
 
-        if (strncmp(tmpbuf, "nid:", 4) != 0)
-                return lprocfs_wr_evict_client(file, buffer, count, data);
+        if (strncmp(tmpbuf, "nid:", 4) != 0) {
+                count = lprocfs_wr_evict_client(file, buffer, count, data);
+                goto out;
+        }
 
         CERROR("NOT implement evict client by nid %s\n", tmpbuf);
 
+out:
+        OBD_FREE(kbuf, BUFLEN);
         return count;
 }
 
+#undef BUFLEN
+
 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
                                 int count, int *eof, void *data)
 {
@@ -916,21 +941,45 @@ static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
 {
         struct obd_device *obd = data;
         struct obd_export *exp = NULL;
-        struct obd_uuid uuid;
-        char tmpbuf[sizeof(struct obd_uuid)];
+        struct obd_uuid   *uuid;
+        char              *kbuf;
+        char              *tmpbuf;
+
+        OBD_ALLOC(kbuf, UUID_MAX);
+        if (kbuf == NULL)
+                return -ENOMEM;
 
-        sscanf(buffer, "%40s", tmpbuf);
+        /*
+         * OBD_ALLOC() will zero kbuf, but we only copy UUID_MAX - 1
+         * bytes into kbuf, to ensure that the string is NUL-terminated.
+         * UUID_MAX should include a trailing NUL already.
+         */
+        if (cfs_copy_from_user(kbuf, buffer,
+                               min_t(unsigned long, UUID_MAX - 1, count))) {
+                count = -EFAULT;
+                goto out;
+        }
+        tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, UUID_MAX - 1, count));
+
+        OBD_ALLOC(uuid, UUID_MAX);
+        if (uuid == NULL) {
+                count = -ENOMEM;
+                goto out;
+        }
 
-        obd_str2uuid(&uuid, tmpbuf);
-        exp = cfs_hash_lookup(obd->obd_uuid_hash, &uuid);
+        obd_str2uuid(uuid, tmpbuf);
+        exp = cfs_hash_lookup(obd->obd_uuid_hash, uuid);
         if (exp == NULL) {
                 CERROR("%s: no export %s found\n",
-                       obd->obd_name, obd_uuid2str(&uuid));
+                       obd->obd_name, obd_uuid2str(uuid));
         } else {
                 mdt_hsm_copytool_send(exp);
                 class_export_put(exp);
         }
 
+        OBD_FREE(uuid, UUID_MAX);
+out:
+        OBD_FREE(kbuf, UUID_MAX);
         return count;
 }
 
@@ -969,6 +1018,8 @@ static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
         { "instance",                   lprocfs_target_rd_instance,         0 },
         { "ir_factor",                  lprocfs_obd_rd_ir_factor,
                                         lprocfs_obd_wr_ir_factor,           0 },
+       { "job_cleanup_interval",       lprocfs_rd_job_interval,
+                                       lprocfs_wr_job_interval, 0 },
         { 0 }
 };
 
@@ -983,13 +1034,19 @@ void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
     lvars->obd_vars     = lprocfs_mdt_obd_vars;
 }
 
-void mdt_counter_incr(struct obd_export *exp, int opcode)
+void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
 {
-        if (exp->exp_obd && exp->exp_obd->md_stats)
-                lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
-        if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
-                lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
-
+       struct obd_export *exp = req->rq_export;
+
+       if (exp->exp_obd && exp->exp_obd->md_stats)
+               lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
+       if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
+               lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
+       if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
+           (exp->exp_connect_flags & OBD_CONNECT_JOBSTATS))
+               lprocfs_job_stats_log(exp->exp_obd,
+                                     lustre_msg_get_jobid(req->rq_reqmsg),
+                                     opcode, 1);
 }
 
 void mdt_stats_counter_init(struct lprocfs_stats *stats)