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