Whamcloud - gitweb
ad0373a51c1c2e058adde31365a657f80b177606
[fs/lustre-release.git] / lustre / ofd / ofd_obd.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ofd/ofd_obd.c
37  *
38  * Author: Andreas Dilger <adilger@whamcloud.com>
39  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
40  * Author: Mike Pershin <tappro@whamcloud.com>
41  */
42
43 #define DEBUG_SUBSYSTEM S_FILTER
44
45 #include "ofd_internal.h"
46 #include <obd_cksum.h>
47
48 static int ofd_export_stats_init(struct ofd_device *ofd,
49                                  struct obd_export *exp, void *client_nid)
50 {
51         struct obd_device       *obd = ofd_obd(ofd);
52         struct nid_stat         *stats;
53         int                      num_stats, i;
54         int                      rc, newnid = 0;
55
56         ENTRY;
57
58         if (obd_uuid_equals(&exp->exp_client_uuid, &obd->obd_uuid))
59                 /* Self-export gets no proc entry */
60                 RETURN(0);
61
62         rc = lprocfs_exp_setup(exp, client_nid, &newnid);
63         if (rc) {
64                 /* Mask error for already created
65                  * /proc entries */
66                 if (rc == -EALREADY)
67                         rc = 0;
68                 RETURN(rc);
69         }
70
71         if (newnid == 0)
72                 RETURN(0);
73
74         stats = exp->exp_nid_stats;
75         LASSERT(stats != NULL);
76
77         OBD_ALLOC(stats->nid_brw_stats, sizeof(struct brw_stats));
78         if (stats->nid_brw_stats == NULL)
79                 GOTO(clean, rc = -ENOMEM);
80
81         for (i = 0; i < BRW_LAST; i++)
82                 cfs_spin_lock_init(&stats->nid_brw_stats->hist[i].oh_lock);
83
84         rc = lprocfs_seq_create(stats->nid_proc, "brw_stats", 0644,
85                                 &ofd_per_nid_stats_fops, stats);
86         if (rc)
87                 CWARN("Error adding the brw_stats file\n");
88
89         num_stats = (sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
90                      LPROC_OFD_LAST - 1;
91
92         stats->nid_stats = lprocfs_alloc_stats(num_stats,
93                                                LPROCFS_STATS_FLAG_NOPERCPU);
94         if (stats->nid_stats == NULL)
95                 return -ENOMEM;
96
97         lprocfs_init_ops_stats(LPROC_OFD_LAST, stats->nid_stats);
98         lprocfs_counter_init(stats->nid_stats, LPROC_OFD_READ_BYTES,
99                              LPROCFS_CNTR_AVGMINMAX, "read_bytes", "bytes");
100         lprocfs_counter_init(stats->nid_stats, LPROC_OFD_WRITE_BYTES,
101                              LPROCFS_CNTR_AVGMINMAX, "write_bytes", "bytes");
102
103         rc = lprocfs_register_stats(stats->nid_proc, "stats",
104                                     stats->nid_stats);
105         if (rc)
106                 GOTO(clean, rc);
107
108         rc = lprocfs_nid_ldlm_stats_init(stats);
109         if (rc) {
110                 lprocfs_free_stats(&stats->nid_stats);
111                 GOTO(clean, rc);
112         }
113
114         RETURN(0);
115 clean:
116         return rc;
117 }
118
119 static int ofd_parse_connect_data(const struct lu_env *env,
120                                   struct obd_export *exp,
121                                   struct obd_connect_data *data)
122 {
123         struct ofd_device                *ofd = ofd_exp(exp);
124         struct filter_export_data        *fed = &exp->exp_filter_data;
125
126         if (!data)
127                 RETURN(0);
128
129         CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64
130                " ocd_version: %x ocd_grant: %d ocd_index: %u\n",
131                exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
132                data->ocd_connect_flags, data->ocd_version,
133                data->ocd_grant, data->ocd_index);
134
135         if (fed->fed_group != 0 && fed->fed_group != data->ocd_group) {
136                 CWARN("!!! This export (nid %s) used object group %d "
137                       "earlier; now it's trying to use group %d!  This could "
138                       "be a bug in the MDS. Please report to "
139                       "http://bugs.whamcloud.com/\n",
140                       obd_export_nid2str(exp), fed->fed_group,
141                       data->ocd_group);
142                 RETURN(-EPROTO);
143         }
144         fed->fed_group = data->ocd_group;
145
146         data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
147         exp->exp_connect_flags = data->ocd_connect_flags;
148         data->ocd_version = LUSTRE_VERSION_CODE;
149
150         /* Kindly make sure the SKIP_ORPHAN flag is from MDS. */
151         if (data->ocd_connect_flags & OBD_CONNECT_MDS)
152                 CDEBUG(D_HA, "%s: Received MDS connection for group %u\n",
153                        exp->exp_obd->obd_name, data->ocd_group);
154         else if (data->ocd_connect_flags & OBD_CONNECT_SKIP_ORPHAN)
155                 RETURN(-EPROTO);
156
157         if (data->ocd_connect_flags & OBD_CONNECT_INDEX) {
158                 struct lr_server_data *lsd = &ofd->ofd_lut.lut_lsd;
159                 int                    index = lsd->lsd_ost_index;
160
161                 if (!(lsd->lsd_feature_compat & OBD_COMPAT_OST)) {
162                         /* this will only happen on the first connect */
163                         lsd->lsd_ost_index = data->ocd_index;
164                         lsd->lsd_feature_compat |= OBD_COMPAT_OST;
165                         /* sync is not needed here as lut_client_add will
166                          * set exp_need_sync flag */
167                         lut_server_data_update(env, &ofd->ofd_lut, 0);
168                 } else if (index != data->ocd_index) {
169                         LCONSOLE_ERROR_MSG(0x136, "Connection from %s to index"
170                                            " %u doesn't match actual OST index"
171                                            " %u in last_rcvd file, bad "
172                                            "configuration?\n",
173                                            obd_export_nid2str(exp), index,
174                                            data->ocd_index);
175                         RETURN(-EBADF);
176                 }
177         }
178
179         if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_SIZE)) {
180                 data->ocd_brw_size = 65536;
181         } else if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
182                 data->ocd_brw_size = min(data->ocd_brw_size,
183                               (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
184                 if (data->ocd_brw_size == 0) {
185                         CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
186                                " ocd_version: %x ocd_grant: %d ocd_index: %u "
187                                "ocd_brw_size is unexpectedly zero, "
188                                "network data corruption?"
189                                "Refusing connection of this client\n",
190                                exp->exp_obd->obd_name,
191                                exp->exp_client_uuid.uuid,
192                                exp, data->ocd_connect_flags, data->ocd_version,
193                                data->ocd_grant, data->ocd_index);
194                         RETURN(-EPROTO);
195                 }
196         }
197
198         if (data->ocd_connect_flags & OBD_CONNECT_CKSUM) {
199                 __u32 cksum_types = data->ocd_cksum_types;
200
201                 /* The client set in ocd_cksum_types the checksum types it
202                  * supports. We have to mask off the algorithms that we don't
203                  * support */
204                 data->ocd_cksum_types &= cksum_types_supported_server();
205
206                 if (unlikely(data->ocd_cksum_types == 0)) {
207                         CERROR("%s: Connect with checksum support but no "
208                                "ocd_cksum_types is set\n",
209                                exp->exp_obd->obd_name);
210                         RETURN(-EPROTO);
211                 }
212
213                 CDEBUG(D_RPCTRACE, "%s: cli %s supports cksum type %x, return "
214                        "%x\n", exp->exp_obd->obd_name, obd_export_nid2str(exp),
215                        cksum_types, data->ocd_cksum_types);
216         } else {
217                 /* This client does not support OBD_CONNECT_CKSUM
218                  * fall back to CRC32 */
219                 CDEBUG(D_RPCTRACE, "%s: cli %s does not support "
220                        "OBD_CONNECT_CKSUM, CRC32 will be used\n",
221                        exp->exp_obd->obd_name, obd_export_nid2str(exp));
222         }
223
224         if (data->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
225                 data->ocd_maxbytes = ofd->ofd_dt_conf.ddp_maxbytes;
226
227         RETURN(0);
228 }
229
230 static int ofd_obd_reconnect(const struct lu_env *env, struct obd_export *exp,
231                              struct obd_device *obd, struct obd_uuid *cluuid,
232                              struct obd_connect_data *data, void *localdata)
233 {
234         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
235         int                      rc;
236
237         ENTRY;
238
239         if (exp == NULL || obd == NULL || cluuid == NULL)
240                 RETURN(-EINVAL);
241
242         rc = lu_env_refill((struct lu_env *)env);
243         if (rc != 0) {
244                 CERROR("Failure to refill session: '%d'\n", rc);
245                 RETURN(rc);
246         }
247
248         ofd_info_init(env, exp);
249         rc = ofd_parse_connect_data(env, exp, data);
250         if (rc == 0)
251                 ofd_export_stats_init(ofd, exp, localdata);
252
253         RETURN(rc);
254 }
255
256 static int ofd_obd_connect(const struct lu_env *env, struct obd_export **_exp,
257                            struct obd_device *obd, struct obd_uuid *cluuid,
258                            struct obd_connect_data *data, void *localdata)
259 {
260         struct obd_export       *exp;
261         struct ofd_device       *ofd;
262         struct lustre_handle     conn = { 0 };
263         int                      rc, group;
264
265         ENTRY;
266
267         if (_exp == NULL || obd == NULL || cluuid == NULL)
268                 RETURN(-EINVAL);
269
270         ofd = ofd_dev(obd->obd_lu_dev);
271
272         rc = class_connect(&conn, obd, cluuid);
273         if (rc)
274                 RETURN(rc);
275
276         exp = class_conn2export(&conn);
277         LASSERT(exp != NULL);
278
279         rc = lu_env_refill((struct lu_env *)env);
280         if (rc != 0) {
281                 CERROR("Failure to refill session: '%d'\n", rc);
282                 GOTO(out, rc);
283         }
284
285         ofd_info_init(env, exp);
286
287         rc = ofd_parse_connect_data(env, exp, data);
288         if (rc)
289                 GOTO(out, rc);
290
291         group = data->ocd_group;
292         if (obd->obd_replayable) {
293                 struct tg_export_data *ted = &exp->exp_target_data;
294
295                 memcpy(ted->ted_lcd->lcd_uuid, cluuid,
296                        sizeof(ted->ted_lcd->lcd_uuid));
297                 rc = lut_client_new(env, exp);
298                 if (rc != 0)
299                         GOTO(out, rc);
300                 ofd_export_stats_init(ofd, exp, localdata);
301         }
302         if (group == 0)
303                 GOTO(out, rc = 0);
304
305         /* init new group */
306         if (group > ofd->ofd_max_group) {
307                 ofd->ofd_max_group = group;
308                 rc = ofd_group_load(env, ofd, group);
309         }
310 out:
311         if (rc != 0) {
312                 class_disconnect(exp);
313                 *_exp = NULL;
314         } else {
315                 *_exp = exp;
316         }
317         RETURN(rc);
318 }
319
320 static int ofd_obd_disconnect(struct obd_export *exp)
321 {
322         struct lu_env   env;
323         int             rc;
324
325         ENTRY;
326
327         LASSERT(exp);
328         class_export_get(exp);
329
330         rc = server_disconnect_export(exp);
331
332         rc = lu_env_init(&env, LCT_DT_THREAD);
333         if (rc)
334                 RETURN(rc);
335
336         /* Do not erase record for recoverable client. */
337         if (exp->exp_obd->obd_replayable &&
338             (!exp->exp_obd->obd_fail || exp->exp_failed))
339                 lut_client_del(&env, exp);
340         lu_env_fini(&env);
341
342         class_export_put(exp);
343         RETURN(rc);
344 }
345
346 static int ofd_init_export(struct obd_export *exp)
347 {
348         int rc;
349
350         cfs_spin_lock_init(&exp->exp_filter_data.fed_lock);
351         CFS_INIT_LIST_HEAD(&exp->exp_filter_data.fed_mod_list);
352         cfs_spin_lock(&exp->exp_lock);
353         exp->exp_connecting = 1;
354         cfs_spin_unlock(&exp->exp_lock);
355
356         /* self-export doesn't need client data and ldlm initialization */
357         if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
358                                      &exp->exp_client_uuid)))
359                 return 0;
360
361         rc = lut_client_alloc(exp);
362         if (rc == 0)
363                 ldlm_init_export(exp);
364         if (rc)
365                 CERROR("%s: Can't initialize export: rc %d\n",
366                        exp->exp_obd->obd_name, rc);
367         return rc;
368 }
369
370 static int ofd_destroy_export(struct obd_export *exp)
371 {
372         if (exp->exp_filter_data.fed_pending)
373                 CERROR("%s: cli %s/%p has %lu pending on destroyed export"
374                        "\n", exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
375                        exp, exp->exp_filter_data.fed_pending);
376
377         target_destroy_export(exp);
378
379         if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
380                                      &exp->exp_client_uuid)))
381                 return 0;
382
383         ldlm_destroy_export(exp);
384         lut_client_free(exp);
385
386         ofd_fmd_cleanup(exp);
387
388         LASSERT(cfs_list_empty(&exp->exp_filter_data.fed_mod_list));
389         return 0;
390 }
391
392 int ofd_obd_postrecov(struct obd_device *obd)
393 {
394         struct lu_env            env;
395         struct lu_device        *ldev = obd->obd_lu_dev;
396         int                      rc;
397
398         ENTRY;
399
400         rc = lu_env_init(&env, LCT_DT_THREAD);
401         if (rc)
402                 RETURN(rc);
403         ofd_info_init(&env, obd->obd_self_export);
404
405         rc = ldev->ld_ops->ldo_recovery_complete(&env, ldev);
406         lu_env_fini(&env);
407         RETURN(rc);
408 }
409
410 static int ofd_set_mds_conn(struct obd_export *exp, void *val)
411 {
412         int rc = 0;
413
414         ENTRY;
415
416         LCONSOLE_WARN("%s: received MDS connection from %s\n",
417                       exp->exp_obd->obd_name, obd_export_nid2str(exp));
418         RETURN(rc);
419 }
420
421 static int ofd_set_info_async(const struct lu_env *env, struct obd_export *exp,
422                               __u32 keylen, void *key, __u32 vallen, void *val,
423                               struct ptlrpc_request_set *set)
424 {
425         struct ofd_device       *ofd = ofd_exp(exp);
426         int                      rc = 0;
427
428         ENTRY;
429
430         if (exp->exp_obd == NULL) {
431                 CDEBUG(D_IOCTL, "invalid export %p\n", exp);
432                 RETURN(-EINVAL);
433         }
434
435         if (KEY_IS(KEY_CAPA_KEY)) {
436                 rc = ofd_update_capa_key(ofd, val);
437                 if (rc)
438                         CERROR("ofd update capability key failed: %d\n", rc);
439         } else if (KEY_IS(KEY_MDS_CONN)) {
440                 rc = ofd_set_mds_conn(exp, val);
441         } else {
442                 CERROR("%s: Unsupported key %s\n",
443                        exp->exp_obd->obd_name, (char*)key);
444                 rc = -EOPNOTSUPP;
445         }
446
447         RETURN(rc);
448 }
449
450 static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
451                         __u32 keylen, void *key, __u32 *vallen, void *val,
452                         struct lov_stripe_md *lsm)
453 {
454         struct ofd_device       *ofd = ofd_exp(exp);
455         int                      rc = 0;
456
457         ENTRY;
458
459         if (exp->exp_obd == NULL) {
460                 CDEBUG(D_IOCTL, "invalid client export %p\n", exp);
461                 RETURN(-EINVAL);
462         }
463
464         if (KEY_IS(KEY_BLOCKSIZE)) {
465                 __u32 *blocksize = val;
466                 if (blocksize) {
467                         if (*vallen < sizeof(*blocksize))
468                                 RETURN(-EOVERFLOW);
469                         *blocksize = 1 << ofd->ofd_dt_conf.ddp_block_shift;
470                 }
471                 *vallen = sizeof(*blocksize);
472         } else if (KEY_IS(KEY_BLOCKSIZE_BITS)) {
473                 __u32 *blocksize_bits = val;
474                 if (blocksize_bits) {
475                         if (*vallen < sizeof(*blocksize_bits))
476                                 RETURN(-EOVERFLOW);
477                         *blocksize_bits = ofd->ofd_dt_conf.ddp_block_shift;
478                 }
479                 *vallen = sizeof(*blocksize_bits);
480         } else if (KEY_IS(KEY_LAST_ID)) {
481                 obd_id *last_id = val;
482                 if (last_id) {
483                         if (*vallen < sizeof(*last_id))
484                                 RETURN(-EOVERFLOW);
485                         *last_id = ofd_last_id(ofd,
486                                                exp->exp_filter_data.fed_group);
487                 }
488                 *vallen = sizeof(*last_id);
489         } else {
490                 CERROR("Not supported key %s\n", (char*)key);
491                 rc = -EOPNOTSUPP;
492         }
493
494         RETURN(rc);
495 }
496
497 /** helper function for statfs, also used by grant code */
498 int ofd_statfs_internal(const struct lu_env *env, struct ofd_device *ofd,
499                         struct obd_statfs *osfs, __u64 max_age, int *from_cache)
500 {
501         int rc;
502
503         rc = dt_statfs(env, ofd->ofd_osd, osfs);
504         if (unlikely(rc))
505                 return rc;
506
507         return 0;
508 }
509
510 static int ofd_statfs(const struct lu_env *env,  struct obd_export *exp,
511                       struct obd_statfs *osfs, __u64 max_age, __u32 flags)
512 {
513         struct ofd_device       *ofd = ofd_dev(exp->exp_obd->obd_lu_dev);
514         int                      rc;
515
516         ENTRY;
517
518         rc = ofd_statfs_internal(env, ofd, osfs, max_age, NULL);
519         if (unlikely(rc))
520                 GOTO(out, rc);
521
522         if (OBD_FAIL_CHECK_VALUE(OBD_FAIL_OST_ENOSPC,
523                                  ofd->ofd_lut.lut_lsd.lsd_ost_index))
524                 osfs->os_bfree = osfs->os_bavail = 2;
525
526         if (OBD_FAIL_CHECK_VALUE(OBD_FAIL_OST_ENOINO,
527                                  ofd->ofd_lut.lut_lsd.lsd_ost_index))
528                 osfs->os_ffree = 0;
529
530         /* OS_STATE_READONLY can be set by OSD already */
531         if (ofd->ofd_raid_degraded)
532                 osfs->os_state |= OS_STATE_DEGRADED;
533         EXIT;
534 out:
535         return rc;
536 }
537
538 static int ofd_sync(const struct lu_env *env, struct obd_export *exp,
539                     struct obd_info *oinfo, obd_size start, obd_size end,
540                     struct ptlrpc_request_set *set)
541 {
542         struct ofd_device       *ofd = ofd_exp(exp);
543         int                      rc = 0;
544
545         ENTRY;
546
547         /* if no objid is specified, it means "sync whole filesystem" */
548         if (oinfo->oi_oa == NULL || !(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
549                 rc = dt_sync(env, ofd->ofd_osd);
550                 GOTO(out, rc);
551         }
552
553         EXIT;
554 out:
555         return rc;
556 }
557
558 int ofd_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
559                   void *karg, void *uarg)
560 {
561         struct lu_env            env;
562         struct ofd_device       *ofd = ofd_exp(exp);
563         struct obd_device       *obd = ofd_obd(ofd);
564         int                      rc;
565
566         ENTRY;
567
568         CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
569         rc = lu_env_init(&env, LCT_LOCAL);
570         if (rc)
571                 RETURN(rc);
572
573         switch (cmd) {
574         case OBD_IOC_ABORT_RECOVERY:
575                 CERROR("aborting recovery for device %s\n", obd->obd_name);
576                 target_stop_recovery_thread(obd);
577                 break;
578         case OBD_IOC_SYNC:
579                 CDEBUG(D_RPCTRACE, "syncing ost %s\n", obd->obd_name);
580                 rc = dt_sync(&env, ofd->ofd_osd);
581                 break;
582         case OBD_IOC_SET_READONLY:
583                 rc = dt_sync(&env, ofd->ofd_osd);
584                 if (rc == 0)
585                         rc = dt_ro(&env, ofd->ofd_osd);
586                 break;
587         default:
588                 CERROR("Not supported cmd = %d for device %s\n",
589                        cmd, obd->obd_name);
590                 rc = -ENOTTY;
591         }
592
593         lu_env_fini(&env);
594         RETURN(rc);
595 }
596
597 static int ofd_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
598 {
599         int rc = 0;
600
601         ENTRY;
602
603         switch(stage) {
604         case OBD_CLEANUP_EARLY:
605                 break;
606         case OBD_CLEANUP_EXPORTS:
607                 target_cleanup_recovery(obd);
608                 break;
609         }
610         RETURN(rc);
611 }
612
613 static int ofd_ping(const struct lu_env *env, struct obd_export *exp)
614 {
615         return 0;
616 }
617
618 static int ofd_health_check(const struct lu_env *env, struct obd_device *obd)
619 {
620         struct ofd_device       *ofd = ofd_dev(obd->obd_lu_dev);
621         struct ofd_thread_info  *info;
622 #ifdef USE_HEALTH_CHECK_WRITE
623         struct thandle          *th;
624 #endif
625         int                      rc = 0;
626
627         info = ofd_info_init(env, NULL);
628         rc = dt_statfs(env, ofd->ofd_osd, &info->fti_u.osfs);
629         if (unlikely(rc))
630                 GOTO(out, rc);
631
632         if (info->fti_u.osfs.os_state == OS_STATE_READONLY)
633                 GOTO(out, rc = -EROFS);
634
635 #ifdef USE_HEALTH_CHECK_WRITE
636         OBD_ALLOC(info->fti_buf.lb_buf, CFS_PAGE_SIZE);
637         if (info->fti_buf.lb_buf == NULL)
638                 GOTO(out, rc = -ENOMEM);
639
640         info->fti_buf.lb_len = CFS_PAGE_SIZE;
641         info->fti_off = 0;
642
643         th = dt_trans_create(env, ofd->ofd_osd);
644         if (IS_ERR(th))
645                 GOTO(out, rc = PTR_ERR(th));
646
647         rc = dt_declare_record_write(env, ofd->ofd_health_check_file,
648                                      info->fti_buf.lb_len, info->fti_off, th);
649         if (rc == 0) {
650                 th->th_sync = 1; /* sync IO is needed */
651                 rc = dt_trans_start_local(env, ofd->ofd_osd, th);
652                 if (rc == 0)
653                         rc = dt_record_write(env, ofd->ofd_health_check_file,
654                                              &info->fti_buf, &info->fti_off,
655                                              th);
656         }
657         dt_trans_stop(env, ofd->ofd_osd, th);
658
659         OBD_FREE(info->fti_buf.lb_buf, CFS_PAGE_SIZE);
660
661         CDEBUG(D_INFO, "write 1 page synchronously for checking io rc %d\n",rc);
662 #endif
663 out:
664         return !!rc;
665 }
666
667 static int ofd_obd_notify(struct obd_device *obd, struct obd_device *unused,
668                           enum obd_notify_event ev, void *data)
669 {
670         switch (ev) {
671         case OBD_NOTIFY_CONFIG:
672                 LASSERT(obd->obd_no_conn);
673                 cfs_spin_lock(&obd->obd_dev_lock);
674                 obd->obd_no_conn = 0;
675                 cfs_spin_unlock(&obd->obd_dev_lock);
676                 break;
677         default:
678                 CDEBUG(D_INFO, "%s: Unhandled notification %#x\n",
679                        obd->obd_name, ev);
680         }
681         return 0;
682 }
683
684 struct obd_ops ofd_obd_ops = {
685         .o_owner                = THIS_MODULE,
686         .o_connect              = ofd_obd_connect,
687         .o_reconnect            = ofd_obd_reconnect,
688         .o_disconnect           = ofd_obd_disconnect,
689         .o_set_info_async       = ofd_set_info_async,
690         .o_get_info             = ofd_get_info,
691         .o_statfs               = ofd_statfs,
692         .o_init_export          = ofd_init_export,
693         .o_destroy_export       = ofd_destroy_export,
694         .o_postrecov            = ofd_obd_postrecov,
695         .o_sync                 = ofd_sync,
696         .o_iocontrol            = ofd_iocontrol,
697         .o_precleanup           = ofd_precleanup,
698         .o_ping                 = ofd_ping,
699         .o_health_check         = ofd_health_check,
700         .o_notify               = ofd_obd_notify,
701 };