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