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 |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | */ |
| 32 | #define DEBUG_SUBSYSTEM S_CLASS |
| 33 | |
Greg Kroah-Hartman | e27db14 | 2014-07-11 22:29:36 -0700 | [diff] [blame] | 34 | #include "../include/obd_support.h" |
| 35 | #include "../include/obd.h" |
| 36 | #include "../include/lprocfs_status.h" |
| 37 | #include "../include/lustre/lustre_idl.h" |
| 38 | #include "../include/lustre_net.h" |
| 39 | #include "../include/obd_class.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 40 | #include "ptlrpc_internal.h" |
| 41 | |
Jon Bernard | b3c986d | 2015-01-20 14:55:28 -0500 | [diff] [blame] | 42 | static struct ll_rpc_opcode { |
Kristina Martsenko | 2a76328 | 2013-11-11 21:35:01 +0200 | [diff] [blame] | 43 | __u32 opcode; |
| 44 | const char *opname; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 45 | } ll_rpc_opcode_table[LUSTRE_MAX_OPCODES] = { |
| 46 | { OST_REPLY, "ost_reply" }, |
| 47 | { OST_GETATTR, "ost_getattr" }, |
| 48 | { OST_SETATTR, "ost_setattr" }, |
| 49 | { OST_READ, "ost_read" }, |
| 50 | { OST_WRITE, "ost_write" }, |
Mike Rapoport | b2952d6 | 2015-09-03 11:49:13 +0300 | [diff] [blame] | 51 | { OST_CREATE, "ost_create" }, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 52 | { OST_DESTROY, "ost_destroy" }, |
| 53 | { OST_GET_INFO, "ost_get_info" }, |
| 54 | { OST_CONNECT, "ost_connect" }, |
| 55 | { OST_DISCONNECT, "ost_disconnect" }, |
| 56 | { OST_PUNCH, "ost_punch" }, |
| 57 | { OST_OPEN, "ost_open" }, |
| 58 | { OST_CLOSE, "ost_close" }, |
| 59 | { OST_STATFS, "ost_statfs" }, |
| 60 | { 14, NULL }, /* formerly OST_SAN_READ */ |
| 61 | { 15, NULL }, /* formerly OST_SAN_WRITE */ |
| 62 | { OST_SYNC, "ost_sync" }, |
| 63 | { OST_SET_INFO, "ost_set_info" }, |
| 64 | { OST_QUOTACHECK, "ost_quotacheck" }, |
| 65 | { OST_QUOTACTL, "ost_quotactl" }, |
| 66 | { OST_QUOTA_ADJUST_QUNIT, "ost_quota_adjust_qunit" }, |
| 67 | { MDS_GETATTR, "mds_getattr" }, |
| 68 | { MDS_GETATTR_NAME, "mds_getattr_lock" }, |
| 69 | { MDS_CLOSE, "mds_close" }, |
| 70 | { MDS_REINT, "mds_reint" }, |
| 71 | { MDS_READPAGE, "mds_readpage" }, |
| 72 | { MDS_CONNECT, "mds_connect" }, |
| 73 | { MDS_DISCONNECT, "mds_disconnect" }, |
| 74 | { MDS_GETSTATUS, "mds_getstatus" }, |
| 75 | { MDS_STATFS, "mds_statfs" }, |
| 76 | { MDS_PIN, "mds_pin" }, |
| 77 | { MDS_UNPIN, "mds_unpin" }, |
| 78 | { MDS_SYNC, "mds_sync" }, |
| 79 | { MDS_DONE_WRITING, "mds_done_writing" }, |
| 80 | { MDS_SET_INFO, "mds_set_info" }, |
| 81 | { MDS_QUOTACHECK, "mds_quotacheck" }, |
| 82 | { MDS_QUOTACTL, "mds_quotactl" }, |
| 83 | { MDS_GETXATTR, "mds_getxattr" }, |
| 84 | { MDS_SETXATTR, "mds_setxattr" }, |
| 85 | { MDS_WRITEPAGE, "mds_writepage" }, |
| 86 | { MDS_IS_SUBDIR, "mds_is_subdir" }, |
| 87 | { MDS_GET_INFO, "mds_get_info" }, |
| 88 | { MDS_HSM_STATE_GET, "mds_hsm_state_get" }, |
| 89 | { MDS_HSM_STATE_SET, "mds_hsm_state_set" }, |
| 90 | { MDS_HSM_ACTION, "mds_hsm_action" }, |
| 91 | { MDS_HSM_PROGRESS, "mds_hsm_progress" }, |
| 92 | { MDS_HSM_REQUEST, "mds_hsm_request" }, |
| 93 | { MDS_HSM_CT_REGISTER, "mds_hsm_ct_register" }, |
| 94 | { MDS_HSM_CT_UNREGISTER, "mds_hsm_ct_unregister" }, |
| 95 | { MDS_SWAP_LAYOUTS, "mds_swap_layouts" }, |
| 96 | { LDLM_ENQUEUE, "ldlm_enqueue" }, |
| 97 | { LDLM_CONVERT, "ldlm_convert" }, |
| 98 | { LDLM_CANCEL, "ldlm_cancel" }, |
| 99 | { LDLM_BL_CALLBACK, "ldlm_bl_callback" }, |
| 100 | { LDLM_CP_CALLBACK, "ldlm_cp_callback" }, |
| 101 | { LDLM_GL_CALLBACK, "ldlm_gl_callback" }, |
| 102 | { LDLM_SET_INFO, "ldlm_set_info" }, |
| 103 | { MGS_CONNECT, "mgs_connect" }, |
| 104 | { MGS_DISCONNECT, "mgs_disconnect" }, |
| 105 | { MGS_EXCEPTION, "mgs_exception" }, |
| 106 | { MGS_TARGET_REG, "mgs_target_reg" }, |
| 107 | { MGS_TARGET_DEL, "mgs_target_del" }, |
| 108 | { MGS_SET_INFO, "mgs_set_info" }, |
| 109 | { MGS_CONFIG_READ, "mgs_config_read" }, |
| 110 | { OBD_PING, "obd_ping" }, |
Mikhail Pershin | 65f1c78 | 2013-11-26 10:04:55 +0800 | [diff] [blame] | 111 | { OBD_LOG_CANCEL, "llog_cancel" }, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 112 | { OBD_QC_CALLBACK, "obd_quota_callback" }, |
| 113 | { OBD_IDX_READ, "dt_index_read" }, |
Mikhail Pershin | 65f1c78 | 2013-11-26 10:04:55 +0800 | [diff] [blame] | 114 | { LLOG_ORIGIN_HANDLE_CREATE, "llog_origin_handle_open" }, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 115 | { LLOG_ORIGIN_HANDLE_NEXT_BLOCK, "llog_origin_handle_next_block" }, |
Greg Donald | 1d8cb70 | 2014-08-25 20:07:19 -0500 | [diff] [blame] | 116 | { LLOG_ORIGIN_HANDLE_READ_HEADER, "llog_origin_handle_read_header" }, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 117 | { LLOG_ORIGIN_HANDLE_WRITE_REC, "llog_origin_handle_write_rec" }, |
| 118 | { LLOG_ORIGIN_HANDLE_CLOSE, "llog_origin_handle_close" }, |
| 119 | { LLOG_ORIGIN_CONNECT, "llog_origin_connect" }, |
| 120 | { LLOG_CATINFO, "llog_catinfo" }, |
| 121 | { LLOG_ORIGIN_HANDLE_PREV_BLOCK, "llog_origin_handle_prev_block" }, |
| 122 | { LLOG_ORIGIN_HANDLE_DESTROY, "llog_origin_handle_destroy" }, |
| 123 | { QUOTA_DQACQ, "quota_acquire" }, |
| 124 | { QUOTA_DQREL, "quota_release" }, |
| 125 | { SEQ_QUERY, "seq_query" }, |
| 126 | { SEC_CTX_INIT, "sec_ctx_init" }, |
Greg Donald | 1d8cb70 | 2014-08-25 20:07:19 -0500 | [diff] [blame] | 127 | { SEC_CTX_INIT_CONT, "sec_ctx_init_cont" }, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 128 | { SEC_CTX_FINI, "sec_ctx_fini" }, |
| 129 | { FLD_QUERY, "fld_query" }, |
wang di | b78c2b9b | 2016-04-28 12:07:34 -0400 | [diff] [blame] | 130 | { FLD_READ, "fld_read" }, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 131 | }; |
| 132 | |
Jon Bernard | b3c986d | 2015-01-20 14:55:28 -0500 | [diff] [blame] | 133 | static struct ll_eopcode { |
Kristina Martsenko | 2a76328 | 2013-11-11 21:35:01 +0200 | [diff] [blame] | 134 | __u32 opcode; |
| 135 | const char *opname; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 136 | } ll_eopcode_table[EXTRA_LAST_OPC] = { |
| 137 | { LDLM_GLIMPSE_ENQUEUE, "ldlm_glimpse_enqueue" }, |
| 138 | { LDLM_PLAIN_ENQUEUE, "ldlm_plain_enqueue" }, |
| 139 | { LDLM_EXTENT_ENQUEUE, "ldlm_extent_enqueue" }, |
| 140 | { LDLM_FLOCK_ENQUEUE, "ldlm_flock_enqueue" }, |
| 141 | { LDLM_IBITS_ENQUEUE, "ldlm_ibits_enqueue" }, |
| 142 | { MDS_REINT_SETATTR, "mds_reint_setattr" }, |
| 143 | { MDS_REINT_CREATE, "mds_reint_create" }, |
| 144 | { MDS_REINT_LINK, "mds_reint_link" }, |
| 145 | { MDS_REINT_UNLINK, "mds_reint_unlink" }, |
| 146 | { MDS_REINT_RENAME, "mds_reint_rename" }, |
| 147 | { MDS_REINT_OPEN, "mds_reint_open" }, |
| 148 | { MDS_REINT_SETXATTR, "mds_reint_setxattr" }, |
| 149 | { BRW_READ_BYTES, "read_bytes" }, |
| 150 | { BRW_WRITE_BYTES, "write_bytes" }, |
| 151 | }; |
| 152 | |
| 153 | const char *ll_opcode2str(__u32 opcode) |
| 154 | { |
| 155 | /* When one of the assertions below fail, chances are that: |
| 156 | * 1) A new opcode was added in include/lustre/lustre_idl.h, |
| 157 | * but is missing from the table above. |
| 158 | * or 2) The opcode space was renumbered or rearranged, |
| 159 | * and the opcode_offset() function in |
| 160 | * ptlrpc_internal.h needs to be modified. |
| 161 | */ |
| 162 | __u32 offset = opcode_offset(opcode); |
Mike Rapoport | 50ffcb7 | 2015-10-13 16:03:40 +0300 | [diff] [blame] | 163 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 164 | LASSERTF(offset < LUSTRE_MAX_OPCODES, |
| 165 | "offset %u >= LUSTRE_MAX_OPCODES %u\n", |
| 166 | offset, LUSTRE_MAX_OPCODES); |
| 167 | LASSERTF(ll_rpc_opcode_table[offset].opcode == opcode, |
| 168 | "ll_rpc_opcode_table[%u].opcode %u != opcode %u\n", |
| 169 | offset, ll_rpc_opcode_table[offset].opcode, opcode); |
| 170 | return ll_rpc_opcode_table[offset].opname; |
| 171 | } |
| 172 | |
Jon Bernard | b3c986d | 2015-01-20 14:55:28 -0500 | [diff] [blame] | 173 | static const char *ll_eopcode2str(__u32 opcode) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 174 | { |
| 175 | LASSERT(ll_eopcode_table[opcode].opcode == opcode); |
| 176 | return ll_eopcode_table[opcode].opname; |
| 177 | } |
Jon Bernard | b3c986d | 2015-01-20 14:55:28 -0500 | [diff] [blame] | 178 | |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 179 | static void |
| 180 | ptlrpc_ldebugfs_register(struct dentry *root, char *dir, |
| 181 | char *name, |
| 182 | struct dentry **debugfs_root_ret, |
| 183 | struct lprocfs_stats **stats_ret) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 184 | { |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 185 | struct dentry *svc_debugfs_entry; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 186 | struct lprocfs_stats *svc_stats; |
| 187 | int i, rc; |
| 188 | unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX | |
| 189 | LPROCFS_CNTR_STDDEV; |
| 190 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 191 | LASSERT(!*debugfs_root_ret); |
| 192 | LASSERT(!*stats_ret); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 193 | |
Oleg Drokin | cd94f23 | 2016-08-21 18:04:34 -0400 | [diff] [blame] | 194 | svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES, |
Greg Donald | 1d8cb70 | 2014-08-25 20:07:19 -0500 | [diff] [blame] | 195 | 0); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 196 | if (!svc_stats) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 197 | return; |
| 198 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 199 | if (dir) { |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 200 | svc_debugfs_entry = ldebugfs_register(dir, root, NULL, NULL); |
| 201 | if (IS_ERR(svc_debugfs_entry)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 202 | lprocfs_free_stats(&svc_stats); |
| 203 | return; |
| 204 | } |
| 205 | } else { |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 206 | svc_debugfs_entry = root; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR, |
| 210 | svc_counter_config, "req_waittime", "usec"); |
| 211 | lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR, |
| 212 | svc_counter_config, "req_qdepth", "reqs"); |
| 213 | lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR, |
| 214 | svc_counter_config, "req_active", "reqs"); |
| 215 | lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT, |
| 216 | svc_counter_config, "req_timeout", "sec"); |
| 217 | lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR, |
| 218 | svc_counter_config, "reqbuf_avail", "bufs"); |
| 219 | for (i = 0; i < EXTRA_LAST_OPC; i++) { |
| 220 | char *units; |
| 221 | |
Kristina Martsenko | 3949015e | 2013-11-11 21:34:58 +0200 | [diff] [blame] | 222 | switch (i) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 223 | case BRW_WRITE_BYTES: |
| 224 | case BRW_READ_BYTES: |
| 225 | units = "bytes"; |
| 226 | break; |
| 227 | default: |
| 228 | units = "reqs"; |
| 229 | break; |
| 230 | } |
| 231 | lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i, |
| 232 | svc_counter_config, |
| 233 | ll_eopcode2str(i), units); |
| 234 | } |
| 235 | for (i = 0; i < LUSTRE_MAX_OPCODES; i++) { |
| 236 | __u32 opcode = ll_rpc_opcode_table[i].opcode; |
Mike Rapoport | 50ffcb7 | 2015-10-13 16:03:40 +0300 | [diff] [blame] | 237 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 238 | lprocfs_counter_init(svc_stats, |
| 239 | EXTRA_MAX_OPCODES + i, svc_counter_config, |
| 240 | ll_opcode2str(opcode), "usec"); |
| 241 | } |
| 242 | |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 243 | rc = ldebugfs_register_stats(svc_debugfs_entry, name, svc_stats); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 244 | if (rc < 0) { |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 245 | if (dir) |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 246 | ldebugfs_remove(&svc_debugfs_entry); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 247 | lprocfs_free_stats(&svc_stats); |
| 248 | } else { |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 249 | if (dir) |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 250 | *debugfs_root_ret = svc_debugfs_entry; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 251 | *stats_ret = svc_stats; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static int |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 256 | ptlrpc_lprocfs_req_history_len_seq_show(struct seq_file *m, void *v) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 257 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 258 | struct ptlrpc_service *svc = m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 259 | struct ptlrpc_service_part *svcpt; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 260 | int total = 0; |
| 261 | int i; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 262 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 263 | ptlrpc_service_for_each_part(svcpt, i, svc) |
| 264 | total += svcpt->scp_hist_nrqbds; |
| 265 | |
Joe Perches | 8faeebd | 2015-02-21 18:53:28 -0800 | [diff] [blame] | 266 | seq_printf(m, "%d\n", total); |
| 267 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 268 | } |
Mike Rapoport | c9f6bb9 | 2015-10-13 16:03:42 +0300 | [diff] [blame] | 269 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 270 | LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_req_history_len); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 271 | |
| 272 | static int |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 273 | ptlrpc_lprocfs_req_history_max_seq_show(struct seq_file *m, void *n) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 274 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 275 | struct ptlrpc_service *svc = m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 276 | struct ptlrpc_service_part *svcpt; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 277 | int total = 0; |
| 278 | int i; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 279 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 280 | ptlrpc_service_for_each_part(svcpt, i, svc) |
| 281 | total += svc->srv_hist_nrqbds_cpt_max; |
| 282 | |
Joe Perches | 8faeebd | 2015-02-21 18:53:28 -0800 | [diff] [blame] | 283 | seq_printf(m, "%d\n", total); |
| 284 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 285 | } |
| 286 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 287 | static ssize_t |
Tristan Lelong | e84962e | 2014-12-05 22:43:20 -0800 | [diff] [blame] | 288 | ptlrpc_lprocfs_req_history_max_seq_write(struct file *file, |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 289 | const char __user *buffer, |
| 290 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 291 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 292 | struct ptlrpc_service *svc = ((struct seq_file *)file->private_data)->private; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 293 | int bufpages; |
| 294 | int val; |
| 295 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 296 | |
| 297 | rc = lprocfs_write_helper(buffer, count, &val); |
| 298 | if (rc < 0) |
| 299 | return rc; |
| 300 | |
| 301 | if (val < 0) |
| 302 | return -ERANGE; |
| 303 | |
| 304 | /* This sanity check is more of an insanity check; we can still |
| 305 | * hose a kernel by allowing the request history to grow too |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 306 | * far. |
| 307 | */ |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 308 | bufpages = (svc->srv_buf_size + PAGE_SIZE - 1) >> PAGE_SHIFT; |
Peng Tao | 4f6cc9a | 2013-07-15 22:27:04 +0800 | [diff] [blame] | 309 | if (val > totalram_pages / (2 * bufpages)) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 310 | return -ERANGE; |
| 311 | |
| 312 | spin_lock(&svc->srv_lock); |
| 313 | |
| 314 | if (val == 0) |
| 315 | svc->srv_hist_nrqbds_cpt_max = 0; |
| 316 | else |
| 317 | svc->srv_hist_nrqbds_cpt_max = max(1, (val / svc->srv_ncpts)); |
| 318 | |
| 319 | spin_unlock(&svc->srv_lock); |
| 320 | |
| 321 | return count; |
| 322 | } |
Mike Rapoport | c9f6bb9 | 2015-10-13 16:03:42 +0300 | [diff] [blame] | 323 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 324 | LPROC_SEQ_FOPS(ptlrpc_lprocfs_req_history_max); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 325 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 326 | static ssize_t threads_min_show(struct kobject *kobj, struct attribute *attr, |
| 327 | char *buf) |
| 328 | { |
| 329 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 330 | srv_kobj); |
| 331 | |
| 332 | return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_init * svc->srv_ncpts); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 333 | } |
| 334 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 335 | static ssize_t threads_min_store(struct kobject *kobj, struct attribute *attr, |
| 336 | const char *buffer, size_t count) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 337 | { |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 338 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 339 | srv_kobj); |
| 340 | unsigned long val; |
| 341 | int rc = kstrtoul(buffer, 10, &val); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 342 | |
| 343 | if (rc < 0) |
| 344 | return rc; |
| 345 | |
| 346 | if (val / svc->srv_ncpts < PTLRPC_NTHRS_INIT) |
| 347 | return -ERANGE; |
| 348 | |
| 349 | spin_lock(&svc->srv_lock); |
| 350 | if (val > svc->srv_nthrs_cpt_limit * svc->srv_ncpts) { |
| 351 | spin_unlock(&svc->srv_lock); |
| 352 | return -ERANGE; |
| 353 | } |
| 354 | |
| 355 | svc->srv_nthrs_cpt_init = val / svc->srv_ncpts; |
| 356 | |
| 357 | spin_unlock(&svc->srv_lock); |
| 358 | |
| 359 | return count; |
| 360 | } |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 361 | LUSTRE_RW_ATTR(threads_min); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 362 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 363 | static ssize_t threads_started_show(struct kobject *kobj, |
| 364 | struct attribute *attr, |
| 365 | char *buf) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 366 | { |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 367 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 368 | srv_kobj); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 369 | struct ptlrpc_service_part *svcpt; |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 370 | int total = 0; |
| 371 | int i; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 372 | |
| 373 | ptlrpc_service_for_each_part(svcpt, i, svc) |
| 374 | total += svcpt->scp_nthrs_running; |
| 375 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 376 | return sprintf(buf, "%d\n", total); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 377 | } |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 378 | LUSTRE_RO_ATTR(threads_started); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 379 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 380 | static ssize_t threads_max_show(struct kobject *kobj, struct attribute *attr, |
| 381 | char *buf) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 382 | { |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 383 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 384 | srv_kobj); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 385 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 386 | return sprintf(buf, "%d\n", svc->srv_nthrs_cpt_limit * svc->srv_ncpts); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 387 | } |
| 388 | |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 389 | static ssize_t threads_max_store(struct kobject *kobj, struct attribute *attr, |
| 390 | const char *buffer, size_t count) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 391 | { |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 392 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 393 | srv_kobj); |
| 394 | unsigned long val; |
| 395 | int rc = kstrtoul(buffer, 10, &val); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 396 | |
| 397 | if (rc < 0) |
| 398 | return rc; |
| 399 | |
| 400 | if (val / svc->srv_ncpts < PTLRPC_NTHRS_INIT) |
| 401 | return -ERANGE; |
| 402 | |
| 403 | spin_lock(&svc->srv_lock); |
| 404 | if (val < svc->srv_nthrs_cpt_init * svc->srv_ncpts) { |
| 405 | spin_unlock(&svc->srv_lock); |
| 406 | return -ERANGE; |
| 407 | } |
| 408 | |
| 409 | svc->srv_nthrs_cpt_limit = val / svc->srv_ncpts; |
| 410 | |
| 411 | spin_unlock(&svc->srv_lock); |
| 412 | |
| 413 | return count; |
| 414 | } |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 415 | LUSTRE_RW_ATTR(threads_max); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 416 | |
| 417 | /** |
| 418 | * \addtogoup nrs |
| 419 | * @{ |
| 420 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 421 | |
| 422 | /** |
| 423 | * Translates \e ptlrpc_nrs_pol_state values to human-readable strings. |
| 424 | * |
| 425 | * \param[in] state The policy state |
| 426 | */ |
| 427 | static const char *nrs_state2str(enum ptlrpc_nrs_pol_state state) |
| 428 | { |
| 429 | switch (state) { |
| 430 | default: |
| 431 | LBUG(); |
| 432 | case NRS_POL_STATE_INVALID: |
| 433 | return "invalid"; |
| 434 | case NRS_POL_STATE_STOPPED: |
| 435 | return "stopped"; |
| 436 | case NRS_POL_STATE_STOPPING: |
| 437 | return "stopping"; |
| 438 | case NRS_POL_STATE_STARTING: |
| 439 | return "starting"; |
| 440 | case NRS_POL_STATE_STARTED: |
| 441 | return "started"; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Obtains status information for \a policy. |
| 447 | * |
| 448 | * Information is copied in \a info. |
| 449 | * |
| 450 | * \param[in] policy The policy |
| 451 | * \param[out] info Holds returned status information |
| 452 | */ |
Rocco Folino | 9613546 | 2015-10-02 23:54:26 +0200 | [diff] [blame] | 453 | static void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 454 | struct ptlrpc_nrs_pol_info *info) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 455 | { |
Li Xi | 5e42bc9 | 2014-04-27 13:07:06 -0400 | [diff] [blame] | 456 | assert_spin_locked(&policy->pol_nrs->nrs_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 457 | |
| 458 | memcpy(info->pi_name, policy->pol_desc->pd_name, NRS_POL_NAME_MAX); |
| 459 | |
| 460 | info->pi_fallback = !!(policy->pol_flags & PTLRPC_NRS_FL_FALLBACK); |
| 461 | info->pi_state = policy->pol_state; |
| 462 | /** |
| 463 | * XXX: These are accessed without holding |
| 464 | * ptlrpc_service_part::scp_req_lock. |
| 465 | */ |
| 466 | info->pi_req_queued = policy->pol_req_queued; |
| 467 | info->pi_req_started = policy->pol_req_started; |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Reads and prints policy status information for all policies of a PTLRPC |
| 472 | * service. |
| 473 | */ |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 474 | static int ptlrpc_lprocfs_nrs_seq_show(struct seq_file *m, void *n) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 475 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 476 | struct ptlrpc_service *svc = m->private; |
| 477 | struct ptlrpc_service_part *svcpt; |
| 478 | struct ptlrpc_nrs *nrs; |
| 479 | struct ptlrpc_nrs_policy *policy; |
| 480 | struct ptlrpc_nrs_pol_info *infos; |
| 481 | struct ptlrpc_nrs_pol_info tmp; |
| 482 | unsigned num_pols; |
| 483 | unsigned pol_idx = 0; |
| 484 | bool hp = false; |
| 485 | int i; |
| 486 | int rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * Serialize NRS core lprocfs operations with policy registration/ |
| 490 | * unregistration. |
| 491 | */ |
| 492 | mutex_lock(&nrs_core.nrs_mutex); |
| 493 | |
| 494 | /** |
| 495 | * Use the first service partition's regular NRS head in order to obtain |
| 496 | * the number of policies registered with NRS heads of this service. All |
| 497 | * service partitions will have the same number of policies. |
| 498 | */ |
| 499 | nrs = nrs_svcpt2nrs(svc->srv_parts[0], false); |
| 500 | |
| 501 | spin_lock(&nrs->nrs_lock); |
| 502 | num_pols = svc->srv_parts[0]->scp_nrs_reg.nrs_num_pols; |
| 503 | spin_unlock(&nrs->nrs_lock); |
| 504 | |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 505 | infos = kcalloc(num_pols, sizeof(*infos), GFP_NOFS); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 506 | if (!infos) { |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 507 | rc = -ENOMEM; |
Julia Lawall | 848e90c | 2015-05-01 21:37:49 +0200 | [diff] [blame] | 508 | goto unlock; |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 509 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 510 | again: |
| 511 | |
| 512 | ptlrpc_service_for_each_part(svcpt, i, svc) { |
| 513 | nrs = nrs_svcpt2nrs(svcpt, hp); |
| 514 | spin_lock(&nrs->nrs_lock); |
| 515 | |
| 516 | pol_idx = 0; |
| 517 | |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 518 | list_for_each_entry(policy, &nrs->nrs_policy_list, pol_list) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 519 | LASSERT(pol_idx < num_pols); |
| 520 | |
| 521 | nrs_policy_get_info_locked(policy, &tmp); |
| 522 | /** |
| 523 | * Copy values when handling the first service |
| 524 | * partition. |
| 525 | */ |
| 526 | if (i == 0) { |
| 527 | memcpy(infos[pol_idx].pi_name, tmp.pi_name, |
| 528 | NRS_POL_NAME_MAX); |
| 529 | memcpy(&infos[pol_idx].pi_state, &tmp.pi_state, |
| 530 | sizeof(tmp.pi_state)); |
| 531 | infos[pol_idx].pi_fallback = tmp.pi_fallback; |
| 532 | /** |
| 533 | * For the rest of the service partitions |
| 534 | * sanity-check the values we get. |
| 535 | */ |
| 536 | } else { |
| 537 | LASSERT(strncmp(infos[pol_idx].pi_name, |
| 538 | tmp.pi_name, |
| 539 | NRS_POL_NAME_MAX) == 0); |
| 540 | /** |
| 541 | * Not asserting ptlrpc_nrs_pol_info::pi_state, |
| 542 | * because it may be different between |
| 543 | * instances of the same policy in different |
| 544 | * service partitions. |
| 545 | */ |
| 546 | LASSERT(infos[pol_idx].pi_fallback == |
| 547 | tmp.pi_fallback); |
| 548 | } |
| 549 | |
| 550 | infos[pol_idx].pi_req_queued += tmp.pi_req_queued; |
| 551 | infos[pol_idx].pi_req_started += tmp.pi_req_started; |
| 552 | |
| 553 | pol_idx++; |
| 554 | } |
| 555 | spin_unlock(&nrs->nrs_lock); |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * Policy status information output is in YAML format. |
| 560 | * For example: |
| 561 | * |
| 562 | * regular_requests: |
| 563 | * - name: fifo |
| 564 | * state: started |
| 565 | * fallback: yes |
| 566 | * queued: 0 |
| 567 | * active: 0 |
| 568 | * |
| 569 | * - name: crrn |
| 570 | * state: started |
| 571 | * fallback: no |
| 572 | * queued: 2015 |
| 573 | * active: 384 |
| 574 | * |
| 575 | * high_priority_requests: |
| 576 | * - name: fifo |
| 577 | * state: started |
| 578 | * fallback: yes |
| 579 | * queued: 0 |
| 580 | * active: 2 |
| 581 | * |
| 582 | * - name: crrn |
| 583 | * state: stopped |
| 584 | * fallback: no |
| 585 | * queued: 0 |
| 586 | * active: 0 |
| 587 | */ |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 588 | seq_printf(m, "%s\n", |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 589 | !hp ? "\nregular_requests:" : "high_priority_requests:"); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 590 | |
| 591 | for (pol_idx = 0; pol_idx < num_pols; pol_idx++) { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 592 | seq_printf(m, " - name: %s\n" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 593 | " state: %s\n" |
| 594 | " fallback: %s\n" |
| 595 | " queued: %-20d\n" |
| 596 | " active: %-20d\n\n", |
| 597 | infos[pol_idx].pi_name, |
| 598 | nrs_state2str(infos[pol_idx].pi_state), |
| 599 | infos[pol_idx].pi_fallback ? "yes" : "no", |
| 600 | (int)infos[pol_idx].pi_req_queued, |
| 601 | (int)infos[pol_idx].pi_req_started); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | if (!hp && nrs_svc_has_hp(svc)) { |
| 605 | memset(infos, 0, num_pols * sizeof(*infos)); |
| 606 | |
| 607 | /** |
| 608 | * Redo the processing for the service's HP NRS heads' policies. |
| 609 | */ |
| 610 | hp = true; |
| 611 | goto again; |
| 612 | } |
| 613 | |
Julia Lawall | 848e90c | 2015-05-01 21:37:49 +0200 | [diff] [blame] | 614 | kfree(infos); |
| 615 | unlock: |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 616 | mutex_unlock(&nrs_core.nrs_mutex); |
| 617 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 618 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /** |
Masanari Iida | b6da17f | 2014-02-08 00:30:40 +0900 | [diff] [blame] | 622 | * The longest valid command string is the maximum policy name size, plus the |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 623 | * length of the " reg" substring |
| 624 | */ |
| 625 | #define LPROCFS_NRS_WR_MAX_CMD (NRS_POL_NAME_MAX + sizeof(" reg") - 1) |
| 626 | |
| 627 | /** |
| 628 | * Starts and stops a given policy on a PTLRPC service. |
| 629 | * |
| 630 | * Commands consist of the policy name, followed by an optional [reg|hp] token; |
| 631 | * if the optional token is omitted, the operation is performed on both the |
| 632 | * regular and high-priority (if the service has one) NRS head. |
| 633 | */ |
Anil Belur | 29dd4f9 | 2014-07-31 13:21:02 +0530 | [diff] [blame] | 634 | static ssize_t ptlrpc_lprocfs_nrs_seq_write(struct file *file, |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 635 | const char __user *buffer, |
| 636 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 637 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 638 | struct ptlrpc_service *svc = ((struct seq_file *)file->private_data)->private; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 639 | enum ptlrpc_nrs_queue_type queue = PTLRPC_NRS_QUEUE_BOTH; |
| 640 | char *cmd; |
| 641 | char *cmd_copy = NULL; |
| 642 | char *token; |
| 643 | int rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 644 | |
Julia Lawall | 848e90c | 2015-05-01 21:37:49 +0200 | [diff] [blame] | 645 | if (count >= LPROCFS_NRS_WR_MAX_CMD) |
| 646 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 647 | |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 648 | cmd = kzalloc(LPROCFS_NRS_WR_MAX_CMD, GFP_NOFS); |
Julia Lawall | 597851a | 2015-06-20 18:59:10 +0200 | [diff] [blame] | 649 | if (!cmd) |
Julia Lawall | 848e90c | 2015-05-01 21:37:49 +0200 | [diff] [blame] | 650 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 651 | /** |
| 652 | * strsep() modifies its argument, so keep a copy |
| 653 | */ |
| 654 | cmd_copy = cmd; |
| 655 | |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 656 | if (copy_from_user(cmd, buffer, count)) { |
| 657 | rc = -EFAULT; |
| 658 | goto out; |
| 659 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 660 | |
| 661 | cmd[count] = '\0'; |
| 662 | |
| 663 | token = strsep(&cmd, " "); |
| 664 | |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 665 | if (strlen(token) > NRS_POL_NAME_MAX - 1) { |
| 666 | rc = -EINVAL; |
| 667 | goto out; |
| 668 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * No [reg|hp] token has been specified |
| 672 | */ |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 673 | if (!cmd) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 674 | goto default_queue; |
| 675 | |
| 676 | /** |
| 677 | * The second token is either NULL, or an optional [reg|hp] string |
| 678 | */ |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 679 | if (strcmp(cmd, "reg") == 0) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 680 | queue = PTLRPC_NRS_QUEUE_REG; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 681 | } else if (strcmp(cmd, "hp") == 0) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 682 | queue = PTLRPC_NRS_QUEUE_HP; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 683 | } else { |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 684 | rc = -EINVAL; |
| 685 | goto out; |
| 686 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 687 | |
| 688 | default_queue: |
| 689 | |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 690 | if (queue == PTLRPC_NRS_QUEUE_HP && !nrs_svc_has_hp(svc)) { |
| 691 | rc = -ENODEV; |
| 692 | goto out; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 693 | } else if (queue == PTLRPC_NRS_QUEUE_BOTH && !nrs_svc_has_hp(svc)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 694 | queue = PTLRPC_NRS_QUEUE_REG; |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 695 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 696 | |
| 697 | /** |
| 698 | * Serialize NRS core lprocfs operations with policy registration/ |
| 699 | * unregistration. |
| 700 | */ |
| 701 | mutex_lock(&nrs_core.nrs_mutex); |
| 702 | |
| 703 | rc = ptlrpc_nrs_policy_control(svc, queue, token, PTLRPC_NRS_CTL_START, |
| 704 | false, NULL); |
| 705 | |
| 706 | mutex_unlock(&nrs_core.nrs_mutex); |
| 707 | out: |
Julia Lawall | 848e90c | 2015-05-01 21:37:49 +0200 | [diff] [blame] | 708 | kfree(cmd_copy); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 709 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 710 | return rc < 0 ? rc : count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 711 | } |
Mike Rapoport | c9f6bb9 | 2015-10-13 16:03:42 +0300 | [diff] [blame] | 712 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 713 | LPROC_SEQ_FOPS(ptlrpc_lprocfs_nrs); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 714 | |
| 715 | /** @} nrs */ |
| 716 | |
| 717 | struct ptlrpc_srh_iterator { |
| 718 | int srhi_idx; |
| 719 | __u64 srhi_seq; |
| 720 | struct ptlrpc_request *srhi_req; |
| 721 | }; |
| 722 | |
Jon Bernard | b3c986d | 2015-01-20 14:55:28 -0500 | [diff] [blame] | 723 | static int |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 724 | ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service_part *svcpt, |
| 725 | struct ptlrpc_srh_iterator *srhi, |
| 726 | __u64 seq) |
| 727 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 728 | struct list_head *e; |
| 729 | struct ptlrpc_request *req; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 730 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 731 | if (srhi->srhi_req && srhi->srhi_seq > svcpt->scp_hist_seq_culled && |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 732 | srhi->srhi_seq <= seq) { |
| 733 | /* If srhi_req was set previously, hasn't been culled and |
| 734 | * we're searching for a seq on or after it (i.e. more |
| 735 | * recent), search from it onwards. |
| 736 | * Since the service history is LRU (i.e. culled reqs will |
| 737 | * be near the head), we shouldn't have to do long |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 738 | * re-scans |
| 739 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 740 | LASSERTF(srhi->srhi_seq == srhi->srhi_req->rq_history_seq, |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 741 | "%s:%d: seek seq %llu, request seq %llu\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 742 | svcpt->scp_service->srv_name, svcpt->scp_cpt, |
| 743 | srhi->srhi_seq, srhi->srhi_req->rq_history_seq); |
| 744 | LASSERTF(!list_empty(&svcpt->scp_hist_reqs), |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 745 | "%s:%d: seek offset %llu, request seq %llu, last culled %llu\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 746 | svcpt->scp_service->srv_name, svcpt->scp_cpt, |
| 747 | seq, srhi->srhi_seq, svcpt->scp_hist_seq_culled); |
| 748 | e = &srhi->srhi_req->rq_history_list; |
| 749 | } else { |
| 750 | /* search from start */ |
| 751 | e = svcpt->scp_hist_reqs.next; |
| 752 | } |
| 753 | |
| 754 | while (e != &svcpt->scp_hist_reqs) { |
| 755 | req = list_entry(e, struct ptlrpc_request, rq_history_list); |
| 756 | |
| 757 | if (req->rq_history_seq >= seq) { |
| 758 | srhi->srhi_seq = req->rq_history_seq; |
| 759 | srhi->srhi_req = req; |
| 760 | return 0; |
| 761 | } |
| 762 | e = e->next; |
| 763 | } |
| 764 | |
| 765 | return -ENOENT; |
| 766 | } |
| 767 | |
| 768 | /* |
| 769 | * ptlrpc history sequence is used as "position" of seq_file, in some case, |
| 770 | * seq_read() will increase "position" to indicate reading the next |
| 771 | * element, however, low bits of history sequence are reserved for CPT id |
| 772 | * (check the details from comments before ptlrpc_req_add_history), which |
| 773 | * means seq_read() might change CPT id of history sequence and never |
| 774 | * finish reading of requests on a CPT. To make it work, we have to shift |
| 775 | * CPT id to high bits and timestamp to low bits, so seq_read() will only |
| 776 | * increase timestamp which can correctly indicate the next position. |
| 777 | */ |
| 778 | |
| 779 | /* convert seq_file pos to cpt */ |
| 780 | #define PTLRPC_REQ_POS2CPT(svc, pos) \ |
| 781 | ((svc)->srv_cpt_bits == 0 ? 0 : \ |
| 782 | (__u64)(pos) >> (64 - (svc)->srv_cpt_bits)) |
| 783 | |
| 784 | /* make up seq_file pos from cpt */ |
| 785 | #define PTLRPC_REQ_CPT2POS(svc, cpt) \ |
| 786 | ((svc)->srv_cpt_bits == 0 ? 0 : \ |
| 787 | (cpt) << (64 - (svc)->srv_cpt_bits)) |
| 788 | |
| 789 | /* convert sequence to position */ |
| 790 | #define PTLRPC_REQ_SEQ2POS(svc, seq) \ |
| 791 | ((svc)->srv_cpt_bits == 0 ? (seq) : \ |
| 792 | ((seq) >> (svc)->srv_cpt_bits) | \ |
| 793 | ((seq) << (64 - (svc)->srv_cpt_bits))) |
| 794 | |
| 795 | /* convert position to sequence */ |
| 796 | #define PTLRPC_REQ_POS2SEQ(svc, pos) \ |
| 797 | ((svc)->srv_cpt_bits == 0 ? (pos) : \ |
| 798 | ((__u64)(pos) << (svc)->srv_cpt_bits) | \ |
| 799 | ((__u64)(pos) >> (64 - (svc)->srv_cpt_bits))) |
| 800 | |
| 801 | static void * |
| 802 | ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos) |
| 803 | { |
| 804 | struct ptlrpc_service *svc = s->private; |
| 805 | struct ptlrpc_service_part *svcpt; |
| 806 | struct ptlrpc_srh_iterator *srhi; |
| 807 | unsigned int cpt; |
| 808 | int rc; |
| 809 | int i; |
| 810 | |
| 811 | if (sizeof(loff_t) != sizeof(__u64)) { /* can't support */ |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 812 | CWARN("Failed to read request history because size of loff_t %d can't match size of u64\n", |
| 813 | (int)sizeof(loff_t)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 814 | return NULL; |
| 815 | } |
| 816 | |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 817 | srhi = kzalloc(sizeof(*srhi), GFP_NOFS); |
Julia Lawall | 597851a | 2015-06-20 18:59:10 +0200 | [diff] [blame] | 818 | if (!srhi) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 819 | return NULL; |
| 820 | |
| 821 | srhi->srhi_seq = 0; |
| 822 | srhi->srhi_req = NULL; |
| 823 | |
| 824 | cpt = PTLRPC_REQ_POS2CPT(svc, *pos); |
| 825 | |
| 826 | ptlrpc_service_for_each_part(svcpt, i, svc) { |
| 827 | if (i < cpt) /* skip */ |
| 828 | continue; |
| 829 | if (i > cpt) /* make up the lowest position for this CPT */ |
| 830 | *pos = PTLRPC_REQ_CPT2POS(svc, i); |
| 831 | |
| 832 | spin_lock(&svcpt->scp_lock); |
| 833 | rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, |
| 834 | PTLRPC_REQ_POS2SEQ(svc, *pos)); |
| 835 | spin_unlock(&svcpt->scp_lock); |
| 836 | if (rc == 0) { |
| 837 | *pos = PTLRPC_REQ_SEQ2POS(svc, srhi->srhi_seq); |
| 838 | srhi->srhi_idx = i; |
| 839 | return srhi; |
| 840 | } |
| 841 | } |
| 842 | |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 843 | kfree(srhi); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 844 | return NULL; |
| 845 | } |
| 846 | |
| 847 | static void |
| 848 | ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter) |
| 849 | { |
| 850 | struct ptlrpc_srh_iterator *srhi = iter; |
| 851 | |
Julia Lawall | 848e90c | 2015-05-01 21:37:49 +0200 | [diff] [blame] | 852 | kfree(srhi); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | static void * |
| 856 | ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s, |
| 857 | void *iter, loff_t *pos) |
| 858 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 859 | struct ptlrpc_service *svc = s->private; |
| 860 | struct ptlrpc_srh_iterator *srhi = iter; |
| 861 | struct ptlrpc_service_part *svcpt; |
| 862 | __u64 seq; |
| 863 | int rc; |
| 864 | int i; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 865 | |
| 866 | for (i = srhi->srhi_idx; i < svc->srv_ncpts; i++) { |
| 867 | svcpt = svc->srv_parts[i]; |
| 868 | |
| 869 | if (i > srhi->srhi_idx) { /* reset iterator for a new CPT */ |
| 870 | srhi->srhi_req = NULL; |
Nathaniel Clark | 3d2b8f5 | 2016-06-09 22:35:17 -0400 | [diff] [blame] | 871 | seq = 0; |
| 872 | srhi->srhi_seq = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 873 | } else { /* the next sequence */ |
| 874 | seq = srhi->srhi_seq + (1 << svc->srv_cpt_bits); |
| 875 | } |
| 876 | |
| 877 | spin_lock(&svcpt->scp_lock); |
| 878 | rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, seq); |
| 879 | spin_unlock(&svcpt->scp_lock); |
| 880 | if (rc == 0) { |
| 881 | *pos = PTLRPC_REQ_SEQ2POS(svc, srhi->srhi_seq); |
| 882 | srhi->srhi_idx = i; |
| 883 | return srhi; |
| 884 | } |
| 885 | } |
| 886 | |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 887 | kfree(srhi); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 888 | return NULL; |
| 889 | } |
| 890 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 891 | static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter) |
| 892 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 893 | struct ptlrpc_service *svc = s->private; |
| 894 | struct ptlrpc_srh_iterator *srhi = iter; |
| 895 | struct ptlrpc_service_part *svcpt; |
| 896 | struct ptlrpc_request *req; |
| 897 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 898 | |
| 899 | LASSERT(srhi->srhi_idx < svc->srv_ncpts); |
| 900 | |
| 901 | svcpt = svc->srv_parts[srhi->srhi_idx]; |
| 902 | |
| 903 | spin_lock(&svcpt->scp_lock); |
| 904 | |
| 905 | rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, srhi->srhi_seq); |
| 906 | |
| 907 | if (rc == 0) { |
Dmitry Eremin | 80feb1e | 2015-10-21 21:52:47 -0400 | [diff] [blame] | 908 | char nidstr[LNET_NIDSTR_SIZE]; |
| 909 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 910 | req = srhi->srhi_req; |
| 911 | |
Dmitry Eremin | 80feb1e | 2015-10-21 21:52:47 -0400 | [diff] [blame] | 912 | libcfs_nid2str_r(req->rq_self, nidstr, sizeof(nidstr)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 913 | /* Print common req fields. |
| 914 | * CAVEAT EMPTOR: we're racing with the service handler |
| 915 | * here. The request could contain any old crap, so you |
| 916 | * must be just as careful as the service's request |
| 917 | * parser. Currently I only print stuff here I know is OK |
Oleg Drokin | dadfcda | 2016-02-24 22:00:38 -0500 | [diff] [blame] | 918 | * to look at coz it was set up in request_in_callback()!!! |
| 919 | */ |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 920 | seq_printf(s, "%lld:%s:%s:x%llu:%d:%s:%lld:%lds(%+lds) ", |
Dmitry Eremin | 80feb1e | 2015-10-21 21:52:47 -0400 | [diff] [blame] | 921 | req->rq_history_seq, nidstr, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 922 | libcfs_id2str(req->rq_peer), req->rq_xid, |
| 923 | req->rq_reqlen, ptlrpc_rqphase2str(req), |
Arnd Bergmann | 219e6de | 2015-09-27 16:45:30 -0400 | [diff] [blame] | 924 | (s64)req->rq_arrival_time.tv_sec, |
| 925 | (long)(req->rq_sent - req->rq_arrival_time.tv_sec), |
| 926 | (long)(req->rq_sent - req->rq_deadline)); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 927 | if (!svc->srv_ops.so_req_printer) |
Amitoj Kaur Chawla | 8d816fb | 2015-10-26 22:37:26 +0530 | [diff] [blame] | 928 | seq_putc(s, '\n'); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 929 | else |
| 930 | svc->srv_ops.so_req_printer(s, srhi->srhi_req); |
| 931 | } |
| 932 | |
| 933 | spin_unlock(&svcpt->scp_lock); |
| 934 | return rc; |
| 935 | } |
| 936 | |
| 937 | static int |
| 938 | ptlrpc_lprocfs_svc_req_history_open(struct inode *inode, struct file *file) |
| 939 | { |
Julia Lawall | faac7a8 | 2016-08-28 23:27:06 +0200 | [diff] [blame] | 940 | static const struct seq_operations sops = { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 941 | .start = ptlrpc_lprocfs_svc_req_history_start, |
| 942 | .stop = ptlrpc_lprocfs_svc_req_history_stop, |
| 943 | .next = ptlrpc_lprocfs_svc_req_history_next, |
| 944 | .show = ptlrpc_lprocfs_svc_req_history_show, |
| 945 | }; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 946 | struct seq_file *seqf; |
| 947 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 948 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 949 | rc = seq_open(file, &sops); |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 950 | if (rc) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 951 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 952 | |
| 953 | seqf = file->private_data; |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 954 | seqf->private = inode->i_private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | /* See also lprocfs_rd_timeouts */ |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 959 | static int ptlrpc_lprocfs_timeouts_seq_show(struct seq_file *m, void *n) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 960 | { |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 961 | struct ptlrpc_service *svc = m->private; |
| 962 | struct ptlrpc_service_part *svcpt; |
| 963 | struct dhms ts; |
Arnd Bergmann | 0ac0478 | 2015-09-27 16:45:19 -0400 | [diff] [blame] | 964 | time64_t worstt; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 965 | unsigned int cur; |
| 966 | unsigned int worst; |
| 967 | int i; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 968 | |
| 969 | if (AT_OFF) { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 970 | seq_printf(m, "adaptive timeouts off, using obd_timeout %u\n", |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 971 | obd_timeout); |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 972 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | ptlrpc_service_for_each_part(svcpt, i, svc) { |
| 976 | cur = at_get(&svcpt->scp_at_estimate); |
| 977 | worst = svcpt->scp_at_estimate.at_worst_ever; |
| 978 | worstt = svcpt->scp_at_estimate.at_worst_time; |
Arnd Bergmann | 0ac0478 | 2015-09-27 16:45:19 -0400 | [diff] [blame] | 979 | s2dhms(&ts, ktime_get_real_seconds() - worstt); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 980 | |
Arnd Bergmann | 0ac0478 | 2015-09-27 16:45:19 -0400 | [diff] [blame] | 981 | seq_printf(m, "%10s : cur %3u worst %3u (at %lld, " |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 982 | DHMS_FMT " ago) ", "service", |
| 983 | cur, worst, (s64)worstt, DHMS_VARS(&ts)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 984 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 985 | lprocfs_at_hist_helper(m, &svcpt->scp_at_estimate); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 986 | } |
| 987 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 988 | return 0; |
| 989 | } |
Mike Rapoport | c9f6bb9 | 2015-10-13 16:03:42 +0300 | [diff] [blame] | 990 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 991 | LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_timeouts); |
| 992 | |
Oleg Drokin | b40881e | 2015-05-21 15:32:10 -0400 | [diff] [blame] | 993 | static ssize_t high_priority_ratio_show(struct kobject *kobj, |
| 994 | struct attribute *attr, |
| 995 | char *buf) |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 996 | { |
Oleg Drokin | b40881e | 2015-05-21 15:32:10 -0400 | [diff] [blame] | 997 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 998 | srv_kobj); |
| 999 | return sprintf(buf, "%d\n", svc->srv_hpreq_ratio); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Oleg Drokin | b40881e | 2015-05-21 15:32:10 -0400 | [diff] [blame] | 1002 | static ssize_t high_priority_ratio_store(struct kobject *kobj, |
| 1003 | struct attribute *attr, |
| 1004 | const char *buffer, |
| 1005 | size_t count) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1006 | { |
Oleg Drokin | b40881e | 2015-05-21 15:32:10 -0400 | [diff] [blame] | 1007 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 1008 | srv_kobj); |
| 1009 | int rc; |
Dan Carpenter | b815555 | 2015-06-05 12:22:57 +0300 | [diff] [blame] | 1010 | int val; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1011 | |
Dan Carpenter | b815555 | 2015-06-05 12:22:57 +0300 | [diff] [blame] | 1012 | rc = kstrtoint(buffer, 10, &val); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1013 | if (rc < 0) |
| 1014 | return rc; |
| 1015 | |
| 1016 | if (val < 0) |
| 1017 | return -ERANGE; |
| 1018 | |
| 1019 | spin_lock(&svc->srv_lock); |
| 1020 | svc->srv_hpreq_ratio = val; |
| 1021 | spin_unlock(&svc->srv_lock); |
| 1022 | |
| 1023 | return count; |
| 1024 | } |
Oleg Drokin | b40881e | 2015-05-21 15:32:10 -0400 | [diff] [blame] | 1025 | LUSTRE_RW_ATTR(high_priority_ratio); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1026 | |
Oleg Drokin | 328676f | 2015-05-21 15:32:08 -0400 | [diff] [blame] | 1027 | static struct attribute *ptlrpc_svc_attrs[] = { |
Oleg Drokin | 673a679 | 2015-05-21 15:32:09 -0400 | [diff] [blame] | 1028 | &lustre_attr_threads_min.attr, |
| 1029 | &lustre_attr_threads_started.attr, |
| 1030 | &lustre_attr_threads_max.attr, |
Oleg Drokin | b40881e | 2015-05-21 15:32:10 -0400 | [diff] [blame] | 1031 | &lustre_attr_high_priority_ratio.attr, |
Oleg Drokin | 328676f | 2015-05-21 15:32:08 -0400 | [diff] [blame] | 1032 | NULL, |
| 1033 | }; |
| 1034 | |
| 1035 | static void ptlrpc_sysfs_svc_release(struct kobject *kobj) |
| 1036 | { |
| 1037 | struct ptlrpc_service *svc = container_of(kobj, struct ptlrpc_service, |
| 1038 | srv_kobj); |
| 1039 | |
| 1040 | complete(&svc->srv_kobj_unregister); |
| 1041 | } |
| 1042 | |
| 1043 | static struct kobj_type ptlrpc_svc_ktype = { |
| 1044 | .default_attrs = ptlrpc_svc_attrs, |
| 1045 | .sysfs_ops = &lustre_sysfs_ops, |
| 1046 | .release = ptlrpc_sysfs_svc_release, |
| 1047 | }; |
| 1048 | |
| 1049 | void ptlrpc_sysfs_unregister_service(struct ptlrpc_service *svc) |
| 1050 | { |
| 1051 | /* Let's see if we had a chance at initialization first */ |
| 1052 | if (svc->srv_kobj.kset) { |
| 1053 | kobject_put(&svc->srv_kobj); |
| 1054 | wait_for_completion(&svc->srv_kobj_unregister); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | int ptlrpc_sysfs_register_service(struct kset *parent, |
| 1059 | struct ptlrpc_service *svc) |
| 1060 | { |
| 1061 | int rc; |
| 1062 | |
| 1063 | svc->srv_kobj.kset = parent; |
| 1064 | init_completion(&svc->srv_kobj_unregister); |
| 1065 | rc = kobject_init_and_add(&svc->srv_kobj, &ptlrpc_svc_ktype, NULL, |
| 1066 | "%s", svc->srv_name); |
| 1067 | |
| 1068 | return rc; |
| 1069 | } |
| 1070 | |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 1071 | void ptlrpc_ldebugfs_register_service(struct dentry *entry, |
| 1072 | struct ptlrpc_service *svc) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1073 | { |
| 1074 | struct lprocfs_vars lproc_vars[] = { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1075 | {.name = "req_buffer_history_len", |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1076 | .fops = &ptlrpc_lprocfs_req_history_len_fops, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1077 | .data = svc}, |
| 1078 | {.name = "req_buffer_history_max", |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1079 | .fops = &ptlrpc_lprocfs_req_history_max_fops, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1080 | .data = svc}, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1081 | {.name = "timeouts", |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1082 | .fops = &ptlrpc_lprocfs_timeouts_fops, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1083 | .data = svc}, |
| 1084 | {.name = "nrs_policies", |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1085 | .fops = &ptlrpc_lprocfs_nrs_fops, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1086 | .data = svc}, |
| 1087 | {NULL} |
| 1088 | }; |
Melike Yurtoglu | dddf4c2 | 2015-02-27 22:42:09 +0200 | [diff] [blame] | 1089 | static const struct file_operations req_history_fops = { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1090 | .owner = THIS_MODULE, |
| 1091 | .open = ptlrpc_lprocfs_svc_req_history_open, |
| 1092 | .read = seq_read, |
| 1093 | .llseek = seq_lseek, |
| 1094 | .release = lprocfs_seq_release, |
| 1095 | }; |
| 1096 | |
| 1097 | int rc; |
| 1098 | |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 1099 | ptlrpc_ldebugfs_register(entry, svc->srv_name, |
| 1100 | "stats", &svc->srv_debugfs_entry, |
| 1101 | &svc->srv_stats); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1102 | |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 1103 | if (IS_ERR_OR_NULL(svc->srv_debugfs_entry)) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1104 | return; |
| 1105 | |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 1106 | ldebugfs_add_vars(svc->srv_debugfs_entry, lproc_vars, NULL); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1107 | |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 1108 | rc = ldebugfs_seq_create(svc->srv_debugfs_entry, "req_history", |
| 1109 | 0400, &req_history_fops, svc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1110 | if (rc) |
| 1111 | CWARN("Error adding the req_history file\n"); |
| 1112 | } |
| 1113 | |
| 1114 | void ptlrpc_lprocfs_register_obd(struct obd_device *obddev) |
| 1115 | { |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 1116 | ptlrpc_ldebugfs_register(obddev->obd_debugfs_entry, NULL, "stats", |
| 1117 | &obddev->obd_svc_debugfs_entry, |
| 1118 | &obddev->obd_svc_stats); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1119 | } |
| 1120 | EXPORT_SYMBOL(ptlrpc_lprocfs_register_obd); |
| 1121 | |
| 1122 | void ptlrpc_lprocfs_rpc_sent(struct ptlrpc_request *req, long amount) |
| 1123 | { |
| 1124 | struct lprocfs_stats *svc_stats; |
| 1125 | __u32 op = lustre_msg_get_opc(req->rq_reqmsg); |
| 1126 | int opc = opcode_offset(op); |
| 1127 | |
| 1128 | svc_stats = req->rq_import->imp_obd->obd_svc_stats; |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 1129 | if (!svc_stats || opc <= 0) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1130 | return; |
| 1131 | LASSERT(opc < LUSTRE_MAX_OPCODES); |
| 1132 | if (!(op == LDLM_ENQUEUE || op == MDS_REINT)) |
| 1133 | lprocfs_counter_add(svc_stats, opc + EXTRA_MAX_OPCODES, amount); |
| 1134 | } |
| 1135 | |
| 1136 | void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes) |
| 1137 | { |
| 1138 | struct lprocfs_stats *svc_stats; |
| 1139 | int idx; |
| 1140 | |
| 1141 | if (!req->rq_import) |
| 1142 | return; |
| 1143 | svc_stats = req->rq_import->imp_obd->obd_svc_stats; |
| 1144 | if (!svc_stats) |
| 1145 | return; |
| 1146 | idx = lustre_msg_get_opc(req->rq_reqmsg); |
| 1147 | switch (idx) { |
| 1148 | case OST_READ: |
| 1149 | idx = BRW_READ_BYTES + PTLRPC_LAST_CNTR; |
| 1150 | break; |
| 1151 | case OST_WRITE: |
| 1152 | idx = BRW_WRITE_BYTES + PTLRPC_LAST_CNTR; |
| 1153 | break; |
| 1154 | default: |
| 1155 | LASSERTF(0, "unsupported opcode %u\n", idx); |
| 1156 | break; |
| 1157 | } |
| 1158 | |
| 1159 | lprocfs_counter_add(svc_stats, idx, bytes); |
| 1160 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1161 | EXPORT_SYMBOL(ptlrpc_lprocfs_brw); |
| 1162 | |
| 1163 | void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc) |
| 1164 | { |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 1165 | if (!IS_ERR_OR_NULL(svc->srv_debugfs_entry)) |
Dmitry Eremin | 700815d | 2015-05-21 15:32:11 -0400 | [diff] [blame] | 1166 | ldebugfs_remove(&svc->srv_debugfs_entry); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1167 | |
| 1168 | if (svc->srv_stats) |
| 1169 | lprocfs_free_stats(&svc->srv_stats); |
| 1170 | } |
| 1171 | |
| 1172 | void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd) |
| 1173 | { |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 1174 | if (!IS_ERR_OR_NULL(obd->obd_svc_debugfs_entry)) |
| 1175 | ldebugfs_remove(&obd->obd_svc_debugfs_entry); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1176 | |
| 1177 | if (obd->obd_svc_stats) |
| 1178 | lprocfs_free_stats(&obd->obd_svc_stats); |
| 1179 | } |
| 1180 | EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd); |
| 1181 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1182 | #undef BUFLEN |
| 1183 | |
Tristan Lelong | e84962e | 2014-12-05 22:43:20 -0800 | [diff] [blame] | 1184 | int lprocfs_wr_ping(struct file *file, const char __user *buffer, |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1185 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1186 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1187 | struct obd_device *obd = ((struct seq_file *)file->private_data)->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1188 | struct ptlrpc_request *req; |
Chris Hanna | d0bfef3 | 2015-06-03 10:28:26 -0400 | [diff] [blame] | 1189 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1190 | |
Ksenija Stanojevic | a15b222 | 2015-10-26 08:05:57 -0700 | [diff] [blame] | 1191 | rc = lprocfs_climp_check(obd); |
| 1192 | if (rc) |
| 1193 | return rc; |
| 1194 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1195 | req = ptlrpc_prep_ping(obd->u.cli.cl_import); |
Ksenija Stanojevic | e5b6b5d | 2015-10-28 17:30:43 -0700 | [diff] [blame] | 1196 | up_read(&obd->u.cli.cl_sem); |
Oleg Drokin | 8b38208 | 2016-02-16 00:46:58 -0500 | [diff] [blame] | 1197 | if (!req) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1198 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1199 | |
| 1200 | req->rq_send_state = LUSTRE_IMP_FULL; |
| 1201 | |
| 1202 | rc = ptlrpc_queue_wait(req); |
| 1203 | |
| 1204 | ptlrpc_req_finished(req); |
| 1205 | if (rc >= 0) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 1206 | return count; |
| 1207 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1208 | } |
| 1209 | EXPORT_SYMBOL(lprocfs_wr_ping); |
| 1210 | |
| 1211 | /* Write the connection UUID to this file to attempt to connect to that node. |
| 1212 | * The connection UUID is a node's primary NID. For example, |
| 1213 | * "echo connection=192.168.0.1@tcp0::instance > .../import". |
| 1214 | */ |
Tristan Lelong | e84962e | 2014-12-05 22:43:20 -0800 | [diff] [blame] | 1215 | int lprocfs_wr_import(struct file *file, const char __user *buffer, |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1216 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1217 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1218 | struct obd_device *obd = ((struct seq_file *)file->private_data)->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1219 | struct obd_import *imp = obd->u.cli.cl_import; |
| 1220 | char *kbuf = NULL; |
| 1221 | char *uuid; |
| 1222 | char *ptr; |
| 1223 | int do_reconn = 1; |
| 1224 | const char prefix[] = "connection="; |
| 1225 | const int prefix_len = sizeof(prefix) - 1; |
| 1226 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1227 | if (count > PAGE_SIZE - 1 || count <= prefix_len) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1228 | return -EINVAL; |
| 1229 | |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 1230 | kbuf = kzalloc(count + 1, GFP_NOFS); |
Julia Lawall | 597851a | 2015-06-20 18:59:10 +0200 | [diff] [blame] | 1231 | if (!kbuf) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1232 | return -ENOMEM; |
| 1233 | |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1234 | if (copy_from_user(kbuf, buffer, count)) { |
| 1235 | count = -EFAULT; |
| 1236 | goto out; |
| 1237 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1238 | |
| 1239 | kbuf[count] = 0; |
| 1240 | |
| 1241 | /* only support connection=uuid::instance now */ |
Julia Lawall | a9b3e8f | 2014-09-07 18:18:29 +0200 | [diff] [blame] | 1242 | if (strncmp(prefix, kbuf, prefix_len) != 0) { |
| 1243 | count = -EINVAL; |
| 1244 | goto out; |
| 1245 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1246 | |
| 1247 | uuid = kbuf + prefix_len; |
| 1248 | ptr = strstr(uuid, "::"); |
| 1249 | if (ptr) { |
| 1250 | __u32 inst; |
| 1251 | char *endptr; |
| 1252 | |
| 1253 | *ptr = 0; |
| 1254 | do_reconn = 0; |
| 1255 | ptr += strlen("::"); |
Shivani Bhardwaj | e3ce40cb7 | 2015-10-16 02:17:20 +0530 | [diff] [blame] | 1256 | inst = simple_strtoul(ptr, &endptr, 10); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1257 | if (*endptr) { |
| 1258 | CERROR("config: wrong instance # %s\n", ptr); |
| 1259 | } else if (inst != imp->imp_connect_data.ocd_instance) { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1260 | CDEBUG(D_INFO, "IR: %s is connecting to an obsoleted target(%u/%u), reconnecting...\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1261 | imp->imp_obd->obd_name, |
| 1262 | imp->imp_connect_data.ocd_instance, inst); |
| 1263 | do_reconn = 1; |
| 1264 | } else { |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 1265 | CDEBUG(D_INFO, "IR: %s has already been connecting to new target(%u)\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1266 | imp->imp_obd->obd_name, inst); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | if (do_reconn) |
| 1271 | ptlrpc_recover_import(imp, uuid, 1); |
| 1272 | |
| 1273 | out: |
Julia Lawall | 9ae1059 | 2015-05-01 17:51:12 +0200 | [diff] [blame] | 1274 | kfree(kbuf); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1275 | return count; |
| 1276 | } |
| 1277 | EXPORT_SYMBOL(lprocfs_wr_import); |
| 1278 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1279 | int lprocfs_rd_pinger_recov(struct seq_file *m, void *n) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1280 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1281 | struct obd_device *obd = m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1282 | struct obd_import *imp = obd->u.cli.cl_import; |
Ksenija Stanojevic | a15b222 | 2015-10-26 08:05:57 -0700 | [diff] [blame] | 1283 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1284 | |
Ksenija Stanojevic | a15b222 | 2015-10-26 08:05:57 -0700 | [diff] [blame] | 1285 | rc = lprocfs_climp_check(obd); |
| 1286 | if (rc) |
| 1287 | return rc; |
| 1288 | |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 1289 | seq_printf(m, "%d\n", !imp->imp_no_pinger_recover); |
Ksenija Stanojevic | e5b6b5d | 2015-10-28 17:30:43 -0700 | [diff] [blame] | 1290 | up_read(&obd->u.cli.cl_sem); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1291 | |
Joe Perches | 91b3a68 | 2015-03-01 19:58:57 -0800 | [diff] [blame] | 1292 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1293 | } |
| 1294 | EXPORT_SYMBOL(lprocfs_rd_pinger_recov); |
| 1295 | |
Tristan Lelong | e84962e | 2014-12-05 22:43:20 -0800 | [diff] [blame] | 1296 | int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer, |
Oleg Drokin | 30c0aa3 | 2016-02-26 01:50:02 -0500 | [diff] [blame] | 1297 | size_t count, loff_t *off) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1298 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 1299 | struct obd_device *obd = ((struct seq_file *)file->private_data)->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1300 | struct client_obd *cli = &obd->u.cli; |
| 1301 | struct obd_import *imp = cli->cl_import; |
| 1302 | int rc, val; |
| 1303 | |
| 1304 | rc = lprocfs_write_helper(buffer, count, &val); |
| 1305 | if (rc < 0) |
| 1306 | return rc; |
| 1307 | |
| 1308 | if (val != 0 && val != 1) |
| 1309 | return -ERANGE; |
| 1310 | |
Ksenija Stanojevic | a15b222 | 2015-10-26 08:05:57 -0700 | [diff] [blame] | 1311 | rc = lprocfs_climp_check(obd); |
| 1312 | if (rc) |
| 1313 | return rc; |
| 1314 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1315 | spin_lock(&imp->imp_lock); |
| 1316 | imp->imp_no_pinger_recover = !val; |
| 1317 | spin_unlock(&imp->imp_lock); |
Ksenija Stanojevic | e5b6b5d | 2015-10-28 17:30:43 -0700 | [diff] [blame] | 1318 | up_read(&obd->u.cli.cl_sem); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1319 | |
| 1320 | return count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1321 | } |
| 1322 | EXPORT_SYMBOL(lprocfs_wr_pinger_recov); |