Whamcloud - gitweb
LU-1866 osd: ancillary work for initial 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, 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
50 /*
51  * struct OBD_{ALLOC,FREE}*()
52  * OBD_FAIL_CHECK
53  */
54 #include <obd_support.h>
55 #include <lvfs.h>
56
57 #include "osd_internal.h"
58 #include "osd_oi.h"
59
60 static void osd_push_ctxt(const struct osd_device *dev,
61                           struct lvfs_run_ctxt *newctxt,
62                           struct lvfs_run_ctxt *save)
63 {
64         OBD_SET_CTXT_MAGIC(newctxt);
65         newctxt->pwdmnt = dev->od_mnt;
66         newctxt->pwd = dev->od_mnt->mnt_root;
67         newctxt->fs = get_ds();
68
69         push_ctxt(save, newctxt, NULL);
70 }
71
72 static void osd_pop_ctxt(const struct osd_device *dev,
73                          struct lvfs_run_ctxt *new,
74                          struct lvfs_run_ctxt *save)
75 {
76         pop_ctxt(save, new, NULL);
77 }
78
79 int osd_last_rcvd_subdir_count(struct osd_device *osd)
80 {
81         struct lr_server_data lsd;
82         struct dentry        *dlast;
83         loff_t                off;
84         int                   rc = 0;
85         int                   count = FILTER_SUBDIR_COUNT;
86
87         ENTRY;
88
89         dlast = ll_lookup_one_len(LAST_RCVD, osd_sb(osd)->s_root,
90                                   strlen(LAST_RCVD));
91         if (IS_ERR(dlast))
92                 return PTR_ERR(dlast);
93         else if (dlast->d_inode == NULL)
94                 goto out;
95
96         off = 0;
97         rc = osd_ldiskfs_read(dlast->d_inode, &lsd, sizeof(lsd), &off);
98         if (rc == sizeof(lsd)) {
99                 CDEBUG(D_INFO, "read last_rcvd header, uuid = %s, "
100                        "subdir count = %d\n", lsd.lsd_uuid,
101                        lsd.lsd_subdir_count);
102                 if (le16_to_cpu(lsd.lsd_subdir_count) > 0)
103                         count = le16_to_cpu(lsd.lsd_subdir_count);
104         } else if (rc != 0) {
105                 CERROR("Can't read last_rcvd file, rc = %d\n", rc);
106                 if (rc > 0)
107                         rc = -EFAULT;
108                 dput(dlast);
109                 return rc;
110         }
111 out:
112         dput(dlast);
113         LASSERT(count > 0);
114         return count;
115 }
116
117 /*
118  * directory structure on legacy OST:
119  *
120  * O/<seq>/d0-31/<objid>
121  * O/<seq>/LAST_ID
122  * last_rcvd
123  * LAST_GROUP
124  * CONFIGS
125  *
126  */
127 int osd_ost_init(struct osd_device *dev)
128 {
129         struct lvfs_run_ctxt  new;
130         struct lvfs_run_ctxt  save;
131         struct dentry        *rootd = osd_sb(dev)->s_root;
132         struct dentry        *d;
133         int                   rc;
134         ENTRY;
135
136         OBD_ALLOC_PTR(dev->od_ost_map);
137         if (dev->od_ost_map == NULL)
138                 RETURN(-ENOMEM);
139
140         /* to get subdir count from last_rcvd */
141         rc = osd_last_rcvd_subdir_count(dev);
142         if (rc < 0) {
143                 OBD_FREE_PTR(dev->od_ost_map);
144                 RETURN(rc);
145         }
146
147         dev->od_ost_map->om_subdir_count = rc;
148         rc = 0;
149
150         CFS_INIT_LIST_HEAD(&dev->od_ost_map->om_seq_list);
151         rwlock_init(&dev->od_ost_map->om_seq_list_lock);
152         sema_init(&dev->od_ost_map->om_dir_init_sem, 1);
153
154         LASSERT(dev->od_fsops);
155         osd_push_ctxt(dev, &new, &save);
156
157         d = simple_mkdir(rootd, dev->od_mnt, "O", 0755, 1);
158         if (IS_ERR(d))
159                 GOTO(cleanup, rc = PTR_ERR(d));
160
161         ldiskfs_set_inode_state(d->d_inode, LDISKFS_STATE_LUSTRE_NO_OI);
162         dev->od_ost_map->om_root = d;
163
164 cleanup:
165         osd_pop_ctxt(dev, &new, &save);
166         if (IS_ERR(d)) {
167                 OBD_FREE_PTR(dev->od_ost_map);
168                 RETURN(PTR_ERR(d));
169         }
170
171         RETURN(rc);
172 }
173
174 static void osd_seq_free(struct osd_obj_map *map,
175                          struct osd_obj_seq *osd_seq)
176 {
177         int j;
178
179         cfs_list_del_init(&osd_seq->oos_seq_list);
180
181         if (osd_seq->oos_dirs) {
182                 for (j = 0; j < osd_seq->oos_subdir_count; j++) {
183                         if (osd_seq->oos_dirs[j])
184                                 dput(osd_seq->oos_dirs[j]);
185                 }
186                 OBD_FREE(osd_seq->oos_dirs,
187                          sizeof(struct dentry *) * osd_seq->oos_subdir_count);
188         }
189
190         if (osd_seq->oos_root)
191                 dput(osd_seq->oos_root);
192
193         OBD_FREE_PTR(osd_seq);
194 }
195
196 int osd_obj_map_init(struct osd_device *dev)
197 {
198         int rc;
199         ENTRY;
200
201         /* prepare structures for OST */
202         rc = osd_ost_init(dev);
203
204         /* prepare structures for MDS */
205
206         RETURN(rc);
207 }
208
209 struct osd_obj_seq *osd_seq_find_locked(struct osd_obj_map *map, obd_seq seq)
210 {
211         struct osd_obj_seq *osd_seq;
212
213         cfs_list_for_each_entry(osd_seq, &map->om_seq_list, oos_seq_list) {
214                 if (osd_seq->oos_seq == seq)
215                         return osd_seq;
216         }
217         return NULL;
218 }
219
220 struct osd_obj_seq *osd_seq_find(struct osd_obj_map *map, obd_seq seq)
221 {
222         struct osd_obj_seq *osd_seq;
223
224         read_lock(&map->om_seq_list_lock);
225         osd_seq = osd_seq_find_locked(map, seq);
226         read_unlock(&map->om_seq_list_lock);
227         return osd_seq;
228 }
229
230 void osd_obj_map_fini(struct osd_device *dev)
231 {
232         struct osd_obj_seq    *osd_seq;
233         struct osd_obj_seq    *tmp;
234         struct osd_obj_map    *map = dev->od_ost_map;
235         ENTRY;
236
237         map = dev->od_ost_map;
238         if (map == NULL)
239                 return;
240
241         write_lock(&dev->od_ost_map->om_seq_list_lock);
242         cfs_list_for_each_entry_safe(osd_seq, tmp,
243                                      &dev->od_ost_map->om_seq_list,
244                                      oos_seq_list) {
245                 osd_seq_free(map, osd_seq);
246         }
247         write_unlock(&dev->od_ost_map->om_seq_list_lock);
248         if (map->om_root)
249                 dput(map->om_root);
250         OBD_FREE_PTR(dev->od_ost_map);
251         dev->od_ost_map = NULL;
252         EXIT;
253 }
254
255 static int osd_obj_del_entry(struct osd_thread_info *info,
256                              struct osd_device *osd,
257                              struct dentry *dird, char *name,
258                              struct thandle *th)
259 {
260         struct ldiskfs_dir_entry_2 *de;
261         struct buffer_head         *bh;
262         struct osd_thandle         *oh;
263         struct dentry              *child;
264         struct inode               *dir = dird->d_inode;
265         int                         rc;
266
267         ENTRY;
268
269         oh = container_of(th, struct osd_thandle, ot_super);
270         LASSERT(oh->ot_handle != NULL);
271         LASSERT(oh->ot_handle->h_transaction != NULL);
272
273
274         child = &info->oti_child_dentry;
275         child->d_name.hash = 0;
276         child->d_name.name = name;
277         child->d_name.len = strlen(name);
278         child->d_parent = dird;
279         child->d_inode = NULL;
280
281         ll_vfs_dq_init(dir);
282         mutex_lock(&dir->i_mutex);
283         rc = -ENOENT;
284         bh = osd_ldiskfs_find_entry(dir, child, &de, NULL);
285         if (bh) {
286                 rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
287                 brelse(bh);
288         }
289         mutex_unlock(&dir->i_mutex);
290
291         RETURN(rc);
292 }
293
294 int osd_obj_add_entry(struct osd_thread_info *info,
295                       struct osd_device *osd,
296                       struct dentry *dir, char *name,
297                       const struct osd_inode_id *id,
298                       struct thandle *th)
299 {
300         struct osd_thandle *oh;
301         struct dentry *child;
302         struct inode *inode;
303         int rc;
304
305         ENTRY;
306
307         oh = container_of(th, struct osd_thandle, ot_super);
308         LASSERT(oh->ot_handle != NULL);
309         LASSERT(oh->ot_handle->h_transaction != NULL);
310
311         inode = &info->oti_inode;
312         inode->i_sb = osd_sb(osd);
313         osd_id_to_inode(inode, id);
314         inode->i_mode = S_IFREG; /* for type in ldiskfs dir entry */
315
316         child = &info->oti_child_dentry;
317         child->d_name.hash = 0;
318         child->d_name.name = name;
319         child->d_name.len = strlen(name);
320         child->d_parent = dir;
321         child->d_inode = inode;
322
323         ll_vfs_dq_init(dir->d_inode);
324         mutex_lock(&dir->d_inode->i_mutex);
325         rc = osd_ldiskfs_add_entry(oh->ot_handle, child, inode, NULL);
326         mutex_unlock(&dir->d_inode->i_mutex);
327
328         RETURN(rc);
329 }
330
331 /**
332  * Use LPU64 for legacy OST sequences, but use LPX64i for new
333  * sequences names, so that the O/{seq}/dN/{oid} more closely
334  * follows the DFID/PFID format. This makes it easier to map from
335  * debug messages to objects in the future, and the legacy space
336  * of FID_SEQ_OST_MDT0 will be unused in the future.
337  **/
338 static inline void osd_seq_name(char *seq_name, obd_seq seq)
339 {
340         sprintf(seq_name, (fid_seq_is_rsvd(seq) ||
341                            fid_seq_is_mdt0(seq)) ? LPU64 : LPX64i,
342                 fid_seq_is_idif(seq) ? 0 : seq);
343 }
344
345 static inline void osd_oid_name(char *name, const struct lu_fid *fid, obd_id id)
346 {
347         sprintf(name, (fid_seq_is_rsvd(fid_seq(fid)) ||
348                 fid_seq_is_mdt0(fid_seq(fid)) ||
349                 fid_seq_is_idif(fid_seq(fid))) ? LPU64 : LPX64i, id);
350 }
351
352 /* external locking is required */
353 static int osd_seq_load_locked(struct osd_device *osd,
354                                struct osd_obj_seq *osd_seq)
355 {
356         struct osd_obj_map  *map = osd->od_ost_map;
357         struct dentry       *seq_dir;
358         int                 rc = 0;
359         int                 i;
360         char                seq_name[32];
361         ENTRY;
362
363         if (osd_seq->oos_root != NULL)
364                 RETURN(0);
365
366         LASSERT(map);
367         LASSERT(map->om_root);
368
369         osd_seq_name(seq_name, osd_seq->oos_seq);
370
371         seq_dir = simple_mkdir(map->om_root, osd->od_mnt, seq_name, 0755, 1);
372         if (IS_ERR(seq_dir))
373                 GOTO(out_err, rc = PTR_ERR(seq_dir));
374         else if (seq_dir->d_inode == NULL)
375                 GOTO(out_put, rc = -EFAULT);
376
377         ldiskfs_set_inode_state(seq_dir->d_inode, LDISKFS_STATE_LUSTRE_NO_OI);
378         osd_seq->oos_root = seq_dir;
379
380         LASSERT(osd_seq->oos_dirs == NULL);
381         OBD_ALLOC(osd_seq->oos_dirs,
382                   sizeof(seq_dir) * osd_seq->oos_subdir_count);
383         if (osd_seq->oos_dirs == NULL)
384                 GOTO(out_put, rc = -ENOMEM);
385
386         for (i = 0; i < osd_seq->oos_subdir_count; i++) {
387                 struct dentry   *dir;
388                 char         name[32];
389
390                 sprintf(name, "d%u", i);
391                 dir = simple_mkdir(osd_seq->oos_root, osd->od_mnt, name,
392                                    0700, 1);
393                 if (IS_ERR(dir)) {
394                         rc = PTR_ERR(dir);
395                 } else if (dir->d_inode) {
396                         ldiskfs_set_inode_state(dir->d_inode,
397                                                 LDISKFS_STATE_LUSTRE_NO_OI);
398                         osd_seq->oos_dirs[i] = dir;
399                         rc = 0;
400                 } else {
401                         LBUG();
402                 }
403         }
404
405         if (rc != 0)
406                 osd_seq_free(map, osd_seq);
407 out_put:
408         if (rc != 0) {
409                 dput(seq_dir);
410                 osd_seq->oos_root = NULL;
411         }
412 out_err:
413         RETURN(rc);
414 }
415
416 static struct osd_obj_seq *osd_seq_load(struct osd_device *osd, obd_seq seq)
417 {
418         struct osd_obj_map      *map;
419         struct osd_obj_seq      *osd_seq;
420         int                     rc = 0;
421         ENTRY;
422
423         map = osd->od_ost_map;
424         LASSERT(map);
425         LASSERT(map->om_root);
426
427         osd_seq = osd_seq_find(map, seq);
428         if (likely(osd_seq != NULL))
429                 RETURN(osd_seq);
430
431         /* Serializing init process */
432         down(&map->om_dir_init_sem);
433
434         /* Check whether the seq has been added */
435         read_lock(&map->om_seq_list_lock);
436         osd_seq = osd_seq_find_locked(map, seq);
437         if (osd_seq != NULL) {
438                 read_unlock(&map->om_seq_list_lock);
439                 GOTO(cleanup, rc = 0);
440         }
441         read_unlock(&map->om_seq_list_lock);
442
443         OBD_ALLOC_PTR(osd_seq);
444         if (osd_seq == NULL)
445                 GOTO(cleanup, rc = -ENOMEM);
446
447         CFS_INIT_LIST_HEAD(&osd_seq->oos_seq_list);
448         osd_seq->oos_seq = seq;
449         /* Init subdir count to be 32, but each seq can have
450          * different subdir count */
451         osd_seq->oos_subdir_count = map->om_subdir_count;
452         rc = osd_seq_load_locked(osd, osd_seq);
453         if (rc != 0)
454                 GOTO(cleanup, rc);
455
456         write_lock(&map->om_seq_list_lock);
457         cfs_list_add(&osd_seq->oos_seq_list, &map->om_seq_list);
458         write_unlock(&map->om_seq_list_lock);
459
460 cleanup:
461         up(&map->om_dir_init_sem);
462         if (rc != 0) {
463                 if (osd_seq != NULL)
464                         OBD_FREE_PTR(osd_seq);
465                 RETURN(ERR_PTR(rc));
466         }
467
468         RETURN(osd_seq);
469 }
470
471 int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev,
472                        const struct lu_fid *fid, struct osd_inode_id *id)
473 {
474         struct osd_obj_map              *map;
475         struct osd_obj_seq              *osd_seq;
476         struct dentry                   *d_seq;
477         struct dentry                   *child;
478         struct ost_id                   *ostid = &info->oti_ostid;
479         int                             dirn;
480         char                            name[32];
481         struct ldiskfs_dir_entry_2      *de;
482         struct buffer_head              *bh;
483         struct inode                    *dir;
484         struct inode                    *inode;
485         ENTRY;
486
487         /* on the very first lookup we find and open directories */
488
489         map = dev->od_ost_map;
490         LASSERT(map);
491         LASSERT(map->om_root);
492
493         fid_ostid_pack(fid, ostid);
494         osd_seq = osd_seq_load(dev, ostid->oi_seq);
495         if (IS_ERR(osd_seq))
496                 RETURN(PTR_ERR(osd_seq));
497
498         dirn = ostid->oi_id & (osd_seq->oos_subdir_count - 1);
499         d_seq = osd_seq->oos_dirs[dirn];
500         LASSERT(d_seq);
501
502         osd_oid_name(name, fid, ostid->oi_id);
503
504         child = &info->oti_child_dentry;
505         child->d_parent = d_seq;
506         child->d_name.hash = 0;
507         child->d_name.name = name;
508         /* XXX: we can use rc from sprintf() instead of strlen() */
509         child->d_name.len = strlen(name);
510
511         dir = d_seq->d_inode;
512         mutex_lock(&dir->i_mutex);
513         bh = osd_ldiskfs_find_entry(dir, child, &de, NULL);
514         mutex_unlock(&dir->i_mutex);
515
516         if (bh == NULL)
517                 RETURN(-ENOENT);
518
519         osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
520         brelse(bh);
521
522         inode = osd_iget(info, dev, id);
523         if (IS_ERR(inode))
524                 RETURN(PTR_ERR(inode));
525
526         iput(inode);
527         RETURN(0);
528 }
529
530 int osd_obj_map_insert(struct osd_thread_info *info,
531                        struct osd_device *osd,
532                        const struct lu_fid *fid,
533                        const struct osd_inode_id *id,
534                        struct thandle *th)
535 {
536         struct osd_obj_map      *map;
537         struct osd_obj_seq      *osd_seq;
538         struct dentry           *d;
539         struct ost_id           *ostid = &info->oti_ostid;
540         int                     dirn, rc = 0;
541         char                    name[32];
542         ENTRY;
543
544         map = osd->od_ost_map;
545         LASSERT(map);
546
547         /* map fid to seq:objid */
548         fid_ostid_pack(fid, ostid);
549
550         osd_seq = osd_seq_load(osd, ostid->oi_seq);
551         if (IS_ERR(osd_seq))
552                 RETURN(PTR_ERR(osd_seq));
553
554         dirn = ostid->oi_id & (osd_seq->oos_subdir_count - 1);
555         d = osd_seq->oos_dirs[dirn];
556         LASSERT(d);
557
558         osd_oid_name(name, fid, ostid->oi_id);
559         rc = osd_obj_add_entry(info, osd, d, name, id, th);
560
561         RETURN(rc);
562 }
563
564 int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd,
565                        const struct lu_fid *fid, struct thandle *th)
566 {
567         struct osd_obj_map      *map;
568         struct osd_obj_seq      *osd_seq;
569         struct dentry           *d;
570         struct ost_id           *ostid = &info->oti_ostid;
571         int                     dirn, rc = 0;
572         char                    name[32];
573         ENTRY;
574
575         map = osd->od_ost_map;
576         LASSERT(map);
577
578         /* map fid to seq:objid */
579         fid_ostid_pack(fid, ostid);
580
581         osd_seq = osd_seq_load(osd, ostid->oi_seq);
582         if (IS_ERR(osd_seq))
583                 GOTO(cleanup, rc = PTR_ERR(osd_seq));
584
585         dirn = ostid->oi_id & (osd_seq->oos_subdir_count - 1);
586         d = osd_seq->oos_dirs[dirn];
587         LASSERT(d);
588
589         osd_oid_name(name, fid, ostid->oi_id);
590         rc = osd_obj_del_entry(info, osd, d, name, th);
591 cleanup:
592         RETURN(rc);
593 }
594
595 struct named_oid {
596         unsigned long  oid;
597         char          *name;
598 };
599
600 static const struct named_oid oids[] = {
601         { FLD_INDEX_OID,        "fld" },
602         { FID_SEQ_CTL_OID,      "seq_ctl" },
603         { FID_SEQ_SRV_OID,      "seq_srv" },
604         { MDD_ROOT_INDEX_OID,   "" /* "ROOT" */ },
605         { MDD_ORPHAN_OID,       "" /* "PENDING" */ },
606         { MDD_LOV_OBJ_OID,      LOV_OBJID },
607         { MDD_CAPA_KEYS_OID,    "" /* CAPA_KEYS */ },
608         { MDT_LAST_RECV_OID,    LAST_RCVD },
609         { LFSCK_BOOKMARK_OID,   "" /* "lfsck_bookmark" */ },
610         { OTABLE_IT_OID,        "" /* "otable iterator" */},
611         { OFD_LAST_RECV_OID,    LAST_RCVD },
612         { OFD_LAST_GROUP_OID,   "LAST_GROUP" },
613         { LLOG_CATALOGS_OID,    "CATALOGS" },
614         { MGS_CONFIGS_OID,      "" /* MOUNT_CONFIGS_DIR */ },
615         { OFD_HEALTH_CHECK_OID, HEALTH_CHECK },
616         { MDD_LOV_OBJ_OSEQ,     LOV_OBJSEQ },
617         { 0,                    NULL }
618 };
619
620 static char *oid2name(const unsigned long oid)
621 {
622         int i = 0;
623
624         while (oids[i].oid) {
625                 if (oids[i].oid == oid)
626                         return oids[i].name;
627                 i++;
628         }
629         return NULL;
630 }
631
632 int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
633                         const struct lu_fid *fid,
634                         const struct osd_inode_id *id,
635                         struct thandle *th)
636 {
637         struct osd_obj_map      *map = osd->od_ost_map;
638         struct dentry           *root = osd_sb(osd)->s_root;
639         char                    *name;
640         int                     rc = 0;
641         ENTRY;
642
643         if (fid_is_last_id(fid)) {
644                 struct osd_obj_seq      *osd_seq;
645
646                 /* on creation of LAST_ID we create O/<seq> hierarchy */
647                 LASSERT(map);
648                 osd_seq = osd_seq_load(osd, fid_seq(fid));
649                 if (IS_ERR(osd_seq))
650                         RETURN(PTR_ERR(osd_seq));
651                 rc = osd_obj_add_entry(info, osd, osd_seq->oos_root,
652                                        "LAST_ID", id, th);
653         } else {
654                 name = oid2name(fid_oid(fid));
655                 if (name == NULL)
656                         CWARN("UNKNOWN COMPAT FID "DFID"\n", PFID(fid));
657                 else if (name[0])
658                         rc = osd_obj_add_entry(info, osd, root, name, id, th);
659         }
660
661         RETURN(rc);
662 }
663
664 int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
665                         const struct lu_fid *fid, struct osd_inode_id *id)
666 {
667         struct dentry   *root;
668         struct dentry *dentry;
669         struct inode  *inode;
670         char          *name;
671         int            rc = -ENOENT;
672         ENTRY;
673
674         if (fid_is_last_id(fid)) {
675                 struct osd_obj_seq *osd_seq;
676
677                 osd_seq = osd_seq_load(osd, fid_seq(fid));
678                 if (IS_ERR(osd_seq))
679                         RETURN(PTR_ERR(osd_seq));
680                 root = osd_seq->oos_root;
681                 name = "LAST_ID";
682         } else {
683                 root = osd_sb(osd)->s_root;
684                 name = oid2name(fid_oid(fid));
685                 if (name == NULL || strlen(name) == 0)
686                         RETURN(-ENOENT);
687         }
688
689         dentry = ll_lookup_one_len(name, root, strlen(name));
690         if (!IS_ERR(dentry)) {
691                 inode = dentry->d_inode;
692                 if (inode) {
693                         if (is_bad_inode(inode)) {
694                                 rc = -EIO;
695                         } else {
696                                 osd_id_gen(id, inode->i_ino,
697                                            inode->i_generation);
698                                 rc = 0;
699                         }
700                 }
701                 /* if dentry is accessible after osd_compat_spec_insert it
702                  * will still contain NULL inode, so don't keep it in cache */
703                 d_invalidate(dentry);
704                 dput(dentry);
705         }
706
707         RETURN(rc);
708 }