Whamcloud - gitweb
LU-1445 ofd: Add fid support on OFD
[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         ofd->ofd_seq_count++;
146         write_unlock(&ofd->ofd_seq_list_lock);
147         return new_seq;
148 }
149
150 obd_id ofd_seq_last_oid(struct ofd_seq *oseq)
151 {
152         obd_id id;
153
154         spin_lock(&oseq->os_last_oid_lock);
155         id = oseq->os_last_oid;
156         spin_unlock(&oseq->os_last_oid_lock);
157
158         return id;
159 }
160
161 void ofd_seq_last_oid_set(struct ofd_seq *oseq, obd_id id)
162 {
163         spin_lock(&oseq->os_last_oid_lock);
164         if (likely(oseq->os_last_oid < id))
165                 oseq->os_last_oid = id;
166         spin_unlock(&oseq->os_last_oid_lock);
167 }
168
169 int ofd_seq_last_oid_write(const struct lu_env *env, struct ofd_device *ofd,
170                            struct ofd_seq *oseq)
171 {
172         struct ofd_thread_info  *info = ofd_info(env);
173         obd_id                   tmp;
174         int                      rc;
175
176         ENTRY;
177
178         info->fti_buf.lb_buf = &tmp;
179         info->fti_buf.lb_len = sizeof(tmp);
180         info->fti_off = 0;
181
182         CDEBUG(D_INODE, "%s: write last_objid for seq "LPX64" : "LPX64"\n",
183                ofd_name(ofd), oseq->os_seq, ofd_seq_last_oid(oseq));
184
185         tmp = cpu_to_le64(ofd_seq_last_oid(oseq));
186
187         rc = ofd_record_write(env, ofd, oseq->os_lastid_obj, &info->fti_buf,
188                               &info->fti_off);
189         RETURN(rc);
190 }
191
192 static void ofd_deregister_seq_exp(struct ofd_device *ofd)
193 {
194         struct seq_server_site  *ss = &ofd->ofd_seq_site;
195
196         if (ss->ss_client_seq != NULL) {
197                 lustre_deregister_osp_item(&ss->ss_client_seq->lcs_exp);
198                 ss->ss_client_seq->lcs_exp = NULL;
199         }
200 }
201
202 void ofd_seqs_fini(const struct lu_env *env, struct ofd_device *ofd)
203 {
204         struct ofd_seq  *oseq;
205         struct ofd_seq  *tmp;
206         cfs_list_t       dispose;
207         int             rc;
208
209         ofd_deregister_seq_exp(ofd);
210
211         rc = ofd_fid_fini(env, ofd);
212         if (rc != 0)
213                 CERROR("%s: fid fini error: rc = %d\n", ofd_name(ofd), rc);
214
215         CFS_INIT_LIST_HEAD(&dispose);
216         write_lock(&ofd->ofd_seq_list_lock);
217         cfs_list_for_each_entry_safe(oseq, tmp, &ofd->ofd_seq_list, os_list) {
218                 cfs_list_move(&oseq->os_list, &dispose);
219         }
220         write_unlock(&ofd->ofd_seq_list_lock);
221
222         while (!cfs_list_empty(&dispose)) {
223                 oseq = container_of0(dispose.next, struct ofd_seq, os_list);
224                 ofd_seq_delete(env, oseq);
225         }
226
227         LASSERT(cfs_list_empty(&ofd->ofd_seq_list));
228         return;
229 }
230
231 struct ofd_seq *ofd_seq_load(const struct lu_env *env, struct ofd_device *ofd,
232                              obd_seq seq)
233 {
234         struct ofd_thread_info  *info = ofd_info(env);
235         struct ofd_seq          *oseq = NULL;
236         struct dt_object        *dob;
237         obd_id                   lastid;
238         int                      rc;
239
240         ENTRY;
241
242         /* if seq is already initialized */
243         oseq = ofd_seq_get(ofd, seq);
244         if (oseq != NULL)
245                 RETURN(oseq);
246
247         OBD_ALLOC_PTR(oseq);
248         if (oseq == NULL)
249                 RETURN(ERR_PTR(-ENOMEM));
250
251         lu_last_id_fid(&info->fti_fid, seq);
252         memset(&info->fti_attr, 0, sizeof(info->fti_attr));
253         info->fti_attr.la_valid = LA_MODE;
254         info->fti_attr.la_mode = S_IFREG |  S_IRUGO | S_IWUSR;
255         info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
256
257         /* create object tracking per-seq last created
258          * id to be used by orphan recovery mechanism */
259         dob = dt_find_or_create(env, ofd->ofd_osd, &info->fti_fid,
260                                 &info->fti_dof, &info->fti_attr);
261         if (IS_ERR(dob)) {
262                 OBD_FREE_PTR(oseq);
263                 RETURN((void *)dob);
264         }
265
266         oseq->os_lastid_obj = dob;
267
268         CFS_INIT_LIST_HEAD(&oseq->os_list);
269         mutex_init(&oseq->os_create_lock);
270         spin_lock_init(&oseq->os_last_oid_lock);
271         oseq->os_seq = seq;
272
273         cfs_atomic_set(&oseq->os_refc, 1);
274
275         rc = dt_attr_get(env, dob, &info->fti_attr, BYPASS_CAPA);
276         if (rc)
277                 GOTO(cleanup, rc);
278
279         if (info->fti_attr.la_size == 0) {
280                 /* object is just created, initialize last id */
281                 oseq->os_last_oid = OFD_INIT_OBJID;
282                 ofd_seq_last_oid_write(env, ofd, oseq);
283         } else if (info->fti_attr.la_size == sizeof(lastid)) {
284                 info->fti_off = 0;
285                 info->fti_buf.lb_buf = &lastid;
286                 info->fti_buf.lb_len = sizeof(lastid);
287
288                 rc = dt_record_read(env, dob, &info->fti_buf, &info->fti_off);
289                 if (rc) {
290                         CERROR("%s: can't read last_id: rc = %d\n",
291                                 ofd_name(ofd), rc);
292                         GOTO(cleanup, rc);
293                 }
294                 oseq->os_last_oid = le64_to_cpu(lastid);
295         } else {
296                 CERROR("%s: corrupted size "LPU64" LAST_ID of seq "LPX64"\n",
297                         ofd_name(ofd), (__u64)info->fti_attr.la_size, seq);
298                 GOTO(cleanup, rc = -EINVAL);
299         }
300
301         oseq = ofd_seq_add(env, ofd, oseq);
302         RETURN(oseq);
303 cleanup:
304         ofd_seq_put(env, oseq);
305         return ERR_PTR(rc);
306 }
307
308 static int ofd_register_seq_exp(struct ofd_device *ofd)
309 {
310         struct seq_server_site  *ss = &ofd->ofd_seq_site;
311         char                    *osp_name = NULL;
312         int                     rc;
313
314         OBD_ALLOC(osp_name, MAX_OBD_NAME);
315         if (osp_name == NULL)
316                 GOTO(out_free, rc = -ENOMEM);
317
318         rc = tgt_name2ospname(ofd_name(ofd), osp_name);
319         if (rc != 0)
320                 GOTO(out_free, rc);
321
322         rc = lustre_register_osp_item(osp_name, &ss->ss_client_seq->lcs_exp,
323                                       NULL, NULL);
324 out_free:
325         if (osp_name != NULL)
326                 OBD_FREE(osp_name, MAX_OBD_NAME);
327
328         return rc;
329 }
330
331 /* object sequence management */
332 int ofd_seqs_init(const struct lu_env *env, struct ofd_device *ofd)
333 {
334         int rc;
335
336         rc = ofd_fid_init(env, ofd);
337         if (rc != 0) {
338                 CERROR("%s: fid init error: rc = %d\n", ofd_name(ofd), rc);
339                 return rc;
340         }
341
342         rc = ofd_register_seq_exp(ofd);
343         if (rc) {
344                 CERROR("%s: Can't init seq exp, rc %d\n", ofd_name(ofd), rc);
345                 return rc;
346         }
347
348         rwlock_init(&ofd->ofd_seq_list_lock);
349         CFS_INIT_LIST_HEAD(&ofd->ofd_seq_list);
350         ofd->ofd_seq_count = 0;
351         return rc;
352 }
353
354 int ofd_clients_data_init(const struct lu_env *env, struct ofd_device *ofd,
355                           unsigned long fsize)
356 {
357         struct obd_device               *obd = ofd_obd(ofd);
358         struct lr_server_data           *lsd = &ofd->ofd_lut.lut_lsd;
359         struct lsd_client_data          *lcd = NULL;
360         struct filter_export_data       *fed;
361         int                              cl_idx;
362         int                              rc = 0;
363         loff_t                           off = lsd->lsd_client_start;
364
365         CLASSERT(offsetof(struct lsd_client_data, lcd_padding) +
366                  sizeof(lcd->lcd_padding) == LR_CLIENT_SIZE);
367
368         OBD_ALLOC_PTR(lcd);
369         if (lcd == NULL)
370                 RETURN(-ENOMEM);
371
372         for (cl_idx = 0; off < fsize; cl_idx++) {
373                 struct obd_export       *exp;
374                 __u64                    last_rcvd;
375
376                 /* Don't assume off is incremented properly by
377                  * fsfilt_read_record(), in case sizeof(*lcd)
378                  * isn't the same as fsd->lsd_client_size.  */
379                 off = lsd->lsd_client_start + cl_idx * lsd->lsd_client_size;
380                 rc = tgt_client_data_read(env, &ofd->ofd_lut, lcd, &off, cl_idx);
381                 if (rc) {
382                         CERROR("%s: error reading FILT %s idx %d off %llu: "
383                                "rc = %d\n", ofd_name(ofd), LAST_RCVD, cl_idx,
384                                off, rc);
385                         rc = 0;
386                         break; /* read error shouldn't cause startup to fail */
387                 }
388
389                 if (lcd->lcd_uuid[0] == '\0') {
390                         CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
391                                cl_idx);
392                         continue;
393                 }
394
395                 last_rcvd = lcd->lcd_last_transno;
396
397                 /* These exports are cleaned up by ofd_disconnect(), so they
398                  * need to be set up like real exports as ofd_connect() does.
399                  */
400                 exp = class_new_export(obd, (struct obd_uuid *)lcd->lcd_uuid);
401
402                 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
403                        " srv lr: "LPU64"\n", lcd->lcd_uuid, cl_idx,
404                        last_rcvd, lsd->lsd_last_transno);
405
406                 if (IS_ERR(exp)) {
407                         if (PTR_ERR(exp) == -EALREADY) {
408                                 /* export already exists, zero out this one */
409                                 CERROR("%s: Duplicate export %s!\n",
410                                        ofd_name(ofd), lcd->lcd_uuid);
411                                 continue;
412                         }
413                         GOTO(err_out, rc = PTR_ERR(exp));
414                 }
415
416                 fed = &exp->exp_filter_data;
417                 *fed->fed_ted.ted_lcd = *lcd;
418
419                 rc = tgt_client_add(env, exp, cl_idx);
420                 LASSERTF(rc == 0, "rc = %d\n", rc); /* can't fail existing */
421                 /* VBR: set export last committed version */
422                 exp->exp_last_committed = last_rcvd;
423                 spin_lock(&exp->exp_lock);
424                 exp->exp_connecting = 0;
425                 exp->exp_in_recovery = 0;
426                 spin_unlock(&exp->exp_lock);
427                 obd->obd_max_recoverable_clients++;
428                 class_export_put(exp);
429
430                 /* Need to check last_rcvd even for duplicated exports. */
431                 CDEBUG(D_OTHER, "client at idx %d has last_rcvd = "LPU64"\n",
432                        cl_idx, last_rcvd);
433
434                 spin_lock(&ofd->ofd_lut.lut_translock);
435                 if (last_rcvd > lsd->lsd_last_transno)
436                         lsd->lsd_last_transno = last_rcvd;
437                 spin_unlock(&ofd->ofd_lut.lut_translock);
438         }
439
440 err_out:
441         OBD_FREE_PTR(lcd);
442         RETURN(rc);
443 }
444
445 int ofd_server_data_init(const struct lu_env *env, struct ofd_device *ofd)
446 {
447         struct ofd_thread_info  *info = ofd_info(env);
448         struct lr_server_data   *lsd = &ofd->ofd_lut.lut_lsd;
449         struct obd_device       *obd = ofd_obd(ofd);
450         unsigned long           last_rcvd_size;
451         __u32                   index;
452         int                     rc;
453
454         rc = dt_attr_get(env, ofd->ofd_lut.lut_last_rcvd, &info->fti_attr,
455                          BYPASS_CAPA);
456         if (rc)
457                 RETURN(rc);
458
459         last_rcvd_size = (unsigned long)info->fti_attr.la_size;
460
461         /* ensure padding in the struct is the correct size */
462         CLASSERT (offsetof(struct lr_server_data, lsd_padding) +
463                   sizeof(lsd->lsd_padding) == LR_SERVER_SIZE);
464
465         rc = server_name2index(obd->obd_name, &index, NULL);
466         if (rc < 0) {
467                 CERROR("%s: Can not get index from obd_name: rc = %d\n",
468                        obd->obd_name, rc);
469                 RETURN(rc);
470         }
471
472         if (last_rcvd_size == 0) {
473                 LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
474
475                 memcpy(lsd->lsd_uuid, obd->obd_uuid.uuid,
476                        sizeof(lsd->lsd_uuid));
477                 lsd->lsd_last_transno = 0;
478                 lsd->lsd_mount_count = 0;
479                 lsd->lsd_server_size = LR_SERVER_SIZE;
480                 lsd->lsd_client_start = LR_CLIENT_START;
481                 lsd->lsd_client_size = LR_CLIENT_SIZE;
482                 lsd->lsd_subdir_count = FILTER_SUBDIR_COUNT;
483                 lsd->lsd_feature_incompat = OBD_INCOMPAT_OST;
484                 lsd->lsd_osd_index = index;
485         } else {
486                 rc = tgt_server_data_read(env, &ofd->ofd_lut);
487                 if (rc) {
488                         CDEBUG(D_INODE,"OBD ofd: error reading %s: rc %d\n",
489                                LAST_RCVD, rc);
490                         GOTO(err_fsd, rc);
491                 }
492                 if (strcmp((char *)lsd->lsd_uuid,
493                            (char *)obd->obd_uuid.uuid)) {
494                         LCONSOLE_ERROR("Trying to start OBD %s using the wrong"
495                                        " disk %s. Were the /dev/ assignments "
496                                        "rearranged?\n",
497                                        obd->obd_uuid.uuid, lsd->lsd_uuid);
498                         GOTO(err_fsd, rc = -EINVAL);
499                 }
500
501                 if (lsd->lsd_osd_index == 0) {
502                         lsd->lsd_osd_index = index;
503                 } else if (lsd->lsd_osd_index != index) {
504                         LCONSOLE_ERROR("%s: index %d in last rcvd is different"
505                                        " with the index %d in config log."
506                                        " It might be disk corruption!\n",
507                                        obd->obd_name, lsd->lsd_osd_index,
508                                        index);
509                         GOTO(err_fsd, rc = -EINVAL);
510                 }
511         }
512
513         lsd->lsd_mount_count++;
514         obd->u.obt.obt_mount_count = lsd->lsd_mount_count;
515         obd->u.obt.obt_instance = (__u32)obd->u.obt.obt_mount_count;
516         ofd->ofd_subdir_count = lsd->lsd_subdir_count;
517
518         if (lsd->lsd_feature_incompat & ~OFD_INCOMPAT_SUPP) {
519                 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
520                        obd->obd_name,
521                        lsd->lsd_feature_incompat & ~OFD_INCOMPAT_SUPP);
522                 GOTO(err_fsd, rc = -EINVAL);
523         }
524         if (lsd->lsd_feature_rocompat & ~OFD_ROCOMPAT_SUPP) {
525                 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
526                        obd->obd_name,
527                        lsd->lsd_feature_rocompat & ~OFD_ROCOMPAT_SUPP);
528                 /* Do something like remount filesystem read-only */
529                 GOTO(err_fsd, rc = -EINVAL);
530         }
531
532         CDEBUG(D_INODE, "%s: server last_transno : "LPU64"\n",
533                obd->obd_name, lsd->lsd_last_transno);
534         CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
535                obd->obd_name, lsd->lsd_mount_count);
536         CDEBUG(D_INODE, "%s: server data size: %u\n",
537                obd->obd_name, lsd->lsd_server_size);
538         CDEBUG(D_INODE, "%s: per-client data start: %u\n",
539                obd->obd_name, lsd->lsd_client_start);
540         CDEBUG(D_INODE, "%s: per-client data size: %u\n",
541                obd->obd_name, lsd->lsd_client_size);
542         CDEBUG(D_INODE, "%s: server subdir_count: %u\n",
543                obd->obd_name, lsd->lsd_subdir_count);
544         CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
545                last_rcvd_size <= lsd->lsd_client_start ? 0 :
546                (last_rcvd_size - lsd->lsd_client_start) /
547                lsd->lsd_client_size);
548
549         if (!obd->obd_replayable)
550                 CWARN("%s: recovery support OFF\n", obd->obd_name);
551
552         rc = ofd_clients_data_init(env, ofd, last_rcvd_size);
553
554         spin_lock(&ofd->ofd_lut.lut_translock);
555         obd->obd_last_committed = lsd->lsd_last_transno;
556         ofd->ofd_lut.lut_last_transno = lsd->lsd_last_transno;
557         spin_unlock(&ofd->ofd_lut.lut_translock);
558
559         /* save it, so mount count and last_transno is current */
560         rc = tgt_server_data_update(env, &ofd->ofd_lut, 0);
561         if (rc)
562                 GOTO(err_fsd, rc);
563
564         RETURN(0);
565
566 err_fsd:
567         class_disconnect_exports(obd);
568         RETURN(rc);
569 }
570
571 int ofd_fs_setup(const struct lu_env *env, struct ofd_device *ofd,
572                  struct obd_device *obd)
573 {
574         struct ofd_thread_info  *info = ofd_info(env);
575         struct dt_object        *fo;
576         int                      rc = 0;
577
578         ENTRY;
579
580         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FS_SETUP))
581                 RETURN (-ENOENT);
582
583         /* prepare transactions callbacks */
584         ofd->ofd_txn_cb.dtc_txn_start = NULL;
585         ofd->ofd_txn_cb.dtc_txn_stop = ofd_txn_stop_cb;
586         ofd->ofd_txn_cb.dtc_txn_commit = NULL;
587         ofd->ofd_txn_cb.dtc_cookie = ofd;
588         ofd->ofd_txn_cb.dtc_tag = LCT_DT_THREAD;
589         CFS_INIT_LIST_HEAD(&ofd->ofd_txn_cb.dtc_linkage);
590
591         dt_txn_callback_add(ofd->ofd_osd, &ofd->ofd_txn_cb);
592
593         rc = ofd_server_data_init(env, ofd);
594         if (rc)
595                 GOTO(out, rc);
596
597         lu_local_obj_fid(&info->fti_fid, OFD_HEALTH_CHECK_OID);
598         memset(&info->fti_attr, 0, sizeof(info->fti_attr));
599         info->fti_attr.la_valid = LA_MODE;
600         info->fti_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
601         info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
602
603         fo = dt_find_or_create(env, ofd->ofd_osd, &info->fti_fid,
604                                &info->fti_dof, &info->fti_attr);
605         if (IS_ERR(fo))
606                 GOTO(out, rc = PTR_ERR(fo));
607
608         ofd->ofd_health_check_file = fo;
609
610         rc = ofd_seqs_init(env, ofd);
611         if (rc)
612                 GOTO(out_hc, rc);
613
614         RETURN(0);
615 out_hc:
616         lu_object_put(env, &ofd->ofd_health_check_file->do_lu);
617 out:
618         dt_txn_callback_del(ofd->ofd_osd, &ofd->ofd_txn_cb);
619         return rc;
620 }
621
622 void ofd_fs_cleanup(const struct lu_env *env, struct ofd_device *ofd)
623 {
624         int i;
625
626         ENTRY;
627
628         ofd_info_init(env, NULL);
629
630         ofd_seqs_fini(env, ofd);
631
632         i = dt_sync(env, ofd->ofd_osd);
633         if (i)
634                 CERROR("can't sync: %d\n", i);
635
636         /* Remove transaction callback */
637         dt_txn_callback_del(ofd->ofd_osd, &ofd->ofd_txn_cb);
638
639         if (ofd->ofd_health_check_file) {
640                 lu_object_put(env, &ofd->ofd_health_check_file->do_lu);
641                 ofd->ofd_health_check_file = NULL;
642         }
643
644         EXIT;
645 }
646