4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ofd/ofd_obd.c
38 * Author: Andreas Dilger <adilger@whamcloud.com>
39 * Author: Alex Zhuravlev <bzzz@whamcloud.com>
40 * Author: Mike Pershin <tappro@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_FILTER
45 #include "ofd_internal.h"
46 #include <obd_cksum.h>
48 static int ofd_parse_connect_data(const struct lu_env *env,
49 struct obd_export *exp,
50 struct obd_connect_data *data)
52 struct ofd_device *ofd = ofd_exp(exp);
57 CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64
58 " ocd_version: %x ocd_grant: %d ocd_index: %u\n",
59 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
60 data->ocd_connect_flags, data->ocd_version,
61 data->ocd_grant, data->ocd_index);
63 data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
64 exp->exp_connect_flags = data->ocd_connect_flags;
65 data->ocd_version = LUSTRE_VERSION_CODE;
67 /* Kindly make sure the SKIP_ORPHAN flag is from MDS. */
68 if (data->ocd_connect_flags & OBD_CONNECT_MDS)
69 CDEBUG(D_HA, "%s: Received MDS connection for group %u\n",
70 exp->exp_obd->obd_name, data->ocd_group);
71 else if (data->ocd_connect_flags & OBD_CONNECT_SKIP_ORPHAN)
74 if (data->ocd_connect_flags & OBD_CONNECT_INDEX) {
75 struct lr_server_data *lsd = &ofd->ofd_lut.lut_lsd;
76 int index = lsd->lsd_ost_index;
78 if (!(lsd->lsd_feature_compat & OBD_COMPAT_OST)) {
79 /* this will only happen on the first connect */
80 lsd->lsd_ost_index = data->ocd_index;
81 lsd->lsd_feature_compat |= OBD_COMPAT_OST;
82 /* sync is not needed here as lut_client_add will
83 * set exp_need_sync flag */
84 lut_server_data_update(env, &ofd->ofd_lut, 0);
85 } else if (index != data->ocd_index) {
86 LCONSOLE_ERROR_MSG(0x136, "Connection from %s to index"
87 " %u doesn't match actual OST index"
88 " %u in last_rcvd file, bad "
90 obd_export_nid2str(exp), index,
96 if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_SIZE)) {
97 data->ocd_brw_size = 65536;
98 } else if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
99 data->ocd_brw_size = min(data->ocd_brw_size,
100 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
101 if (data->ocd_brw_size == 0) {
102 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
103 " ocd_version: %x ocd_grant: %d ocd_index: %u "
104 "ocd_brw_size is unexpectedly zero, "
105 "network data corruption?"
106 "Refusing connection of this client\n",
107 exp->exp_obd->obd_name,
108 exp->exp_client_uuid.uuid,
109 exp, data->ocd_connect_flags, data->ocd_version,
110 data->ocd_grant, data->ocd_index);
115 if (data->ocd_connect_flags & OBD_CONNECT_CKSUM) {
116 __u32 cksum_types = data->ocd_cksum_types;
118 /* The client set in ocd_cksum_types the checksum types it
119 * supports. We have to mask off the algorithms that we don't
121 data->ocd_cksum_types &= cksum_types_supported();
123 if (unlikely(data->ocd_cksum_types == 0)) {
124 CERROR("%s: Connect with checksum support but no "
125 "ocd_cksum_types is set\n",
126 exp->exp_obd->obd_name);
130 CDEBUG(D_RPCTRACE, "%s: cli %s supports cksum type %x, return "
131 "%x\n", exp->exp_obd->obd_name, obd_export_nid2str(exp),
132 cksum_types, data->ocd_cksum_types);
134 /* This client does not support OBD_CONNECT_CKSUM
135 * fall back to CRC32 */
136 CDEBUG(D_RPCTRACE, "%s: cli %s does not support "
137 "OBD_CONNECT_CKSUM, CRC32 will be used\n",
138 exp->exp_obd->obd_name, obd_export_nid2str(exp));
141 if (data->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
142 data->ocd_maxbytes = ofd->ofd_dt_conf.ddp_maxbytes;
147 static int ofd_obd_reconnect(const struct lu_env *env, struct obd_export *exp,
148 struct obd_device *obd, struct obd_uuid *cluuid,
149 struct obd_connect_data *data, void *localdata)
155 if (exp == NULL || obd == NULL || cluuid == NULL)
158 rc = lu_env_refill((struct lu_env *)env);
160 CERROR("Failure to refill session: '%d'\n", rc);
164 ofd_info_init(env, exp);
165 rc = ofd_parse_connect_data(env, exp, data);
170 static int ofd_obd_connect(const struct lu_env *env, struct obd_export **_exp,
171 struct obd_device *obd, struct obd_uuid *cluuid,
172 struct obd_connect_data *data, void *localdata)
174 struct obd_export *exp;
175 struct ofd_device *ofd;
176 struct lustre_handle conn = { 0 };
181 if (_exp == NULL || obd == NULL || cluuid == NULL)
184 ofd = ofd_dev(obd->obd_lu_dev);
186 rc = class_connect(&conn, obd, cluuid);
190 exp = class_conn2export(&conn);
191 LASSERT(exp != NULL);
193 rc = lu_env_refill((struct lu_env *)env);
195 CERROR("Failure to refill session: '%d'\n", rc);
199 ofd_info_init(env, exp);
201 rc = ofd_parse_connect_data(env, exp, data);
205 ofd_export_stats_init(ofd, exp, localdata);
206 group = data->ocd_group;
207 if (obd->obd_replayable) {
208 struct tg_export_data *ted = &exp->exp_target_data;
210 memcpy(ted->ted_lcd->lcd_uuid, cluuid,
211 sizeof(ted->ted_lcd->lcd_uuid));
212 rc = lut_client_new(env, exp);
220 if (group > ofd->ofd_max_group) {
221 ofd->ofd_max_group = group;
222 rc = ofd_group_load(env, ofd, group);
226 class_disconnect(exp);
234 static int ofd_obd_disconnect(struct obd_export *exp)
242 class_export_get(exp);
244 rc = server_disconnect_export(exp);
246 rc = lu_env_init(&env, LCT_DT_THREAD);
250 /* Do not erase record for recoverable client. */
251 if (exp->exp_obd->obd_replayable &&
252 (!exp->exp_obd->obd_fail || exp->exp_failed))
253 lut_client_del(&env, exp);
256 class_export_put(exp);
260 static int ofd_init_export(struct obd_export *exp)
264 cfs_spin_lock_init(&exp->exp_filter_data.fed_lock);
265 CFS_INIT_LIST_HEAD(&exp->exp_filter_data.fed_mod_list);
266 cfs_spin_lock(&exp->exp_lock);
267 exp->exp_connecting = 1;
268 cfs_spin_unlock(&exp->exp_lock);
270 /* self-export doesn't need client data and ldlm initialization */
271 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
272 &exp->exp_client_uuid)))
275 rc = lut_client_alloc(exp);
277 ldlm_init_export(exp);
279 CERROR("%s: Can't initialize export: rc %d\n",
280 exp->exp_obd->obd_name, rc);
284 static int ofd_destroy_export(struct obd_export *exp)
286 if (exp->exp_filter_data.fed_pending)
287 CERROR("%s: cli %s/%p has %lu pending on destroyed export"
288 "\n", exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
289 exp, exp->exp_filter_data.fed_pending);
291 target_destroy_export(exp);
293 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
294 &exp->exp_client_uuid)))
297 ldlm_destroy_export(exp);
298 lut_client_free(exp);
300 LASSERT(cfs_list_empty(&exp->exp_filter_data.fed_mod_list));
304 int ofd_obd_postrecov(struct obd_device *obd)
307 struct lu_device *ldev = obd->obd_lu_dev;
312 rc = lu_env_init(&env, LCT_DT_THREAD);
315 ofd_info_init(&env, obd->obd_self_export);
317 rc = ldev->ld_ops->ldo_recovery_complete(&env, ldev);
322 static int ofd_obd_notify(struct obd_device *obd, struct obd_device *unused,
323 enum obd_notify_event ev, void *data)
326 case OBD_NOTIFY_CONFIG:
327 LASSERT(obd->obd_no_conn);
328 cfs_spin_lock(&obd->obd_dev_lock);
329 obd->obd_no_conn = 0;
330 cfs_spin_unlock(&obd->obd_dev_lock);
333 CDEBUG(D_INFO, "%s: Unhandled notification %#x\n",
339 struct obd_ops ofd_obd_ops = {
340 .o_owner = THIS_MODULE,
341 .o_connect = ofd_obd_connect,
342 .o_reconnect = ofd_obd_reconnect,
343 .o_disconnect = ofd_obd_disconnect,
344 .o_init_export = ofd_init_export,
345 .o_destroy_export = ofd_destroy_export,
346 .o_postrecov = ofd_obd_postrecov,
347 .o_notify = ofd_obd_notify,