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