lproc_fid.c revision 73bb1da692d0dc3e93b9c9e29084d6a5dcbc37a6
1/* 2 * GPL HEADER START 3 * 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 only, 8 * as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License version 2 for more details (a copy is included 14 * in the LICENSE file that accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License 17 * version 2 along with this program; If not, see 18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 19 * 20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 21 * CA 95054 USA or visit www.sun.com if you need additional information or 22 * have any questions. 23 * 24 * GPL HEADER END 25 */ 26/* 27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 28 * Use is subject to license terms. 29 * 30 * Copyright (c) 2011, 2012, Intel Corporation. 31 */ 32/* 33 * This file is part of Lustre, http://www.lustre.org/ 34 * Lustre is a trademark of Sun Microsystems, Inc. 35 * 36 * lustre/fid/lproc_fid.c 37 * 38 * Lustre Sequence Manager 39 * 40 * Author: Yury Umanets <umka@clusterfs.com> 41 */ 42 43#define DEBUG_SUBSYSTEM S_FID 44 45# include <linux/libcfs/libcfs.h> 46# include <linux/module.h> 47 48#include <obd.h> 49#include <obd_class.h> 50#include <dt_object.h> 51#include <md_object.h> 52#include <obd_support.h> 53#include <lustre_req_layout.h> 54#include <lustre_fid.h> 55#include "fid_internal.h" 56 57#ifdef LPROCFS 58/* 59 * Note: this function is only used for testing, it is no safe for production 60 * use. 61 */ 62static int 63lprocfs_fid_write_common(const char *buffer, unsigned long count, 64 struct lu_seq_range *range) 65{ 66 struct lu_seq_range tmp; 67 int rc; 68 ENTRY; 69 70 LASSERT(range != NULL); 71 72 rc = sscanf(buffer, "[%llx - %llx]\n", 73 (long long unsigned *)&tmp.lsr_start, 74 (long long unsigned *)&tmp.lsr_end); 75 if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp)) 76 RETURN(-EINVAL); 77 *range = tmp; 78 RETURN(0); 79} 80 81/* Client side procfs stuff */ 82static ssize_t 83lprocfs_fid_space_seq_write(struct file *file, const char *buffer, 84 size_t count, loff_t *off) 85{ 86 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private; 87 int rc; 88 ENTRY; 89 90 LASSERT(seq != NULL); 91 92 mutex_lock(&seq->lcs_mutex); 93 rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space); 94 95 if (rc == 0) { 96 CDEBUG(D_INFO, "%s: Space: "DRANGE"\n", 97 seq->lcs_name, PRANGE(&seq->lcs_space)); 98 } 99 100 mutex_unlock(&seq->lcs_mutex); 101 102 RETURN(count); 103} 104 105static int 106lprocfs_fid_space_seq_show(struct seq_file *m, void *unused) 107{ 108 struct lu_client_seq *seq = (struct lu_client_seq *)m->private; 109 int rc; 110 ENTRY; 111 112 LASSERT(seq != NULL); 113 114 mutex_lock(&seq->lcs_mutex); 115 rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n", PRANGE(&seq->lcs_space)); 116 mutex_unlock(&seq->lcs_mutex); 117 118 RETURN(rc); 119} 120 121static ssize_t 122lprocfs_fid_width_seq_write(struct file *file, const char *buffer, 123 size_t count, loff_t *off) 124{ 125 struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private; 126 __u64 max; 127 int rc, val; 128 ENTRY; 129 130 LASSERT(seq != NULL); 131 132 rc = lprocfs_write_helper(buffer, count, &val); 133 if (rc) 134 RETURN(rc); 135 136 mutex_lock(&seq->lcs_mutex); 137 if (seq->lcs_type == LUSTRE_SEQ_DATA) 138 max = LUSTRE_DATA_SEQ_MAX_WIDTH; 139 else 140 max = LUSTRE_METADATA_SEQ_MAX_WIDTH; 141 142 if (val <= max && val > 0) { 143 seq->lcs_width = val; 144 145 if (rc == 0) { 146 CDEBUG(D_INFO, "%s: Sequence size: "LPU64"\n", 147 seq->lcs_name, seq->lcs_width); 148 } 149 } 150 151 mutex_unlock(&seq->lcs_mutex); 152 153 RETURN(count); 154} 155 156static int 157lprocfs_fid_width_seq_show(struct seq_file *m, void *unused) 158{ 159 struct lu_client_seq *seq = (struct lu_client_seq *)m->private; 160 int rc; 161 ENTRY; 162 163 LASSERT(seq != NULL); 164 165 mutex_lock(&seq->lcs_mutex); 166 rc = seq_printf(m, LPU64"\n", seq->lcs_width); 167 mutex_unlock(&seq->lcs_mutex); 168 169 RETURN(rc); 170} 171 172static int 173lprocfs_fid_fid_seq_show(struct seq_file *m, void *unused) 174{ 175 struct lu_client_seq *seq = (struct lu_client_seq *)m->private; 176 int rc; 177 ENTRY; 178 179 LASSERT(seq != NULL); 180 181 mutex_lock(&seq->lcs_mutex); 182 rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid)); 183 mutex_unlock(&seq->lcs_mutex); 184 185 RETURN(rc); 186} 187 188static int 189lprocfs_fid_server_seq_show(struct seq_file *m, void *unused) 190{ 191 struct lu_client_seq *seq = (struct lu_client_seq *)m->private; 192 struct client_obd *cli; 193 int rc; 194 ENTRY; 195 196 LASSERT(seq != NULL); 197 198 if (seq->lcs_exp != NULL) { 199 cli = &seq->lcs_exp->exp_obd->u.cli; 200 rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid); 201 } else { 202 rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name); 203 } 204 RETURN(rc); 205} 206 207struct lprocfs_vars seq_server_proc_list[] = { 208}; 209 210LPROC_SEQ_FOPS(lprocfs_fid_space); 211LPROC_SEQ_FOPS(lprocfs_fid_width); 212LPROC_SEQ_FOPS_RO(lprocfs_fid_server); 213LPROC_SEQ_FOPS_RO(lprocfs_fid_fid); 214 215struct lprocfs_vars seq_client_proc_list[] = { 216 { "space", &lprocfs_fid_space_fops }, 217 { "width", &lprocfs_fid_width_fops }, 218 { "server", &lprocfs_fid_server_fops }, 219 { "fid", &lprocfs_fid_fid_fops }, 220 { NULL } 221}; 222#endif 223