Whamcloud - gitweb
LU-1866 osd: ancillary work for initial OI scrub
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_oi.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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 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/osd/osd_oi.c
37  *
38  * Object Index.
39  *
40  * Author: Nikita Danilov <nikita@clusterfs.com>
41  */
42
43 /*
44  * oi uses two mechanisms to implement fid->cookie mapping:
45  *
46  *     - persistent index, where cookie is a record and fid is a key, and
47  *
48  *     - algorithmic mapping for "igif" fids.
49  *
50  */
51
52 #define DEBUG_SUBSYSTEM S_MDS
53
54 #include <linux/module.h>
55
56 /* LUSTRE_VERSION_CODE */
57 #include <lustre_ver.h>
58 /*
59  * struct OBD_{ALLOC,FREE}*()
60  * OBD_FAIL_CHECK
61  */
62 #include <obd.h>
63 #include <obd_support.h>
64
65 /* fid_cpu_to_be() */
66 #include <lustre_fid.h>
67 #include <dt_object.h>
68
69 #include "osd_oi.h"
70 /* osd_lookup(), struct osd_thread_info */
71 #include "osd_internal.h"
72 #include "osd_scrub.h"
73
74 static unsigned int osd_oi_count = OSD_OI_FID_NR;
75 CFS_MODULE_PARM(osd_oi_count, "i", int, 0444,
76                 "Number of Object Index containers to be created, "
77                 "it's only valid for new filesystem.");
78
79 /** to serialize concurrent OI index initialization */
80 static struct mutex oi_init_lock;
81
82 static struct dt_index_features oi_feat = {
83         .dif_flags       = DT_IND_UPDATE,
84         .dif_recsize_min = sizeof(struct osd_inode_id),
85         .dif_recsize_max = sizeof(struct osd_inode_id),
86         .dif_ptrsize     = 4
87 };
88
89 #define OSD_OI_NAME_BASE        "oi.16"
90
91 static void osd_oi_table_put(struct osd_thread_info *info,
92                              struct osd_oi **oi_table, unsigned oi_count)
93 {
94         struct iam_container *bag;
95         int                   i;
96
97         for (i = 0; i < oi_count; i++) {
98                 if (oi_table[i] == NULL)
99                         continue;
100
101                 LASSERT(oi_table[i]->oi_inode != NULL);
102
103                 bag = &(oi_table[i]->oi_dir.od_container);
104                 if (bag->ic_object == oi_table[i]->oi_inode)
105                         iam_container_fini(bag);
106                 iput(oi_table[i]->oi_inode);
107                 oi_table[i]->oi_inode = NULL;
108                 OBD_FREE_PTR(oi_table[i]);
109                 oi_table[i] = NULL;
110         }
111 }
112
113 static int osd_oi_index_create_one(struct osd_thread_info *info,
114                                    struct osd_device *osd, const char *name,
115                                    struct dt_index_features *feat)
116 {
117         const struct lu_env             *env = info->oti_env;
118         struct osd_inode_id             *id  = &info->oti_id;
119         struct buffer_head              *bh;
120         struct inode                    *inode;
121         struct ldiskfs_dir_entry_2      *de;
122         struct dentry                   *dentry;
123         struct super_block              *sb  = osd_sb(osd);
124         struct inode                    *dir = sb->s_root->d_inode;
125         handle_t                        *jh;
126         int                              rc;
127
128         dentry = osd_child_dentry_by_inode(env, dir, name, strlen(name));
129         bh = osd_ldiskfs_find_entry(dir, dentry, &de, NULL);
130         if (bh) {
131                 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
132                 brelse(bh);
133                 inode = osd_iget(info, osd, id);
134                 if (!IS_ERR(inode)) {
135                         iput(inode);
136                         inode = ERR_PTR(-EEXIST);
137                 }
138                 return PTR_ERR(inode);
139         }
140
141         jh = ldiskfs_journal_start_sb(sb, 100);
142         if (IS_ERR(jh))
143                 return PTR_ERR(jh);
144
145         inode = ldiskfs_create_inode(jh, dir, (S_IFREG | S_IRUGO | S_IWUSR));
146         if (IS_ERR(inode)) {
147                 ldiskfs_journal_stop(jh);
148                 return PTR_ERR(inode);
149         }
150
151         if (feat->dif_flags & DT_IND_VARKEY)
152                 rc = iam_lvar_create(inode, feat->dif_keysize_max,
153                                      feat->dif_ptrsize, feat->dif_recsize_max,
154                                      jh);
155         else
156                 rc = iam_lfix_create(inode, feat->dif_keysize_max,
157                                      feat->dif_ptrsize, feat->dif_recsize_max,
158                                      jh);
159         dentry = osd_child_dentry_by_inode(env, dir, name, strlen(name));
160         rc = osd_ldiskfs_add_entry(jh, dentry, inode, NULL);
161         ldiskfs_journal_stop(jh);
162         iput(inode);
163         return rc;
164 }
165
166 static struct inode *osd_oi_index_open(struct osd_thread_info *info,
167                                        struct osd_device *osd,
168                                        const char *name,
169                                        struct dt_index_features *f,
170                                        bool create)
171 {
172         struct dentry *dentry;
173         struct inode  *inode;
174         int            rc;
175
176         dentry = ll_lookup_one_len(name, osd_sb(osd)->s_root, strlen(name));
177         if (IS_ERR(dentry))
178                 return (void *) dentry;
179
180         if (dentry->d_inode) {
181                 LASSERT(!is_bad_inode(dentry->d_inode));
182                 inode = dentry->d_inode;
183                 atomic_inc(&inode->i_count);
184                 dput(dentry);
185                 return inode;
186         }
187
188         /* create */
189         dput(dentry);
190         shrink_dcache_parent(osd_sb(osd)->s_root);
191         if (!create)
192                 return ERR_PTR(-ENOENT);
193
194         rc = osd_oi_index_create_one(info, osd, name, f);
195         if (rc)
196                 return ERR_PTR(rc);
197
198         dentry = ll_lookup_one_len(name, osd_sb(osd)->s_root, strlen(name));
199         if (IS_ERR(dentry))
200                 return (void *) dentry;
201
202         if (dentry->d_inode) {
203                 LASSERT(!is_bad_inode(dentry->d_inode));
204                 inode = dentry->d_inode;
205                 atomic_inc(&inode->i_count);
206                 dput(dentry);
207                 return inode;
208         }
209
210         return ERR_PTR(-ENOENT);
211 }
212
213 /**
214  * Open an OI(Ojbect Index) container.
215  *
216  * \param       name    Name of OI container
217  * \param       objp    Pointer of returned OI
218  *
219  * \retval      0       success
220  * \retval      -ve     failure
221  */
222 static int osd_oi_open(struct osd_thread_info *info, struct osd_device *osd,
223                        char *name, struct osd_oi **oi_slot, bool create)
224 {
225         struct osd_directory *dir;
226         struct iam_container *bag;
227         struct inode         *inode;
228         struct osd_oi        *oi;
229         int                   rc;
230
231         ENTRY;
232
233         oi_feat.dif_keysize_min = sizeof(struct lu_fid);
234         oi_feat.dif_keysize_max = sizeof(struct lu_fid);
235
236         inode = osd_oi_index_open(info, osd, name, &oi_feat, create);
237         if (IS_ERR(inode))
238                 RETURN(PTR_ERR(inode));
239
240         ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
241         OBD_ALLOC_PTR(oi);
242         if (oi == NULL)
243                 GOTO(out_inode, rc = -ENOMEM);
244
245         oi->oi_inode = inode;
246         dir = &oi->oi_dir;
247
248         bag = &dir->od_container;
249         rc = iam_container_init(bag, &dir->od_descr, inode);
250         if (rc < 0)
251                 GOTO(out_free, rc);
252
253         rc = iam_container_setup(bag);
254         if (rc < 0)
255                 GOTO(out_container, rc);
256
257         *oi_slot = oi;
258         RETURN(0);
259
260 out_container:
261         iam_container_fini(bag);
262 out_free:
263         OBD_FREE_PTR(oi);
264 out_inode:
265         iput(inode);
266         return rc;
267 }
268
269 /**
270  * Open OI(Object Index) table.
271  * If \a oi_count is zero, which means caller doesn't know how many OIs there
272  * will be, this function can either return 0 for new filesystem, or number
273  * of OIs on existed filesystem.
274  *
275  * If \a oi_count is non-zero, which means caller does know number of OIs on
276  * filesystem, this function should return the exactly same number on
277  * success, or error code in failure.
278  *
279  * \param     oi_count  Number of expected OI containers
280  * \param     create    Create OIs if doesn't exist
281  *
282  * \retval    +ve       number of opened OI containers
283  * \retval      0       no OI containers found
284  * \retval    -ve       failure
285  */
286 static int
287 osd_oi_table_open(struct osd_thread_info *info, struct osd_device *osd,
288                   struct osd_oi **oi_table, unsigned oi_count, bool create)
289 {
290         struct scrub_file *sf = &osd->od_scrub.os_file;
291         int                count = 0;
292         int                rc = 0;
293         int                i;
294         ENTRY;
295
296         /* NB: oi_count != 0 means that we have already created/known all OIs
297          * and have known exact number of OIs. */
298         LASSERT(oi_count <= OSD_OI_FID_NR_MAX);
299
300         for (i = 0; i < (oi_count != 0 ? oi_count : OSD_OI_FID_NR_MAX); i++) {
301                 char name[12];
302
303                 if (oi_table[i] != NULL) {
304                         count++;
305                         continue;
306                 }
307
308                 sprintf(name, "%s.%d", OSD_OI_NAME_BASE, i);
309                 rc = osd_oi_open(info, osd, name, &oi_table[i], create);
310                 if (rc == 0) {
311                         count++;
312                         continue;
313                 }
314
315                 if (rc == -ENOENT && create == false) {
316                         if (oi_count == 0)
317                                 return count;
318
319                         rc = 0;
320                         ldiskfs_set_bit(i, sf->sf_oi_bitmap);
321                         continue;
322                 }
323
324                 CERROR("%.16s: can't open %s: rc = %d\n",
325                        LDISKFS_SB(osd_sb(osd))->s_es->s_volume_name, name, rc);
326                 if (oi_count > 0)
327                         CERROR("%.16s: expect to open total %d OI files.\n",
328                                LDISKFS_SB(osd_sb(osd))->s_es->s_volume_name,
329                                oi_count);
330                 break;
331         }
332
333         if (rc < 0) {
334                 osd_oi_table_put(info, oi_table, oi_count > 0 ? oi_count : i);
335                 count = rc;
336         }
337
338         RETURN(count);
339 }
340
341 int osd_oi_init(struct osd_thread_info *info, struct osd_device *osd)
342 {
343         struct osd_scrub  *scrub = &osd->od_scrub;
344         struct scrub_file *sf = &scrub->os_file;
345         struct osd_oi    **oi;
346         int                rc;
347         ENTRY;
348
349         OBD_ALLOC(oi, sizeof(*oi) * OSD_OI_FID_NR_MAX);
350         if (oi == NULL)
351                 RETURN(-ENOMEM);
352
353         mutex_lock(&oi_init_lock);
354         /* try to open existing multiple OIs first */
355         rc = osd_oi_table_open(info, osd, oi, sf->sf_oi_count, false);
356         if (rc < 0)
357                 GOTO(out, rc);
358
359         if (rc > 0) {
360                 if (rc == sf->sf_oi_count || sf->sf_oi_count == 0)
361                         GOTO(out, rc);
362
363                 osd_scrub_file_reset(scrub,
364                                      LDISKFS_SB(osd_sb(osd))->s_es->s_uuid,
365                                      SF_RECREATED);
366                 osd_oi_count = sf->sf_oi_count;
367                 goto create;
368         }
369
370         /* if previous failed then try found single OI from old filesystem */
371         rc = osd_oi_open(info, osd, OSD_OI_NAME_BASE, &oi[0], false);
372         if (rc == 0) { /* found single OI from old filesystem */
373                 GOTO(out, rc = 1);
374         } else if (rc != -ENOENT) {
375                 CERROR("%.16s: can't open %s: rc = %d\n",
376                        LDISKFS_SB(osd_sb(osd))->s_es->s_volume_name,
377                        OSD_OI_NAME_BASE, rc);
378                 GOTO(out, rc);
379         }
380
381         if (sf->sf_oi_count > 0) {
382                 int i;
383
384                 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
385                 for (i = 0; i < osd_oi_count; i++)
386                         ldiskfs_set_bit(i, sf->sf_oi_bitmap);
387                 osd_scrub_file_reset(scrub,
388                                      LDISKFS_SB(osd_sb(osd))->s_es->s_uuid,
389                                      SF_RECREATED);
390         }
391         sf->sf_oi_count = osd_oi_count;
392
393 create:
394         rc = osd_scrub_file_store(scrub);
395         if (rc < 0) {
396                 osd_oi_table_put(info, oi, sf->sf_oi_count);
397                 GOTO(out, rc);
398         }
399
400         /* No OIs exist, new filesystem, create OI objects */
401         rc = osd_oi_table_open(info, osd, oi, osd_oi_count, true);
402         LASSERT(ergo(rc >= 0, rc == osd_oi_count));
403
404         GOTO(out, rc);
405
406 out:
407         if (rc < 0) {
408                 OBD_FREE(oi, sizeof(*oi) * OSD_OI_FID_NR_MAX);
409         } else {
410                 LASSERT((rc & (rc - 1)) == 0);
411                 osd->od_oi_table = oi;
412                 osd->od_oi_count = rc;
413                 rc = 0;
414         }
415
416         mutex_unlock(&oi_init_lock);
417         return rc;
418 }
419
420 void osd_oi_fini(struct osd_thread_info *info, struct osd_device *osd)
421 {
422         if (unlikely(osd->od_oi_table == NULL))
423                 return;
424
425         osd_oi_table_put(info, osd->od_oi_table, osd->od_oi_count);
426
427         OBD_FREE(osd->od_oi_table,
428                  sizeof(*(osd->od_oi_table)) * OSD_OI_FID_NR_MAX);
429         osd->od_oi_table = NULL;
430 }
431
432 static inline int fid_is_fs_root(const struct lu_fid *fid)
433 {
434         /* Map root inode to special local object FID */
435         return (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE &&
436                          fid_oid(fid) == OSD_FS_ROOT_OID));
437 }
438
439 static int osd_oi_iam_lookup(struct osd_thread_info *oti,
440                              struct osd_oi *oi, struct dt_rec *rec,
441                              const struct dt_key *key)
442 {
443         struct iam_container  *bag;
444         struct iam_iterator   *it = &oti->oti_idx_it;
445         struct iam_path_descr *ipd;
446         int                    rc;
447         ENTRY;
448
449         LASSERT(oi);
450         LASSERT(oi->oi_inode);
451
452         bag = &oi->oi_dir.od_container;
453         ipd = osd_idx_ipd_get(oti->oti_env, bag);
454         if (IS_ERR(ipd))
455                 RETURN(-ENOMEM);
456
457         /* got ipd now we can start iterator. */
458         iam_it_init(it, bag, 0, ipd);
459
460         rc = iam_it_get(it, (struct iam_key *)key);
461         if (rc > 0)
462                 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)rec);
463         iam_it_put(it);
464         iam_it_fini(it);
465         osd_ipd_put(oti->oti_env, bag, ipd);
466
467         LINVRNT(osd_invariant(obj));
468
469         RETURN(rc);
470 }
471
472 int fid_is_on_ost(struct osd_thread_info *info, struct osd_device *osd,
473                   const struct lu_fid *fid)
474 {
475         struct lu_seq_range *range = &info->oti_seq_range;
476         int rc;
477         ENTRY;
478
479         if (fid_is_idif(fid) || fid_is_last_id(fid))
480                 RETURN(1);
481
482         rc = osd_fld_lookup(info->oti_env, osd, fid, range);
483         if (rc != 0) {
484                 CERROR("%s: Can not lookup fld for "DFID"\n",
485                        osd2lu_dev(osd)->ld_obd->obd_name, PFID(fid));
486                 RETURN(rc);
487         }
488
489         CDEBUG(D_INFO, "fid "DFID" range "DRANGE"\n", PFID(fid),
490                PRANGE(range));
491
492         if (range->lsr_flags == LU_SEQ_RANGE_OST)
493                 RETURN(1);
494
495         RETURN(0);
496 }
497
498 int __osd_oi_lookup(struct osd_thread_info *info, struct osd_device *osd,
499                     const struct lu_fid *fid, struct osd_inode_id *id)
500 {
501         struct lu_fid *oi_fid = &info->oti_fid2;
502         int            rc;
503
504         fid_cpu_to_be(oi_fid, fid);
505         rc = osd_oi_iam_lookup(info, osd_fid2oi(osd, fid), (struct dt_rec *)id,
506                                (const struct dt_key *)oi_fid);
507         if (rc > 0) {
508                 osd_id_unpack(id, id);
509                 rc = 0;
510         } else if (rc == 0) {
511                 rc = -ENOENT;
512         }
513         return rc;
514 }
515
516 int osd_oi_lookup(struct osd_thread_info *info, struct osd_device *osd,
517                   const struct lu_fid *fid, struct osd_inode_id *id,
518                   bool check_fld)
519 {
520         int                  rc = 0;
521
522         if ((!fid_is_last_id(fid) && check_fld &&
523              fid_is_on_ost(info, osd, fid)) ||
524             fid_is_llog(fid)) {
525                 /* old OSD obj id */
526                 /* FIXME: actually for all of the OST object */
527                 rc = osd_obj_map_lookup(info, osd, fid, id);
528         } else if (fid_is_igif(fid)) {
529                 osd_id_gen(id, lu_igif_ino(fid), lu_igif_gen(fid));
530         } else if (fid_is_fs_root(fid)) {
531                 osd_id_gen(id, osd_sb(osd)->s_root->d_inode->i_ino,
532                            osd_sb(osd)->s_root->d_inode->i_generation);
533         } else {
534                 if (unlikely(fid_is_acct(fid)))
535                         return osd_acct_obj_lookup(info, osd, fid, id);
536                 else if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE) ||
537                          fid_is_last_id(fid))
538                         return osd_obj_spec_lookup(info, osd, fid, id);
539
540                 rc = __osd_oi_lookup(info, osd, fid, id);
541         }
542         return rc;
543 }
544
545 static int osd_oi_iam_insert(struct osd_thread_info *oti, struct osd_oi *oi,
546                              const struct dt_rec *rec, const struct dt_key *key,
547                              struct thandle *th)
548 {
549         struct iam_container  *bag;
550         struct iam_rec        *iam_rec = (struct iam_rec *)oti->oti_ldp;
551         struct iam_path_descr *ipd;
552         struct osd_thandle    *oh;
553         int                    rc;
554         ENTRY;
555
556         LASSERT(oi);
557         LASSERT(oi->oi_inode);
558         ll_vfs_dq_init(oi->oi_inode);
559
560         bag = &oi->oi_dir.od_container;
561         ipd = osd_idx_ipd_get(oti->oti_env, bag);
562         if (unlikely(ipd == NULL))
563                 RETURN(-ENOMEM);
564
565         oh = container_of0(th, struct osd_thandle, ot_super);
566         LASSERT(oh->ot_handle != NULL);
567         LASSERT(oh->ot_handle->h_transaction != NULL);
568         if (S_ISDIR(oi->oi_inode->i_mode))
569                 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec,
570                              &oti->oti_fid);
571         else
572                 iam_rec = (struct iam_rec *) rec;
573         rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
574                         iam_rec, ipd);
575         osd_ipd_put(oti->oti_env, bag, ipd);
576         LINVRNT(osd_invariant(obj));
577         RETURN(rc);
578 }
579
580 int osd_oi_insert(struct osd_thread_info *info, struct osd_device *osd,
581                   const struct lu_fid *fid, const struct osd_inode_id *id,
582                   struct thandle *th)
583 {
584         struct lu_fid       *oi_fid = &info->oti_fid2;
585         struct osd_inode_id *oi_id = &info->oti_id2;
586
587         if (fid_is_igif(fid) || unlikely(fid_seq(fid) == FID_SEQ_DOT_LUSTRE))
588                 return 0;
589
590         if ((fid_is_on_ost(info, osd, fid) && !fid_is_last_id(fid)) ||
591              fid_is_llog(fid))
592                 return osd_obj_map_insert(info, osd, fid, id, th);
593
594         /* Server mount should not depends on OI files */
595         if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE) ||
596             fid_is_last_id(fid))
597                 return osd_obj_spec_insert(info, osd, fid, id, th);
598
599         fid_cpu_to_be(oi_fid, fid);
600         osd_id_pack(oi_id, id);
601         return osd_oi_iam_insert(info, osd_fid2oi(osd, fid),
602                                  (const struct dt_rec *)oi_id,
603                                  (const struct dt_key *)oi_fid, th);
604 }
605
606 static int osd_oi_iam_delete(struct osd_thread_info *oti, struct osd_oi *oi,
607                              const struct dt_key *key, struct thandle *handle)
608 {
609         struct iam_container  *bag;
610         struct iam_path_descr *ipd;
611         struct osd_thandle    *oh;
612         int                    rc;
613         ENTRY;
614
615         LASSERT(oi);
616         LASSERT(oi->oi_inode);
617         ll_vfs_dq_init(oi->oi_inode);
618
619         bag = &oi->oi_dir.od_container;
620         ipd = osd_idx_ipd_get(oti->oti_env, bag);
621         if (unlikely(ipd == NULL))
622                 RETURN(-ENOMEM);
623
624         oh = container_of0(handle, struct osd_thandle, ot_super);
625         LASSERT(oh->ot_handle != NULL);
626         LASSERT(oh->ot_handle->h_transaction != NULL);
627
628         rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
629         osd_ipd_put(oti->oti_env, bag, ipd);
630         LINVRNT(osd_invariant(obj));
631         RETURN(rc);
632 }
633
634 int osd_oi_delete(struct osd_thread_info *info,
635                   struct osd_device *osd, const struct lu_fid *fid,
636                   struct thandle *th)
637 {
638         struct lu_fid *oi_fid = &info->oti_fid2;
639
640         if (fid_is_igif(fid) || fid_is_last_id(fid))
641                 return 0;
642
643         LASSERT(fid_seq(fid) != FID_SEQ_LOCAL_FILE);
644
645         if (fid_is_on_ost(info, osd, fid) || fid_is_llog(fid))
646                 return osd_obj_map_delete(info, osd, fid, th);
647
648         fid_cpu_to_be(oi_fid, fid);
649         return osd_oi_iam_delete(info, osd_fid2oi(osd, fid),
650                                  (const struct dt_key *)oi_fid, th);
651 }
652
653 int osd_oi_mod_init(void)
654 {
655         if (osd_oi_count == 0 || osd_oi_count > OSD_OI_FID_NR_MAX)
656                 osd_oi_count = OSD_OI_FID_NR;
657
658         if ((osd_oi_count & (osd_oi_count - 1)) != 0) {
659                 LCONSOLE_WARN("Round up oi_count %d to power2 %d\n",
660                               osd_oi_count, size_roundup_power2(osd_oi_count));
661                 osd_oi_count = size_roundup_power2(osd_oi_count);
662         }
663
664         mutex_init(&oi_init_lock);
665         return 0;
666 }