Whamcloud - gitweb
LU-2275 mdt: Avoid setting positive dispositions too early
[fs/lustre-release.git] / lustre / ofd / ofd_fs.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) 2012, Intel Corporation.
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_fs.c
37  *
38  * Author: Alexey Zhuravlev <bzzz@whamcloud.com>
39  * Author: Mikhail Pershin <tappro@whamcloud.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_FILTER
43
44 #include "ofd_internal.h"
45
46 int ofd_record_write(const struct lu_env *env, struct ofd_device *ofd,
47                      struct dt_object *dt, struct lu_buf *buf, loff_t *off)
48 {
49         struct thandle  *th;
50         int              rc;
51
52         ENTRY;
53
54         LASSERT(dt);
55
56         th = dt_trans_create(env, ofd->ofd_osd);
57         if (IS_ERR(th))
58                 RETURN(PTR_ERR(th));
59
60         rc = dt_declare_record_write(env, dt, buf->lb_len, *off, th);
61         if (rc == 0) {
62                 rc = dt_trans_start_local(env, ofd->ofd_osd, th);
63                 if (rc == 0)
64                         rc = dt_record_write(env, dt, buf, off, th);
65         }
66         dt_trans_stop(env, ofd->ofd_osd, th);
67
68         RETURN(rc);
69 }
70
71 int ofd_precreate_batch(struct ofd_device *ofd, int batch)
72 {
73         int count;
74
75         spin_lock(&ofd->ofd_batch_lock);
76         count = min(ofd->ofd_precreate_batch, batch);
77         spin_unlock(&ofd->ofd_batch_lock);
78
79         return count;
80 }
81
82 struct ofd_seq *ofd_seq_get(struct ofd_device *ofd, obd_seq seq)
83 {
84         struct ofd_seq *oseq;
85
86         read_lock(&ofd->ofd_seq_list_lock);
87         cfs_list_for_each_entry(oseq, &ofd->ofd_seq_list, os_list) {
88                 if (oseq->os_seq == seq) {
89                         cfs_atomic_inc(&oseq->os_refc);
90                         read_unlock(&ofd->ofd_seq_list_lock);
91                         return oseq;
92                 }
93         }
94         read_unlock(&ofd->ofd_seq_list_lock);
95         return NULL;
96 }
97
98 static void ofd_seq_destroy(const struct lu_env *env,
99                             struct ofd_seq *oseq)
100 {
101         LASSERT(cfs_list_empty(&oseq->os_list));
102         LASSERT(oseq->os_lastid_obj != NULL);
103         lu_object_put(env, &oseq->os_lastid_obj->do_lu);
104         OBD_FREE_PTR(oseq);
105 }
106
107 void ofd_seq_put(const struct lu_env *env, struct ofd_seq *oseq)
108 {
109         if (cfs_atomic_dec_and_test(&oseq->os_refc))
110                 ofd_seq_destroy(env, oseq);
111 }
112
113 static void ofd_seq_delete(const struct lu_env *env, struct ofd_seq *oseq)
114 {
115         cfs_list_del_init(&oseq->os_list);
116         ofd_seq_put(env, oseq);
117 }
118
119 /**
120  * Add a new sequence to the OFD device.
121  *
122  * \param ofd OFD device
123  * \param new_seq new sequence to be added
124  *
125  * \retval the seq to be added or the existing seq
126  **/
127 static struct ofd_seq *ofd_seq_add(const struct lu_env *env,
128                                    struct ofd_device *ofd,
129                                    struct ofd_seq *new_seq)
130 {
131         struct ofd_seq *os = NULL;
132
133         write_lock(&ofd->ofd_seq_list_lock);
134         cfs_list_for_each_entry(os, &ofd->ofd_seq_list, os_list) {
135                 if (os->os_seq == new_seq->os_seq) {
136                         cfs_atomic_inc(&os->os_refc);
137                         write_unlock(&ofd->ofd_seq_list_lock);
138                         /* The seq has not been added to the list */
139                         ofd_seq_put(env, new_seq);
140                         return os;
141                 }
142         }
143         cfs_atomic_inc(&new_seq->os_refc);
144         cfs_list_add_tail(&new_seq->os_list, &ofd->ofd_seq_list);
145         write_unlock(&ofd->ofd_seq_list_lock);
146         return new_seq;
147 }
148
149 obd_id ofd_seq_last_oid(struct ofd_seq *oseq)
150 {
151         obd_id id;
152
153         spin_lock(&oseq->os_last_oid_lock);
154         id = oseq->os_last_oid;
155         spin_unlock(&oseq->os_last_oid_lock);
156
157         return id;
158 }
159
160 void ofd_seq_last_oid_set(struct ofd_seq *oseq, obd_id id)
161 {
162         spin_lock(&oseq->os_last_oid_lock);
163         if (likely(oseq->os_last_oid < id))
164                 oseq->os_last_oid = id;
165         spin_unlock(&oseq->os_last_oid_lock);
166 }
167
168 int ofd_seq_last_oid_write(const struct lu_env *env, struct ofd_device *ofd,
169                            struct ofd_seq *oseq)
170 {
171         struct ofd_thread_info  *info = ofd_info(env);
172         obd_id                   tmp;
173         int                      rc;
174
175         ENTRY;
176
177         info->fti_buf.lb_buf = &tmp;
178         info->fti_buf.lb_len = sizeof(tmp);
179         info->fti_off = 0;
180
181         CDEBUG(D_INODE, "%s: write last_objid for seq "LPX64" : "LPX64"\n",
182                ofd_name(ofd), oseq->os_seq, ofd_seq_last_oid(oseq));
183
184         tmp = cpu_to_le64(ofd_seq_last_oid(oseq));
185
186         rc = ofd_record_write(env, ofd, oseq->os_lastid_obj, &info->fti_buf,
187                               &info->fti_off);
188         RETURN(rc);
189 }
190
191 static int ofd_seq_count_write(const struct lu_env *env, struct ofd_device *ofd)
192 {
193         struct ofd_thread_info  *info = ofd_info(env);
194         obd_seq                  tmp;
195         int                      rc;
196
197         ENTRY;
198
199         info->fti_buf.lb_buf = &tmp;
200         info->fti_buf.lb_len = sizeof(tmp);
201         info->fti_off = 0;
202
203         tmp = cpu_to_le32(ofd->ofd_seq_count);
204
205         rc = ofd_record_write(env, ofd, ofd->ofd_seq_count_file,
206                               &info->fti_buf, &info->fti_off);
207
208         RETURN(rc);
209 }
210
211 void ofd_seqs_fini(const struct lu_env *env, struct ofd_device *ofd)
212 {
213         struct ofd_seq  *oseq;
214         struct ofd_seq  *tmp;
215         cfs_list_t       dispose;
216
217         CFS_INIT_LIST_HEAD(&dispose);
218         write_lock(&ofd->ofd_seq_list_lock);
219         cfs_list_for_each_entry_safe(oseq, tmp, &ofd->ofd_seq_list, os_list) {
220                 cfs_list_move(&oseq->os_list, &dispose);
221         }
222         write_unlock(&ofd->ofd_seq_list_lock);
223
224         while (!cfs_list_empty(&dispose)) {
225                 oseq = container_of0(dispose.next, struct ofd_seq, os_list);
226                 ofd_seq_delete(env, oseq);
227         }
228
229         LASSERT(cfs_list_empty(&ofd->ofd_seq_list));
230         return;
231 }
232
233 struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
234                              obd_seq seq)
235 {
236         struct ofd_thread_info  *info = ofd_info(env);
237         struct ofd_seq          *oseq = NULL;
238         struct dt_object        *dob;
239         obd_id                   lastid;
240         int                      rc;
241
242         ENTRY;
243
244         /* if seq is already initialized */
245         oseq = ofd_seq_get(ofd, seq);
246         if (oseq != NULL)
247                 RETURN(oseq);
248
249         OBD_ALLOC_PTR(oseq);
250         if (oseq == NULL)
251                 RETURN(ERR_PTR(-ENOMEM));
252
253         lu_local_obj_fid(&info->fti_fid, OFD_GROUP0_LAST_OID + seq);
254
255         memset(&info->fti_attr, 0, sizeof(info->fti_attr));
256         info->fti_attr.la_valid = LA_MODE;
257         info->fti_attr.la_mode = S_IFREG |  S_IRUGO | S_IWUSR;
258         info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
259
260         /* create object tracking per-seq last created
261          * id to be used by orphan recovery mechanism */
262         dob = dt_find_or_create(env, ofd->ofd_osd, &info->fti_fid,
263                                 &info->fti_dof, &info->fti_attr);
264         if (IS_ERR(dob)) {
265                 OBD_FREE_PTR(oseq);
266                 RETURN((void *)dob);
267         }
268
269         oseq->os_lastid_obj = dob;
270
271         CFS_INIT_LIST_HEAD(&oseq->os_list);
272         mutex_init(&oseq->os_create_lock);
273         spin_lock_init(&oseq->os_last_oid_lock);
274         oseq->os_seq = seq;
275
276         cfs_atomic_set(&oseq->os_refc, 1);
277
278         rc = dt_attr_get(env, dob, &info->fti_attr, BYPASS_CAPA);
279         if (rc)
280                 GOTO(cleanup, rc);
281
282         if (info->fti_attr.la_size == 0) {
283                 /* object is just created, initialize last id */
284                 oseq->os_last_oid = OFD_INIT_OBJID;
285                 ofd_seq_last_oid_write(env, ofd, oseq);
286                 ofd_seq_count_write(env, ofd);
287         } else if (info->fti_attr.la_size == sizeof(lastid)) {
288                 info->fti_off = 0;
289                 info->fti_buf.lb_buf = &lastid;
290                 info->fti_buf.lb_len = sizeof(lastid);
291
292                 rc = dt_record_read(env, dob, &info->fti_buf, &info->fti_off);
293                 if (rc) {
294                         CERROR("%s: can't read last_id: rc = %d\n",
295                                 ofd_name(ofd), rc);
296                         GOTO(cleanup, rc);
297                 }
298                 oseq->os_last_oid = le64_to_cpu(lastid);
299         } else {
300                 CERROR("%s: corrupted size "LPU64" LAST_ID of seq "LPX64"\n",
301                         ofd_name(ofd), (__u64)info->fti_attr.la_size, seq);
302                 GOTO(cleanup, rc = -EINVAL);
303         }
304
305         oseq = ofd_seq_add(env, ofd, oseq);
306         RETURN(oseq);
307 cleanup:
308         ofd_seq_put(env, oseq);
309         return ERR_PTR(rc);
310 }
311
312 /* object sequence management */
313 int ofd_seqs_init(const struct lu_env *env, struct ofd_device *ofd)
314 {
315         struct ofd_thread_info  *info = ofd_info(env);
316         unsigned long           seq_count_size;
317         obd_seq                 seq_count;
318         int                     rc = 0;
319         int                     i;
320
321         ENTRY;
322
323         rwlock_init(&ofd->ofd_seq_list_lock);
324         CFS_INIT_LIST_HEAD(&ofd->ofd_seq_list);
325
326         rc = dt_attr_get(env, ofd->ofd_seq_count_file,
327                          &info->fti_attr, BYPASS_CAPA);
328         if (rc)
329                 GOTO(cleanup, rc);
330
331         seq_count_size = (unsigned long)info->fti_attr.la_size;
332
333         if (seq_count_size == sizeof(seq_count)) {
334                 info->fti_off = 0;
335                 info->fti_buf.lb_buf = &seq_count;
336                 info->fti_buf.lb_len = sizeof(seq_count);
337
338                 rc = dt_record_read(env, ofd->ofd_seq_count_file,
339                                     &info->fti_buf, &info->fti_off);
340                 if (rc) {
341                         CERROR("%s: can't read LAST_GROUP: rc = %d\n",
342                                ofd_name(ofd), rc);
343                         GOTO(cleanup, rc);
344                 }
345
346                 ofd->ofd_seq_count = le64_to_cpu(seq_count);
347         } else if (seq_count_size == 0) {
348                 ofd->ofd_seq_count = 0;
349         } else {
350                 CERROR("%s: seqs file is corrupted? size = %lu\n",
351                        ofd_name(ofd), seq_count_size);
352                 GOTO(cleanup, rc = -EIO);
353         }
354
355         for (i = 0; i <= ofd->ofd_seq_count; i++) {
356                 struct ofd_seq *oseq;
357
358                 oseq = ofd_seq_load(env, ofd, i);
359                 if (IS_ERR(oseq)) {
360                         CERROR("%s: can't load seq %d: rc = %d\n",
361                                ofd_name(ofd), i, rc);
362                         /* Clean all previously set seqs */
363                         ofd_seqs_fini(env, ofd);
364                         GOTO(cleanup, rc);
365                 } else {
366                         ofd_seq_put(env, oseq);
367                 }
368         }
369
370         CDEBUG(D_OTHER, "%s: %u seqs initialized\n", ofd_name(ofd),
371                ofd->ofd_seq_count + 1);
372 cleanup:
373         RETURN(rc);
374 }
375
376 int ofd_clients_data_init(const struct lu_env *env, struct ofd_device *ofd,
377                           unsigned long fsize)
378 {
379         struct obd_device               *obd = ofd_obd(ofd);
380         struct lr_server_data           *lsd = &ofd->ofd_lut.lut_lsd;
381         struct lsd_client_data          *lcd = NULL;
382         struct filter_export_data       *fed;
383         int                              cl_idx;
384         int                              rc = 0;
385         loff_t                           off = lsd->lsd_client_start;
386
387         CLASSERT(offsetof(struct lsd_client_data, lcd_padding) +
388                  sizeof(lcd->lcd_padding) == LR_CLIENT_SIZE);
389
390         OBD_ALLOC_PTR(lcd);
391         if (lcd == NULL)
392                 RETURN(-ENOMEM);
393
394         for (cl_idx = 0; off < fsize; cl_idx++) {
395                 struct obd_export       *exp;
396                 __u64                    last_rcvd;
397
398                 /* Don't assume off is incremented properly by
399                  * fsfilt_read_record(), in case sizeof(*lcd)
400                  * isn't the same as fsd->lsd_client_size.  */
401                 off = lsd->lsd_client_start + cl_idx * lsd->lsd_client_size;
402                 rc = tgt_client_data_read(env, &ofd->ofd_lut, lcd, &off, cl_idx);
403                 if (rc) {
404                         CERROR("%s: error reading FILT %s idx %d off %llu: "
405                                "rc = %d\n", ofd_name(ofd), LAST_RCVD, cl_idx,
406                                off, rc);
407                         rc = 0;
408                         break; /* read error shouldn't cause startup to fail */
409                 }
410
411                 if (lcd->lcd_uuid[0] == '\0') {
412                         CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
413                                cl_idx);
414                         continue;
415                 }
416
417                 last_rcvd = lcd->lcd_last_transno;
418
419                 /* These exports are cleaned up by ofd_disconnect(), so they
420                  * need to be set up like real exports as ofd_connect() does.
421                  */
422                 exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
423
424                 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
425                        " srv lr: "LPU64"\n", lcd->lcd_uuid, cl_idx,
426                        last_rcvd, lsd->lsd_last_transno);
427
428                 if (IS_ERR(exp)) {
429                         if (PTR_ERR(exp) == -EALREADY) {
430                                 /* export already exists, zero out this one */
431                                 CERROR("%s: Duplicate export %s!\n",
432                                        ofd_name(ofd), lcd->lcd_uuid);
433                                 continue;
434                         }
435                         GOTO(err_out, rc = PTR_ERR(exp));
436                 }
437
438                 fed = &exp->exp_filter_data;
439                 *fed->fed_ted.ted_lcd = *lcd;
440
441                 rc = tgt_client_add(env, exp, cl_idx);
442                 LASSERTF(rc == 0, "rc = %d\n", rc); /* can't fail existing */
443                 /* VBR: set export last committed version */
444                 exp->exp_last_committed = last_rcvd;
445                 spin_lock(&exp->exp_lock);
446                 exp->exp_connecting = 0;
447                 exp->exp_in_recovery = 0;
448                 spin_unlock(&exp->exp_lock);
449                 obd->obd_max_recoverable_clients++;
450                 class_export_put(exp);
451
452                 /* Need to check last_rcvd even for duplicated exports. */
453                 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
454                        cl_idx, last_rcvd);
455
456                 spin_lock(&ofd->ofd_lut.lut_translock);
457                 if (last_rcvd > lsd->lsd_last_transno)
458                         lsd->lsd_last_transno = last_rcvd;
459                 spin_unlock(&ofd->ofd_lut.lut_translock);
460         }
461
462 err_out:
463         OBD_FREE_PTR(lcd);
464         RETURN(rc);
465 }
466
467 int ofd_server_data_init(const struct lu_env *env, struct ofd_device *ofd)
468 {
469         struct ofd_thread_info  *info = ofd_info(env);
470         struct lr_server_data   *lsd = &ofd->ofd_lut.lut_lsd;
471         struct obd_device       *obd = ofd_obd(ofd);
472         unsigned long            last_rcvd_size;
473         int                      rc;
474
475         rc = dt_attr_get(env, ofd->ofd_lut.lut_last_rcvd, &info->fti_attr,
476                          BYPASS_CAPA);
477         if (rc)
478                 RETURN(rc);
479
480         last_rcvd_size = (unsigned long)info->fti_attr.la_size;
481
482         /* ensure padding in the struct is the correct size */
483         CLASSERT (offsetof(struct lr_server_data, lsd_padding) +
484                   sizeof(lsd->lsd_padding) == LR_SERVER_SIZE);
485
486         if (last_rcvd_size == 0) {
487                 LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
488
489                 memcpy(lsd->lsd_uuid, obd->obd_uuid.uuid,
490                        sizeof(lsd->lsd_uuid));
491                 lsd->lsd_last_transno = 0;
492                 lsd->lsd_mount_count = 0;
493                 lsd->lsd_server_size = LR_SERVER_SIZE;
494                 lsd->lsd_client_start = LR_CLIENT_START;
495                 lsd->lsd_client_size = LR_CLIENT_SIZE;
496                 lsd->lsd_subdir_count = FILTER_SUBDIR_COUNT;
497                 lsd->lsd_feature_incompat = OBD_INCOMPAT_OST;
498         } else {
499                 rc = tgt_server_data_read(env, &ofd->ofd_lut);
500                 if (rc) {
501                         CDEBUG(D_INODE,"OBD ofd: error reading %s: rc %d\n",
502                                LAST_RCVD, rc);
503                         GOTO(err_fsd, rc);
504                 }
505                 if (strcmp((char *)lsd->lsd_uuid,
506                            (char *)obd->obd_uuid.uuid)) {
507                         LCONSOLE_ERROR("Trying to start OBD %s using the wrong"
508                                        " disk %s. Were the /dev/ assignments "
509                                        "rearranged?\n",
510                                        obd->obd_uuid.uuid, lsd->lsd_uuid);
511                         GOTO(err_fsd, rc = -EINVAL);
512                 }
513         }
514
515         lsd->lsd_mount_count++;
516         obd->u.obt.obt_mount_count = lsd->lsd_mount_count;
517         obd->u.obt.obt_instance = (__u32)obd->u.obt.obt_mount_count;
518         ofd->ofd_subdir_count = lsd->lsd_subdir_count;
519
520         if (lsd->lsd_feature_incompat & ~OFD_INCOMPAT_SUPP) {
521                 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
522                        obd->obd_name,
523                        lsd->lsd_feature_incompat & ~OFD_INCOMPAT_SUPP);
524                 GOTO(err_fsd, rc = -EINVAL);
525         }
526         if (lsd->lsd_feature_rocompat & ~OFD_ROCOMPAT_SUPP) {
527                 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
528                        obd->obd_name,
529                        lsd->lsd_feature_rocompat & ~OFD_ROCOMPAT_SUPP);
530                 /* Do something like remount filesystem read-only */
531                 GOTO(err_fsd, rc = -EINVAL);
532         }
533
534         CDEBUG(D_INODE, "%s: server last_transno : "LPU64"\n",
535                obd->obd_name, lsd->lsd_last_transno);
536         CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
537                obd->obd_name, lsd->lsd_mount_count);
538         CDEBUG(D_INODE, "%s: server data size: %u\n",
539                obd->obd_name, lsd->lsd_server_size);
540         CDEBUG(D_INODE, "%s: per-client data start: %u\n",
541                obd->obd_name, lsd->lsd_client_start);
542         CDEBUG(D_INODE, "%s: per-client data size: %u\n",
543                obd->obd_name, lsd->lsd_client_size);
544         CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
545                obd->obd_name, lsd->lsd_subdir_count);
546         CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
547                last_rcvd_size <= lsd->lsd_client_start ? 0 :
548                (last_rcvd_size - lsd->lsd_client_start) /
549                lsd->lsd_client_size);
550
551         if (!obd->obd_replayable)
552                 CWARN("%s: recovery support OFF\n", obd->obd_name);
553
554         rc = ofd_clients_data_init(env, ofd, last_rcvd_size);
555
556         spin_lock(&ofd->ofd_lut.lut_translock);
557         obd->obd_last_committed = lsd->lsd_last_transno;
558         ofd->ofd_lut.lut_last_transno = lsd->lsd_last_transno;
559         spin_unlock(&ofd->ofd_lut.lut_translock);
560
561         /* save it, so mount count and last_transno is current */
562         rc = tgt_server_data_update(env, &ofd->ofd_lut, 0);
563         if (rc)
564                 GOTO(err_fsd, rc);
565
566         RETURN(0);
567
568 err_fsd:
569         class_disconnect_exports(obd);
570         RETURN(rc);
571 }
572
573 int ofd_fs_setup(const struct lu_env *env, struct ofd_device *ofd,
574                  struct obd_device *obd)
575 {
576         struct ofd_thread_info  *info = ofd_info(env);
577         struct dt_object        *fo;
578         int                      rc = 0;
579
580         ENTRY;
581
582         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
583                 RETURN (-ENOENT);
584
585         /* prepare transactions callbacks */
586         ofd->ofd_txn_cb.dtc_txn_start = NULL;
587         ofd->ofd_txn_cb.dtc_txn_stop = ofd_txn_stop_cb;
588         ofd->ofd_txn_cb.dtc_txn_commit = NULL;
589         ofd->ofd_txn_cb.dtc_cookie = ofd;
590         ofd->ofd_txn_cb.dtc_tag = LCT_DT_THREAD;
591         CFS_INIT_LIST_HEAD(&ofd->ofd_txn_cb.dtc_linkage);
592
593         dt_txn_callback_add(ofd->ofd_osd, &ofd->ofd_txn_cb);
594
595         rc = ofd_server_data_init(env, ofd);
596         if (rc)
597                 GOTO(out, rc);
598
599         lu_local_obj_fid(&info->fti_fid, OFD_HEALTH_CHECK_OID);
600         memset(&info->fti_attr, 0, sizeof(info->fti_attr));
601         info->fti_attr.la_valid = LA_MODE;
602         info->fti_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
603         info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
604
605         fo = dt_find_or_create(env, ofd->ofd_osd, &info->fti_fid,
606                                &info->fti_dof, &info->fti_attr);
607         if (IS_ERR(fo))
608                 GOTO(out, rc = PTR_ERR(fo));
609
610         ofd->ofd_health_check_file = fo;
611
612         lu_local_obj_fid(&info->fti_fid, OFD_LAST_GROUP_OID);
613         memset(&info->fti_attr, 0, sizeof(info->fti_attr));
614         info->fti_attr.la_valid = LA_MODE;
615         info->fti_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
616         info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
617
618         fo = dt_find_or_create(env, ofd->ofd_osd, &info->fti_fid,
619                                &info->fti_dof, &info->fti_attr);
620         if (IS_ERR(fo))
621                 GOTO(out_hc, rc = PTR_ERR(fo));
622
623         ofd->ofd_seq_count_file = fo;
624
625         rc = ofd_seqs_init(env, ofd);
626         if (rc)
627                 GOTO(out_lg, rc);
628
629         RETURN(0);
630 out_lg:
631         lu_object_put(env, &ofd->ofd_seq_count_file->do_lu);
632 out_hc:
633         lu_object_put(env, &ofd->ofd_health_check_file->do_lu);
634 out:
635         dt_txn_callback_del(ofd->ofd_osd, &ofd->ofd_txn_cb);
636         return rc;
637 }
638
639 void ofd_fs_cleanup(const struct lu_env *env, struct ofd_device *ofd)
640 {
641         int i;
642
643         ENTRY;
644
645         ofd_info_init(env, NULL);
646
647         ofd_seqs_fini(env, ofd);
648
649         i = dt_sync(env, ofd->ofd_osd);
650         if (i)
651                 CERROR("can't sync: %d\n", i);
652
653         /* Remove transaction callback */
654         dt_txn_callback_del(ofd->ofd_osd, &ofd->ofd_txn_cb);
655
656         if (ofd->ofd_seq_count_file) {
657                 lu_object_put(env, &ofd->ofd_seq_count_file->do_lu);
658                 ofd->ofd_seq_count_file = NULL;
659         }
660
661         if (ofd->ofd_health_check_file) {
662                 lu_object_put(env, &ofd->ofd_health_check_file->do_lu);
663                 ofd->ofd_health_check_file = NULL;
664         }
665
666         EXIT;
667 }
668