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