Whamcloud - gitweb
LU-137 obdclass: add dt_object_put() and use it
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_quota.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, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 021110-1307, USA
20  *
21  * GPL HEADER END
22  */
23 /*
24  * Copyright (c) 2012, 2015, Intel Corporation.
25  * Use is subject to license terms.
26  *
27  * Author: Johann Lombardi <johann@whamcloud.com>
28  * Author: Niu    Yawei    <niu@whamcloud.com>
29  */
30
31 #include <lustre_quota.h>
32 #include "osd_internal.h"
33
34 /**
35  * Helpers function to find out the quota type (USRQUOTA/GRPQUOTA) of a
36  * given object
37  */
38 static inline int fid2type(const struct lu_fid *fid)
39 {
40         LASSERT(fid_is_acct(fid));
41         if (fid_oid(fid) == ACCT_GROUP_OID)
42                 return GRPQUOTA;
43         return USRQUOTA;
44 }
45
46 static inline int obj2type(struct dt_object *obj)
47 {
48         return fid2type(lu_object_fid(&obj->do_lu));
49 }
50
51 /**
52  * Space Accounting Management
53  */
54
55 /**
56  * Look up an accounting object based on its fid.
57  *
58  * \param info - is the osd thread info passed by the caller
59  * \param osd  - is the osd device
60  * \param fid  - is the fid of the accounting object we want to look up
61  * \param id   - is the osd_inode_id struct to fill with the inode number of
62  *               the quota file if the lookup is successful
63  */
64 int osd_acct_obj_lookup(struct osd_thread_info *info, struct osd_device *osd,
65                         const struct lu_fid *fid, struct osd_inode_id *id)
66 {
67         struct super_block *sb = osd_sb(osd);
68         unsigned long qf_inums[2] = {
69                 le32_to_cpu(LDISKFS_SB(sb)->s_es->s_usr_quota_inum),
70                 le32_to_cpu(LDISKFS_SB(sb)->s_es->s_grp_quota_inum)
71         };
72
73         ENTRY;
74         LASSERT(fid_is_acct(fid));
75
76         if (!LDISKFS_HAS_RO_COMPAT_FEATURE(sb,
77                                            LDISKFS_FEATURE_RO_COMPAT_QUOTA))
78                 RETURN(-ENOENT);
79
80         id->oii_gen = OSD_OII_NOGEN;
81         id->oii_ino = qf_inums[fid2type(fid)];
82         if (!ldiskfs_valid_inum(sb, id->oii_ino))
83                 RETURN(-ENOENT);
84         RETURN(0);
85 }
86
87 /**
88  * Return space usage (#blocks & #inodes) consumed by a given uid or gid.
89  *
90  * \param env   - is the environment passed by the caller
91  * \param dtobj - is the accounting object
92  * \param dtrec - is the record to fill with space usage information
93  * \param dtkey - is the id of the user or group for which we would
94  *                like to access disk usage.
95  *
96  * \retval +ve - success : exact match
97  * \retval -ve - failure
98  */
99 static int osd_acct_index_lookup(const struct lu_env *env,
100                                  struct dt_object *dtobj,
101                                  struct dt_rec *dtrec,
102                                  const struct dt_key *dtkey)
103 {
104         struct osd_thread_info  *info = osd_oti_get(env);
105 #if defined(HAVE_DQUOT_QC_DQBLK)
106         struct qc_dqblk         *dqblk = &info->oti_qdq;
107 #elif defined(HAVE_DQUOT_FS_DISK_QUOTA)
108         struct fs_disk_quota    *dqblk = &info->oti_fdq;
109 #else
110         struct if_dqblk         *dqblk = &info->oti_dqblk;
111 #endif
112         struct super_block      *sb = osd_sb(osd_obj2dev(osd_dt_obj(dtobj)));
113         struct lquota_acct_rec  *rec = (struct lquota_acct_rec *)dtrec;
114         __u64                    id = *((__u64 *)dtkey);
115         int                      rc;
116 #ifdef HAVE_DQUOT_KQID
117         struct kqid              qid;
118 #endif
119
120         ENTRY;
121
122         memset(dqblk, 0, sizeof(*dqblk));
123 #ifdef HAVE_DQUOT_KQID
124         qid = make_kqid(&init_user_ns, obj2type(dtobj), id);
125         rc = sb->s_qcop->get_dqblk(sb, qid, dqblk);
126 #else
127         rc = sb->s_qcop->get_dqblk(sb, obj2type(dtobj), (qid_t)id, dqblk);
128 #endif
129         if (rc)
130                 RETURN(rc);
131 #if defined(HAVE_DQUOT_QC_DQBLK)
132         rec->bspace = dqblk->d_space;
133         rec->ispace = dqblk->d_ino_count;
134 #elif defined(HAVE_DQUOT_FS_DISK_QUOTA)
135         rec->bspace = dqblk->d_bcount;
136         rec->ispace = dqblk->d_icount;
137 #else
138         rec->bspace = dqblk->dqb_curspace;
139         rec->ispace = dqblk->dqb_curinodes;
140 #endif
141         RETURN(+1);
142 }
143
144 #define QUOTA_IT_READ_ERROR(it, rc)                                    \
145         CERROR("%s: Error while trying to read quota information, "    \
146                "failed with %d\n",                                     \
147                osd_dev(it->oiq_obj->oo_dt.do_lu.lo_dev)->od_svname, rc); \
148
149 /**
150  * Initialize osd Iterator for given osd index object.
151  *
152  * \param  dt    - osd index object
153  * \param  attr  - not used
154  */
155 static struct dt_it *osd_it_acct_init(const struct lu_env *env,
156                                       struct dt_object *dt,
157                                       __u32 attr)
158 {
159         struct osd_it_quota     *it;
160         struct lu_object        *lo = &dt->do_lu;
161         struct osd_object       *obj = osd_dt_obj(dt);
162
163         ENTRY;
164
165         LASSERT(lu_object_exists(lo));
166
167         OBD_ALLOC_PTR(it);
168         if (it == NULL)
169                 RETURN(ERR_PTR(-ENOMEM));
170
171         lu_object_get(lo);
172         it->oiq_obj = obj;
173         INIT_LIST_HEAD(&it->oiq_list);
174
175         /* LUSTRE_DQTREEOFF is the initial offset where the tree can be found */
176         it->oiq_blk[0] = LUSTRE_DQTREEOFF;
177
178         /* NB: we don't need to store the tree depth since it is always
179          * equal to LUSTRE_DQTREEDEPTH - 1 (root has depth = 0) for a leaf
180          * block. */
181         RETURN((struct dt_it *)it);
182 }
183
184 /**
185  * Free given iterator.
186  *
187  * \param  di   - osd iterator
188  */
189 static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di)
190 {
191         struct osd_it_quota *it = (struct osd_it_quota *)di;
192         struct osd_quota_leaf *leaf, *tmp;
193         ENTRY;
194
195         osd_object_put(env, it->oiq_obj);
196
197         list_for_each_entry_safe(leaf, tmp, &it->oiq_list, oql_link) {
198                 list_del_init(&leaf->oql_link);
199                 OBD_FREE_PTR(leaf);
200         }
201
202         OBD_FREE_PTR(it);
203
204         EXIT;
205 }
206
207 /**
208  * Move Iterator to record specified by \a key, if the \a key isn't found,
209  * move to the first valid record.
210  *
211  * \param  di   - osd iterator
212  * \param  key  - uid or gid
213  *
214  * \retval +ve  - di points to the first valid record
215  * \retval  +1  - di points to exact matched key
216  * \retval -ve  - failure
217  */
218 static int osd_it_acct_get(const struct lu_env *env, struct dt_it *di,
219                            const struct dt_key *key)
220 {
221         struct osd_it_quota     *it = (struct osd_it_quota *)di;
222         const struct lu_fid     *fid =
223                                 lu_object_fid(&it->oiq_obj->oo_dt.do_lu);
224         int                      type = fid2type(fid);
225         qid_t                    dqid = *(qid_t *)key;
226         loff_t                   offset;
227         int                      rc;
228
229         ENTRY;
230
231         offset = find_tree_dqentry(env, it->oiq_obj, type, dqid,
232                                    LUSTRE_DQTREEOFF, 0, it);
233         if (offset > 0) { /* Found */
234                 RETURN(+1);
235         } else if (offset < 0) { /* Error */
236                 QUOTA_IT_READ_ERROR(it, (int)offset);
237                 RETURN((int)offset);
238         }
239
240         /* The @key is not found, move to the first valid entry */
241         rc = walk_tree_dqentry(env, it->oiq_obj, type, it->oiq_blk[0], 0,
242                                0, it);
243         if (rc == 0)
244                 rc = 1;
245         else if (rc > 0)
246                 rc = -ENOENT;
247
248         RETURN(rc);
249 }
250
251 /**
252  * Release Iterator
253  *
254  * \param  di   - osd iterator
255  */
256 static void osd_it_acct_put(const struct lu_env *env, struct dt_it *di)
257 {
258         return;
259 }
260
261 static int osd_it_add_processed(struct osd_it_quota *it, int depth)
262 {
263         struct osd_quota_leaf *leaf;
264
265         OBD_ALLOC_PTR(leaf);
266         if (leaf == NULL)
267                 RETURN(-ENOMEM);
268         INIT_LIST_HEAD(&leaf->oql_link);
269         leaf->oql_blk = it->oiq_blk[depth];
270         list_add_tail(&leaf->oql_link, &it->oiq_list);
271         RETURN(0);
272 }
273
274 /**
275  * Move on to the next valid entry.
276  *
277  * \param  di   - osd iterator
278  *
279  * \retval +ve  - iterator reached the end
280  * \retval   0  - iterator has not reached the end yet
281  * \retval -ve  - unexpected failure
282  */
283 static int osd_it_acct_next(const struct lu_env *env, struct dt_it *di)
284 {
285         struct osd_it_quota     *it = (struct osd_it_quota *)di;
286         const struct lu_fid     *fid =
287                                 lu_object_fid(&it->oiq_obj->oo_dt.do_lu);
288         int                      type = fid2type(fid);
289         int                      depth, rc;
290         uint                     index;
291
292         ENTRY;
293
294         /* Let's first check if there are any remaining valid entry in the
295          * current leaf block. Start with the next entry after the current one.
296          */
297         depth = LUSTRE_DQTREEDEPTH;
298         index = it->oiq_index[depth];
299         if (++index < LUSTRE_DQSTRINBLK) {
300                 /* Search for the next valid entry from current index */
301                 rc = walk_block_dqentry(env, it->oiq_obj, type,
302                                         it->oiq_blk[depth], index, it);
303                 if (rc < 0) {
304                         QUOTA_IT_READ_ERROR(it, rc);
305                         RETURN(rc);
306                 } else if (rc == 0) {
307                         /* Found on entry, @it is already updated to the
308                          * new position in walk_block_dqentry(). */
309                         RETURN(0);
310                 } else {
311                         rc = osd_it_add_processed(it, depth);
312                         if (rc)
313                                 RETURN(rc);
314                 }
315         } else {
316                 rc = osd_it_add_processed(it, depth);
317                 if (rc)
318                         RETURN(rc);
319         }
320         rc = 1;
321
322         /* We have consumed all the entries of the current leaf block, move on
323          * to the next one. */
324         depth--;
325
326         /* We keep searching as long as walk_tree_dqentry() returns +1
327          * (= no valid entry found). */
328         for (; depth >= 0 && rc > 0; depth--) {
329                 index = it->oiq_index[depth];
330                 if (++index > 0xff)
331                         continue;
332                 rc = walk_tree_dqentry(env, it->oiq_obj, type,
333                                        it->oiq_blk[depth], depth, index, it);
334         }
335
336         if (rc < 0)
337                 QUOTA_IT_READ_ERROR(it, rc);
338         RETURN(rc);
339 }
340
341 /**
342  * Return pointer to the key under iterator.
343  *
344  * \param  di   - osd iterator
345  */
346 static struct dt_key *osd_it_acct_key(const struct lu_env *env,
347                                       const struct dt_it *di)
348 {
349         struct osd_it_quota *it = (struct osd_it_quota *)di;
350
351         ENTRY;
352         RETURN((struct dt_key *)&it->oiq_id);
353 }
354
355 /**
356  * Return size of key under iterator (in bytes)
357  *
358  * \param  di   - osd iterator
359  */
360 static int osd_it_acct_key_size(const struct lu_env *env,
361                                 const struct dt_it *di)
362 {
363         struct osd_it_quota *it = (struct osd_it_quota *)di;
364
365         ENTRY;
366         RETURN((int)sizeof(it->oiq_id));
367 }
368
369 /**
370  * Return pointer to the record under iterator.
371  *
372  * \param  di    - osd iterator
373  * \param  attr  - not used
374  */
375 static int osd_it_acct_rec(const struct lu_env *env,
376                            const struct dt_it *di,
377                            struct dt_rec *dtrec, __u32 attr)
378 {
379         struct osd_it_quota     *it = (struct osd_it_quota *)di;
380         const struct dt_key     *key = osd_it_acct_key(env, di);
381         int                      rc;
382
383         ENTRY;
384
385         rc = osd_acct_index_lookup(env, &it->oiq_obj->oo_dt, dtrec, key);
386         RETURN(rc > 0 ? 0 : rc);
387 }
388
389 /**
390  * Returns cookie for current Iterator position.
391  *
392  * \param  di    - osd iterator
393  */
394 static __u64 osd_it_acct_store(const struct lu_env *env,
395                                const struct dt_it *di)
396 {
397         struct osd_it_quota *it = (struct osd_it_quota *)di;
398
399         ENTRY;
400         RETURN(it->oiq_id);
401 }
402
403 /**
404  * Restore iterator from cookie. if the \a hash isn't found,
405  * restore the first valid record.
406  *
407  * \param  di    - osd iterator
408  * \param  hash  - iterator location cookie
409  *
410  * \retval +ve   - di points to the first valid record
411  * \retval  +1   - di points to exact matched hash
412  * \retval -ve   - failure
413  */
414 static int osd_it_acct_load(const struct lu_env *env,
415                             const struct dt_it *di, __u64 hash)
416 {
417         ENTRY;
418         RETURN(osd_it_acct_get(env, (struct dt_it *)di,
419                                (const struct dt_key *)&hash));
420 }
421
422 /**
423  * Index and Iterator operations for accounting objects
424  */
425 const struct dt_index_operations osd_acct_index_ops = {
426         .dio_lookup     = osd_acct_index_lookup,
427         .dio_it         = {
428                 .init           = osd_it_acct_init,
429                 .fini           = osd_it_acct_fini,
430                 .get            = osd_it_acct_get,
431                 .put            = osd_it_acct_put,
432                 .next           = osd_it_acct_next,
433                 .key            = osd_it_acct_key,
434                 .key_size       = osd_it_acct_key_size,
435                 .rec            = osd_it_acct_rec,
436                 .store          = osd_it_acct_store,
437                 .load           = osd_it_acct_load
438         }
439 };
440
441 static inline void osd_quota_swab(char *ptr, size_t size)
442 {
443         int offset;
444
445         LASSERT((size & (sizeof(__u64) - 1)) == 0);
446
447         for (offset = 0; offset < size; offset += sizeof(__u64))
448              __swab64s((__u64 *)(ptr + offset));
449 }
450
451 const struct dt_rec *osd_quota_pack(struct osd_object *obj,
452                                     const struct dt_rec *rec,
453                                     union lquota_rec *quota_rec)
454 {
455 #ifdef __BIG_ENDIAN
456         struct iam_descr        *descr;
457
458         LASSERT(obj->oo_dir != NULL);
459         descr = obj->oo_dir->od_container.ic_descr;
460
461         memcpy(quota_rec, rec, descr->id_rec_size);
462
463         osd_quota_swab((char *)quota_rec, descr->id_rec_size);
464         return (const struct dt_rec *)quota_rec;
465 #else
466         return rec;
467 #endif
468 }
469
470 void osd_quota_unpack(struct osd_object *obj, const struct dt_rec *rec)
471 {
472 #ifdef __BIG_ENDIAN
473         struct iam_descr *descr;
474
475         LASSERT(obj->oo_dir != NULL);
476         descr = obj->oo_dir->od_container.ic_descr;
477
478         osd_quota_swab((char *)rec, descr->id_rec_size);
479 #else
480         return;
481 #endif
482 }
483
484 static inline int osd_qid_type(struct osd_thandle *oh, int i)
485 {
486         return (oh->ot_id_type & (1 << i)) ? GRPQUOTA : USRQUOTA;
487 }
488
489 static inline void osd_qid_set_type(struct osd_thandle *oh, int i, int type)
490 {
491         oh->ot_id_type |= ((type == GRPQUOTA) ? (1 << i) : 0);
492 }
493
494 /**
495  * Reserve journal credits for quota files update first, then call
496  * ->op_begin() to perform quota enforcement.
497  *
498  * \param  env     - the environment passed by the caller
499  * \param  oh      - osd transaction handle
500  * \param  qi      - quota id & space required for this operation
501  * \param  obj     - osd object, could be NULL when it's under create
502  * \param  enforce - whether to perform quota enforcement
503  * \param  flags   - if the operation is write, return no user quota, no
504  *                   group quota, or sync commit flags to the caller
505  *
506  * \retval 0       - success
507  * \retval -ve     - failure
508  */
509 int osd_declare_qid(const struct lu_env *env, struct osd_thandle *oh,
510                     struct lquota_id_info *qi, struct osd_object *obj,
511                     bool enforce, int *flags)
512 {
513         struct osd_device       *dev;
514         struct qsd_instance     *qsd;
515         struct inode            *inode = NULL;
516         int                      i, rc = 0, crd;
517         bool                     found = false;
518         ENTRY;
519
520         LASSERT(oh != NULL);
521         LASSERTF(oh->ot_id_cnt <= OSD_MAX_UGID_CNT, "count=%d\n",
522                  oh->ot_id_cnt);
523
524         dev = osd_dt_dev(oh->ot_super.th_dev);
525         LASSERT(dev != NULL);
526
527         qsd = dev->od_quota_slave;
528
529         for (i = 0; i < oh->ot_id_cnt; i++) {
530                 if (oh->ot_id_array[i] == qi->lqi_id.qid_uid &&
531                     osd_qid_type(oh, i) == qi->lqi_type) {
532                         found = true;
533                         break;
534                 }
535         }
536
537         if (!found) {
538                 /* we need to account for credits for this new ID */
539                 if (i >= OSD_MAX_UGID_CNT) {
540                         CERROR("Too many(%d) trans qids!\n", i + 1);
541                         RETURN(-EOVERFLOW);
542                 }
543
544                 if (obj != NULL)
545                         inode = obj->oo_inode;
546
547                 /* root ID entry should be always present in the quota file */
548                 if (qi->lqi_id.qid_uid == 0) {
549                         crd = 1;
550                 } else {
551                         /* used space for this ID could be dropped to zero,
552                          * reserve extra credits for removing ID entry from
553                          * the quota file */
554                         if (qi->lqi_space < 0)
555                                 crd = LDISKFS_QUOTA_DEL_BLOCKS(osd_sb(dev));
556                         /* reserve credits for adding ID entry to the quota
557                          * file if the i_dquot isn't initialized yet. */
558                         else if (inode == NULL ||
559 #ifdef HAVE_EXT4_INFO_DQUOT
560                                  LDISKFS_I(inode)->i_dquot[qi->lqi_type] == NULL)
561 #else
562                                  inode->i_dquot[qi->lqi_type] == NULL)
563 #endif
564                                 crd = LDISKFS_QUOTA_INIT_BLOCKS(osd_sb(dev));
565                         else
566                                 crd = 1;
567                 }
568
569                 osd_trans_declare_op(env, oh, OSD_OT_QUOTA, crd);
570
571                 oh->ot_id_array[i] = qi->lqi_id.qid_uid;
572                 osd_qid_set_type(oh, i, qi->lqi_type);
573                 oh->ot_id_cnt++;
574         }
575
576         if (unlikely(qsd == NULL))
577                 /* quota slave instance hasn't been allocated yet */
578                 RETURN(0);
579
580         /* check quota */
581         if (enforce)
582                 rc = qsd_op_begin(env, qsd, oh->ot_quota_trans, qi, flags);
583         RETURN(rc);
584 }
585
586 /**
587  * Wrapper for osd_declare_qid()
588  *
589  * \param  env    - the environment passed by the caller
590  * \param  uid    - user id of the inode
591  * \param  gid    - group id of the inode
592  * \param  space  - how many blocks/inodes will be consumed/released
593  * \param  oh     - osd transaction handle
594  * \param  obj    - osd object, could be NULL when it's under create
595  * \param  is_blk - block quota or inode quota?
596  * \param  flags  - if the operation is write, return no user quota, no
597  *                  group quota, or sync commit flags to the caller
598  * \param force   - set to 1 when changes are performed by root user and thus
599  *                  can't failed with EDQUOT
600  *
601  * \retval 0      - success
602  * \retval -ve    - failure
603  */
604 int osd_declare_inode_qid(const struct lu_env *env, qid_t uid, qid_t gid,
605                           long long space, struct osd_thandle *oh,
606                           struct osd_object *obj, bool is_blk, int *flags,
607                           bool force)
608 {
609         struct osd_thread_info  *info = osd_oti_get(env);
610         struct lquota_id_info   *qi = &info->oti_qi;
611         int                      rcu, rcg; /* user & group rc */
612         ENTRY;
613
614         /* let's start with user quota */
615         qi->lqi_id.qid_uid = uid;
616         qi->lqi_type       = USRQUOTA;
617         qi->lqi_space      = space;
618         qi->lqi_is_blk     = is_blk;
619         rcu = osd_declare_qid(env, oh, qi, obj, true, flags);
620
621         if (force && (rcu == -EDQUOT || rcu == -EINPROGRESS))
622                 /* ignore EDQUOT & EINPROGRESS when changes are done by root */
623                 rcu = 0;
624
625         /* For non-fatal error, we want to continue to get the noquota flags
626          * for group id. This is only for commit write, which has @flags passed
627          * in. See osd_declare_write_commit().
628          * When force is set to true, we also want to proceed with the gid */
629         if (rcu && (rcu != -EDQUOT || flags == NULL))
630                 RETURN(rcu);
631
632         /* and now group quota */
633         qi->lqi_id.qid_gid = gid;
634         qi->lqi_type       = GRPQUOTA;
635         rcg = osd_declare_qid(env, oh, qi, obj, true, flags);
636
637         if (force && (rcg == -EDQUOT || rcg == -EINPROGRESS))
638                 /* as before, ignore EDQUOT & EINPROGRESS for root */
639                 rcg = 0;
640
641         RETURN(rcu ? rcu : rcg);
642 }
643
644 int osd_quota_migration(const struct lu_env *env, struct dt_object *dt)
645 {
646         struct osd_thread_info  *oti = osd_oti_get(env);
647         struct osd_device       *osd = osd_obj2dev(osd_dt_obj(dt));
648         struct dt_object        *root, *parent = NULL, *admin = NULL;
649         dt_obj_version_t         version;
650         char                    *fname, *fnames[] = {ADMIN_USR, ADMIN_GRP};
651         int                      rc, i;
652         ENTRY;
653
654         /* not newly created global index */
655         version = dt_version_get(env, dt);
656         if (version != 0)
657                 RETURN(0);
658
659         /* locate root */
660         rc = dt_root_get(env, &osd->od_dt_dev, &oti->oti_fid);
661         if (rc) {
662                 CERROR("%s: Can't get root FID, rc:%d\n", osd->od_svname, rc);
663                 RETURN(rc);
664         }
665
666         root = dt_locate(env, &osd->od_dt_dev, &oti->oti_fid);
667         if (IS_ERR(root)) {
668                 CERROR("%s: Failed to locate root "DFID", rc:%ld\n",
669                        osd->od_svname, PFID(&oti->oti_fid), PTR_ERR(root));
670                 RETURN(PTR_ERR(root));
671         }
672
673         /* locate /OBJECTS */
674         rc = dt_lookup_dir(env, root, OBJECTS, &oti->oti_fid);
675         if (rc == -ENOENT) {
676                 GOTO(out, rc = 0);
677         } else if (rc) {
678                 CERROR("%s: Failed to lookup %s, rc:%d\n",
679                        osd->od_svname, OBJECTS, rc);
680                 GOTO(out, rc);
681         }
682
683         parent = dt_locate(env, &osd->od_dt_dev, &oti->oti_fid);
684         if (IS_ERR(parent)) {
685                 CERROR("%s: Failed to locate %s "DFID", rc:%ld\n",
686                        osd->od_svname, OBJECTS, PFID(&oti->oti_fid),
687                        PTR_ERR(parent));
688                 GOTO(out, rc = PTR_ERR(parent));
689         }
690
691         /* locate quota admin files */
692         for (i = 0; i < 2; i++) {
693                 fname = fnames[i];
694                 rc = dt_lookup_dir(env, parent, fname, &oti->oti_fid);
695                 if (rc == -ENOENT) {
696                         rc = 0;
697                         continue;
698                 } else if (rc) {
699                         CERROR("%s: Failed to lookup %s, rc:%d\n",
700                                osd->od_svname, fname, rc);
701                         GOTO(out, rc);
702                 }
703
704                 admin = dt_locate(env, &osd->od_dt_dev, &oti->oti_fid);
705                 if (IS_ERR(admin)) {
706                         CERROR("%s: Failed to locate %s "DFID", rc:%d\n",
707                                osd->od_svname, fname, PFID(&oti->oti_fid), rc);
708                         GOTO(out, rc = PTR_ERR(admin));
709                 }
710
711                 if (!dt_object_exists(admin)) {
712                         CERROR("%s: Old admin file %s doesn't exist, but is "
713                                "still referenced in parent directory.\n",
714                                osd->od_svname, fname);
715                         dt_object_put(env, admin);
716                         GOTO(out, rc = -ENOENT);
717                 }
718
719                 LCONSOLE_WARN("%s: Detected old quota admin file(%s)! If you "
720                               "want to keep the old quota limits settings, "
721                               "please upgrade to lower version(2.5) first to "
722                               "convert them into new format.\n",
723                               osd->od_svname, fname);
724
725                 dt_object_put(env, admin);
726                 GOTO(out, rc = -EINVAL);
727         }
728 out:
729         if (parent && !IS_ERR(parent))
730                 dt_object_put(env, parent);
731         dt_object_put(env, root);
732         RETURN(rc);
733 }