Whamcloud - gitweb
a4323d092d8bd0852ecd45babb9521614dfbb99e
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.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) 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, 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_compat.c
37  *
38  * on-disk structure for managing /O
39  *
40  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
41  */
42
43 /* LUSTRE_VERSION_CODE */
44 #include <lustre_ver.h>
45 /* prerequisite for linux/xattr.h */
46 #include <linux/types.h>
47 /* prerequisite for linux/xattr.h */
48 #include <linux/fs.h>
49 /* XATTR_{REPLACE,CREATE} */
50 #include <linux/xattr.h>
51
52 /*
53  * struct OBD_{ALLOC,FREE}*()
54  * OBD_FAIL_CHECK
55  */
56 #include <obd_support.h>
57
58 #include "osd_internal.h"
59 #include "osd_oi.h"
60
61 static void osd_push_ctxt(const struct osd_device *dev,
62                           struct lvfs_run_ctxt *newctxt,
63                           struct lvfs_run_ctxt *save)
64 {
65         OBD_SET_CTXT_MAGIC(newctxt);
66         newctxt->pwdmnt = dev->od_mnt;
67         newctxt->pwd = dev->od_mnt->mnt_root;
68         newctxt->fs = get_ds();
69
70         push_ctxt(save, newctxt, NULL);
71 }
72
73 static void osd_pop_ctxt(const struct osd_device *dev,
74                          struct lvfs_run_ctxt *new,
75                          struct lvfs_run_ctxt *save)
76 {
77         pop_ctxt(save, new, NULL);
78 }
79
80 /* utility to make a directory */
81 static struct dentry *simple_mkdir(struct dentry *dir, struct vfsmount *mnt,
82                                    const char *name, int mode, int fix)
83 {
84         struct dentry *dchild;
85         int err = 0;
86         ENTRY;
87
88         // ASSERT_KERNEL_CTXT("kernel doing mkdir outside kernel context\n");
89         CDEBUG(D_INODE, "creating directory %.*s\n", (int)strlen(name), name);
90         dchild = ll_lookup_one_len(name, dir, strlen(name));
91         if (IS_ERR(dchild))
92                 GOTO(out_up, dchild);
93
94         if (dchild->d_inode) {
95                 int old_mode = dchild->d_inode->i_mode;
96                 if (!S_ISDIR(old_mode)) {
97                         CERROR("found %s (%lu/%u) is mode %o\n", name,
98                                dchild->d_inode->i_ino,
99                                dchild->d_inode->i_generation, old_mode);
100                         GOTO(out_err, err = -ENOTDIR);
101                 }
102
103                 /* Fixup directory permissions if necessary */
104                 if (fix && (old_mode & S_IALLUGO) != (mode & S_IALLUGO)) {
105                         CDEBUG(D_CONFIG,
106                                "fixing permissions on %s from %o to %o\n",
107                                name, old_mode, mode);
108                         dchild->d_inode->i_mode = (mode & S_IALLUGO) |
109                                                   (old_mode & ~S_IALLUGO);
110                         mark_inode_dirty(dchild->d_inode);
111                 }
112                 GOTO(out_up, dchild);
113         }
114
115         err = vfs_mkdir(dir->d_inode, dchild, mode);
116         if (err)
117                 GOTO(out_err, err);
118
119         RETURN(dchild);
120
121 out_err:
122         dput(dchild);
123         dchild = ERR_PTR(err);
124 out_up:
125         return dchild;
126 }
127
128 int osd_last_rcvd_subdir_count(struct osd_device *osd)
129 {
130         struct lr_server_data lsd;
131         struct dentry        *dlast;
132         loff_t                off;
133         int                   rc = 0;
134         int                   count = OBJ_SUBDIR_COUNT;
135
136         ENTRY;
137
138         dlast = ll_lookup_one_len(LAST_RCVD, osd_sb(osd)->s_root,
139                                   strlen(LAST_RCVD));
140         if (IS_ERR(dlast))
141                 return PTR_ERR(dlast);
142         else if (dlast->d_inode == NULL)
143                 goto out;
144
145         off = 0;
146         rc = osd_ldiskfs_read(dlast->d_inode, &lsd, sizeof(lsd), &off);
147         if (rc == sizeof(lsd)) {
148                 CDEBUG(D_INFO, "read last_rcvd header, uuid = %s, "
149                        "subdir count = %d\n", lsd.lsd_uuid,
150                        lsd.lsd_subdir_count);
151                 if (le16_to_cpu(lsd.lsd_subdir_count) > 0)
152                         count = le16_to_cpu(lsd.lsd_subdir_count);
153         } else if (rc != 0) {
154                 CERROR("Can't read last_rcvd file, rc = %d\n", rc);
155                 if (rc > 0)
156                         rc = -EFAULT;
157                 dput(dlast);
158                 return rc;
159         }
160 out:
161         dput(dlast);
162         LASSERT(count > 0);
163         return count;
164 }
165
166 static const char remote_parent_dir[] = "REMOTE_PARENT_DIR";
167 static int osd_mdt_init(const struct lu_env *env, struct osd_device *dev)
168 {
169         struct lvfs_run_ctxt    new;
170         struct lvfs_run_ctxt    save;
171         struct dentry           *parent;
172         struct osd_mdobj_map    *omm;
173         struct dentry           *d;
174         struct osd_thread_info  *info = osd_oti_get(env);
175         struct lu_fid           *fid = &info->oti_fid3;
176         int                     rc = 0;
177         ENTRY;
178
179         OBD_ALLOC_PTR(dev->od_mdt_map);
180         if (dev->od_mdt_map == NULL)
181                 RETURN(-ENOMEM);
182
183         omm = dev->od_mdt_map;
184
185         parent = osd_sb(dev)->s_root;
186         osd_push_ctxt(dev, &new, &save);
187
188         d = simple_mkdir(parent, dev->od_mnt, remote_parent_dir,
189                          0755, 1);
190         if (IS_ERR(d))
191                 GOTO(cleanup, rc = PTR_ERR(d));
192
193         ldiskfs_set_inode_state(d->d_inode, LDISKFS_STATE_LUSTRE_NO_OI);
194         omm->omm_remote_parent = d;
195
196         /* Set LMA for remote parent inode */
197         lu_local_obj_fid(fid, REMOTE_PARENT_DIR_OID);
198         rc = osd_ea_fid_set(info, d->d_inode, fid, LMAC_NOT_IN_OI, 0);
199
200         GOTO(cleanup, rc);
201
202 cleanup:
203         pop_ctxt(&save, &new, NULL);
204         if (rc) {
205                 if (omm->omm_remote_parent != NULL)
206                         dput(omm->omm_remote_parent);
207                 OBD_FREE_PTR(omm);
208                 dev->od_mdt_map = NULL;
209         }
210         return rc;
211 }
212
213 static void osd_mdt_fini(struct osd_device *osd)
214 {
215         struct osd_mdobj_map *omm = osd->od_mdt_map;
216
217         if (omm == NULL)
218                 return;
219
220         if (omm->omm_remote_parent)
221                 dput(omm->omm_remote_parent);
222
223         OBD_FREE_PTR(omm);
224         osd->od_ost_map = NULL;
225 }
226
227 int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
228                              struct osd_object *obj, struct osd_thandle *oh)
229 {
230         struct osd_mdobj_map    *omm = osd->od_mdt_map;
231         struct osd_thread_info  *oti = osd_oti_get(env);
232         struct lustre_mdt_attrs *lma = &oti->oti_mdt_attrs;
233         char                    *name = oti->oti_name;
234         struct dentry           *dentry;
235         struct dentry           *parent;
236         int                     rc;
237
238         /* Set REMOTE_PARENT in lma, so other process like unlink or lfsck
239          * can identify this object quickly */
240         rc = osd_get_lma(oti, obj->oo_inode, &oti->oti_obj_dentry, lma);
241         if (rc != 0)
242                 RETURN(rc);
243
244         lma->lma_incompat |= LMAI_REMOTE_PARENT;
245         lustre_lma_swab(lma);
246         rc = __osd_xattr_set(oti, obj->oo_inode, XATTR_NAME_LMA, lma,
247                              sizeof(*lma), XATTR_REPLACE);
248         if (rc != 0)
249                 RETURN(rc);
250
251         parent = omm->omm_remote_parent;
252         sprintf(name, DFID_NOBRACE, PFID(lu_object_fid(&obj->oo_dt.do_lu)));
253         dentry = osd_child_dentry_by_inode(env, parent->d_inode,
254                                            name, strlen(name));
255         mutex_lock(&parent->d_inode->i_mutex);
256         rc = osd_ldiskfs_add_entry(oh->ot_handle, dentry, obj->oo_inode,
257                                    NULL);
258         CDEBUG(D_INODE, "%s: add %s:%lu to remote parent %lu.\n", osd_name(osd),
259                name, obj->oo_inode->i_ino, parent->d_inode->i_ino);
260         ldiskfs_inc_count(oh->ot_handle, parent->d_inode);
261         mark_inode_dirty(parent->d_inode);
262         mutex_unlock(&parent->d_inode->i_mutex);
263         RETURN(rc);
264 }
265
266 int osd_delete_from_remote_parent(const struct lu_env *env,
267                                   struct osd_device *osd,
268                                   struct osd_object *obj,
269                                   struct osd_thandle *oh)
270 {
271         struct osd_mdobj_map       *omm = osd->od_mdt_map;
272         struct osd_thread_info     *oti = osd_oti_get(env);
273         struct lustre_mdt_attrs    *lma = &oti->oti_mdt_attrs;
274         char                       *name = oti->oti_name;
275         struct dentry              *dentry;
276         struct dentry              *parent;
277         struct ldiskfs_dir_entry_2 *de;
278         struct buffer_head         *bh;
279         int                        rc;
280
281         /* Check lma to see whether it is remote object */
282         rc = osd_get_lma(oti, obj->oo_inode, &oti->oti_obj_dentry, lma);
283         if (rc != 0)
284                 RETURN(rc);
285
286         if (likely(!(lma->lma_incompat & LMAI_REMOTE_PARENT)))
287                 RETURN(0);
288
289         parent = omm->omm_remote_parent;
290         sprintf(name, DFID_NOBRACE, PFID(lu_object_fid(&obj->oo_dt.do_lu)));
291         dentry = osd_child_dentry_by_inode(env, parent->d_inode,
292                                            name, strlen(name));
293         mutex_lock(&parent->d_inode->i_mutex);
294         bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de,
295                                     NULL, NULL);
296         if (bh == NULL) {
297                 mutex_unlock(&parent->d_inode->i_mutex);
298                 RETURN(-ENOENT);
299         }
300         CDEBUG(D_INODE, "%s: el %s:%lu to remote parent %lu.\n", osd_name(osd),
301                name, obj->oo_inode->i_ino, parent->d_inode->i_ino);
302         rc = ldiskfs_delete_entry(oh->ot_handle, parent->d_inode, de, bh);
303         ldiskfs_dec_count(oh->ot_handle, parent->d_inode);
304         mark_inode_dirty(parent->d_inode);
305         mutex_unlock(&parent->d_inode->i_mutex);
306         brelse(bh);
307
308         /* Get rid of REMOTE_PARENT flag from incompat */
309         lma->lma_incompat &= ~LMAI_REMOTE_PARENT;
310         lustre_lma_swab(lma);
311         rc = __osd_xattr_set(oti, obj->oo_inode, XATTR_NAME_LMA, lma,
312                              sizeof(*lma), XATTR_REPLACE);
313         RETURN(rc);
314 }
315
316 int osd_lookup_in_remote_parent(struct osd_thread_info *oti,
317                                 struct osd_device *osd,
318                                 const struct lu_fid *fid,
319                                 struct osd_inode_id *id)
320 {
321         struct osd_mdobj_map        *omm = osd->od_mdt_map;
322         char                        *name = oti->oti_name;
323         struct dentry               *parent;
324         struct dentry               *dentry;
325         struct ldiskfs_dir_entry_2 *de;
326         struct buffer_head         *bh;
327         int                         rc;
328         ENTRY;
329
330         parent = omm->omm_remote_parent;
331         sprintf(name, DFID_NOBRACE, PFID(fid));
332         dentry = osd_child_dentry_by_inode(oti->oti_env, parent->d_inode,
333                                            name, strlen(name));
334         mutex_lock(&parent->d_inode->i_mutex);
335         bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de,
336                                     NULL, NULL);
337         if (bh == NULL) {
338                 rc = -ENOENT;
339         } else {
340                 rc = 0;
341                 osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
342                 brelse(bh);
343         }
344         mutex_unlock(&parent->d_inode->i_mutex);
345         if (rc == 0)
346                 osd_add_oi_cache(oti, osd, id, fid);
347         RETURN(rc);
348 }
349
350 /*
351  * directory structure on legacy OST:
352  *
353  * O/<seq>/d0-31/<objid>
354  * O/<seq>/LAST_ID
355  * last_rcvd
356  * LAST_GROUP
357  * CONFIGS
358  *
359  */
360 static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
361 {
362         struct lvfs_run_ctxt     new;
363         struct lvfs_run_ctxt     save;
364         struct dentry           *rootd = osd_sb(dev)->s_root;
365         struct dentry           *d;
366         struct osd_thread_info  *info = osd_oti_get(env);
367         struct inode            *inode;
368         struct lu_fid           *fid = &info->oti_fid3;
369         int                      rc;
370         ENTRY;
371
372         OBD_ALLOC_PTR(dev->od_ost_map);
373         if (dev->od_ost_map == NULL)
374                 RETURN(-ENOMEM);
375
376         /* to get subdir count from last_rcvd */
377         rc = osd_last_rcvd_subdir_count(dev);
378         if (rc < 0) {
379                 OBD_FREE_PTR(dev->od_ost_map);
380                 RETURN(rc);
381         }
382
383         dev->od_ost_map->om_subdir_count = rc;
384         rc = 0;
385
386         CFS_INIT_LIST_HEAD(&dev->od_ost_map->om_seq_list);
387         rwlock_init(&dev->od_ost_map->om_seq_list_lock);
388         sema_init(&dev->od_ost_map->om_dir_init_sem, 1);
389
390         osd_push_ctxt(dev, &new, &save);
391
392         d = ll_lookup_one_len("O", rootd, strlen("O"));
393         if (IS_ERR(d))
394                 GOTO(cleanup, rc = PTR_ERR(d));
395         if (d->d_inode == NULL) {
396                 dput(d);
397                 /* The lookup() may be called again inside simple_mkdir().
398                  * Since the repeated lookup() only be called for "/O" at
399                  * mount time, it will not affect the whole performance. */
400                 d = simple_mkdir(rootd, dev->od_mnt, "O", 0755, 1);
401                 if (IS_ERR(d))
402                         GOTO(cleanup, rc = PTR_ERR(d));
403
404                 /* It is quite probably that the device is new formatted. */
405                 dev->od_maybe_new = 1;
406         }
407
408         inode = d->d_inode;
409         ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
410         dev->od_ost_map->om_root = d;
411
412         /* 'What the @fid is' is not imporatant, because the object
413          * has no OI mapping, and only is visible inside the OSD.*/
414         lu_igif_build(fid, inode->i_ino, inode->i_generation);
415         rc = osd_ea_fid_set(info, inode, fid,
416                             LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
417
418         GOTO(cleanup, rc);
419
420 cleanup:
421         osd_pop_ctxt(dev, &new, &save);
422         if (IS_ERR(d)) {
423                 OBD_FREE_PTR(dev->od_ost_map);
424                 RETURN(PTR_ERR(d));
425         }
426         return rc;
427 }
428
429 static void osd_seq_free(struct osd_obj_map *map,
430                          struct osd_obj_seq *osd_seq)
431 {
432         int j;
433
434         cfs_list_del_init(&osd_seq->oos_seq_list);
435
436         if (osd_seq->oos_dirs) {
437                 for (j = 0; j < osd_seq->oos_subdir_count; j++) {
438                         if (osd_seq->oos_dirs[j])
439                                 dput(osd_seq->oos_dirs[j]);
440                 }
441                 OBD_FREE(osd_seq->oos_dirs,
442                          sizeof(struct dentry *) * osd_seq->oos_subdir_count);
443         }
444
445         if (osd_seq->oos_root)
446                 dput(osd_seq->oos_root);
447
448         OBD_FREE_PTR(osd_seq);
449 }
450
451 static void osd_ost_fini(struct osd_device *osd)
452 {
453         struct osd_obj_seq    *osd_seq;
454         struct osd_obj_seq    *tmp;
455         struct osd_obj_map    *map = osd->od_ost_map;
456         ENTRY;
457
458         if (map == NULL)
459                 return;
460
461         write_lock(&map->om_seq_list_lock);
462         cfs_list_for_each_entry_safe(osd_seq, tmp,
463                                      &map->om_seq_list,
464                                      oos_seq_list) {
465                 osd_seq_free(map, osd_seq);
466         }
467         write_unlock(&map->om_seq_list_lock);
468         if (map->om_root)
469                 dput(map->om_root);
470         OBD_FREE_PTR(map);
471         osd->od_ost_map = NULL;
472         EXIT;
473 }
474
475 int osd_obj_map_init(const struct lu_env *env, struct osd_device *dev)
476 {
477         int rc;
478         ENTRY;
479
480         /* prepare structures for OST */
481         rc = osd_ost_init(env, dev);
482         if (rc)
483                 RETURN(rc);
484
485         /* prepare structures for MDS */
486         rc = osd_mdt_init(env, dev);
487
488         RETURN(rc);
489 }
490
491 struct osd_obj_seq *osd_seq_find_locked(struct osd_obj_map *map, obd_seq seq)
492 {
493         struct osd_obj_seq *osd_seq;
494
495         cfs_list_for_each_entry(osd_seq, &map->om_seq_list, oos_seq_list) {
496                 if (osd_seq->oos_seq == seq)
497                         return osd_seq;
498         }
499         return NULL;
500 }
501
502 struct osd_obj_seq *osd_seq_find(struct osd_obj_map *map, obd_seq seq)
503 {
504         struct osd_obj_seq *osd_seq;
505
506         read_lock(&map->om_seq_list_lock);
507         osd_seq = osd_seq_find_locked(map, seq);
508         read_unlock(&map->om_seq_list_lock);
509         return osd_seq;
510 }
511
512 void osd_obj_map_fini(struct osd_device *dev)
513 {
514         osd_ost_fini(dev);
515         osd_mdt_fini(dev);
516 }
517
518 /**
519  * Update the specified OI mapping.
520  *
521  * \retval   1, changed nothing
522  * \retval   0, changed successfully
523  * \retval -ve, on error
524  */
525 static int osd_obj_update_entry(struct osd_thread_info *info,
526                                 struct osd_device *osd,
527                                 struct dentry *dir, const char *name,
528                                 const struct lu_fid *fid,
529                                 const struct osd_inode_id *id,
530                                 struct thandle *th)
531 {
532         struct inode               *parent = dir->d_inode;
533         struct osd_thandle         *oh;
534         struct dentry              *child;
535         struct ldiskfs_dir_entry_2 *de;
536         struct buffer_head         *bh;
537         struct inode               *inode;
538         struct dentry              *dentry = &info->oti_obj_dentry;
539         struct osd_inode_id        *oi_id  = &info->oti_id3;
540         struct lustre_mdt_attrs    *lma    = &info->oti_mdt_attrs;
541         struct lu_fid              *oi_fid = &lma->lma_self_fid;
542         int                         rc;
543         ENTRY;
544
545         oh = container_of(th, struct osd_thandle, ot_super);
546         LASSERT(oh->ot_handle != NULL);
547         LASSERT(oh->ot_handle->h_transaction != NULL);
548
549         child = &info->oti_child_dentry;
550         child->d_parent = dir;
551         child->d_name.hash = 0;
552         child->d_name.name = name;
553         child->d_name.len = strlen(name);
554
555         ll_vfs_dq_init(parent);
556         mutex_lock(&parent->i_mutex);
557         bh = osd_ldiskfs_find_entry(parent, &child->d_name, &de, NULL, NULL);
558         if (bh == NULL)
559                 GOTO(out, rc = -ENOENT);
560
561         if (le32_to_cpu(de->inode) == id->oii_ino)
562                 GOTO(out, rc = 1);
563
564         osd_id_gen(oi_id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
565         inode = osd_iget(info, osd, oi_id);
566         if (IS_ERR(inode)) {
567                 rc = PTR_ERR(inode);
568                 if (rc == -ENOENT || rc == -ESTALE)
569                         goto update;
570                 GOTO(out, rc);
571         }
572
573         rc = osd_get_lma(info, inode, dentry, lma);
574         if (rc == -ENODATA) {
575                 rc = osd_get_idif(info, inode, dentry, oi_fid);
576                 if (rc > 0) {
577                         oi_fid = NULL;
578                         rc = 0;
579                 }
580         }
581         iput(inode);
582
583         /* If the OST-object has neither FID-in-LMA nor FID-in-ff, it is
584          * either a crashed object or a uninitialized one. Replace it. */
585         if (rc == -ENODATA || oi_fid == NULL)
586                 goto update;
587
588         if (rc != 0)
589                 GOTO(out, rc);
590
591         if (lu_fid_eq(fid, oi_fid)) {
592                 CERROR("%s: the FID "DFID" is used by two objects: "
593                        "%u/%u %u/%u\n", osd_name(osd), PFID(fid),
594                        oi_id->oii_ino, oi_id->oii_gen,
595                        id->oii_ino, id->oii_gen);
596                 GOTO(out, rc = -EEXIST);
597         }
598
599 update:
600         /* There may be temporary inconsistency: On one hand, the new
601          * object may be referenced by multiple entries, which is out
602          * of our control unless we traverse the whole /O completely,
603          * which is non-flat order and inefficient, should be avoided;
604          * On the other hand, the old object may become orphan if it
605          * is still valid. Since it was referenced by an invalid entry,
606          * making it as invisible temporary may be not worse. OI scrub
607          * will process it later. */
608         rc = ldiskfs_journal_get_write_access(oh->ot_handle, bh);
609         if (rc != 0)
610                 GOTO(out, rc);
611
612         de->inode = cpu_to_le32(id->oii_ino);
613         rc = ldiskfs_journal_dirty_metadata(oh->ot_handle, bh);
614
615         GOTO(out, rc);
616
617 out:
618         brelse(bh);
619         mutex_unlock(&parent->i_mutex);
620         return rc;
621 }
622
623 static int osd_obj_del_entry(struct osd_thread_info *info,
624                              struct osd_device *osd,
625                              struct dentry *dird, char *name,
626                              struct thandle *th)
627 {
628         struct ldiskfs_dir_entry_2 *de;
629         struct buffer_head         *bh;
630         struct osd_thandle         *oh;
631         struct dentry              *child;
632         struct inode               *dir = dird->d_inode;
633         int                         rc;
634         ENTRY;
635
636         oh = container_of(th, struct osd_thandle, ot_super);
637         LASSERT(oh->ot_handle != NULL);
638         LASSERT(oh->ot_handle->h_transaction != NULL);
639
640
641         child = &info->oti_child_dentry;
642         child->d_name.hash = 0;
643         child->d_name.name = name;
644         child->d_name.len = strlen(name);
645         child->d_parent = dird;
646         child->d_inode = NULL;
647
648         ll_vfs_dq_init(dir);
649         mutex_lock(&dir->i_mutex);
650         rc = -ENOENT;
651         bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
652         if (bh) {
653                 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
654                 brelse(bh);
655         }
656         mutex_unlock(&dir->i_mutex);
657
658         RETURN(rc);
659 }
660
661 int osd_obj_add_entry(struct osd_thread_info *info,
662                       struct osd_device *osd,
663                       struct dentry *dir, char *name,
664                       const struct osd_inode_id *id,
665                       struct thandle *th)
666 {
667         struct osd_thandle *oh;
668         struct dentry *child;
669         struct inode *inode;
670         int rc;
671
672         ENTRY;
673
674         if (OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_NO_ENTRY))
675                 RETURN(0);
676
677         oh = container_of(th, struct osd_thandle, ot_super);
678         LASSERT(oh->ot_handle != NULL);
679         LASSERT(oh->ot_handle->h_transaction != NULL);
680
681         inode = &info->oti_inode;
682         inode->i_sb = osd_sb(osd);
683         osd_id_to_inode(inode, id);
684         inode->i_mode = S_IFREG; /* for type in ldiskfs dir entry */
685
686         child = &info->oti_child_dentry;
687         child->d_name.hash = 0;
688         child->d_name.name = name;
689         child->d_name.len = strlen(name);
690         child->d_parent = dir;
691         child->d_inode = inode;
692
693         if (OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_INVALID_ENTRY))
694                 inode->i_ino++;
695
696         ll_vfs_dq_init(dir->d_inode);
697         mutex_lock(&dir->d_inode->i_mutex);
698         rc = osd_ldiskfs_add_entry(oh->ot_handle, child, inode, NULL);
699         mutex_unlock(&dir->d_inode->i_mutex);
700
701         RETURN(rc);
702 }
703
704 /**
705  * Use LPU64 for legacy OST sequences, but use LPX64i for new
706  * sequences names, so that the O/{seq}/dN/{oid} more closely
707  * follows the DFID/PFID format. This makes it easier to map from
708  * debug messages to objects in the future, and the legacy space
709  * of FID_SEQ_OST_MDT0 will be unused in the future.
710  **/
711 static inline void osd_seq_name(char *seq_name, size_t name_size, obd_seq seq)
712 {
713         snprintf(seq_name, name_size,
714                  (fid_seq_is_rsvd(seq) ||
715                   fid_seq_is_mdt0(seq)) ? LPU64 : LPX64i,
716                  fid_seq_is_idif(seq) ? 0 : seq);
717 }
718
719 static inline void osd_oid_name(char *name, size_t name_size,
720                                 const struct lu_fid *fid, obd_id id)
721 {
722         snprintf(name, name_size,
723                  (fid_seq_is_rsvd(fid_seq(fid)) ||
724                   fid_seq_is_mdt0(fid_seq(fid)) ||
725                   fid_seq_is_idif(fid_seq(fid))) ? LPU64 : LPX64i, id);
726 }
727
728 /* external locking is required */
729 static int osd_seq_load_locked(struct osd_thread_info *info,
730                                struct osd_device *osd,
731                                struct osd_obj_seq *osd_seq)
732 {
733         struct osd_obj_map  *map = osd->od_ost_map;
734         struct dentry       *seq_dir;
735         struct inode        *inode;
736         struct lu_fid       *fid = &info->oti_fid3;
737         int                 rc = 0;
738         int                 i;
739         char                dir_name[32];
740         ENTRY;
741
742         if (osd_seq->oos_root != NULL)
743                 RETURN(0);
744
745         LASSERT(map);
746         LASSERT(map->om_root);
747
748         osd_seq_name(dir_name, sizeof(dir_name), osd_seq->oos_seq);
749
750         seq_dir = simple_mkdir(map->om_root, osd->od_mnt, dir_name, 0755, 1);
751         if (IS_ERR(seq_dir))
752                 GOTO(out_err, rc = PTR_ERR(seq_dir));
753         else if (seq_dir->d_inode == NULL)
754                 GOTO(out_put, rc = -EFAULT);
755
756         inode = seq_dir->d_inode;
757         ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
758         osd_seq->oos_root = seq_dir;
759
760         /* 'What the @fid is' is not imporatant, because the object
761          * has no OI mapping, and only is visible inside the OSD.*/
762         lu_igif_build(fid, inode->i_ino, inode->i_generation);
763         rc = osd_ea_fid_set(info, inode, fid,
764                             LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
765         if (rc != 0)
766                 GOTO(out_put, rc);
767
768         LASSERT(osd_seq->oos_dirs == NULL);
769         OBD_ALLOC(osd_seq->oos_dirs,
770                   sizeof(seq_dir) * osd_seq->oos_subdir_count);
771         if (osd_seq->oos_dirs == NULL)
772                 GOTO(out_put, rc = -ENOMEM);
773
774         for (i = 0; i < osd_seq->oos_subdir_count; i++) {
775                 struct dentry   *dir;
776
777                 snprintf(dir_name, sizeof(dir_name), "d%u", i);
778                 dir = simple_mkdir(osd_seq->oos_root, osd->od_mnt, dir_name,
779                                    0700, 1);
780                 if (IS_ERR(dir)) {
781                         GOTO(out_free, rc = PTR_ERR(dir));
782                 } else if (dir->d_inode == NULL) {
783                         dput(dir);
784                         GOTO(out_free, rc = -EFAULT);
785                 }
786
787                 inode = dir->d_inode;
788                 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
789                 osd_seq->oos_dirs[i] = dir;
790
791                 /* 'What the @fid is' is not imporatant, because the object
792                  * has no OI mapping, and only is visible inside the OSD.*/
793                 lu_igif_build(fid, inode->i_ino, inode->i_generation);
794                 rc = osd_ea_fid_set(info, inode, fid,
795                                     LMAC_NOT_IN_OI | LMAC_FID_ON_OST, 0);
796                 if (rc != 0)
797                         GOTO(out_free, rc);
798         }
799
800         if (rc != 0) {
801 out_free:
802                 for (i = 0; i < osd_seq->oos_subdir_count; i++) {
803                         if (osd_seq->oos_dirs[i] != NULL)
804                                 dput(osd_seq->oos_dirs[i]);
805                 }
806                 OBD_FREE(osd_seq->oos_dirs,
807                          sizeof(seq_dir) * osd_seq->oos_subdir_count);
808 out_put:
809                 dput(seq_dir);
810                 osd_seq->oos_root = NULL;
811         }
812 out_err:
813         RETURN(rc);
814 }
815
816 static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
817                                         struct osd_device *osd, obd_seq seq)
818 {
819         struct osd_obj_map      *map;
820         struct osd_obj_seq      *osd_seq;
821         int                     rc = 0;
822         ENTRY;
823
824         map = osd->od_ost_map;
825         LASSERT(map);
826         LASSERT(map->om_root);
827
828         osd_seq = osd_seq_find(map, seq);
829         if (likely(osd_seq != NULL))
830                 RETURN(osd_seq);
831
832         /* Serializing init process */
833         down(&map->om_dir_init_sem);
834
835         /* Check whether the seq has been added */
836         read_lock(&map->om_seq_list_lock);
837         osd_seq = osd_seq_find_locked(map, seq);
838         if (osd_seq != NULL) {
839                 read_unlock(&map->om_seq_list_lock);
840                 GOTO(cleanup, rc = 0);
841         }
842         read_unlock(&map->om_seq_list_lock);
843
844         OBD_ALLOC_PTR(osd_seq);
845         if (osd_seq == NULL)
846                 GOTO(cleanup, rc = -ENOMEM);
847
848         CFS_INIT_LIST_HEAD(&osd_seq->oos_seq_list);
849         osd_seq->oos_seq = seq;
850         /* Init subdir count to be 32, but each seq can have
851          * different subdir count */
852         osd_seq->oos_subdir_count = map->om_subdir_count;
853         rc = osd_seq_load_locked(info, osd, osd_seq);
854         if (rc != 0)
855                 GOTO(cleanup, rc);
856
857         write_lock(&map->om_seq_list_lock);
858         cfs_list_add(&osd_seq->oos_seq_list, &map->om_seq_list);
859         write_unlock(&map->om_seq_list_lock);
860
861 cleanup:
862         up(&map->om_dir_init_sem);
863         if (rc != 0) {
864                 if (osd_seq != NULL)
865                         OBD_FREE_PTR(osd_seq);
866                 RETURN(ERR_PTR(rc));
867         }
868
869         RETURN(osd_seq);
870 }
871
872 int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev,
873                        const struct lu_fid *fid, struct osd_inode_id *id)
874 {
875         struct osd_obj_map              *map;
876         struct osd_obj_seq              *osd_seq;
877         struct dentry                   *d_seq;
878         struct dentry                   *child;
879         struct ost_id                   *ostid = &info->oti_ostid;
880         int                             dirn;
881         char                            name[32];
882         struct ldiskfs_dir_entry_2      *de;
883         struct buffer_head              *bh;
884         struct inode                    *dir;
885         struct inode                    *inode;
886         ENTRY;
887
888         /* on the very first lookup we find and open directories */
889
890         map = dev->od_ost_map;
891         LASSERT(map);
892         LASSERT(map->om_root);
893
894         fid_to_ostid(fid, ostid);
895         osd_seq = osd_seq_load(info, dev, ostid_seq(ostid));
896         if (IS_ERR(osd_seq))
897                 RETURN(PTR_ERR(osd_seq));
898
899         dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
900         d_seq = osd_seq->oos_dirs[dirn];
901         LASSERT(d_seq);
902
903         osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
904
905         child = &info->oti_child_dentry;
906         child->d_parent = d_seq;
907         child->d_name.hash = 0;
908         child->d_name.name = name;
909         /* XXX: we can use rc from sprintf() instead of strlen() */
910         child->d_name.len = strlen(name);
911
912         dir = d_seq->d_inode;
913         mutex_lock(&dir->i_mutex);
914         bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
915         mutex_unlock(&dir->i_mutex);
916
917         if (bh == NULL)
918                 RETURN(-ENOENT);
919
920         osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
921         brelse(bh);
922
923         inode = osd_iget(info, dev, id);
924         if (IS_ERR(inode))
925                 RETURN(PTR_ERR(inode));
926
927         iput(inode);
928         RETURN(0);
929 }
930
931 int osd_obj_map_insert(struct osd_thread_info *info,
932                        struct osd_device *osd,
933                        const struct lu_fid *fid,
934                        const struct osd_inode_id *id,
935                        struct thandle *th)
936 {
937         struct osd_obj_map      *map;
938         struct osd_obj_seq      *osd_seq;
939         struct dentry           *d;
940         struct ost_id           *ostid = &info->oti_ostid;
941         obd_id                   oid;
942         int                     dirn, rc = 0;
943         char                    name[32];
944         ENTRY;
945
946         map = osd->od_ost_map;
947         LASSERT(map);
948
949         /* map fid to seq:objid */
950         fid_to_ostid(fid, ostid);
951
952         oid = ostid_id(ostid);
953         osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
954         if (IS_ERR(osd_seq))
955                 RETURN(PTR_ERR(osd_seq));
956
957         dirn = oid & (osd_seq->oos_subdir_count - 1);
958         d = osd_seq->oos_dirs[dirn];
959         LASSERT(d);
960
961         osd_oid_name(name, sizeof(name), fid, oid);
962
963 again:
964         rc = osd_obj_add_entry(info, osd, d, name, id, th);
965         if (rc == -EEXIST) {
966                 rc = osd_obj_update_entry(info, osd, d, name, fid, id, th);
967                 if (unlikely(rc == -ENOENT))
968                         goto again;
969
970                 if (unlikely(rc == 1))
971                         RETURN(0);
972         }
973
974         RETURN(rc);
975 }
976
977 int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd,
978                        const struct lu_fid *fid, struct thandle *th)
979 {
980         struct osd_obj_map      *map;
981         struct osd_obj_seq      *osd_seq;
982         struct dentry           *d;
983         struct ost_id           *ostid = &info->oti_ostid;
984         int                     dirn, rc = 0;
985         char                    name[32];
986         ENTRY;
987
988         map = osd->od_ost_map;
989         LASSERT(map);
990
991         /* map fid to seq:objid */
992         fid_to_ostid(fid, ostid);
993
994         osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
995         if (IS_ERR(osd_seq))
996                 GOTO(cleanup, rc = PTR_ERR(osd_seq));
997
998         dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
999         d = osd_seq->oos_dirs[dirn];
1000         LASSERT(d);
1001
1002         osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
1003         rc = osd_obj_del_entry(info, osd, d, name, th);
1004 cleanup:
1005         RETURN(rc);
1006 }
1007
1008 int osd_obj_map_update(struct osd_thread_info *info,
1009                        struct osd_device *osd,
1010                        const struct lu_fid *fid,
1011                        const struct osd_inode_id *id,
1012                        struct thandle *th)
1013 {
1014         struct osd_obj_seq      *osd_seq;
1015         struct dentry           *d;
1016         struct ost_id           *ostid = &info->oti_ostid;
1017         int                     dirn, rc = 0;
1018         char                    name[32];
1019         ENTRY;
1020
1021         fid_to_ostid(fid, ostid);
1022         osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
1023         if (IS_ERR(osd_seq))
1024                 RETURN(PTR_ERR(osd_seq));
1025
1026         dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
1027         d = osd_seq->oos_dirs[dirn];
1028         LASSERT(d);
1029
1030         osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
1031         rc = osd_obj_update_entry(info, osd, d, name, fid, id, th);
1032
1033         RETURN(rc);
1034 }
1035
1036 int osd_obj_map_recover(struct osd_thread_info *info,
1037                         struct osd_device *osd,
1038                         struct inode *src_parent,
1039                         struct dentry *src_child,
1040                         const struct lu_fid *fid)
1041 {
1042         struct osd_obj_seq         *osd_seq;
1043         struct dentry              *tgt_parent;
1044         struct dentry              *tgt_child = &info->oti_child_dentry;
1045         struct inode               *dir;
1046         struct inode               *inode     = src_child->d_inode;
1047         struct ost_id              *ostid     = &info->oti_ostid;
1048         handle_t                   *jh;
1049         struct ldiskfs_dir_entry_2 *de;
1050         struct buffer_head         *bh;
1051         char                        name[32];
1052         int                         dirn;
1053         int                         rc        = 0;
1054         ENTRY;
1055
1056         if (fid_is_last_id(fid)) {
1057                 osd_seq = osd_seq_load(info, osd, fid_seq(fid));
1058                 if (IS_ERR(osd_seq))
1059                         RETURN(PTR_ERR(osd_seq));
1060
1061                 tgt_parent = osd_seq->oos_root;
1062                 tgt_child->d_name.name = "LAST_ID";
1063                 tgt_child->d_name.len = strlen("LAST_ID");
1064         } else {
1065                 fid_to_ostid(fid, ostid);
1066                 osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
1067                 if (IS_ERR(osd_seq))
1068                         RETURN(PTR_ERR(osd_seq));
1069
1070                 dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
1071                 tgt_parent = osd_seq->oos_dirs[dirn];
1072                 osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
1073                 tgt_child->d_name.name = name;
1074                 tgt_child->d_name.len = strlen(name);
1075         }
1076         LASSERT(tgt_parent != NULL);
1077
1078         dir = tgt_parent->d_inode;
1079         tgt_child->d_name.hash = 0;
1080         tgt_child->d_parent = tgt_parent;
1081         tgt_child->d_inode = inode;
1082
1083         /* The non-initialized src_child may be destroyed. */
1084         jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
1085                                 osd_dto_credits_noquota[DTO_INDEX_DELETE] +
1086                                 osd_dto_credits_noquota[DTO_INDEX_INSERT] +
1087                                 osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
1088         if (IS_ERR(jh))
1089                 RETURN(PTR_ERR(jh));
1090
1091         ll_vfs_dq_init(src_parent);
1092         ll_vfs_dq_init(dir);
1093
1094         mutex_lock(&src_parent->i_mutex);
1095         mutex_lock(&dir->i_mutex);
1096         bh = osd_ldiskfs_find_entry(dir, &tgt_child->d_name, &de, NULL, NULL);
1097         if (bh != NULL) {
1098                 /* XXX: If some other object occupied the same slot. And If such
1099                  *      inode is zero-sized and with SUID+SGID, then means it is
1100                  *      a new created one. Maybe we can remove it and insert the
1101                  *      original one back to the /O/<seq>/d<x>. But there are
1102                  *      something to be considered:
1103                  *
1104                  *      1) The OST-object under /lost+found has crashed LMA.
1105                  *         So it should not conflict with the current one.
1106                  *
1107                  *      2) There are race conditions that: someone may just want
1108                  *         to modify the current one. Even if the OI scrub takes
1109                  *         the object lock when remove the current one, it still
1110                  *         cause the modification to be lost becasue the target
1111                  *         has been removed when the RPC service thread waiting
1112                  *         for the lock.
1113                  *
1114                  *      So keep it there before we have suitable solution. */
1115                 brelse(bh);
1116                 mutex_unlock(&dir->i_mutex);
1117
1118                 rc = -EEXIST;
1119                 /* If the src object has never been modified, then remove it. */
1120                 if (inode->i_size == 0 && inode->i_mode & S_ISUID &&
1121                     inode->i_mode & S_ISGID) {
1122                         bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name,
1123                                                     &de, NULL, NULL);
1124                         if (unlikely(bh == NULL)) {
1125                                 mutex_unlock(&src_parent->i_mutex);
1126                                 ldiskfs_journal_stop(jh);
1127                                 RETURN(0);
1128                         }
1129
1130                         rc = ldiskfs_delete_entry(jh, src_parent, de, bh);
1131                         brelse(bh);
1132                         if (rc == 0) {
1133                                 drop_nlink(inode);
1134                                 ll_dirty_inode(inode, I_DIRTY_DATASYNC);
1135                         }
1136                 }
1137                 mutex_unlock(&src_parent->i_mutex);
1138                 ldiskfs_journal_stop(jh);
1139                 RETURN(rc);
1140         }
1141
1142         bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name, &de,
1143                                     NULL, NULL);
1144         if (unlikely(bh == NULL))
1145                 GOTO(unlock, rc = -ENOENT);
1146
1147         rc = ldiskfs_delete_entry(jh, src_parent, de, bh);
1148         brelse(bh);
1149         if (rc != 0)
1150                 GOTO(unlock, rc);
1151
1152         rc = osd_ldiskfs_add_entry(jh, tgt_child, inode, NULL);
1153
1154         GOTO(unlock, rc);
1155
1156 unlock:
1157         mutex_unlock(&dir->i_mutex);
1158         mutex_unlock(&src_parent->i_mutex);
1159         ldiskfs_journal_stop(jh);
1160         return rc;
1161 }
1162
1163 static struct dentry *
1164 osd_object_spec_find(struct osd_thread_info *info, struct osd_device *osd,
1165                      const struct lu_fid *fid, char **name)
1166 {
1167         struct dentry *root = ERR_PTR(-ENOENT);
1168
1169         if (fid_is_last_id(fid)) {
1170                 struct osd_obj_seq *osd_seq;
1171
1172                 /* on creation of LAST_ID we create O/<seq> hierarchy */
1173                 osd_seq = osd_seq_load(info, osd, fid_seq(fid));
1174                 if (IS_ERR(osd_seq))
1175                         RETURN((struct dentry *)osd_seq);
1176
1177                 *name = "LAST_ID";
1178                 root = osd_seq->oos_root;
1179         } else {
1180                 *name = osd_lf_fid2name(fid);
1181                 if (*name == NULL)
1182                         CWARN("UNKNOWN COMPAT FID "DFID"\n", PFID(fid));
1183                 else if ((*name)[0])
1184                         root = osd_sb(osd)->s_root;
1185         }
1186
1187         return root;
1188 }
1189
1190 int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
1191                         const struct lu_fid *fid, const struct osd_inode_id *id,
1192                         struct thandle *th)
1193 {
1194         struct dentry   *root;
1195         char            *name;
1196         int              rc;
1197         ENTRY;
1198
1199         root = osd_object_spec_find(info, osd, fid, &name);
1200         if (!IS_ERR(root)) {
1201                 rc = osd_obj_update_entry(info, osd, root, name, fid, id, th);
1202         } else {
1203                 rc = PTR_ERR(root);
1204                 if (rc == -ENOENT)
1205                         rc = 1;
1206         }
1207
1208         RETURN(rc);
1209 }
1210
1211 int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
1212                         const struct lu_fid *fid, const struct osd_inode_id *id,
1213                         struct thandle *th)
1214 {
1215         struct dentry   *root;
1216         char            *name;
1217         int              rc;
1218         ENTRY;
1219
1220         root = osd_object_spec_find(info, osd, fid, &name);
1221         if (!IS_ERR(root)) {
1222                 rc = osd_obj_add_entry(info, osd, root, name, id, th);
1223         } else {
1224                 rc = PTR_ERR(root);
1225                 if (rc == -ENOENT)
1226                         rc = 0;
1227         }
1228
1229         RETURN(rc);
1230 }
1231
1232 int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
1233                         const struct lu_fid *fid, struct osd_inode_id *id)
1234 {
1235         struct dentry   *root;
1236         struct dentry   *dentry;
1237         struct inode    *inode;
1238         char            *name;
1239         int             rc = -ENOENT;
1240         ENTRY;
1241
1242         if (fid_is_last_id(fid)) {
1243                 struct osd_obj_seq *osd_seq;
1244
1245                 osd_seq = osd_seq_load(info, osd, fid_seq(fid));
1246                 if (IS_ERR(osd_seq))
1247                         RETURN(PTR_ERR(osd_seq));
1248                 root = osd_seq->oos_root;
1249                 name = "LAST_ID";
1250         } else {
1251                 root = osd_sb(osd)->s_root;
1252                 name = osd_lf_fid2name(fid);
1253                 if (name == NULL || strlen(name) == 0)
1254                         RETURN(-ENOENT);
1255         }
1256
1257         dentry = ll_lookup_one_len(name, root, strlen(name));
1258         if (!IS_ERR(dentry)) {
1259                 inode = dentry->d_inode;
1260                 if (inode) {
1261                         if (is_bad_inode(inode)) {
1262                                 rc = -EIO;
1263                         } else {
1264                                 osd_id_gen(id, inode->i_ino,
1265                                            inode->i_generation);
1266                                 rc = 0;
1267                         }
1268                 }
1269                 /* if dentry is accessible after osd_compat_spec_insert it
1270                  * will still contain NULL inode, so don't keep it in cache */
1271                 d_invalidate(dentry);
1272                 dput(dentry);
1273         }
1274
1275         RETURN(rc);
1276 }