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