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) 2003, 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) 2010, 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 | |
| 33 | /** |
| 34 | * This file deals with various client/target related logic including recovery. |
| 35 | * |
| 36 | * TODO: This code more logically belongs in the ptlrpc module than in ldlm and |
| 37 | * should be moved. |
| 38 | */ |
| 39 | |
| 40 | #define DEBUG_SUBSYSTEM S_LDLM |
| 41 | |
Greg Kroah-Hartman | 9fdaf8c | 2014-07-11 20:51:16 -0700 | [diff] [blame] | 42 | #include "../../include/linux/libcfs/libcfs.h" |
Greg Kroah-Hartman | e27db14 | 2014-07-11 22:29:36 -0700 | [diff] [blame] | 43 | #include "../include/obd.h" |
| 44 | #include "../include/obd_class.h" |
| 45 | #include "../include/lustre_dlm.h" |
| 46 | #include "../include/lustre_net.h" |
| 47 | #include "../include/lustre_sec.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 48 | #include "ldlm_internal.h" |
| 49 | |
| 50 | /* @priority: If non-zero, move the selected connection to the list head. |
| 51 | * @create: If zero, only search in existing connections. |
| 52 | */ |
| 53 | static int import_set_conn(struct obd_import *imp, struct obd_uuid *uuid, |
| 54 | int priority, int create) |
| 55 | { |
| 56 | struct ptlrpc_connection *ptlrpc_conn; |
| 57 | struct obd_import_conn *imp_conn = NULL, *item; |
| 58 | int rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 59 | |
| 60 | if (!create && !priority) { |
| 61 | CDEBUG(D_HA, "Nothing to do\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 62 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | ptlrpc_conn = ptlrpc_uuid_to_connection(uuid); |
| 66 | if (!ptlrpc_conn) { |
| 67 | CDEBUG(D_HA, "can't find connection %s\n", uuid->uuid); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 68 | return -ENOENT; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | if (create) { |
Julia Lawall | 352f789 | 2015-05-01 17:51:19 +0200 | [diff] [blame] | 72 | imp_conn = kzalloc(sizeof(*imp_conn), GFP_NOFS); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 73 | if (!imp_conn) { |
| 74 | rc = -ENOMEM; |
| 75 | goto out_put; |
| 76 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | spin_lock(&imp->imp_lock); |
| 80 | list_for_each_entry(item, &imp->imp_conn_list, oic_item) { |
| 81 | if (obd_uuid_equals(uuid, &item->oic_uuid)) { |
| 82 | if (priority) { |
| 83 | list_del(&item->oic_item); |
| 84 | list_add(&item->oic_item, |
Oleg Drokin | 24c198e | 2016-08-21 18:04:35 -0400 | [diff] [blame] | 85 | &imp->imp_conn_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 86 | item->oic_last_attempt = 0; |
| 87 | } |
| 88 | CDEBUG(D_HA, "imp %p@%s: found existing conn %s%s\n", |
| 89 | imp, imp->imp_obd->obd_name, uuid->uuid, |
| 90 | (priority ? ", moved to head" : "")); |
| 91 | spin_unlock(&imp->imp_lock); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 92 | rc = 0; |
| 93 | goto out_free; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | /* No existing import connection found for \a uuid. */ |
| 97 | if (create) { |
| 98 | imp_conn->oic_conn = ptlrpc_conn; |
| 99 | imp_conn->oic_uuid = *uuid; |
| 100 | imp_conn->oic_last_attempt = 0; |
| 101 | if (priority) |
| 102 | list_add(&imp_conn->oic_item, &imp->imp_conn_list); |
| 103 | else |
| 104 | list_add_tail(&imp_conn->oic_item, |
Oleg Drokin | 24c198e | 2016-08-21 18:04:35 -0400 | [diff] [blame] | 105 | &imp->imp_conn_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 106 | CDEBUG(D_HA, "imp %p@%s: add connection %s at %s\n", |
| 107 | imp, imp->imp_obd->obd_name, uuid->uuid, |
| 108 | (priority ? "head" : "tail")); |
| 109 | } else { |
| 110 | spin_unlock(&imp->imp_lock); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 111 | rc = -ENOENT; |
| 112 | goto out_free; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | spin_unlock(&imp->imp_lock); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 116 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 117 | out_free: |
Julia Lawall | 1134507 | 2015-05-01 21:38:06 +0200 | [diff] [blame] | 118 | kfree(imp_conn); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | out_put: |
| 120 | ptlrpc_connection_put(ptlrpc_conn); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 121 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid) |
| 125 | { |
| 126 | return import_set_conn(imp, uuid, 1, 0); |
| 127 | } |
| 128 | |
| 129 | int client_import_add_conn(struct obd_import *imp, struct obd_uuid *uuid, |
| 130 | int priority) |
| 131 | { |
| 132 | return import_set_conn(imp, uuid, priority, 1); |
| 133 | } |
| 134 | EXPORT_SYMBOL(client_import_add_conn); |
| 135 | |
| 136 | int client_import_del_conn(struct obd_import *imp, struct obd_uuid *uuid) |
| 137 | { |
| 138 | struct obd_import_conn *imp_conn; |
| 139 | struct obd_export *dlmexp; |
| 140 | int rc = -ENOENT; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 141 | |
| 142 | spin_lock(&imp->imp_lock); |
| 143 | if (list_empty(&imp->imp_conn_list)) { |
| 144 | LASSERT(!imp->imp_connection); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 145 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | list_for_each_entry(imp_conn, &imp->imp_conn_list, oic_item) { |
| 149 | if (!obd_uuid_equals(uuid, &imp_conn->oic_uuid)) |
| 150 | continue; |
| 151 | LASSERT(imp_conn->oic_conn); |
| 152 | |
| 153 | if (imp_conn == imp->imp_conn_current) { |
| 154 | LASSERT(imp_conn->oic_conn == imp->imp_connection); |
| 155 | |
| 156 | if (imp->imp_state != LUSTRE_IMP_CLOSED && |
| 157 | imp->imp_state != LUSTRE_IMP_DISCON) { |
| 158 | CERROR("can't remove current connection\n"); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 159 | rc = -EBUSY; |
| 160 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | ptlrpc_connection_put(imp->imp_connection); |
| 164 | imp->imp_connection = NULL; |
| 165 | |
| 166 | dlmexp = class_conn2export(&imp->imp_dlm_handle); |
| 167 | if (dlmexp && dlmexp->exp_connection) { |
| 168 | LASSERT(dlmexp->exp_connection == |
| 169 | imp_conn->oic_conn); |
| 170 | ptlrpc_connection_put(dlmexp->exp_connection); |
| 171 | dlmexp->exp_connection = NULL; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | list_del(&imp_conn->oic_item); |
| 176 | ptlrpc_connection_put(imp_conn->oic_conn); |
Julia Lawall | 352f789 | 2015-05-01 17:51:19 +0200 | [diff] [blame] | 177 | kfree(imp_conn); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 178 | CDEBUG(D_HA, "imp %p@%s: remove connection %s\n", |
| 179 | imp, imp->imp_obd->obd_name, uuid->uuid); |
| 180 | rc = 0; |
| 181 | break; |
| 182 | } |
| 183 | out: |
| 184 | spin_unlock(&imp->imp_lock); |
| 185 | if (rc == -ENOENT) |
| 186 | CERROR("connection %s not found\n", uuid->uuid); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 187 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 188 | } |
| 189 | EXPORT_SYMBOL(client_import_del_conn); |
| 190 | |
| 191 | /** |
| 192 | * Find conn UUID by peer NID. \a peer is a server NID. This function is used |
| 193 | * to find a conn uuid of \a imp which can reach \a peer. |
| 194 | */ |
| 195 | int client_import_find_conn(struct obd_import *imp, lnet_nid_t peer, |
| 196 | struct obd_uuid *uuid) |
| 197 | { |
| 198 | struct obd_import_conn *conn; |
| 199 | int rc = -ENOENT; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 200 | |
| 201 | spin_lock(&imp->imp_lock); |
| 202 | list_for_each_entry(conn, &imp->imp_conn_list, oic_item) { |
| 203 | /* Check if conn UUID does have this peer NID. */ |
| 204 | if (class_check_uuid(&conn->oic_uuid, peer)) { |
| 205 | *uuid = conn->oic_uuid; |
| 206 | rc = 0; |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | spin_unlock(&imp->imp_lock); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 211 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 212 | } |
| 213 | EXPORT_SYMBOL(client_import_find_conn); |
| 214 | |
| 215 | void client_destroy_import(struct obd_import *imp) |
| 216 | { |
| 217 | /* Drop security policy instance after all RPCs have finished/aborted |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 218 | * to let all busy contexts be released. |
| 219 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 220 | class_import_get(imp); |
| 221 | class_destroy_import(imp); |
| 222 | sptlrpc_import_sec_put(imp); |
| 223 | class_import_put(imp); |
| 224 | } |
| 225 | EXPORT_SYMBOL(client_destroy_import); |
| 226 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 227 | /* Configure an RPC client OBD device. |
| 228 | * |
| 229 | * lcfg parameters: |
| 230 | * 1 - client UUID |
| 231 | * 2 - server UUID |
| 232 | * 3 - inactive-on-startup |
| 233 | */ |
| 234 | int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg) |
| 235 | { |
| 236 | struct client_obd *cli = &obddev->u.cli; |
| 237 | struct obd_import *imp; |
| 238 | struct obd_uuid server_uuid; |
| 239 | int rq_portal, rp_portal, connect_op; |
| 240 | char *name = obddev->obd_type->typ_name; |
Oleg Drokin | 87ba6eb | 2016-02-24 22:00:04 -0500 | [diff] [blame] | 241 | enum ldlm_ns_type ns_type = LDLM_NS_TYPE_UNKNOWN; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 242 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 243 | |
| 244 | /* In a more perfect world, we would hang a ptlrpc_client off of |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 245 | * obd_type and just use the values from there. |
| 246 | */ |
Mikhail Pershin | a331052 | 2014-09-08 21:41:27 -0400 | [diff] [blame] | 247 | if (!strcmp(name, LUSTRE_OSC_NAME)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 248 | rq_portal = OST_REQUEST_PORTAL; |
| 249 | rp_portal = OSC_REPLY_PORTAL; |
| 250 | connect_op = OST_CONNECT; |
| 251 | cli->cl_sp_me = LUSTRE_SP_CLI; |
| 252 | cli->cl_sp_to = LUSTRE_SP_OST; |
| 253 | ns_type = LDLM_NS_TYPE_OSC; |
| 254 | } else if (!strcmp(name, LUSTRE_MDC_NAME) || |
Mikhail Pershin | a331052 | 2014-09-08 21:41:27 -0400 | [diff] [blame] | 255 | !strcmp(name, LUSTRE_LWP_NAME)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 256 | rq_portal = MDS_REQUEST_PORTAL; |
| 257 | rp_portal = MDC_REPLY_PORTAL; |
| 258 | connect_op = MDS_CONNECT; |
| 259 | cli->cl_sp_me = LUSTRE_SP_CLI; |
| 260 | cli->cl_sp_to = LUSTRE_SP_MDT; |
| 261 | ns_type = LDLM_NS_TYPE_MDC; |
| 262 | } else if (!strcmp(name, LUSTRE_MGC_NAME)) { |
| 263 | rq_portal = MGS_REQUEST_PORTAL; |
| 264 | rp_portal = MGC_REPLY_PORTAL; |
| 265 | connect_op = MGS_CONNECT; |
| 266 | cli->cl_sp_me = LUSTRE_SP_MGC; |
| 267 | cli->cl_sp_to = LUSTRE_SP_MGS; |
| 268 | cli->cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_INVALID; |
| 269 | ns_type = LDLM_NS_TYPE_MGC; |
| 270 | } else { |
| 271 | CERROR("unknown client OBD type \"%s\", can't setup\n", |
| 272 | name); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 273 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { |
| 277 | CERROR("requires a TARGET UUID\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 278 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) { |
| 282 | CERROR("client UUID must be less than 38 characters\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 283 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) { |
| 287 | CERROR("setup requires a SERVER UUID\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 288 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) { |
| 292 | CERROR("target UUID must be less than 38 characters\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 293 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | init_rwsem(&cli->cl_sem); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 297 | cli->cl_conn_count = 0; |
| 298 | memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2), |
| 299 | min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2), |
| 300 | sizeof(server_uuid))); |
| 301 | |
Hongchao Zhang | 3147b26 | 2016-08-16 16:19:22 -0400 | [diff] [blame] | 302 | cli->cl_dirty_pages = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 303 | cli->cl_avail_grant = 0; |
Hongchao Zhang | 3147b26 | 2016-08-16 16:19:22 -0400 | [diff] [blame] | 304 | /* FIXME: Should limit this for the sum of all cl_dirty_max_pages. */ |
| 305 | /* |
| 306 | * cl_dirty_max_pages may be changed at connect time in |
| 307 | * ptlrpc_connect_interpret(). |
| 308 | */ |
| 309 | client_adjust_max_dirty(cli); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 310 | INIT_LIST_HEAD(&cli->cl_cache_waiters); |
| 311 | INIT_LIST_HEAD(&cli->cl_loi_ready_list); |
| 312 | INIT_LIST_HEAD(&cli->cl_loi_hp_ready_list); |
| 313 | INIT_LIST_HEAD(&cli->cl_loi_write_list); |
| 314 | INIT_LIST_HEAD(&cli->cl_loi_read_list); |
John L. Hammond | 7d53d8f | 2016-03-30 19:48:36 -0400 | [diff] [blame] | 315 | spin_lock_init(&cli->cl_loi_list_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 316 | atomic_set(&cli->cl_pending_w_pages, 0); |
| 317 | atomic_set(&cli->cl_pending_r_pages, 0); |
| 318 | cli->cl_r_in_flight = 0; |
| 319 | cli->cl_w_in_flight = 0; |
| 320 | |
| 321 | spin_lock_init(&cli->cl_read_rpc_hist.oh_lock); |
| 322 | spin_lock_init(&cli->cl_write_rpc_hist.oh_lock); |
| 323 | spin_lock_init(&cli->cl_read_page_hist.oh_lock); |
| 324 | spin_lock_init(&cli->cl_write_page_hist.oh_lock); |
| 325 | spin_lock_init(&cli->cl_read_offset_hist.oh_lock); |
| 326 | spin_lock_init(&cli->cl_write_offset_hist.oh_lock); |
| 327 | |
| 328 | /* lru for osc. */ |
| 329 | INIT_LIST_HEAD(&cli->cl_lru_osc); |
| 330 | atomic_set(&cli->cl_lru_shrinkers, 0); |
Stephen Champion | 29c877a | 2016-09-18 16:37:43 -0400 | [diff] [blame] | 331 | atomic_long_set(&cli->cl_lru_busy, 0); |
| 332 | atomic_long_set(&cli->cl_lru_in_list, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 333 | INIT_LIST_HEAD(&cli->cl_lru_list); |
John L. Hammond | 7d53d8f | 2016-03-30 19:48:36 -0400 | [diff] [blame] | 334 | spin_lock_init(&cli->cl_lru_list_lock); |
Stephen Champion | 29c877a | 2016-09-18 16:37:43 -0400 | [diff] [blame] | 335 | atomic_long_set(&cli->cl_unstable_count, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 336 | |
| 337 | init_waitqueue_head(&cli->cl_destroy_waitq); |
| 338 | atomic_set(&cli->cl_destroy_in_flight, 0); |
| 339 | /* Turn on checksumming by default. */ |
| 340 | cli->cl_checksum = 1; |
| 341 | /* |
| 342 | * The supported checksum types will be worked out at connect time |
| 343 | * Set cl_chksum* to CRC32 for now to avoid returning screwed info |
| 344 | * through procfs. |
| 345 | */ |
Nathaniel Clark | 95c9c00 | 2016-06-09 22:35:13 -0400 | [diff] [blame] | 346 | cli->cl_cksum_type = OBD_CKSUM_CRC32; |
| 347 | cli->cl_supp_cksum_types = OBD_CKSUM_CRC32; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 348 | atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS); |
| 349 | |
| 350 | /* This value may be reduced at connect time in |
| 351 | * ptlrpc_connect_interpret() . We initialize it to only |
| 352 | * 1MB until we know what the performance looks like. |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 353 | * In the future this should likely be increased. LU-1431 |
| 354 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 355 | cli->cl_max_pages_per_rpc = min_t(int, PTLRPC_MAX_BRW_PAGES, |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 356 | LNET_MTU >> PAGE_SHIFT); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 357 | |
Sebastien Buisson | 6f6c8e7 | 2016-04-28 12:07:35 -0400 | [diff] [blame] | 358 | /* |
| 359 | * set cl_chunkbits default value to PAGE_CACHE_SHIFT, |
| 360 | * it will be updated at OSC connection time. |
| 361 | */ |
| 362 | cli->cl_chunkbits = PAGE_SHIFT; |
| 363 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 364 | if (!strcmp(name, LUSTRE_MDC_NAME)) { |
Fan Yong | 1d5d5ec | 2016-08-16 16:18:48 -0400 | [diff] [blame] | 365 | cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 366 | } else if (totalram_pages >> (20 - PAGE_SHIFT) <= 128 /* MB */) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 367 | cli->cl_max_rpcs_in_flight = 2; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 368 | } else if (totalram_pages >> (20 - PAGE_SHIFT) <= 256 /* MB */) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 369 | cli->cl_max_rpcs_in_flight = 3; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 370 | } else if (totalram_pages >> (20 - PAGE_SHIFT) <= 512 /* MB */) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 371 | cli->cl_max_rpcs_in_flight = 4; |
| 372 | } else { |
Fan Yong | 1d5d5ec | 2016-08-16 16:18:48 -0400 | [diff] [blame] | 373 | cli->cl_max_rpcs_in_flight = OBD_MAX_RIF_DEFAULT; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 374 | } |
| 375 | rc = ldlm_get_ref(); |
| 376 | if (rc) { |
| 377 | CERROR("ldlm_get_ref failed: %d\n", rc); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 378 | goto err; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | ptlrpc_init_client(rq_portal, rp_portal, name, |
| 382 | &obddev->obd_ldlm_client); |
| 383 | |
| 384 | imp = class_new_import(obddev); |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 385 | if (!imp) { |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 386 | rc = -ENOENT; |
| 387 | goto err_ldlm; |
| 388 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 389 | imp->imp_client = &obddev->obd_ldlm_client; |
| 390 | imp->imp_connect_op = connect_op; |
| 391 | memcpy(cli->cl_target_uuid.uuid, lustre_cfg_buf(lcfg, 1), |
| 392 | LUSTRE_CFG_BUFLEN(lcfg, 1)); |
| 393 | class_import_put(imp); |
| 394 | |
| 395 | rc = client_import_add_conn(imp, &server_uuid, 1); |
| 396 | if (rc) { |
| 397 | CERROR("can't add initial connection\n"); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 398 | goto err_import; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | cli->cl_import = imp; |
| 402 | /* cli->cl_max_mds_{easize,cookiesize} updated by mdc_init_ea_size() */ |
| 403 | cli->cl_max_mds_easize = sizeof(struct lov_mds_md_v3); |
| 404 | cli->cl_max_mds_cookiesize = sizeof(struct llog_cookie); |
| 405 | |
| 406 | if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) { |
| 407 | if (!strcmp(lustre_cfg_string(lcfg, 3), "inactive")) { |
| 408 | CDEBUG(D_HA, "marking %s %s->%s as inactive\n", |
| 409 | name, obddev->obd_name, |
| 410 | cli->cl_target_uuid.uuid); |
| 411 | spin_lock(&imp->imp_lock); |
| 412 | imp->imp_deactive = 1; |
| 413 | spin_unlock(&imp->imp_lock); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | obddev->obd_namespace = ldlm_namespace_new(obddev, obddev->obd_name, |
| 418 | LDLM_NAMESPACE_CLIENT, |
| 419 | LDLM_NAMESPACE_GREEDY, |
| 420 | ns_type); |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 421 | if (!obddev->obd_namespace) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 422 | CERROR("Unable to create client namespace - %s\n", |
| 423 | obddev->obd_name); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 424 | rc = -ENOMEM; |
| 425 | goto err_import; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | cli->cl_qchk_stat = CL_NOT_QUOTACHECKED; |
| 429 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 430 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 431 | |
| 432 | err_import: |
| 433 | class_destroy_import(imp); |
| 434 | err_ldlm: |
| 435 | ldlm_put_ref(); |
| 436 | err: |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 437 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 438 | } |
| 439 | EXPORT_SYMBOL(client_obd_setup); |
| 440 | |
| 441 | int client_obd_cleanup(struct obd_device *obddev) |
| 442 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 443 | ldlm_namespace_free_post(obddev->obd_namespace); |
| 444 | obddev->obd_namespace = NULL; |
| 445 | |
Swapnil Pimpale | d855506 | 2016-04-27 21:37:14 -0400 | [diff] [blame] | 446 | obd_cleanup_client_import(obddev); |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 447 | LASSERT(!obddev->u.cli.cl_import); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 448 | |
| 449 | ldlm_put_ref(); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 450 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 451 | } |
| 452 | EXPORT_SYMBOL(client_obd_cleanup); |
| 453 | |
| 454 | /* ->o_connect() method for client side (OSC and MDC and MGC) */ |
| 455 | int client_connect_import(const struct lu_env *env, |
| 456 | struct obd_export **exp, |
| 457 | struct obd_device *obd, struct obd_uuid *cluuid, |
| 458 | struct obd_connect_data *data, void *localdata) |
| 459 | { |
| 460 | struct client_obd *cli = &obd->u.cli; |
| 461 | struct obd_import *imp = cli->cl_import; |
| 462 | struct obd_connect_data *ocd; |
| 463 | struct lustre_handle conn = { 0 }; |
| 464 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 465 | |
| 466 | *exp = NULL; |
| 467 | down_write(&cli->cl_sem); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 468 | if (cli->cl_conn_count > 0) { |
| 469 | rc = -EALREADY; |
| 470 | goto out_sem; |
| 471 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 472 | |
| 473 | rc = class_connect(&conn, obd, cluuid); |
| 474 | if (rc) |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 475 | goto out_sem; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 476 | |
| 477 | cli->cl_conn_count++; |
| 478 | *exp = class_conn2export(&conn); |
| 479 | |
| 480 | LASSERT(obd->obd_namespace); |
| 481 | |
| 482 | imp->imp_dlm_handle = conn; |
| 483 | rc = ptlrpc_init_import(imp); |
| 484 | if (rc != 0) |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 485 | goto out_ldlm; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 486 | |
| 487 | ocd = &imp->imp_connect_data; |
| 488 | if (data) { |
| 489 | *ocd = *data; |
| 490 | imp->imp_connect_flags_orig = data->ocd_connect_flags; |
| 491 | } |
| 492 | |
| 493 | rc = ptlrpc_connect_import(imp); |
| 494 | if (rc != 0) { |
Anil Belur | 05dca37 | 2014-06-20 02:01:48 +1000 | [diff] [blame] | 495 | LASSERT(imp->imp_state == LUSTRE_IMP_DISCON); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 496 | goto out_ldlm; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 497 | } |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 498 | LASSERT(*exp && (*exp)->exp_connection); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 499 | |
| 500 | if (data) { |
| 501 | LASSERTF((ocd->ocd_connect_flags & data->ocd_connect_flags) == |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 502 | ocd->ocd_connect_flags, "old %#llx, new %#llx\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 503 | data->ocd_connect_flags, ocd->ocd_connect_flags); |
| 504 | data->ocd_connect_flags = ocd->ocd_connect_flags; |
| 505 | } |
| 506 | |
| 507 | ptlrpc_pinger_add_import(imp); |
| 508 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 509 | if (rc) { |
| 510 | out_ldlm: |
| 511 | cli->cl_conn_count--; |
| 512 | class_disconnect(*exp); |
| 513 | *exp = NULL; |
| 514 | } |
| 515 | out_sem: |
| 516 | up_write(&cli->cl_sem); |
| 517 | |
| 518 | return rc; |
| 519 | } |
| 520 | EXPORT_SYMBOL(client_connect_import); |
| 521 | |
| 522 | int client_disconnect_export(struct obd_export *exp) |
| 523 | { |
| 524 | struct obd_device *obd = class_exp2obd(exp); |
| 525 | struct client_obd *cli; |
| 526 | struct obd_import *imp; |
| 527 | int rc = 0, err; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 528 | |
| 529 | if (!obd) { |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 530 | CERROR("invalid export for disconnect: exp %p cookie %#llx\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 531 | exp, exp ? exp->exp_handle.h_cookie : -1); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 532 | return -EINVAL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | cli = &obd->u.cli; |
| 536 | imp = cli->cl_import; |
| 537 | |
| 538 | down_write(&cli->cl_sem); |
Dmitry Eremin | 6314ccb | 2016-09-18 16:38:39 -0400 | [diff] [blame] | 539 | CDEBUG(D_INFO, "disconnect %s - %zu\n", obd->obd_name, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 540 | cli->cl_conn_count); |
| 541 | |
| 542 | if (!cli->cl_conn_count) { |
| 543 | CERROR("disconnecting disconnected device (%s)\n", |
| 544 | obd->obd_name); |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 545 | rc = -EINVAL; |
| 546 | goto out_disconnect; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | cli->cl_conn_count--; |
Julia Lawall | d1c0d44 | 2014-09-01 22:21:09 +0200 | [diff] [blame] | 550 | if (cli->cl_conn_count) { |
| 551 | rc = 0; |
| 552 | goto out_disconnect; |
| 553 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 554 | |
| 555 | /* Mark import deactivated now, so we don't try to reconnect if any |
| 556 | * of the cleanup RPCs fails (e.g. LDLM cancel, etc). We don't |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 557 | * fully deactivate the import, or that would drop all requests. |
| 558 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 559 | spin_lock(&imp->imp_lock); |
| 560 | imp->imp_deactive = 1; |
| 561 | spin_unlock(&imp->imp_lock); |
| 562 | |
| 563 | /* Some non-replayable imports (MDS's OSCs) are pinged, so just |
| 564 | * delete it regardless. (It's safe to delete an import that was |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 565 | * never added.) |
| 566 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 567 | (void)ptlrpc_pinger_del_import(imp); |
| 568 | |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 569 | if (obd->obd_namespace) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 570 | /* obd_force == local only */ |
| 571 | ldlm_cli_cancel_unused(obd->obd_namespace, NULL, |
| 572 | obd->obd_force ? LCF_LOCAL : 0, NULL); |
Andreas Ruprecht | e7ddc48 | 2014-11-23 14:37:49 +0100 | [diff] [blame] | 573 | ldlm_namespace_free_prior(obd->obd_namespace, imp, |
| 574 | obd->obd_force); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* There's no need to hold sem while disconnecting an import, |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 578 | * and it may actually cause deadlock in GSS. |
| 579 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 580 | up_write(&cli->cl_sem); |
| 581 | rc = ptlrpc_disconnect_import(imp, 0); |
| 582 | down_write(&cli->cl_sem); |
| 583 | |
| 584 | ptlrpc_invalidate_import(imp); |
| 585 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 586 | out_disconnect: |
| 587 | /* Use server style - class_disconnect should be always called for |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 588 | * o_disconnect. |
| 589 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 590 | err = class_disconnect(exp); |
| 591 | if (!rc && err) |
| 592 | rc = err; |
| 593 | |
| 594 | up_write(&cli->cl_sem); |
| 595 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 596 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 597 | } |
| 598 | EXPORT_SYMBOL(client_disconnect_export); |
| 599 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 600 | /** |
| 601 | * Packs current SLV and Limit into \a req. |
| 602 | */ |
| 603 | int target_pack_pool_reply(struct ptlrpc_request *req) |
| 604 | { |
| 605 | struct obd_device *obd; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 606 | |
| 607 | /* Check that we still have all structures alive as this may |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 608 | * be some late RPC at shutdown time. |
| 609 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 610 | if (unlikely(!req->rq_export || !req->rq_export->exp_obd || |
| 611 | !exp_connect_lru_resize(req->rq_export))) { |
| 612 | lustre_msg_set_slv(req->rq_repmsg, 0); |
| 613 | lustre_msg_set_limit(req->rq_repmsg, 0); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 614 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /* OBD is alive here as export is alive, which we checked above. */ |
| 618 | obd = req->rq_export->exp_obd; |
| 619 | |
| 620 | read_lock(&obd->obd_pool_lock); |
| 621 | lustre_msg_set_slv(req->rq_repmsg, obd->obd_pool_slv); |
| 622 | lustre_msg_set_limit(req->rq_repmsg, obd->obd_pool_limit); |
| 623 | read_unlock(&obd->obd_pool_lock); |
| 624 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 625 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 626 | } |
| 627 | EXPORT_SYMBOL(target_pack_pool_reply); |
| 628 | |
Cihangir Akturk | 3377bad | 2015-07-21 10:22:52 +0300 | [diff] [blame] | 629 | static int |
| 630 | target_send_reply_msg(struct ptlrpc_request *req, int rc, int fail_id) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 631 | { |
| 632 | if (OBD_FAIL_CHECK_ORSET(fail_id & ~OBD_FAIL_ONCE, OBD_FAIL_ONCE)) { |
| 633 | DEBUG_REQ(D_ERROR, req, "dropping reply"); |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 634 | return -ECOMM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | if (unlikely(rc)) { |
| 638 | DEBUG_REQ(D_NET, req, "processing error (%d)", rc); |
| 639 | req->rq_status = rc; |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 640 | return ptlrpc_send_error(req, 1); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 641 | } |
| 642 | |
Antonio Murdaca | 71e8dd9 | 2015-06-08 21:48:41 +0200 | [diff] [blame] | 643 | DEBUG_REQ(D_NET, req, "sending reply"); |
Julia Lawall | fbe7c6c | 2014-08-26 22:00:33 +0200 | [diff] [blame] | 644 | return ptlrpc_send_reply(req, PTLRPC_REPLY_MAYBE_DIFFICULT); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id) |
| 648 | { |
| 649 | struct ptlrpc_service_part *svcpt; |
| 650 | int netrc; |
| 651 | struct ptlrpc_reply_state *rs; |
| 652 | struct obd_export *exp; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 653 | |
Anil Belur | b7cfd6d | 2014-06-20 02:01:47 +1000 | [diff] [blame] | 654 | if (req->rq_no_reply) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 655 | return; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 656 | |
| 657 | svcpt = req->rq_rqbd->rqbd_svcpt; |
| 658 | rs = req->rq_reply_state; |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 659 | if (!rs || !rs->rs_difficult) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 660 | /* no notifiers */ |
Anil Belur | 05dca37 | 2014-06-20 02:01:48 +1000 | [diff] [blame] | 661 | target_send_reply_msg(req, rc, fail_id); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 662 | return; |
| 663 | } |
| 664 | |
| 665 | /* must be an export if locks saved */ |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 666 | LASSERT(req->rq_export); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 667 | /* req/reply consistent */ |
| 668 | LASSERT(rs->rs_svcpt == svcpt); |
| 669 | |
| 670 | /* "fresh" reply */ |
Anil Belur | 05dca37 | 2014-06-20 02:01:48 +1000 | [diff] [blame] | 671 | LASSERT(!rs->rs_scheduled); |
| 672 | LASSERT(!rs->rs_scheduled_ever); |
| 673 | LASSERT(!rs->rs_handled); |
| 674 | LASSERT(!rs->rs_on_net); |
Oleg Drokin | 44b53f1 | 2016-02-16 00:46:47 -0500 | [diff] [blame] | 675 | LASSERT(!rs->rs_export); |
Anil Belur | 05dca37 | 2014-06-20 02:01:48 +1000 | [diff] [blame] | 676 | LASSERT(list_empty(&rs->rs_obd_list)); |
| 677 | LASSERT(list_empty(&rs->rs_exp_list)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 678 | |
Anil Belur | 05dca37 | 2014-06-20 02:01:48 +1000 | [diff] [blame] | 679 | exp = class_export_get(req->rq_export); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 680 | |
| 681 | /* disable reply scheduling while I'm setting up */ |
| 682 | rs->rs_scheduled = 1; |
| 683 | rs->rs_on_net = 1; |
| 684 | rs->rs_xid = req->rq_xid; |
| 685 | rs->rs_transno = req->rq_transno; |
| 686 | rs->rs_export = exp; |
| 687 | rs->rs_opc = lustre_msg_get_opc(req->rq_reqmsg); |
| 688 | |
| 689 | spin_lock(&exp->exp_uncommitted_replies_lock); |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 690 | CDEBUG(D_NET, "rs transno = %llu, last committed = %llu\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 691 | rs->rs_transno, exp->exp_last_committed); |
| 692 | if (rs->rs_transno > exp->exp_last_committed) { |
| 693 | /* not committed already */ |
| 694 | list_add_tail(&rs->rs_obd_list, |
Oleg Drokin | 24c198e | 2016-08-21 18:04:35 -0400 | [diff] [blame] | 695 | &exp->exp_uncommitted_replies); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 696 | } |
| 697 | spin_unlock(&exp->exp_uncommitted_replies_lock); |
| 698 | |
| 699 | spin_lock(&exp->exp_lock); |
| 700 | list_add_tail(&rs->rs_exp_list, &exp->exp_outstanding_replies); |
| 701 | spin_unlock(&exp->exp_lock); |
| 702 | |
| 703 | netrc = target_send_reply_msg(req, rc, fail_id); |
| 704 | |
| 705 | spin_lock(&svcpt->scp_rep_lock); |
| 706 | |
| 707 | atomic_inc(&svcpt->scp_nreps_difficult); |
| 708 | |
| 709 | if (netrc != 0) { |
| 710 | /* error sending: reply is off the net. Also we need +1 |
| 711 | * reply ref until ptlrpc_handle_rs() is done |
| 712 | * with the reply state (if the send was successful, there |
| 713 | * would have been +1 ref for the net, which |
Oleg Drokin | 6f789a6 | 2016-02-24 22:00:29 -0500 | [diff] [blame] | 714 | * reply_out_callback leaves alone) |
| 715 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 716 | rs->rs_on_net = 0; |
| 717 | ptlrpc_rs_addref(rs); |
| 718 | } |
| 719 | |
| 720 | spin_lock(&rs->rs_lock); |
| 721 | if (rs->rs_transno <= exp->exp_last_committed || |
| 722 | (!rs->rs_on_net && !rs->rs_no_ack) || |
| 723 | list_empty(&rs->rs_exp_list) || /* completed already */ |
| 724 | list_empty(&rs->rs_obd_list)) { |
| 725 | CDEBUG(D_HA, "Schedule reply immediately\n"); |
| 726 | ptlrpc_dispatch_difficult_reply(rs); |
| 727 | } else { |
| 728 | list_add(&rs->rs_list, &svcpt->scp_rep_active); |
| 729 | rs->rs_scheduled = 0; /* allow notifier to schedule */ |
| 730 | } |
| 731 | spin_unlock(&rs->rs_lock); |
| 732 | spin_unlock(&svcpt->scp_rep_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 733 | } |
| 734 | EXPORT_SYMBOL(target_send_reply); |
| 735 | |
Oleg Drokin | 52ee0d2 | 2016-02-24 21:59:54 -0500 | [diff] [blame] | 736 | enum ldlm_mode lck_compat_array[] = { |
Emil Goode | 805e517 | 2013-07-28 00:38:56 +0200 | [diff] [blame] | 737 | [LCK_EX] = LCK_COMPAT_EX, |
| 738 | [LCK_PW] = LCK_COMPAT_PW, |
| 739 | [LCK_PR] = LCK_COMPAT_PR, |
| 740 | [LCK_CW] = LCK_COMPAT_CW, |
| 741 | [LCK_CR] = LCK_COMPAT_CR, |
| 742 | [LCK_NL] = LCK_COMPAT_NL, |
| 743 | [LCK_GROUP] = LCK_COMPAT_GROUP, |
| 744 | [LCK_COS] = LCK_COMPAT_COS, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 745 | }; |
| 746 | |
| 747 | /** |
| 748 | * Rather arbitrary mapping from LDLM error codes to errno values. This should |
| 749 | * not escape to the user level. |
| 750 | */ |
Oleg Drokin | d1777aa | 2016-02-24 22:00:02 -0500 | [diff] [blame] | 751 | int ldlm_error2errno(enum ldlm_error error) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 752 | { |
| 753 | int result; |
| 754 | |
| 755 | switch (error) { |
| 756 | case ELDLM_OK: |
Jinshan Xiong | 06563b5 | 2016-03-30 19:48:40 -0400 | [diff] [blame] | 757 | case ELDLM_LOCK_MATCHED: |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 758 | result = 0; |
| 759 | break; |
| 760 | case ELDLM_LOCK_CHANGED: |
| 761 | result = -ESTALE; |
| 762 | break; |
| 763 | case ELDLM_LOCK_ABORTED: |
| 764 | result = -ENAVAIL; |
| 765 | break; |
| 766 | case ELDLM_LOCK_REPLACED: |
| 767 | result = -ESRCH; |
| 768 | break; |
| 769 | case ELDLM_NO_LOCK_DATA: |
| 770 | result = -ENOENT; |
| 771 | break; |
| 772 | case ELDLM_NAMESPACE_EXISTS: |
| 773 | result = -EEXIST; |
| 774 | break; |
| 775 | case ELDLM_BAD_NAMESPACE: |
| 776 | result = -EBADF; |
| 777 | break; |
| 778 | default: |
| 779 | if (((int)error) < 0) /* cast to signed type */ |
Oleg Drokin | d1777aa | 2016-02-24 22:00:02 -0500 | [diff] [blame] | 780 | result = error; /* as enum ldlm_error can be unsigned */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 781 | else { |
| 782 | CERROR("Invalid DLM result code: %d\n", error); |
| 783 | result = -EPROTO; |
| 784 | } |
| 785 | } |
| 786 | return result; |
| 787 | } |
| 788 | EXPORT_SYMBOL(ldlm_error2errno); |
| 789 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 790 | #if LUSTRE_TRACKS_LOCK_EXP_REFS |
| 791 | void ldlm_dump_export_locks(struct obd_export *exp) |
| 792 | { |
| 793 | spin_lock(&exp->exp_locks_list_guard); |
| 794 | if (!list_empty(&exp->exp_locks_list)) { |
| 795 | struct ldlm_lock *lock; |
| 796 | |
Joe Perches | 2d00bd1 | 2014-11-23 11:28:50 -0800 | [diff] [blame] | 797 | CERROR("dumping locks for export %p,ignore if the unmount doesn't hang\n", |
| 798 | exp); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 799 | list_for_each_entry(lock, &exp->exp_locks_list, |
Oleg Drokin | 24c198e | 2016-08-21 18:04:35 -0400 | [diff] [blame] | 800 | l_exp_refs_link) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 801 | LDLM_ERROR(lock, "lock:"); |
| 802 | } |
| 803 | spin_unlock(&exp->exp_locks_list_guard); |
| 804 | } |
| 805 | #endif |