X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=lustre%2Fmdd%2Fmdd_lproc.c;h=4d64e43afd758022899c4f3bed1bf0942b53f873;hb=27f77f5de6fe27611c9f819f8cdaba89d70f15d9;hp=903a6754918581a72777ba331155d41bda3d8482;hpb=1829e654506c5b798eae5ef4a91948f1411513b4;p=fs%2Flustre-release.git diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c index 903a675..4d64e43 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, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -40,37 +40,25 @@ * Author: Wang Di */ -#ifndef EXPORT_SYMTAB -# define EXPORT_SYMTAB -#endif #define DEBUG_SUBSYSTEM S_MDS -#include -#include #include #include -#include #include #include -#include -#include -#include #include - #include "mdd_internal.h" -static const char *mdd_counter_names[LPROC_MDD_NR] = { -}; - int mdd_procfs_init(struct mdd_device *mdd, const char *name) { 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; + /* 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); @@ -87,9 +75,7 @@ int mdd_procfs_init(struct mdd_device *mdd, const char *name) GOTO(out, rc); } - rc = lu_time_init(&mdd->mdd_stats, - mdd->mdd_proc_entry, - mdd_counter_names, ARRAY_SIZE(mdd_counter_names)); + rc = 0; EXIT; out: @@ -100,9 +86,6 @@ out: int mdd_procfs_fini(struct mdd_device *mdd) { - if (mdd->mdd_stats) - lu_time_fini(&mdd->mdd_stats); - if (mdd->mdd_proc_entry) { lprocfs_remove(&mdd->mdd_proc_entry); mdd->mdd_proc_entry = NULL; @@ -110,17 +93,6 @@ int mdd_procfs_fini(struct mdd_device *mdd) RETURN(0); } -void mdd_lprocfs_time_start(const struct lu_env *env) -{ - lu_lprocfs_time_start(env); -} - -void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd, - int idx) -{ - lu_lprocfs_time_end(env, mdd->mdd_stats, idx); -} - static int lprocfs_wr_atime_diff(struct file *file, const char *buffer, unsigned long count, void *data) { @@ -131,7 +103,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'; @@ -155,15 +127,6 @@ static int lprocfs_rd_atime_diff(char *page, char **start, off_t off, /**** changelogs ****/ -DECLARE_CHANGELOG_NAMES; - -const char *changelog_bit2str(int bit) -{ - if (bit < CL_LAST) - return changelog_str[bit]; - return NULL; -} - static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off, int count, int *eof, void *data) { @@ -174,7 +137,7 @@ static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off, while (i < CL_LAST) { if (mdd->mdd_cl.mc_mask & (1 << i)) rc += snprintf(page + rc, count - rc, "%s ", - changelog_str[i]); + changelog_type2str(i)); i++; } return rc; @@ -193,12 +156,12 @@ static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer, OBD_ALLOC(kernbuf, CFS_PAGE_SIZE); if (kernbuf == NULL) RETURN(-ENOMEM); - if (copy_from_user(kernbuf, buffer, count)) + if (cfs_copy_from_user(kernbuf, buffer, count)) GOTO(out, rc = -EFAULT); kernbuf[count] = 0; - rc = libcfs_str2mask(kernbuf, changelog_bit2str, &mdd->mdd_cl.mc_mask, - CHANGELOG_MINMASK, CHANGELOG_ALLMASK); + rc = cfs_str2mask(kernbuf, changelog_type2str, &mdd->mdd_cl.mc_mask, + CHANGELOG_MINMASK, CHANGELOG_ALLMASK); if (rc == 0) rc = count; out: @@ -212,8 +175,9 @@ struct cucb_data { int idx; }; -static int lprocfs_changelog_users_cb(struct llog_handle *llh, - struct llog_rec_hdr *hdr, void *data) +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; @@ -234,21 +198,30 @@ static int lprocfs_changelog_users_cb(struct llog_handle *llh, 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; + struct lu_env env; + struct mdd_device *mdd = data; + struct llog_ctxt *ctxt; + struct cucb_data cucb; + __u64 cur; + int rc; *eof = 1; - ctxt = llog_get_context(mdd2obd_dev(mdd),LLOG_CHANGELOG_USER_ORIG_CTXT); + 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); - spin_lock(&mdd->mdd_cl.mc_lock); - cur = mdd->mdd_cl.mc_index; - spin_unlock(&mdd->mdd_cl.mc_lock); + 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); cucb.count = count; cucb.page = page; @@ -260,188 +233,105 @@ static int lprocfs_rd_changelog_users(char *page, char **start, off_t off, cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx, "%-5s %s\n", "ID", "index"); - llog_cat_process(ctxt->loc_handle, lprocfs_changelog_users_cb, - &cucb, 0, 0); + llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb, + &cucb, 0, 0); - llog_ctxt_put(ctxt); - return cucb.idx; + lu_env_fini(&env); + llog_ctxt_put(ctxt); + return cucb.idx; } -/* non-seq version for direct calling by class_process_proc_param */ -static int mdd_changelog_write(struct file *file, const char *buffer, - unsigned long count, void *data) +static int lprocfs_rd_sync_perm(char *page, char **start, off_t off, + int count, int *eof, void *data) { - struct mdd_device *mdd = (struct mdd_device *)data; - char kernbuf[32]; - char *end; - int rc; - - if (count > (sizeof(kernbuf) - 1)) - goto out_usage; - - count = min_t(unsigned long, count, sizeof(kernbuf)); - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; - - kernbuf[count] = '\0'; - /* strip trailing newline from "echo blah" */ - if (kernbuf[count - 1] == '\n') - kernbuf[count - 1] = '\0'; - - /* Forced on/off/purge rec, independent of changelog users! */ - if (strcmp(kernbuf, "on") == 0) { - rc = mdd_changelog_on(mdd, 1); - } else if (strcmp(kernbuf, "off") == 0) { - rc = mdd_changelog_on(mdd, 0); - } else { - /* purge to an index */ - long long unsigned endrec; - - endrec = (long long)simple_strtoull(kernbuf, &end, 0); - if (end == kernbuf) - goto out_usage; - - LCONSOLE_INFO("changelog purge to %llu\n", endrec); - - rc = mdd_changelog_llog_cancel(mdd, endrec); - } - - if (rc < 0) - return rc; - return count; - -out_usage: - CWARN("changelog write usage: [on|off] | \n"); - return -EINVAL; -} - -static ssize_t mdd_changelog_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) -{ - struct seq_file *seq = file->private_data; - struct changelog_seq_iter *csi = seq->private; - struct mdd_device *mdd = (struct mdd_device *)csi->csi_dev; - - return mdd_changelog_write(file, buffer, count, mdd); -} - -static int mdd_changelog_done(struct changelog_seq_iter *csi) -{ - struct mdd_device *mdd = (struct mdd_device *)csi->csi_dev; - int done = 0; + struct mdd_device *mdd = data; - spin_lock(&mdd->mdd_cl.mc_lock); - done = (csi->csi_endrec >= mdd->mdd_cl.mc_index); - spin_unlock(&mdd->mdd_cl.mc_lock); - return done; + LASSERT(mdd != NULL); + return snprintf(page, count, "%d\n", mdd->mdd_sync_permission); } -/* handle nonblocking */ -static ssize_t mdd_changelog_seq_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) +static int lprocfs_wr_sync_perm(struct file *file, const char *buffer, + unsigned long count, void *data) { - struct seq_file *seq = (struct seq_file *)file->private_data; - struct changelog_seq_iter *csi = seq->private; - int rc; - ENTRY; + struct mdd_device *mdd = data; + int val, rc; - if ((file->f_flags & O_NONBLOCK) && mdd_changelog_done(csi)) - RETURN(-EAGAIN); + LASSERT(mdd != NULL); + rc = lprocfs_write_helper(buffer, count, &val); + if (rc) + return rc; - csi->csi_done = 0; - rc = seq_read(file, buf, count, ppos); - RETURN(rc); + mdd->mdd_sync_permission = !!val; + return count; } -/* handle nonblocking */ -static unsigned int mdd_changelog_seq_poll(struct file *file, poll_table *wait) +static int lprocfs_rd_lfsck_speed_limit(char *page, char **start, off_t off, + int count, int *eof, void *data) { - struct seq_file *seq = (struct seq_file *)file->private_data; - struct changelog_seq_iter *csi = seq->private; - struct mdd_device *mdd = (struct mdd_device *)csi->csi_dev; - ENTRY; - - csi->csi_done = 0; - poll_wait(file, &mdd->mdd_cl.mc_waitq, wait); - if (!mdd_changelog_done(csi)) - RETURN(POLLIN | POLLRDNORM); + struct mdd_device *mdd = data; - RETURN(0); + LASSERT(mdd != NULL); + *eof = 1; + return snprintf(page, count, "%u\n", + mdd->mdd_lfsck.ml_bookmark_ram.lb_speed_limit); } -static int mdd_changelog_seq_open(struct inode *inode, struct file *file) +static int lprocfs_wr_lfsck_speed_limit(struct file *file, const char *buffer, + unsigned long count, void *data) { - struct changelog_seq_iter *csi; - struct obd_device *obd; - int rc; - ENTRY; - - rc = changelog_seq_open(inode, file, &csi); - if (rc) - RETURN(rc); - - /* The proc file is set up with mdd in data, not obd */ - obd = mdd2obd_dev((struct mdd_device *)csi->csi_dev); - csi->csi_ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT); - if (csi->csi_ctxt == NULL) { - changelog_seq_release(inode, file); - RETURN(-ENOENT); - } - /* The handle is set up in llog_obd_origin_setup */ - csi->csi_llh = csi->csi_ctxt->loc_handle; - RETURN(rc); + 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 != 0) + return rc; + + lfsck = &mdd->mdd_lfsck; + if (val != lfsck->ml_bookmark_ram.lb_speed_limit) { + struct lu_env env; + + rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD); + if (rc != 0) + return rc; + + rc = mdd_lfsck_set_speed(&env, lfsck, val); + lu_env_fini(&env); + } + return rc != 0 ? rc : count; } -static int mdd_changelog_seq_release(struct inode *inode, struct file *file) +static int lprocfs_rd_lfsck_namespace(char *page, char **start, off_t off, + int count, int *eof, void *data) { - struct seq_file *seq = file->private_data; - struct changelog_seq_iter *csi = seq->private; + struct lu_env env; + struct mdd_device *mdd = data; + int rc; - if (csi && csi->csi_ctxt) - llog_ctxt_put(csi->csi_ctxt); - - return (changelog_seq_release(inode, file)); -} - -/* mdd changelog proc can handle nonblocking ops and writing to purge recs */ -struct file_operations mdd_changelog_fops = { - .owner = THIS_MODULE, - .open = mdd_changelog_seq_open, - .read = mdd_changelog_seq_read, - .write = mdd_changelog_seq_write, - .llseek = changelog_seq_lseek, - .poll = mdd_changelog_seq_poll, - .release = mdd_changelog_seq_release, -}; + LASSERT(mdd != NULL); + *eof = 1; -#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); -} + rc = lu_env_init(&env, LCT_MD_THREAD | LCT_DT_THREAD); + if (rc != 0) + return rc; -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); + rc = mdd_lfsck_dump(&env, &mdd->mdd_lfsck, LT_NAMESPACE, page, count); + lu_env_fini(&env); + return rc; } -#endif static struct lprocfs_vars lprocfs_mdd_obd_vars[] = { { "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}, - { "changelog", 0, mdd_changelog_write, 0, &mdd_changelog_fops, 0600 }, -#ifdef HAVE_QUOTA_SUPPORT - { "quota_type", mdd_lprocfs_quota_rd_type, - mdd_lprocfs_quota_wr_type, 0 }, -#endif - { 0 } + { "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 }, + { "lfsck_namespace", lprocfs_rd_lfsck_namespace, 0, 0 }, + { 0 } }; static struct lprocfs_vars lprocfs_mdd_module_vars[] = {