X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdd%2Fmdd_lproc.c;h=baf3d7ce670d3c63621a747e5d5763a830bd099f;hb=3442db6faf685fbdbd092bdfdc8d273e4990a141;hp=6e043bfe4639085e94359787694a98a95fbf72fd;hpb=a775bb1e09ebc0d5058a765cca978b61b7653370;p=fs%2Flustre-release.git diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c index 6e043bf..baf3d7c 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. @@ -17,17 +15,15 @@ * * 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. + * http://www.gnu.org/licenses/gpl-2.0.html * * 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, 2016, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -40,434 +36,540 @@ * 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] = { -}; +static ssize_t +mdd_atime_diff_seq_write(struct file *file, const char __user *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; -int mdd_procfs_init(struct mdd_device *mdd, const char *name) + if (count > (sizeof(kernbuf) - 1)) + return -EINVAL; + + if (copy_from_user(kernbuf, buffer, count)) + return -EFAULT; + + 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 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; -out: - if (rc) - mdd_procfs_fini(mdd); - return rc; + struct mdd_device *mdd = m->private; + + seq_printf(m, "%lu\n", mdd->mdd_atime_diff); + return 0; } +LPROC_SEQ_FOPS(mdd_atime_diff); -int mdd_procfs_fini(struct mdd_device *mdd) +/**** changelogs ****/ +static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data) { - 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; - } - RETURN(0); + 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++; + } + seq_putc(m, '\n'); + return 0; } -void mdd_lprocfs_time_start(const struct lu_env *env) +static ssize_t +mdd_changelog_mask_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) { - lu_lprocfs_time_start(env); + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + char *kernbuf; + int rc; + ENTRY; + + if (count >= PAGE_SIZE) + RETURN(-EINVAL); + OBD_ALLOC(kernbuf, PAGE_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: + OBD_FREE(kernbuf, PAGE_SIZE); + return rc; } +LPROC_SEQ_FOPS(mdd_changelog_mask); -void mdd_lprocfs_time_end(const struct lu_env *env, struct mdd_device *mdd, - int idx) +static int lprocfs_changelog_users_cb(const struct lu_env *env, + struct llog_handle *llh, + struct llog_rec_hdr *hdr, void *data) { - lu_lprocfs_time_end(env, mdd->mdd_stats, idx); + 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 %llu (%u)\n", + rec->cur_id, rec->cur_endrec, (__u32)get_seconds() - + rec->cur_time); + return 0; } -static int lprocfs_wr_atime_diff(struct file *file, const char *buffer, - unsigned long count, void *data) +static int mdd_changelog_users_seq_show(struct seq_file *m, void *data) { - struct mdd_device *mdd = data; - char kernbuf[20], *end; - unsigned long diff = 0; + struct lu_env env; + struct mdd_device *mdd = m->private; + struct llog_ctxt *ctxt; + __u64 cur; + int rc; + + 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); - if (count > (sizeof(kernbuf) - 1)) - return -EINVAL; + rc = lu_env_init(&env, LCT_LOCAL); + if (rc) { + llog_ctxt_put(ctxt); + return rc; + } - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; + spin_lock(&mdd->mdd_cl.mc_lock); + cur = mdd->mdd_cl.mc_index; + spin_unlock(&mdd->mdd_cl.mc_lock); - kernbuf[count] = '\0'; + seq_printf(m, "current index: %llu\n", cur); + seq_printf(m, "%-5s %s %s\n", "ID", "index", "(idle seconds)"); - diff = simple_strtoul(kernbuf, &end, 0); - if (kernbuf == end) - return -EINVAL; + llog_cat_process(&env, ctxt->loc_handle, lprocfs_changelog_users_cb, + m, 0, 0); - mdd->mdd_atime_diff = diff; - return count; + lu_env_fini(&env); + llog_ctxt_put(ctxt); + return 0; } +LPROC_SEQ_FOPS_RO(mdd_changelog_users); -static int lprocfs_rd_atime_diff(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int mdd_changelog_size_ctxt(const struct lu_env *env, + struct mdd_device *mdd, + int index, __u64 *val) { - struct mdd_device *mdd = data; + struct llog_ctxt *ctxt; - *eof = 1; - return snprintf(page, count, "%lu\n", mdd->mdd_atime_diff); -} + ctxt = llog_get_context(mdd2obd_dev(mdd), + index); + if (ctxt == NULL) + return -ENXIO; + if (!(ctxt->loc_handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) { + CERROR("%s: ChangeLog has wrong flags: rc = %d\n", + ctxt->loc_obd->obd_name, -EINVAL); + llog_ctxt_put(ctxt); + return -EINVAL; + } -/**** changelogs ****/ -DECLARE_CHANGELOG_NAMES; + *val += llog_cat_size(env, ctxt->loc_handle); + + llog_ctxt_put(ctxt); -const char *changelog_bit2str(int bit) + return 0; +} + +static int mdd_changelog_size_seq_show(struct seq_file *m, void *data) { - if (bit < CL_LAST) - return changelog_str[bit]; - return NULL; + struct lu_env env; + struct mdd_device *mdd = m->private; + __u64 tmp = 0; + int rc; + + rc = lu_env_init(&env, LCT_LOCAL); + if (rc) + return rc; + + rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_ORIG_CTXT, &tmp); + if (rc) { + lu_env_fini(&env); + return rc; + } + + rc = mdd_changelog_size_ctxt(&env, mdd, LLOG_CHANGELOG_USER_ORIG_CTXT, + &tmp); + + seq_printf(m, "%llu\n", tmp); + lu_env_fini(&env); + return rc; } +LPROC_SEQ_FOPS_RO(mdd_changelog_size); -static int lprocfs_rd_changelog_mask(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int mdd_changelog_gc_seq_show(struct seq_file *m, 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_str[i]); - i++; - } - return rc; + struct mdd_device *mdd = m->private; + + LASSERT(mdd != NULL); + seq_printf(m, "%u\n", mdd->mdd_changelog_gc); + return 0; } -static int lprocfs_wr_changelog_mask(struct file *file, const char *buffer, - unsigned long count, void *data) +static ssize_t +mdd_changelog_gc_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) { - 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 (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); - if (rc == 0) - rc = count; -out: - OBD_FREE(kernbuf, CFS_PAGE_SIZE); - return rc; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int rc; + __s64 val; + + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; + + mdd->mdd_changelog_gc = !!val; + + return count; } +LPROC_SEQ_FOPS(mdd_changelog_gc); -struct cucb_data { - char *page; - int count; - int idx; -}; +static int mdd_changelog_max_idle_time_seq_show(struct seq_file *m, void *data) +{ + struct mdd_device *mdd = m->private; -static int lprocfs_changelog_users_cb(struct llog_handle *llh, - struct llog_rec_hdr *hdr, void *data) + LASSERT(mdd != NULL); + seq_printf(m, "%u\n", mdd->mdd_changelog_max_idle_time); + return 0; +} + +static ssize_t +mdd_changelog_max_idle_time_seq_write(struct file *file, + const char __user *buffer, size_t count, + loff_t *off) { - struct llog_changelog_user_rec *rec; - struct cucb_data *cucb = (struct cucb_data *)data; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int rc; + __s64 val; - LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN); + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; - rec = (struct llog_changelog_user_rec *)hdr; + /* XXX may need to limit with reasonable elapsed/idle times */ + if (val < 1 || val > INT_MAX) + return -ERANGE; - 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; + mdd->mdd_changelog_max_idle_time = val; - return 0; + return count; } +LPROC_SEQ_FOPS(mdd_changelog_max_idle_time); -static int lprocfs_rd_changelog_users(char *page, char **start, off_t off, - int count, int *eof, void *data) +static int mdd_changelog_max_idle_indexes_seq_show(struct seq_file *m, + void *data) { - struct mdd_device *mdd = data; - struct llog_ctxt *ctxt; - struct cucb_data cucb; - __u64 cur; + struct mdd_device *mdd = m->private; - *eof = 1; + LASSERT(mdd != NULL); + seq_printf(m, "%lu\n", mdd->mdd_changelog_max_idle_indexes); + 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); +static ssize_t +mdd_changelog_max_idle_indexes_seq_write(struct file *file, + const char __user *buffer, + size_t count, loff_t *off) +{ + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int rc; + __s64 val; - spin_lock(&mdd->mdd_cl.mc_lock); - cur = mdd->mdd_cl.mc_index; - spin_unlock(&mdd->mdd_cl.mc_lock); + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; - cucb.count = count; - cucb.page = page; - cucb.idx = 0; + /* XXX may need to limit/check with reasonable elapsed/idle indexes */ + /* XXX may better allow to specify a % of full ChangeLogs */ - cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx, - "current index: "LPU64"\n", cur); + mdd->mdd_changelog_max_idle_indexes = val; - cucb.idx += snprintf(cucb.page + cucb.idx, cucb.count - cucb.idx, - "%-5s %s\n", "ID", "index"); + return count; +} +LPROC_SEQ_FOPS(mdd_changelog_max_idle_indexes); - llog_cat_process(ctxt->loc_handle, lprocfs_changelog_users_cb, - &cucb, 0, 0); +static int mdd_changelog_min_gc_interval_seq_show(struct seq_file *m, + void *data) +{ + struct mdd_device *mdd = m->private; - llog_ctxt_put(ctxt); - return cucb.idx; + LASSERT(mdd != NULL); + seq_printf(m, "%u\n", mdd->mdd_changelog_min_gc_interval); + return 0; } -/* 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 ssize_t +mdd_changelog_min_gc_interval_seq_write(struct file *file, + const char __user *buffer, + size_t count, loff_t *off) { - struct mdd_device *mdd = (struct mdd_device *)data; - char kernbuf[32]; - char *end; - int rc; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int rc; + __s64 val; - if (count > (sizeof(kernbuf) - 1)) - goto out_usage; + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; - count = min_t(unsigned long, count, sizeof(kernbuf)); - if (copy_from_user(kernbuf, buffer, count)) - return -EFAULT; + /* XXX may need to limit with reasonable elapsed/interval times */ + if (val < 1 || val > UINT_MAX) + return -ERANGE; - kernbuf[count] = '\0'; - /* strip trailing newline from "echo blah" */ - if (kernbuf[count - 1] == '\n') - kernbuf[count - 1] = '\0'; - - if (strcmp(kernbuf, "on") == 0) { - LCONSOLE_INFO("changelog on\n"); - if (mdd->mdd_cl.mc_flags & CLM_ERR) { - CERROR("Changelogs cannot be enabled due to error " - "condition.\n"); - } else { - spin_lock(&mdd->mdd_cl.mc_lock); - mdd->mdd_cl.mc_flags |= CLM_ON; - spin_unlock(&mdd->mdd_cl.mc_lock); - rc = mdd_changelog_write_header(mdd, CLM_START); - if (rc) - return rc; - } - } else if (strcmp(kernbuf, "off") == 0) { - LCONSOLE_INFO("changelog off\n"); - rc = mdd_changelog_write_header(mdd, CLM_FINI); - if (rc) - return rc; - spin_lock(&mdd->mdd_cl.mc_lock); - mdd->mdd_cl.mc_flags &= ~CLM_ON; - spin_unlock(&mdd->mdd_cl.mc_lock); - } 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; - } + mdd->mdd_changelog_min_gc_interval = val; - return count; + return count; +} +LPROC_SEQ_FOPS(mdd_changelog_min_gc_interval); -out_usage: - CWARN("changelog write usage: [on|off] | \n"); - return -EINVAL; +static int mdd_changelog_min_free_cat_entries_seq_show(struct seq_file *m, + void *data) +{ + struct mdd_device *mdd = m->private; + + LASSERT(mdd != NULL); + seq_printf(m, "%u\n", mdd->mdd_changelog_min_free_cat_entries); + return 0; } -static ssize_t mdd_changelog_seq_write(struct file *file, const char *buffer, - size_t count, loff_t *off) +static ssize_t +mdd_changelog_min_free_cat_entries_seq_write(struct file *file, + const char __user *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; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int rc; + __s64 val; + + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; - return mdd_changelog_write(file, buffer, count, mdd); + /* XXX may need to limit with more reasonable number of free entries */ + if (val < 1 || (__u64)val > UINT_MAX) + return -ERANGE; + + mdd->mdd_changelog_min_free_cat_entries = val; + + return count; } +LPROC_SEQ_FOPS(mdd_changelog_min_free_cat_entries); -static int mdd_changelog_done(struct changelog_seq_iter *csi) +static int mdd_sync_perm_seq_show(struct seq_file *m, void *data) { - struct mdd_device *mdd = (struct mdd_device *)csi->csi_dev; - int done = 0; + struct mdd_device *mdd = m->private; - 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); + seq_printf(m, "%d\n", mdd->mdd_sync_permission); + return 0; } -/* handle nonblocking */ -static ssize_t mdd_changelog_seq_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) +static ssize_t +mdd_sync_perm_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) { - struct seq_file *seq = (struct seq_file *)file->private_data; - struct changelog_seq_iter *csi = seq->private; - int rc; - ENTRY; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + int rc; + __s64 val; + + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; - if ((file->f_flags & O_NONBLOCK) && mdd_changelog_done(csi)) - RETURN(-EAGAIN); + mdd->mdd_sync_permission = !!val; - csi->csi_done = 0; - rc = seq_read(file, buf, count, ppos); - RETURN(rc); + return count; } +LPROC_SEQ_FOPS(mdd_sync_perm); -/* handle nonblocking */ -static unsigned int mdd_changelog_seq_poll(struct file *file, poll_table *wait) +static int mdd_lfsck_speed_limit_seq_show(struct seq_file *m, 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; + struct mdd_device *mdd = m->private; - csi->csi_done = 0; - poll_wait(file, &mdd->mdd_cl.mc_waitq, wait); - if (!mdd_changelog_done(csi)) - RETURN(POLLIN | POLLRDNORM); + LASSERT(mdd != NULL); + return lfsck_get_speed(m, mdd->mdd_bottom); +} - RETURN(0); +static ssize_t +mdd_lfsck_speed_limit_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) +{ + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + __s64 val; + int rc; + + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc != 0) + return rc; + if (val < 0 || val > INT_MAX) + return -ERANGE; + + rc = lfsck_set_speed(mdd->mdd_bottom, val); + return rc != 0 ? rc : count; } +LPROC_SEQ_FOPS(mdd_lfsck_speed_limit); -static int mdd_changelog_seq_open(struct inode *inode, struct file *file) +static int mdd_lfsck_async_windows_seq_show(struct seq_file *m, 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 = m->private; + + LASSERT(mdd != NULL); + return lfsck_get_windows(m, mdd->mdd_bottom); } -static int mdd_changelog_seq_release(struct inode *inode, struct file *file) +static ssize_t +mdd_lfsck_async_windows_seq_write(struct file *file, const char __user *buffer, + size_t count, loff_t *off) { - struct seq_file *seq = file->private_data; - struct changelog_seq_iter *csi = seq->private; + struct seq_file *m = file->private_data; + struct mdd_device *mdd = m->private; + __s64 val; + int rc; - if (csi && csi->csi_ctxt) - llog_ctxt_put(csi->csi_ctxt); + LASSERT(mdd != NULL); + rc = lprocfs_str_to_s64(buffer, count, &val); + if (rc) + return rc; + if (val < 0 || val > INT_MAX) + return -ERANGE; - return (changelog_seq_release(inode, file)); -} + rc = lfsck_set_windows(mdd->mdd_bottom, val); -/* 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, -}; + 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 }, - { "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 } + { .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 = "changelog_size", + .fops = &mdd_changelog_size_fops }, + { .name = "changelog_gc", + .fops = &mdd_changelog_gc_fops }, + { .name = "changelog_max_idle_time", + .fops = &mdd_changelog_max_idle_time_fops }, + { .name = "changelog_max_idle_indexes", + .fops = &mdd_changelog_max_idle_indexes_fops }, + { .name = "changelog_min_gc_interval", + .fops = &mdd_changelog_min_gc_interval_fops }, + { .name = "changelog_min_free_cat_entries", + .fops = &mdd_changelog_min_free_cat_entries_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 } -}; - -void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars) +int mdd_procfs_init(struct mdd_device *mdd, const char *name) { - lvars->module_vars = lprocfs_mdd_module_vars; - lvars->obd_vars = lprocfs_mdd_obd_vars; + 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 mdd_procfs_fini(struct mdd_device *mdd) +{ + if (mdd->mdd_proc_entry) + lprocfs_remove(&mdd->mdd_proc_entry); +}