Whamcloud - gitweb
92f6d704c0d755303d476a1b02530f7f8dfa1689
[fs/lustre-release.git] / lustre / quota / qmt_pool.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, Intel Corporation.
25  * Use is subject to license terms.
26  *
27  * Author: Johann Lombardi <johann.lombardi@intel.com>
28  * Author: Niu    Yawei    <yawei.niu@intel.com>
29  */
30
31 /*
32  * A Quota Master Target has a hash table where it stores qmt_pool_info
33  * structures. There is one such structure for each pool managed by the QMT.
34  *
35  * Each pool can have different quota types enforced (typically user & group
36  * quota). A pool is in charge of managing lquota_entry structures for each
37  * quota type. This is done by creating one lquota_entry site per quota
38  * type. A site stores entries in a hash table and read quota settings from disk
39  * when a given ID isn't present in the hash.
40  *
41  * The pool API exported here is the following:
42  * - qmt_pool_init(): initializes the general QMT structures used to manage
43  *                    pools.
44  * - qmt_pool_fini(): frees the structures allocated by qmt_pool_fini().
45  * - qmt_pool_prepare(): sets up the on-disk indexes associated with each pool.
46  * - qmt_pool_new_conn(): is used to create a new slave index file.
47  * - qmt_pool_lqe_lookup(): returns an up-to-date lquota entry associated with
48  *                          a given ID.
49  */
50
51 #define DEBUG_SUBSYSTEM S_LQUOTA
52
53 #include <obd_class.h>
54 #include <lprocfs_status.h>
55 #include "qmt_internal.h"
56
57 static void qmt_pool_free(const struct lu_env *, struct qmt_pool_info *);
58
59 /*
60  * Static helper functions not used outside the scope of this file
61  */
62
63 /*
64  * Reference counter management for qmt_pool_info structures
65  */
66 static inline void qpi_getref(struct qmt_pool_info *pool)
67 {
68         cfs_atomic_inc(&pool->qpi_ref);
69 }
70
71 static inline void qpi_putref(const struct lu_env *env,
72                               struct qmt_pool_info *pool)
73 {
74         LASSERT(atomic_read(&pool->qpi_ref) > 0);
75         if (cfs_atomic_dec_and_test(&pool->qpi_ref))
76                 qmt_pool_free(env, pool);
77 }
78
79 static inline void qpi_putref_locked(struct qmt_pool_info *pool)
80 {
81         LASSERT(cfs_atomic_read(&pool->qpi_ref) > 1);
82         cfs_atomic_dec(&pool->qpi_ref);
83 }
84
85 /*
86  * Hash functions for qmt_pool_info management
87  */
88
89 static unsigned qpi_hash_hash(cfs_hash_t *hs, const void *key, unsigned mask)
90 {
91         return cfs_hash_u32_hash(*((__u32 *)key), mask);
92 }
93
94 static void *qpi_hash_key(cfs_hlist_node_t *hnode)
95 {
96         struct qmt_pool_info *pool;
97         pool = cfs_hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
98         return &pool->qpi_key;
99 }
100
101 static int qpi_hash_keycmp(const void *key, cfs_hlist_node_t *hnode)
102 {
103         struct qmt_pool_info *pool;
104         pool = cfs_hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
105         return pool->qpi_key == *((__u32 *)key);
106 }
107
108 static void *qpi_hash_object(cfs_hlist_node_t *hnode)
109 {
110         return cfs_hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
111 }
112
113 static void qpi_hash_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
114 {
115         struct qmt_pool_info *pool;
116         pool = cfs_hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
117         qpi_getref(pool);
118 }
119
120 static void qpi_hash_put_locked(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
121 {
122         struct qmt_pool_info *pool;
123         pool = cfs_hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
124         qpi_putref_locked(pool);
125 }
126
127 static void qpi_hash_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
128 {
129         CERROR("Should not have any item left!\n");
130 }
131
132 /* vector of hash operations */
133 static cfs_hash_ops_t qpi_hash_ops = {
134         .hs_hash        = qpi_hash_hash,
135         .hs_key         = qpi_hash_key,
136         .hs_keycmp      = qpi_hash_keycmp,
137         .hs_object      = qpi_hash_object,
138         .hs_get         = qpi_hash_get,
139         .hs_put_locked  = qpi_hash_put_locked,
140         .hs_exit        = qpi_hash_exit
141 };
142
143 /* some procfs helpers */
144 static int lprocfs_qpi_rd_state(char *page, char **start, off_t off,
145                                 int count, int *eof, void *data)
146 {
147         struct qmt_pool_info    *pool = (struct qmt_pool_info *)data;
148         int                      type, i = 0;
149
150         LASSERT(pool != NULL);
151
152         i = snprintf(page, count,
153                      "pool:\n"
154                      "    id: %u\n"
155                      "    type: %s\n"
156                      "    ref: %d\n"
157                      "    least qunit: %lu\n",
158                      pool->qpi_key & 0x0000ffff,
159                      RES_NAME(pool->qpi_key >> 16),
160                      cfs_atomic_read(&pool->qpi_ref),
161                      pool->qpi_least_qunit);
162
163
164         for (type = 0; type < MAXQUOTAS; type++)
165                 i += snprintf(page + i, count - i,
166                               "    %s:\n"
167                               "        #slv: %d\n"
168                               "        #lqe: %d\n",
169                               QTYPE_NAME(type),
170                               pool->qpi_slv_nr[type],
171                     cfs_atomic_read(&pool->qpi_site[type]->lqs_hash->hs_count));
172
173         return i;
174 }
175
176 static struct lprocfs_vars lprocfs_quota_qpi_vars[] = {
177         { "info", lprocfs_qpi_rd_state, 0, 0},
178         { NULL }
179 };
180
181 /*
182  * Allocate a new qmt_pool_info structure and add it to the pool hash table
183  * of the qmt.
184  *
185  * \param env       - is the environment passed by the caller
186  * \param qmt       - is the quota master target
187  * \param pool_id   - is the 16-bit pool identifier of the new pool to add
188  * \param pool_type - is the resource type of this pool instance, either
189  *                    LQUOTA_RES_MD or LQUOTA_RES_DT.
190  *
191  * \retval - 0 on success, appropriate error on failure
192  */
193 static int qmt_pool_alloc(const struct lu_env *env, struct qmt_device *qmt,
194                           int pool_id, int pool_type)
195 {
196         struct qmt_thread_info  *qti = qmt_info(env);
197         struct qmt_pool_info    *pool;
198         int                      rc = 0;
199         ENTRY;
200
201         OBD_ALLOC_PTR(pool);
202         if (pool == NULL)
203                 RETURN(-ENOMEM);
204         CFS_INIT_LIST_HEAD(&pool->qpi_linkage);
205
206         /* assign key used by hash functions */
207         pool->qpi_key = pool_id + (pool_type << 16);
208
209         /* initialize refcount to 1, hash table will then grab an additional
210          * reference */
211         atomic_set(&pool->qpi_ref, 1);
212
213         /* set up least qunit size to use for this pool */
214         pool->qpi_least_qunit = LQUOTA_LEAST_QUNIT(pool_type);
215
216         /* create pool proc directory */
217         sprintf(qti->qti_buf, "%s-0x%x", RES_NAME(pool_type), pool_id);
218         pool->qpi_proc = lprocfs_register(qti->qti_buf, qmt->qmt_proc,
219                                           lprocfs_quota_qpi_vars, pool);
220         if (IS_ERR(pool->qpi_proc)) {
221                 rc = PTR_ERR(pool->qpi_proc);
222                 CERROR("%s: failed to create proc entry for pool %s (%d)\n",
223                        qmt->qmt_svname, qti->qti_buf, rc);
224                 pool->qpi_proc = NULL;
225                 GOTO(out, rc);
226         }
227
228         /* grab reference on master target that this pool belongs to */
229         lu_device_get(qmt2lu_dev(qmt));
230         lu_ref_add(&qmt2lu_dev(qmt)->ld_reference, "pool", pool);
231         pool->qpi_qmt = qmt;
232
233         /* add to qmt hash table */
234         rc = cfs_hash_add_unique(qmt->qmt_pool_hash, &pool->qpi_key,
235                                  &pool->qpi_hash);
236         if (rc) {
237                 CERROR("%s: failed to add pool %s to qmt hash (%d)\n",
238                        qmt->qmt_svname, qti->qti_buf, rc);
239                 GOTO(out, rc);
240         }
241
242         /* add to qmt pool list */
243         cfs_list_add_tail(&pool->qpi_linkage, &qmt->qmt_pool_list);
244         EXIT;
245 out:
246         if (rc)
247                 /* this frees the pool structure since refcount is equal to 1 */
248                 qpi_putref(env, pool);
249         return rc;
250 }
251
252 /*
253  * Delete a qmt_pool_info instance and all structures associated.
254  *
255  * \param env  - is the environment passed by the caller
256  * \param pool - is the qmt_pool_info structure to free
257  */
258 static void qmt_pool_free(const struct lu_env *env, struct qmt_pool_info *pool)
259 {
260         int     qtype;
261         ENTRY;
262
263         /* release proc entry */
264         if (pool->qpi_proc) {
265                 lprocfs_remove(&pool->qpi_proc);
266                 pool->qpi_proc = NULL;
267         }
268
269         /* release per-quota type site used to manage quota entries as well as
270          * references to global index files */
271         for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
272                 /* release lqe storing grace time */
273                 if (pool->qpi_grace_lqe[qtype] != NULL)
274                         lqe_putref(pool->qpi_grace_lqe[qtype]);
275
276                 /* release site */
277                 if (pool->qpi_site[qtype] != NULL &&
278                     !IS_ERR(pool->qpi_site[qtype]))
279                         lquota_site_free(env, pool->qpi_site[qtype]);
280                 /* release reference to global index */
281                 if (pool->qpi_glb_obj[qtype] != NULL &&
282                     !IS_ERR(pool->qpi_glb_obj[qtype]))
283                         lu_object_put(env, &pool->qpi_glb_obj[qtype]->do_lu);
284         }
285
286         /* release reference on pool directory */
287         if (pool->qpi_root != NULL && !IS_ERR(pool->qpi_root))
288                 lu_object_put(env, &pool->qpi_root->do_lu);
289
290         /* release reference on the master target */
291         if (pool->qpi_qmt != NULL) {
292                 struct lu_device *ld = qmt2lu_dev(pool->qpi_qmt);
293
294                 lu_device_put(ld);
295                 lu_ref_del(&ld->ld_reference, "pool", pool);
296                 pool->qpi_qmt = NULL;
297         }
298
299         LASSERT(cfs_list_empty(&pool->qpi_linkage));
300         OBD_FREE_PTR(pool);
301 }
302
303 /*
304  * Look-up a pool in the hash table based on the pool ID and type.
305  *
306  * \param env     - is the environment passed by the caller
307  * \param qmt     - is the quota master target
308  * \param pool_id   - is the 16-bit identifier of the pool to look up
309  * \param pool_type - is the type of this pool, either LQUOTA_RES_MD or
310  *                    LQUOTA_RES_DT.
311  */
312 static struct qmt_pool_info *qmt_pool_lookup(const struct lu_env *env,
313                                              struct qmt_device *qmt,
314                                              int pool_id, int pool_type)
315 {
316         struct qmt_pool_info    *pool;
317         __u32                    key;
318         ENTRY;
319
320         LASSERT(qmt->qmt_pool_hash != NULL);
321
322         /* look-up pool in hash table */
323         key = pool_id + (pool_type << 16);
324         pool = cfs_hash_lookup(qmt->qmt_pool_hash, (void *)&key);
325         if (pool == NULL) {
326                 /* this qmt isn't managing this pool! */
327                 CERROR("%s: looking up quota entry for a pool (0x%x/%d) which "
328                        "isn't managed by this quota master target\n",
329                        qmt->qmt_svname, pool_id, pool_type);
330                 RETURN(ERR_PTR(-ENOENT));
331         }
332         RETURN(pool);
333 }
334
335 /*
336  * Functions implementing the pool API, used by the qmt handlers
337  */
338
339 /*
340  * Destroy all pools which are still in the hash table and free the pool
341  * hash table.
342  *
343  * \param env - is the environment passed by the caller
344  * \param qmt - is the quota master target
345  *
346  */
347 void qmt_pool_fini(const struct lu_env *env, struct qmt_device *qmt)
348 {
349         struct qmt_pool_info    *pool;
350         cfs_list_t              *pos, *n;
351         ENTRY;
352
353         if (qmt->qmt_pool_hash == NULL)
354                 RETURN_EXIT;
355
356         /* parse list of pool and destroy each element */
357         cfs_list_for_each_safe(pos, n, &qmt->qmt_pool_list) {
358                 pool = cfs_list_entry(pos, struct qmt_pool_info,
359                                       qpi_linkage);
360                 /* remove from hash */
361                 cfs_hash_del(qmt->qmt_pool_hash, &pool->qpi_key,
362                              &pool->qpi_hash);
363
364                 /* remove from list */
365                 cfs_list_del_init(&pool->qpi_linkage);
366
367                 /* release extra reference taken in qmt_pool_alloc */
368                 qpi_putref(env, pool);
369         }
370         LASSERT(cfs_list_empty(&qmt->qmt_pool_list));
371
372         cfs_hash_putref(qmt->qmt_pool_hash);
373         qmt->qmt_pool_hash = NULL;
374         EXIT;
375 }
376
377 /*
378  * Initialize pool configure for the quota master target. For now, we only
379  * support the default data (i.e. all OSTs) and metadata (i.e. all the MDTs)
380  * pool which are instantiated in this function.
381  *
382  * \param env - is the environment passed by the caller
383  * \param qmt - is the quota master target for which we have to initializa the
384  *              pool configuration
385  *
386  * \retval - 0 on success, appropriate error on failure
387  */
388 int qmt_pool_init(const struct lu_env *env, struct qmt_device *qmt)
389 {
390         int     res, rc = 0;
391         ENTRY;
392
393         /* initialize pool hash table */
394         qmt->qmt_pool_hash = cfs_hash_create("POOL_HASH",
395                                              HASH_POOLS_CUR_BITS,
396                                              HASH_POOLS_MAX_BITS,
397                                              HASH_POOLS_BKT_BITS, 0,
398                                              CFS_HASH_MIN_THETA,
399                                              CFS_HASH_MAX_THETA,
400                                              &qpi_hash_ops,
401                                              CFS_HASH_DEFAULT);
402         if (qmt->qmt_pool_hash == NULL) {
403                 CERROR("%s: failed to create pool hash table\n",
404                        qmt->qmt_svname);
405                 RETURN(-ENOMEM);
406         }
407
408         /* initialize pool list */
409         CFS_INIT_LIST_HEAD(&qmt->qmt_pool_list);
410
411         /* Instantiate pool master for the default data and metadata pool (both
412          * have pool ID equals to 0).
413          * This code will have to be revisited once we support quota on
414          * non-default pools */
415         for (res = LQUOTA_FIRST_RES; res < LQUOTA_LAST_RES; res++) {
416                 rc = qmt_pool_alloc(env, qmt, 0, res);
417                 if (rc)
418                         break;
419         }
420
421         if (rc)
422                 qmt_pool_fini(env, qmt);
423
424         RETURN(rc);
425 }
426
427 static int qmt_slv_cnt(const struct lu_env *env, struct lu_fid *glb_fid,
428                        char *slv_name, struct lu_fid *slv_fid, void *arg)
429 {
430         int *nr = arg;
431
432         /* one more slave */
433         (*nr)++;
434
435         return 0;
436 }
437
438 /*
439  * Set up on-disk index files associated with each pool.
440  *
441  * \param env - is the environment passed by the caller
442  * \param qmt - is the quota master target for which we have to initializa the
443  *              pool configuration
444  * \param qmt_root - is the on-disk directory created for the QMT.
445  *
446  * \retval - 0 on success, appropriate error on failure
447  */
448 int qmt_pool_prepare(const struct lu_env *env, struct qmt_device *qmt,
449                      struct dt_object *qmt_root)
450 {
451         struct qmt_thread_info  *qti = qmt_info(env);
452         struct lquota_glb_rec   *rec = &qti->qti_glb_rec;
453         struct qmt_pool_info    *pool;
454         struct dt_device        *dev = NULL;
455         dt_obj_version_t         version;
456         cfs_list_t              *pos;
457         int                      rc = 0, qtype;
458         ENTRY;
459
460         LASSERT(qmt->qmt_pool_hash != NULL);
461
462         /* iterate over each pool in the hash and allocate a quota site for each
463          * one. This involves creating a global index file on disk */
464         cfs_list_for_each(pos, &qmt->qmt_pool_list) {
465                 struct dt_object        *obj;
466                 int                      pool_type, pool_id;
467                 struct lquota_entry     *lqe;
468
469                 pool = cfs_list_entry(pos, struct qmt_pool_info,
470                                       qpi_linkage);
471
472                 pool_id   = pool->qpi_key & 0x0000ffff;
473                 pool_type = pool->qpi_key >> 16;
474                 if (dev == NULL)
475                         dev = pool->qpi_qmt->qmt_child;
476
477                 /* allocate directory for this pool */
478                 sprintf(qti->qti_buf, "%s-0x%x", RES_NAME(pool_type), pool_id);
479                 obj = lquota_disk_dir_find_create(env, qmt->qmt_child, qmt_root,
480                                                   qti->qti_buf);
481                 if (IS_ERR(obj))
482                         RETURN(PTR_ERR(obj));
483                 pool->qpi_root = obj;
484
485                 for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
486                         /* Generating FID of global index in charge of storing
487                          * settings for this quota type */
488                         lquota_generate_fid(&qti->qti_fid, pool_id, pool_type,
489                                             qtype);
490
491                         /* open/create the global index file for this quota
492                          * type */
493                         obj = lquota_disk_glb_find_create(env, dev,
494                                                           pool->qpi_root,
495                                                           &qti->qti_fid, false);
496                         if (IS_ERR(obj)) {
497                                 rc = PTR_ERR(obj);
498                                 CERROR("%s: failed to create glb index copy for"
499                                        " %s type (%d)\n", qmt->qmt_svname,
500                                        QTYPE_NAME(qtype), rc);
501                                 RETURN(rc);
502                         }
503
504                         pool->qpi_glb_obj[qtype] = obj;
505
506                         version = dt_version_get(env, obj);
507                         /* set default grace time for newly created index */
508                         if (version == 0) {
509                                 rec->qbr_hardlimit = 0;
510                                 rec->qbr_softlimit = 0;
511                                 rec->qbr_granted = 0;
512                                 rec->qbr_time = pool_type == LQUOTA_RES_MD ?
513                                         MAX_IQ_TIME : MAX_DQ_TIME;
514
515                                 rc = lquota_disk_write_glb(env, obj, 0, rec);
516                                 if (rc) {
517                                         CERROR("%s: failed to set default "
518                                                "grace time for %s type (%d)\n",
519                                                qmt->qmt_svname,
520                                                QTYPE_NAME(qtype), rc);
521                                         RETURN(rc);
522                                 }
523
524                                 rc = lquota_disk_update_ver(env, dev, obj, 1);
525                                 if (rc) {
526                                         CERROR("%s: failed to set initial "
527                                                "version for %s type (%d)\n",
528                                                qmt->qmt_svname,
529                                                QTYPE_NAME(qtype), rc);
530                                         RETURN(rc);
531                                 }
532                         }
533
534                         /* create quota entry site for this quota type */
535                         pool->qpi_site[qtype] = lquota_site_alloc(env, pool,
536                                                                   true, qtype,
537                                                                   &qmt_lqe_ops);
538                         if (IS_ERR(pool->qpi_site[qtype])) {
539                                 rc = PTR_ERR(pool->qpi_site[qtype]);
540                                 CERROR("%s: failed to create site for %s type "
541                                        "(%d)\n", qmt->qmt_svname,
542                                        QTYPE_NAME(qtype), rc);
543                                 RETURN(rc);
544                         }
545
546                         /* count number of slaves which already connected to
547                          * the master in the past */
548                         pool->qpi_slv_nr[qtype] = 0;
549                         rc = lquota_disk_for_each_slv(env, pool->qpi_root,
550                                                       &qti->qti_fid,
551                                                       qmt_slv_cnt,
552                                                       &pool->qpi_slv_nr[qtype]);
553                         if (rc) {
554                                 CERROR("%s: failed to scan & count slave "
555                                        "indexes for %s type (%d)\n",
556                                        qmt->qmt_svname, QTYPE_NAME(qtype), rc);
557                                 RETURN(rc);
558                         }
559
560                         /* Global grace time is stored in quota settings of
561                          * ID 0. */
562                         qti->qti_id.qid_uid = 0;
563
564                         /* look-up quota entry storing grace time */
565                         lqe = lqe_locate(env, pool->qpi_site[qtype],
566                                          &qti->qti_id);
567                         if (IS_ERR(lqe))
568                                 RETURN(PTR_ERR(lqe));
569                         pool->qpi_grace_lqe[qtype] = lqe;
570 #ifdef LPROCFS
571                         /* add procfs file to dump the global index, mostly for
572                          * debugging purpose */
573                         sprintf(qti->qti_buf, "glb-%s", QTYPE_NAME(qtype));
574                         rc = lprocfs_seq_create(pool->qpi_proc, qti->qti_buf,
575                                                 0444, &lprocfs_quota_seq_fops,
576                                                 obj);
577                         if (rc)
578                                 CWARN("%s: Error adding procfs file for global"
579                                       "quota index "DFID", rc:%d\n",
580                                       qmt->qmt_svname, PFID(&qti->qti_fid), rc);
581 #endif
582                 }
583         }
584
585         RETURN(0);
586 }
587
588 /*
589  * Handle new slave connection. Called when a slave enqueues the global quota
590  * lock at the beginning of the reintegration procedure.
591  *
592  * \param env - is the environment passed by the caller
593  * \parap qmt - is the quota master target handling this request
594  * \param glb_fid - is the fid of the global index file
595  * \param slv_fid - is the fid of the newly created slave index file
596  * \param slv_ver - is the current version of the slave index file
597  * \param uuid    - is the uuid of slave which is (re)connecting to the master
598  *                  target
599  *
600  * \retval - 0 on success, appropriate error on failure
601  */
602 int qmt_pool_new_conn(const struct lu_env *env, struct qmt_device *qmt,
603                       struct lu_fid *glb_fid, struct lu_fid *slv_fid,
604                       __u64 *slv_ver, struct obd_uuid *uuid)
605 {
606         struct qmt_pool_info    *pool;
607         struct dt_object        *slv_obj;
608         int                      pool_id, pool_type, qtype;
609         bool                     created = false;
610         int                      rc = 0;
611
612         /* extract pool info from global index FID */
613         rc = lquota_extract_fid(glb_fid, &pool_id, &pool_type, &qtype);
614         if (rc)
615                 RETURN(rc);
616
617         /* look-up pool in charge of this global index FID */
618         pool = qmt_pool_lookup(env, qmt, pool_id, pool_type);
619         if (IS_ERR(pool))
620                 RETURN(PTR_ERR(pool));
621
622         /* look-up slave index file */
623         slv_obj = lquota_disk_slv_find(env, qmt->qmt_child, pool->qpi_root,
624                                        glb_fid, uuid);
625         if (IS_ERR(slv_obj) && PTR_ERR(slv_obj) == -ENOENT) {
626                 /* create slave index file */
627                 slv_obj = lquota_disk_slv_find_create(env, qmt->qmt_child,
628                                                       pool->qpi_root, glb_fid,
629                                                       uuid, false);
630                 created = true;
631         }
632         if (IS_ERR(slv_obj)) {
633                 rc = PTR_ERR(slv_obj);
634                 CERROR("%s: failed to create quota slave index file for %s (%d)"
635                        "\n", qmt->qmt_svname, obd_uuid2str(uuid), rc);
636                 GOTO(out, rc);
637         }
638
639         /* retrieve slave fid & current object version */
640         memcpy(slv_fid, lu_object_fid(&slv_obj->do_lu), sizeof(*slv_fid));
641         *slv_ver = dt_version_get(env, slv_obj);
642         lu_object_put(env, &slv_obj->do_lu);
643         if (created)
644                 pool->qpi_slv_nr[qtype]++;
645 out:
646         qpi_putref(env, pool);
647         RETURN(rc);
648 }
649
650 /*
651  * Look-up a lquota_entry in the pool hash and allocate it if not found.
652  *
653  * \param env - is the environment passed by the caller
654  * \param qmt - is the quota master target for which we have to initializa the
655  *              pool configuration
656  * \param pool_id   - is the 16-bit identifier of the pool
657  * \param pool_type - is the pool type, either LQUOTA_RES_MD or LQUOTA_RES_DT.
658  * \param qtype     - is the quota type, either user or group.
659  * \param qid       - is the quota ID to look-up
660  *
661  * \retval - valid pointer to lquota entry on success, appropriate error on
662  *           failure
663  */
664 struct lquota_entry *qmt_pool_lqe_lookup(const struct lu_env *env,
665                                          struct qmt_device *qmt,
666                                          int pool_id, int pool_type,
667                                          int qtype, union lquota_id *qid)
668 {
669         struct qmt_pool_info    *pool;
670         struct lquota_entry     *lqe;
671         ENTRY;
672
673         /* look-up pool responsible for this global index FID */
674         pool = qmt_pool_lookup(env, qmt, pool_id, pool_type);
675         if (IS_ERR(pool))
676                 RETURN((void *)pool);
677
678         if (qid->qid_uid == 0) {
679                 /* caller wants to access grace time, no need to look up the
680                  * entry since we keep a reference on ID 0 all the time */
681                 lqe = pool->qpi_grace_lqe[qtype];
682                 lqe_getref(lqe);
683                 GOTO(out, lqe);
684         }
685
686         /* now that we have the pool, let's look-up the quota entry in the
687          * right quota site */
688         lqe = lqe_locate(env, pool->qpi_site[qtype], qid);
689 out:
690         qpi_putref(env, pool);
691         RETURN(lqe);
692 }