Whamcloud - gitweb
LU-1302 llog: llog test update and fixes
[fs/lustre-release.git] / lustre / mdd / mdd_lproc.c
index 026f43e..44e3b8f 100644 (file)
@@ -1,44 +1,51 @@
-/* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
  *
- *  mdd/mdd_lproc.c
- *  Lustre Metadata Server (mdd) routines
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *  Copyright (C) 2006 Cluster File Systems, Inc.
- *   Author: Wang Di <wangdi@clusterfs.com>
+ * 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.
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * 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 may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * 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
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source 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.
+ * 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.
  *
- *   In either case, 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
- *   license text for more details.
+ * GPL HEADER END
  */
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. 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.
+ *
+ * lustre/mdd/mdd_lproc.c
+ *
+ * Lustre Metadata Server (mdd) routines
+ *
+ * Author: Wang Di <wangdi@clusterfs.com>
+ */
+
 #define DEBUG_SUBSYSTEM S_MDS
 
-#include <linux/module.h>
 #include <obd.h>
 #include <obd_class.h>
-#include <lustre_ver.h>
 #include <obd_support.h>
 #include <lprocfs_status.h>
 #include <lu_time.h>
-
-#include <lustre/lustre_idl.h>
+#include <libcfs/libcfs_string.h>
 
 #include "mdd_internal.h"
 
@@ -73,11 +80,12 @@ int mdd_procfs_init(struct mdd_device *mdd, const char *name)
         rc = lu_time_init(&mdd->mdd_stats,
                           mdd->mdd_proc_entry,
                           mdd_counter_names, ARRAY_SIZE(mdd_counter_names));
+
         EXIT;
 out:
         if (rc)
                mdd_procfs_fini(mdd);
-       return rc;
+        return rc;
 }
 
 int mdd_procfs_fini(struct mdd_device *mdd)
@@ -113,7 +121,7 @@ static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
         if (count > (sizeof(kernbuf) - 1))
                 return -EINVAL;
 
-        if (copy_from_user(kernbuf, buffer, count))
+        if (cfs_copy_from_user(kernbuf, buffer, count))
                 return -EFAULT;
 
         kernbuf[count] = '\0';
@@ -135,9 +143,195 @@ static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
         return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff);
 }
 
+
+/**** changelogs ****/
+static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off,
+                                     int count, int *eof, void *data)
+{
+        struct mdd_device *mdd = data;
+        int i = 0, rc = 0;
+
+        *eof = 1;
+        while (i < CL_LAST) {
+                if (mdd->mdd_cl.mc_mask & (1 << i))
+                        rc += snprintf(page + rc, count - rc, "%s ",
+                                       changelog_type2str(i));
+                i++;
+        }
+        return rc;
+}
+
+static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer,
+                                     unsigned long count, void *data)
+{
+        struct mdd_device *mdd = data;
+        char *kernbuf;
+        int rc;
+        ENTRY;
+
+        if (count >= CFS_PAGE_SIZE)
+                RETURN(-EINVAL);
+        OBD_ALLOC(kernbuf, CFS_PAGE_SIZE);
+        if (kernbuf == NULL)
+                RETURN(-ENOMEM);
+        if (cfs_copy_from_user(kernbuf, buffer, count))
+                GOTO(out, rc = -EFAULT);
+        kernbuf[count] = 0;
+
+        rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask,
+                          CHANGELOG_MINMASK, CHANGELOG_ALLMASK);
+        if (rc == 0)
+                rc = count;
+out:
+        OBD_FREE(kernbuf, CFS_PAGE_SIZE);
+        return rc;
+}
+
+struct cucb_data {
+        char *page;
+        int count;
+        int idx;
+};
+
+static int lprocfs_changelog_users_cb(const struct lu_env *env,
+                                     struct llog_handle *llh,
+                                     struct llog_rec_hdr *hdr, void *data)
+{
+        struct llog_changelog_user_rec *rec;
+        struct cucb_data *cucb = (struct cucb_data *)data;
+
+        LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
+
+        rec = (struct llog_changelog_user_rec *)hdr;
+
+        cucb->idx += snprintf(cucb->page + cucb->idx, cucb->count - cucb->idx,
+                              CHANGELOG_USER_PREFIX"%-3d "LPU64"\n",
+                              rec->cur_id, rec->cur_endrec);
+        if (cucb->idx >= cucb->count)
+                return -ENOSPC;
+
+        return 0;
+}
+
+static int lprocfs_rd_changelog_users(char *page, char **start, off_t off,
+                                      int count, int *eof, void *data)
+{
+        struct mdd_device *mdd = data;
+        struct llog_ctxt *ctxt;
+        struct cucb_data cucb;
+        __u64 cur;
+
+        *eof = 1;
+
+        ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT);
+        if (ctxt == NULL)
+                return -ENXIO;
+        LASSERT(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT);
+
+        cfs_spin_lock(&mdd->mdd_cl.mc_lock);
+        cur = mdd->mdd_cl.mc_index;
+        cfs_spin_unlock(&mdd->mdd_cl.mc_lock);
+
+        cucb.count = count;
+        cucb.page = page;
+        cucb.idx = 0;
+
+        cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
+                              "current index: "LPU64"\n", cur);
+
+        cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx,
+                              "%-5s %s\n", "ID", "index");
+
+       llog_cat_process(NULL, ctxt->loc_handle, lprocfs_changelog_users_cb,
+                        &cucb, 0, 0);
+
+        llog_ctxt_put(ctxt);
+        return cucb.idx;
+}
+
+#ifdef HAVE_QUOTA_SUPPORT
+static int mdd_lprocfs_quota_rd_type(char *page, char **start, off_t off,
+                                     int count, int *eof, void *data)
+{
+        struct mdd_device *mdd = data;
+        return lprocfs_quota_rd_type(page, start, off, count, eof,
+                                     mdd->mdd_obd_dev);
+}
+
+static int mdd_lprocfs_quota_wr_type(struct file *file, const char *buffer,
+                                     unsigned long count, void *data)
+{
+        struct mdd_device *mdd = data;
+        return lprocfs_quota_wr_type(file, buffer, count, mdd->mdd_obd_dev);
+}
+#endif
+
+static int lprocfs_rd_sync_perm(char *page, char **start, off_t off,
+                                int count, int *eof, void *data)
+{
+        struct mdd_device *mdd = data;
+
+        LASSERT(mdd != NULL);
+        return snprintf(page, count, "%d\n", mdd->mdd_sync_permission);
+}
+
+static int lprocfs_wr_sync_perm(struct file *file, const char *buffer,
+                                unsigned long count, void *data)
+{
+        struct mdd_device *mdd = data;
+        int val, rc;
+
+        LASSERT(mdd != NULL);
+        rc = lprocfs_write_helper(buffer, count, &val);
+        if (rc)
+                return rc;
+
+        mdd->mdd_sync_permission = !!val;
+        return count;
+}
+
+static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off,
+                                       int count, int *eof, void *data)
+{
+       struct mdd_device *mdd = data;
+
+       LASSERT(mdd != NULL);
+       *eof = 1;
+       return snprintf(page, count, "%u\n", mdd->mdd_lfsck.ml_speed_limit);
+}
+
+static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer,
+                                       unsigned long count, void *data)
+{
+       struct mdd_device *mdd = data;
+       struct md_lfsck *lfsck;
+       __u32 val;
+       int rc;
+
+       LASSERT(mdd != NULL);
+       rc = lprocfs_write_helper(buffer, count, &val);
+       if (rc)
+               return rc;
+
+       lfsck = &mdd->mdd_lfsck;
+       if (val != lfsck->ml_speed_limit)
+               mdd_lfsck_set_speed(lfsck, val);
+       return count;
+}
+
 static struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
-        { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
-        { 0 }
+        { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
+        { "changelog_mask",  lprocfs_rd_changelog_mask,
+                             lprocfs_wr_changelog_mask, 0 },
+        { "changelog_users", lprocfs_rd_changelog_users, 0, 0},
+#ifdef HAVE_QUOTA_SUPPORT
+        { "quota_type",      mdd_lprocfs_quota_rd_type,
+                             mdd_lprocfs_quota_wr_type, 0 },
+#endif
+        { "sync_permission", lprocfs_rd_sync_perm, lprocfs_wr_sync_perm, 0 },
+       { "lfsck_speed_limit", lprocfs_rd_lfsck_speed_limit,
+                              lprocfs_wr_lfsck_speed_limit, 0 },
+       { 0 }
 };
 
 static struct lprocfs_vars lprocfs_mdd_module_vars[] = {
@@ -150,3 +344,4 @@ void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars)
         lvars->module_vars  = lprocfs_mdd_module_vars;
         lvars->obd_vars     = lprocfs_mdd_obd_vars;
 }
+