Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 30 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 9fdaf8c | 2014-07-11 20:51:16 -0700 | [diff] [blame] | 45 | #include "../../include/linux/libcfs/libcfs.h" |
| 46 | #include <linux/module.h> |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 47 | |
Greg Kroah-Hartman | 6156639 | 2014-07-11 21:50:29 -0700 | [diff] [blame] | 48 | #include "../include/obd.h" |
| 49 | #include "../include/obd_class.h" |
Greg Kroah-Hartman | 6156639 | 2014-07-11 21:50:29 -0700 | [diff] [blame] | 50 | #include "../include/obd_support.h" |
| 51 | #include "../include/lustre_req_layout.h" |
| 52 | #include "../include/lustre_fid.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 53 | #include "fid_internal.h" |
| 54 | |
Oleg Drokin | a1e7e2d | 2014-04-27 13:07:10 -0400 | [diff] [blame] | 55 | /* Format: [0x64BIT_INT - 0x64BIT_INT] + 32 bytes just in case */ |
| 56 | #define MAX_FID_RANGE_STRLEN (32 + 2 * 2 * sizeof(__u64)) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 57 | /* |
| 58 | * Note: this function is only used for testing, it is no safe for production |
| 59 | * use. |
| 60 | */ |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 61 | static int |
| 62 | ldebugfs_fid_write_common(const char __user *buffer, size_t count, |
| 63 | struct lu_seq_range *range) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 64 | { |
| 65 | struct lu_seq_range tmp; |
| 66 | int rc; |
Oleg Drokin | a1e7e2d | 2014-04-27 13:07:10 -0400 | [diff] [blame] | 67 | char kernbuf[MAX_FID_RANGE_STRLEN]; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 68 | |
Oleg Drokin | 6a9f748 | 2016-02-16 00:46:49 -0500 | [diff] [blame] | 69 | LASSERT(range); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 70 | |
Oleg Drokin | a1e7e2d | 2014-04-27 13:07:10 -0400 | [diff] [blame] | 71 | if (count >= sizeof(kernbuf)) |
| 72 | return -EINVAL; |
| 73 | |
| 74 | if (copy_from_user(kernbuf, buffer, count)) |
| 75 | return -EFAULT; |
| 76 | |
| 77 | kernbuf[count] = 0; |
| 78 | |
| 79 | if (count == 5 && strcmp(kernbuf, "clear") == 0) { |
| 80 | memset(range, 0, sizeof(*range)); |
| 81 | return count; |
| 82 | } |
| 83 | |
| 84 | /* of the form "[0x0000000240000400 - 0x000000028000400]" */ |
| 85 | rc = sscanf(kernbuf, "[%llx - %llx]\n", |
Eddie Kovsky | 2a3b60d | 2014-09-08 15:22:58 -0600 | [diff] [blame] | 86 | (unsigned long long *)&tmp.lsr_start, |
| 87 | (unsigned long long *)&tmp.lsr_end); |
Valdis Kletnieks | f65a092 | 2015-12-22 19:36:50 -0500 | [diff] [blame] | 88 | if (rc != 2) |
| 89 | return -EINVAL; |
Oleg Drokin | a1e7e2d | 2014-04-27 13:07:10 -0400 | [diff] [blame] | 90 | if (!range_is_sane(&tmp) || range_is_zero(&tmp) || |
| 91 | tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 92 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 93 | *range = tmp; |
Oleg Drokin | a1e7e2d | 2014-04-27 13:07:10 -0400 | [diff] [blame] | 94 | return count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 95 | } |
| 96 | |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 97 | /* Client side debugfs stuff */ |
| 98 | static ssize_t |
| 99 | ldebugfs_fid_space_seq_write(struct file *file, |
| 100 | const char __user *buffer, |
| 101 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 102 | { |
Anil Belur | d1acbe5 | 2014-06-19 17:29:01 +1000 | [diff] [blame] | 103 | struct lu_client_seq *seq; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 104 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 105 | |
Anil Belur | d1acbe5 | 2014-06-19 17:29:01 +1000 | [diff] [blame] | 106 | seq = ((struct seq_file *)file->private_data)->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 107 | |
| 108 | mutex_lock(&seq->lcs_mutex); |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 109 | rc = ldebugfs_fid_write_common(buffer, count, &seq->lcs_space); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 110 | |
| 111 | if (rc == 0) { |
| 112 | CDEBUG(D_INFO, "%s: Space: "DRANGE"\n", |
| 113 | seq->lcs_name, PRANGE(&seq->lcs_space)); |
| 114 | } |
| 115 | |
| 116 | mutex_unlock(&seq->lcs_mutex); |
| 117 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 118 | return count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static int |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 122 | ldebugfs_fid_space_seq_show(struct seq_file *m, void *unused) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 123 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 124 | struct lu_client_seq *seq = (struct lu_client_seq *)m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 125 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 126 | mutex_lock(&seq->lcs_mutex); |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 127 | seq_printf(m, "[%#llx - %#llx]:%x:%s\n", PRANGE(&seq->lcs_space)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 128 | mutex_unlock(&seq->lcs_mutex); |
| 129 | |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 130 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 131 | } |
| 132 | |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 133 | static ssize_t |
| 134 | ldebugfs_fid_width_seq_write(struct file *file, |
| 135 | const char __user *buffer, |
| 136 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 137 | { |
Anil Belur | d1acbe5 | 2014-06-19 17:29:01 +1000 | [diff] [blame] | 138 | struct lu_client_seq *seq; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 139 | __u64 max; |
| 140 | int rc, val; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 141 | |
Anil Belur | d1acbe5 | 2014-06-19 17:29:01 +1000 | [diff] [blame] | 142 | seq = ((struct seq_file *)file->private_data)->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 143 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 144 | rc = lprocfs_write_helper(buffer, count, &val); |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 145 | if (rc) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 146 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 147 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 148 | mutex_lock(&seq->lcs_mutex); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 149 | if (seq->lcs_type == LUSTRE_SEQ_DATA) |
| 150 | max = LUSTRE_DATA_SEQ_MAX_WIDTH; |
| 151 | else |
| 152 | max = LUSTRE_METADATA_SEQ_MAX_WIDTH; |
| 153 | |
| 154 | if (val <= max && val > 0) { |
| 155 | seq->lcs_width = val; |
| 156 | |
Dan Carpenter | 1c01737 | 2015-06-05 12:23:31 +0300 | [diff] [blame] | 157 | CDEBUG(D_INFO, "%s: Sequence size: %llu\n", seq->lcs_name, |
| 158 | seq->lcs_width); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | mutex_unlock(&seq->lcs_mutex); |
| 162 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 163 | return count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static int |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 167 | ldebugfs_fid_width_seq_show(struct seq_file *m, void *unused) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 168 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 169 | struct lu_client_seq *seq = (struct lu_client_seq *)m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 170 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 171 | mutex_lock(&seq->lcs_mutex); |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 172 | seq_printf(m, "%llu\n", seq->lcs_width); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 173 | mutex_unlock(&seq->lcs_mutex); |
| 174 | |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 175 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static int |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 179 | ldebugfs_fid_fid_seq_show(struct seq_file *m, void *unused) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 180 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 181 | struct lu_client_seq *seq = (struct lu_client_seq *)m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 182 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 183 | mutex_lock(&seq->lcs_mutex); |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 184 | seq_printf(m, DFID "\n", PFID(&seq->lcs_fid)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 185 | mutex_unlock(&seq->lcs_mutex); |
| 186 | |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 187 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | static int |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 191 | ldebugfs_fid_server_seq_show(struct seq_file *m, void *unused) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 192 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 193 | struct lu_client_seq *seq = (struct lu_client_seq *)m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 194 | struct client_obd *cli; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 195 | |
Oleg Drokin | 6a9f748 | 2016-02-16 00:46:49 -0500 | [diff] [blame] | 196 | if (seq->lcs_exp) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 197 | cli = &seq->lcs_exp->exp_obd->u.cli; |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 198 | seq_printf(m, "%s\n", cli->cl_target_uuid.uuid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 199 | } |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 200 | |
| 201 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 202 | } |
| 203 | |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 204 | LPROC_SEQ_FOPS(ldebugfs_fid_space); |
| 205 | LPROC_SEQ_FOPS(ldebugfs_fid_width); |
| 206 | LPROC_SEQ_FOPS_RO(ldebugfs_fid_server); |
| 207 | LPROC_SEQ_FOPS_RO(ldebugfs_fid_fid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 208 | |
Dmitry Eremin | f3aa79f | 2015-05-21 15:32:25 -0400 | [diff] [blame] | 209 | struct lprocfs_vars seq_client_debugfs_list[] = { |
| 210 | { "space", &ldebugfs_fid_space_fops }, |
| 211 | { "width", &ldebugfs_fid_width_fops }, |
| 212 | { "server", &ldebugfs_fid_server_fops }, |
| 213 | { "fid", &ldebugfs_fid_fid_fops }, |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 214 | { NULL } |
| 215 | }; |