X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdd%2Fmdd_lproc.c;h=7bf5e335f0def9cf6ecdad85b48c6f2a5b497450;hb=070e8fefe25434394a30ae4407b825a12cce8308;hp=9178114df2fbf8bfec2ca623191bc0cd1db046e1;hpb=cefa8cda2ba2d288ccaa4ec077a6c627592503ea;p=fs%2Flustre-release.git diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c index 9178114..7bf5e33 100644 --- a/lustre/mdd/mdd_lproc.c +++ b/lustre/mdd/mdd_lproc.c @@ -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. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -40,149 +40,298 @@ * Author: Wang Di */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif #define DEBUG_SUBSYSTEM S_MDS -#include #include #include -#include #include #include -#include +#include +#include "mdd_internal.h" -#include +static ssize_t +mdd_atime_diff_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + char kernbuf[20], *end; + unsigned long diff = 0; -#include "mdd_internal.h" + if (count > (sizeof(kernbuf) - 1)) + return -EINVAL; -static const char *mdd_counter_names[LPROC_MDD_NR] = { -}; + if (copy_from_user(kernbuf, buffer, count)) + return -EFAULT; -int mdd_procfs_init(struct mdd_device *mdd, const char *name) + kernbuf[count] = '\0'; + + diff = simple_strtoul(kernbuf, &end, 0); + if (kernbuf == end) + return -EINVAL; + + mdd->mdd_atime_diff = diff; + return count; +} + +static int mdd_atime_diff_seq_show(struct seq_file *m, void *data) +{ + struct mdd_device *mdd = m->private; + + return seq_printf(m, "%lu\n", mdd->mdd_atime_diff); +} +LPROC_SEQ_FOPS(mdd_atime_diff); + +/**** changelogs ****/ +static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data) +{ + struct mdd_device *mdd = m->private; + int i = 0; + + while (i < CL_LAST) { + if (mdd->mdd_cl.mc_mask & (1 << i)) + seq_printf(m, "%s ", changelog_type2str(i)); + i++; + } + return 0; +} + +static ssize_t +mdd_changelog_mask_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - struct lprocfs_static_vars lvars; - struct lu_device *ld = &mdd->mdd_md_dev.md_lu_dev; - struct obd_type *type; - int rc; - ENTRY; - - type = ld->ld_type->ldt_obd_type; - - LASSERT(name != NULL); - LASSERT(type != NULL); - - /* Find the type procroot and add the proc entry for this device */ - lprocfs_mdd_init_vars(&lvars); - mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot, - lvars.obd_vars, mdd); - if (IS_ERR(mdd->mdd_proc_entry)) { - rc = PTR_ERR(mdd->mdd_proc_entry); - CERROR("Error %d setting up lprocfs for %s\n", - rc, name); - mdd->mdd_proc_entry = NULL; - GOTO(out, rc); - } - - rc = lu_time_init(&mdd->mdd_stats, - mdd->mdd_proc_entry, - mdd_counter_names, ARRAY_SIZE(mdd_counter_names)); - EXIT; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + char *kernbuf; + int rc; + ENTRY; + + if (count >= PAGE_CACHE_SIZE) + RETURN(-EINVAL); + OBD_ALLOC(kernbuf, PAGE_CACHE_SIZE); + if (kernbuf == NULL) + RETURN(-ENOMEM); + if (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: - if (rc) - mdd_procfs_fini(mdd); + OBD_FREE(kernbuf, PAGE_CACHE_SIZE); return rc; } +LPROC_SEQ_FOPS(mdd_changelog_mask); + +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 seq_file *m = data; + + LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN); + + rec = (struct llog_changelog_user_rec *)hdr; + + seq_printf(m, CHANGELOG_USER_PREFIX"%-3d "LPU64"\n", + rec->cur_id, rec->cur_endrec); + return 0; +} -int mdd_procfs_fini(struct mdd_device *mdd) +static int mdd_changelog_users_seq_show(struct seq_file *m, void *data) { - if (mdd->mdd_stats) - lu_time_fini(&mdd->mdd_stats); + struct lu_env env; + struct mdd_device *mdd = m->private; + struct llog_ctxt *ctxt; + __u64 cur; + int rc; - if (mdd->mdd_proc_entry) { - lprocfs_remove(&mdd->mdd_proc_entry); - mdd->mdd_proc_entry = NULL; - } - RETURN(0); + 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); + + rc = lu_env_init(&env, LCT_LOCAL); + if (rc) { + llog_ctxt_put(ctxt); + return rc; + } + + spin_lock(&mdd->mdd_cl.mc_lock); + cur = mdd->mdd_cl.mc_index; + spin_unlock(&mdd->mdd_cl.mc_lock); + + seq_printf(m, "current index: "LPU64"\n", cur); + seq_printf(m, "%-5s %s\n", "ID", "index"); + + llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb, + m, 0, 0); + + lu_env_fini(&env); + llog_ctxt_put(ctxt); + return 0; } +LPROC_SEQ_FOPS_RO(mdd_changelog_users); -void mdd_lprocfs_time_start(const struct lu_env *env) +static int mdd_sync_perm_seq_show(struct seq_file *m, void *data) { - lu_lprocfs_time_start(env); + struct mdd_device *mdd = m->private; + + LASSERT(mdd != NULL); + return seq_printf(m, "%d\n", mdd->mdd_sync_permission); } -void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd, - int idx) +static ssize_t +mdd_sync_perm_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - lu_lprocfs_time_end(env, mdd->mdd_stats, idx); + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int val, rc; + + LASSERT(mdd != NULL); + rc = lprocfs_write_helper(buffer, count, &val); + if (rc) + return rc; + + mdd->mdd_sync_permission = !!val; + return count; } +LPROC_SEQ_FOPS(mdd_sync_perm); -static int lprocfs_wr_atime_diff(struct file *file, const char *buffer, - unsigned long count, void *data) +static int mdd_lfsck_speed_limit_seq_show(struct seq_file *m, void *data) { - struct mdd_device *mdd = data; - char kernbuf[20], *end; - unsigned long diff = 0; + struct mdd_device *mdd = m->private; - if (count > (sizeof(kernbuf) - 1)) - return -EINVAL; + LASSERT(mdd != NULL); + return lfsck_get_speed(m, mdd->mdd_bottom); +} - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; +static ssize_t +mdd_lfsck_speed_limit_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) +{ + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + __u32 val; + int rc; - kernbuf[count] = '\0'; + LASSERT(mdd != NULL); + rc = lprocfs_write_helper(buffer, count, &val); + if (rc != 0) + return rc; - diff = simple_strtoul(kernbuf, &end, 0); - if (kernbuf == end) - return -EINVAL; + rc = lfsck_set_speed(mdd->mdd_bottom, val); + return rc != 0 ? rc : count; +} +LPROC_SEQ_FOPS(mdd_lfsck_speed_limit); - mdd->mdd_atime_diff = diff; - return count; +static int mdd_lfsck_async_windows_seq_show(struct seq_file *m, void *data) +{ + struct mdd_device *mdd = m->private; + + LASSERT(mdd != NULL); + return lfsck_get_windows(m, mdd->mdd_bottom); } -static int lprocfs_rd_atime_diff(char *page, char **start, off_t off, - int count, int *eof, void *data) +static ssize_t +mdd_lfsck_async_windows_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - struct mdd_device *mdd = data; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + __u32 val; + int rc; - *eof = 1; - return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff); + LASSERT(mdd != NULL); + rc = lprocfs_write_helper(buffer, count, &val); + if (rc == 0) + rc = lfsck_set_windows(mdd->mdd_bottom, val); + + return rc != 0 ? rc : count; } +LPROC_SEQ_FOPS(mdd_lfsck_async_windows); -#ifdef HAVE_QUOTA_SUPPORT -static int mdd_lprocfs_quota_rd_type(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int mdd_lfsck_namespace_seq_show(struct seq_file *m, void *data) { - struct mdd_device *mdd = data; - return lprocfs_quota_rd_type(page, start, off, count, eof, - mdd->mdd_obd_dev); + struct mdd_device *mdd = m->private; + + LASSERT(mdd != NULL); + + return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_NAMESPACE); } +LPROC_SEQ_FOPS_RO(mdd_lfsck_namespace); -static int mdd_lprocfs_quota_wr_type(struct file *file, const char *buffer, - unsigned long count, void *data) +static int mdd_lfsck_layout_seq_show(struct seq_file *m, void *data) { - struct mdd_device *mdd = data; - return lprocfs_quota_wr_type(file, buffer, count, mdd->mdd_obd_dev); + struct mdd_device *mdd = m->private; + + LASSERT(mdd != NULL); + + return lfsck_dump(m, mdd->mdd_bottom, LFSCK_TYPE_LAYOUT); } -#endif +LPROC_SEQ_FOPS_RO(mdd_lfsck_layout); static struct lprocfs_vars lprocfs_mdd_obd_vars[] = { - { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 }, -#ifdef HAVE_QUOTA_SUPPORT - { "quota_type", mdd_lprocfs_quota_rd_type, - mdd_lprocfs_quota_wr_type, 0 }, -#endif - { 0 } + { .name = "atime_diff", + .fops = &mdd_atime_diff_fops }, + { .name = "changelog_mask", + .fops = &mdd_changelog_mask_fops }, + { .name = "changelog_users", + .fops = &mdd_changelog_users_fops }, + { .name = "sync_permission", + .fops = &mdd_sync_perm_fops }, + { .name = "lfsck_speed_limit", + .fops = &mdd_lfsck_speed_limit_fops }, + { .name = "lfsck_async_windows", + .fops = &mdd_lfsck_async_windows_fops }, + { .name = "lfsck_namespace", + .fops = &mdd_lfsck_namespace_fops }, + { .name = "lfsck_layout", + .fops = &mdd_lfsck_layout_fops }, + { NULL } }; -static struct lprocfs_vars lprocfs_mdd_module_vars[] = { - { "num_refs", lprocfs_rd_numrefs, 0, 0 }, - { 0 } -}; +int mdd_procfs_init(struct mdd_device *mdd, const char *name) +{ + struct obd_device *obd = mdd2obd_dev(mdd); + struct obd_type *type; + int rc; + ENTRY; + + /* at the moment there is no linkage between lu_type + * and obd_type, so we lookup obd_type this way */ + type = class_search_type(LUSTRE_MDD_NAME); + + LASSERT(name != NULL); + LASSERT(type != NULL); + LASSERT(obd != NULL); + + /* Find the type procroot and add the proc entry for this device */ + obd->obd_vars = lprocfs_mdd_obd_vars; + mdd->mdd_proc_entry = lprocfs_register(name, type->typ_procroot, + obd->obd_vars, mdd); + if (IS_ERR(mdd->mdd_proc_entry)) { + rc = PTR_ERR(mdd->mdd_proc_entry); + CERROR("Error %d setting up lprocfs for %s\n", + rc, name); + mdd->mdd_proc_entry = NULL; + GOTO(out, rc); + } + rc = 0; + EXIT; +out: + if (rc) + mdd_procfs_fini(mdd); + return rc; +} -void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars) +void mdd_procfs_fini(struct mdd_device *mdd) { - lvars->module_vars = lprocfs_mdd_module_vars; - lvars->obd_vars = lprocfs_mdd_obd_vars; + if (mdd->mdd_proc_entry) + lprocfs_remove(&mdd->mdd_proc_entry); }