4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
24 * Copyright (c) 2012, 2017, Intel Corporation.
25 * Use is subject to license terms.
27 * Author: Johann Lombardi <johann.lombardi@intel.com>
28 * Author: Niu Yawei <yawei.niu@intel.com>
32 * A Quota Master Target has a list(qmt_pool_list) where it stores qmt_pool_info
33 * structures. There is one such structure for each pool managed by the QMT.
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.
41 * The pool API exported here is the following:
42 * - qmt_pool_init(): initializes the general QMT structures used to manage
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
51 #define DEBUG_SUBSYSTEM S_LQUOTA
53 #include <obd_class.h>
54 #include <lprocfs_status.h>
55 #include "qmt_internal.h"
57 static inline int qmt_sarr_pool_init(struct qmt_pool_info *qpi);
58 static inline int qmt_sarr_pool_add(struct qmt_pool_info *qpi,
60 static inline int qmt_sarr_pool_rem(struct qmt_pool_info *qpi, int idx);
61 static inline int qmt_sarr_pool_free(struct qmt_pool_info *qpi);
62 static inline int qmt_sarr_check_idx(struct qmt_pool_info *qpi, int idx);
63 static inline void qmt_stop_pool_recalc(struct qmt_pool_info *qpi);
66 * Static helper functions not used outside the scope of this file
69 static inline void qpi_putref_locked(struct qmt_pool_info *pool)
71 LASSERT(atomic_read(&pool->qpi_ref) > 1);
72 atomic_dec(&pool->qpi_ref);
75 /* some procfs helpers */
76 static int qpi_state_seq_show(struct seq_file *m, void *data)
78 struct qmt_pool_info *pool = m->private;
81 LASSERT(pool != NULL);
83 seq_printf(m, "pool:\n"
87 " least qunit: %lu\n",
89 RES_NAME(pool->qpi_rtype),
90 atomic_read(&pool->qpi_ref),
91 pool->qpi_least_qunit);
93 for (type = 0; type < LL_MAXQUOTAS; type++)
94 seq_printf(m, " %s:\n"
98 qpi_slv_nr(pool, type),
99 atomic_read(&pool->qpi_site[type]->lqs_hash->hs_count));
103 LPROC_SEQ_FOPS_RO(qpi_state);
105 static int qpi_soft_least_qunit_seq_show(struct seq_file *m, void *data)
107 struct qmt_pool_info *pool = m->private;
108 LASSERT(pool != NULL);
110 seq_printf(m, "%lu\n", pool->qpi_soft_least_qunit);
115 qpi_soft_least_qunit_seq_write(struct file *file, const char __user *buffer,
116 size_t count, loff_t *off)
118 struct seq_file *m = file->private_data;
119 struct qmt_pool_info *pool = m->private;
120 long long least_qunit;
123 LASSERT(pool != NULL);
125 /* Not tuneable for inode limit */
126 if (pool->qpi_rtype != LQUOTA_RES_DT)
129 rc = kstrtoll_from_user(buffer, count, 0, &least_qunit);
133 /* Miminal qpi_soft_least_qunit */
134 qunit = pool->qpi_least_qunit << 2;
135 /* The value must be power of miminal qpi_soft_least_qunit, see
136 * how the qunit is adjusted in qmt_adjust_qunit(). */
137 while (qunit > 0 && qunit < least_qunit)
140 qunit = INT_MAX & ~3;
142 pool->qpi_soft_least_qunit = qunit;
145 LPROC_SEQ_FOPS(qpi_soft_least_qunit);
147 static struct lprocfs_vars lprocfs_quota_qpi_vars[] = {
149 .fops = &qpi_state_fops },
150 { .name = "soft_least_qunit",
151 .fops = &qpi_soft_least_qunit_fops },
156 * Allocate a new qmt_pool_info structure and add it to qmt_pool_list.
158 * \param env - is the environment passed by the caller
159 * \param qmt - is the quota master target
160 * \param pool_type - is the resource type of this pool instance, either
161 * LQUOTA_RES_MD or LQUOTA_RES_DT.
163 * \retval - 0 on success, appropriate error on failure
165 static int qmt_pool_alloc(const struct lu_env *env, struct qmt_device *qmt,
166 char *pool_name, int pool_type)
168 struct qmt_thread_info *qti = qmt_info(env);
169 struct qmt_pool_info *pool;
176 INIT_LIST_HEAD(&pool->qpi_linkage);
177 init_rwsem(&pool->qpi_recalc_sem);
179 pool->qpi_rtype = pool_type;
181 /* initialize refcount to 1, hash table will then grab an additional
183 atomic_set(&pool->qpi_ref, 1);
185 /* set up least qunit size to use for this pool */
186 pool->qpi_least_qunit = LQUOTA_LEAST_QUNIT(pool_type);
187 if (pool_type == LQUOTA_RES_DT)
188 pool->qpi_soft_least_qunit = pool->qpi_least_qunit << 2;
190 pool->qpi_soft_least_qunit = pool->qpi_least_qunit;
192 /* grab reference on master target that this pool belongs to */
193 lu_device_get(qmt2lu_dev(qmt));
194 lu_ref_add(&qmt2lu_dev(qmt)->ld_reference, "pool", pool);
197 /* create pool proc directory */
198 snprintf(qti->qti_buf, LQUOTA_NAME_MAX, "%s-%s",
199 RES_NAME(pool_type), pool_name);
200 strncpy(pool->qpi_name, pool_name, QPI_MAXNAME);
201 pool->qpi_proc = lprocfs_register(qti->qti_buf, qmt->qmt_proc,
202 lprocfs_quota_qpi_vars, pool);
203 if (IS_ERR(pool->qpi_proc)) {
204 rc = PTR_ERR(pool->qpi_proc);
205 CERROR("%s: failed to create proc entry for pool %s (%d)\n",
206 qmt->qmt_svname, qti->qti_buf, rc);
207 pool->qpi_proc = NULL;
211 rc = qmt_sarr_pool_init(pool);
215 /* add to qmt pool list */
216 down_write(&qmt->qmt_pool_lock);
217 list_add_tail(&pool->qpi_linkage, &qmt->qmt_pool_list);
218 up_write(&qmt->qmt_pool_lock);
222 /* this frees the pool structure since refcount is equal to 1 */
223 qpi_putref(env, pool);
228 * Delete a qmt_pool_info instance and all structures associated.
230 * \param env - is the environment passed by the caller
231 * \param pool - is the qmt_pool_info structure to free
233 void qmt_pool_free(const struct lu_env *env, struct qmt_pool_info *pool)
235 struct qmt_device *qmt = pool->qpi_qmt;
239 /* remove from list */
240 down_write(&qmt->qmt_pool_lock);
241 list_del_init(&pool->qpi_linkage);
242 up_write(&qmt->qmt_pool_lock);
244 if (atomic_read(&pool->qpi_ref) > 0)
247 qmt_stop_pool_recalc(pool);
248 qmt_sarr_pool_free(pool);
250 /* release proc entry */
251 if (pool->qpi_proc) {
252 lprocfs_remove(&pool->qpi_proc);
253 pool->qpi_proc = NULL;
256 /* release per-quota type site used to manage quota entries as well as
257 * references to global index files */
258 for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
259 /* release lqe storing grace time */
260 if (pool->qpi_grace_lqe[qtype] != NULL)
261 lqe_putref(pool->qpi_grace_lqe[qtype]);
264 if (pool->qpi_site[qtype] != NULL &&
265 !IS_ERR(pool->qpi_site[qtype]))
266 lquota_site_free(env, pool->qpi_site[qtype]);
267 /* release reference to global index */
268 if (pool->qpi_glb_obj[qtype] != NULL &&
269 !IS_ERR(pool->qpi_glb_obj[qtype]))
270 dt_object_put(env, pool->qpi_glb_obj[qtype]);
273 /* release reference on pool directory */
274 if (pool->qpi_root != NULL && !IS_ERR(pool->qpi_root))
275 dt_object_put(env, pool->qpi_root);
277 /* release reference on the master target */
278 if (pool->qpi_qmt != NULL) {
279 struct lu_device *ld = qmt2lu_dev(pool->qpi_qmt);
281 lu_ref_del(&ld->ld_reference, "pool", pool);
283 pool->qpi_qmt = NULL;
286 LASSERT(list_empty(&pool->qpi_linkage));
290 static inline void qti_pools_init(const struct lu_env *env)
292 struct qmt_thread_info *qti = qmt_info(env);
294 qti->qti_pools_cnt = 0;
295 qti->qti_pools_num = QMT_MAX_POOL_NUM;
298 #define qti_pools(qti) (qti->qti_pools_num > QMT_MAX_POOL_NUM ? \
299 qti->qti_pools : qti->qti_pools_small)
300 #define qti_pools_env(env) \
301 (qmt_info(env)->qti_pools_num > QMT_MAX_POOL_NUM ? \
302 qmt_info(env)->qti_pools : qmt_info(env)->qti_pools_small)
303 #define qti_pools_cnt(env) (qmt_info(env)->qti_pools_cnt)
305 static inline int qti_pools_add(const struct lu_env *env,
306 struct qmt_pool_info *qpi)
308 struct qmt_thread_info *qti = qmt_info(env);
309 struct qmt_pool_info **pools = qti->qti_pools;
311 pools = qti_pools(qti);
312 LASSERTF(qti->qti_pools_num >= QMT_MAX_POOL_NUM,
313 "Forgot init? %p\n", qti);
315 if (qti->qti_pools_cnt > qti->qti_pools_num) {
316 OBD_ALLOC(pools, sizeof(qpi) * qti->qti_pools_num * 2);
319 memcpy(pools, qti_pools(qti), qti->qti_pools_cnt * sizeof(qpi));
320 /* Don't need to free, if it is the very 1st allocation */
321 if (qti->qti_pools_num > QMT_MAX_POOL_NUM)
322 OBD_FREE(qti->qti_pools,
323 qti->qti_pools_num * sizeof(qpi));
324 qti->qti_pools = pools;
325 qti->qti_pools_num *= 2;
329 /* Take this to protect pool's lqes against changing by
330 * recalculation thread. This would be unlocked at
332 down_read(&qpi->qpi_recalc_sem);
333 if (qmt_pool_global(qpi) && qti_pools_cnt(env) > 0) {
334 pools[qti->qti_pools_cnt++] = pools[0];
335 /* Store global pool always at index 0 */
338 pools[qti->qti_pools_cnt++] = qpi;
341 CDEBUG(D_QUOTA, "Pool %s is added, pools %p qti_pools %p pool_num %d\n",
342 qpi->qpi_name, pools, qti->qti_pools, qti->qti_pools_cnt);
347 static inline void qti_pools_fini(const struct lu_env *env)
349 struct qmt_thread_info *qti = qmt_info(env);
350 struct qmt_pool_info **pools = qti->qti_pools;
353 LASSERT(qti->qti_pools_cnt > 0);
355 pools = qti_pools(qti);
356 for (i = 0; i < qti->qti_pools_cnt; i++) {
357 up_read(&pools[i]->qpi_recalc_sem);
358 qpi_putref(env, pools[i]);
361 if (qti->qti_pools_num > QMT_MAX_POOL_NUM)
362 OBD_FREE(qti->qti_pools,
363 qti->qti_pools_num * sizeof(struct qmt_pool_info *));
367 * Look-up a pool in a list based on the type.
369 * \param env - is the environment passed by the caller
370 * \param qmt - is the quota master target
371 * \param rtype - is the type of this pool, either LQUOTA_RES_MD or
373 * \param pool_name - is the pool name to search for
374 * \param idx - OST or MDT index to search for. When it is >= 0, function
375 * returns array with pointers to all pools that include
376 * targets with requested index.
377 * \param add - add to qti_pool_arr if true
379 struct qmt_pool_info *qmt_pool_lookup(const struct lu_env *env,
380 struct qmt_device *qmt,
385 struct qmt_pool_info *pos, *pool;
389 down_read(&qmt->qmt_pool_lock);
390 if (list_empty(&qmt->qmt_pool_list)) {
391 up_read(&qmt->qmt_pool_lock);
392 RETURN(ERR_PTR(-ENOENT));
395 CDEBUG(D_QUOTA, "type %d name %p index %d\n",
396 rtype, pool_name, idx);
397 /* Now just find a pool with correct type in a list. Further we need
398 * to go through the list and find a pool that includes requested OST
399 * or MDT. Possibly this would return a list of pools that includes
400 * needed target(OST/MDT). */
402 if (idx == -1 && !pool_name)
403 pool_name = GLB_POOL_NAME;
405 list_for_each_entry(pos, &qmt->qmt_pool_list, qpi_linkage) {
406 if (pos->qpi_rtype != rtype)
409 if (idx >= 0 && !qmt_sarr_check_idx(pos, idx)) {
410 rc = qti_pools_add(env, pos);
416 if (pool_name && !strncmp(pool_name, pos->qpi_name,
420 rc = qti_pools_add(env, pos);
429 up_read(&qmt->qmt_pool_lock);
431 if (idx >= 0 && qti_pools_cnt(env))
432 pool = qti_pools_env(env)[0];
434 RETURN(pool ? : ERR_PTR(-ENOENT));
436 CERROR("%s: cannot add pool %s: err = %d\n",
437 qmt->qmt_svname, pos->qpi_name, rc);
442 * Functions implementing the pool API, used by the qmt handlers
446 * Destroy all pools which are still in the pool list.
448 * \param env - is the environment passed by the caller
449 * \param qmt - is the quota master target
452 void qmt_pool_fini(const struct lu_env *env, struct qmt_device *qmt)
454 struct qmt_pool_info *pool, *tmp;
457 /* parse list of pool and destroy each element */
458 list_for_each_entry_safe(pool, tmp, &qmt->qmt_pool_list, qpi_linkage) {
459 /* release extra reference taken in qmt_pool_alloc */
460 qpi_putref(env, pool);
462 LASSERT(list_empty(&qmt->qmt_pool_list));
468 * Initialize pool configure for the quota master target. For now, we only
469 * support the default data (i.e. all OSTs) and metadata (i.e. all the MDTs)
470 * pool which are instantiated in this function.
472 * \param env - is the environment passed by the caller
473 * \param qmt - is the quota master target for which we have to initialize the
476 * \retval - 0 on success, appropriate error on failure
478 int qmt_pool_init(const struct lu_env *env, struct qmt_device *qmt)
483 INIT_LIST_HEAD(&qmt->qmt_pool_list);
484 init_rwsem(&qmt->qmt_pool_lock);
486 /* Instantiate pool master for the default data and metadata pool.
487 * This code will have to be revisited once we support quota on
488 * non-default pools */
489 for (res = LQUOTA_FIRST_RES; res < LQUOTA_LAST_RES; res++) {
490 rc = qmt_pool_alloc(env, qmt, GLB_POOL_NAME, res);
496 qmt_pool_fini(env, qmt);
501 static int qmt_slv_cnt(const struct lu_env *env, struct lu_fid *glb_fid,
502 char *slv_name, struct lu_fid *slv_fid, void *arg)
504 struct obd_uuid uuid;
505 int (*nr)[QMT_STYPE_CNT][LL_MAXQUOTAS] = arg;
509 rc = lquota_extract_fid(glb_fid, NULL, &qtype);
512 obd_str2uuid(&uuid, slv_name);
513 stype = qmt_uuid2idx(&uuid, NULL);
517 (*nr)[stype][qtype]++;
518 CDEBUG(D_QUOTA, "slv_name %s stype %d qtype %d nr %d\n",
519 slv_name, stype, qtype, (*nr)[stype][qtype]);
525 * Set up on-disk index files associated with each pool.
527 * \param env - is the environment passed by the caller
528 * \param qmt - is the quota master target for which we have to initialize the
530 * \param qmt_root - is the on-disk directory created for the QMT.
531 * \param name - is the pool name that we need to setup. Setup all pools
532 * in qmt_pool_list when name is NULL.
534 * \retval - 0 on success, appropriate error on failure
536 int qmt_pool_prepare(const struct lu_env *env, struct qmt_device *qmt,
537 struct dt_object *qmt_root, char *name)
539 struct qmt_thread_info *qti = qmt_info(env);
540 struct lquota_glb_rec *rec = &qti->qti_glb_rec;
541 struct qmt_pool_info *pool;
542 struct dt_device *dev = NULL;
543 dt_obj_version_t version;
544 struct list_head *pos;
545 int rc = 0, i, qtype;
548 /* iterate over each pool in the list and allocate a quota site for each
549 * one. This involves creating a global index file on disk */
550 list_for_each(pos, &qmt->qmt_pool_list) {
551 struct dt_object *obj;
552 struct lquota_entry *lqe;
556 pool = list_entry(pos, struct qmt_pool_info,
559 pool_name = pool->qpi_name;
560 if (name && strncmp(pool_name, name, LOV_MAXPOOLNAME))
562 rtype = pool->qpi_rtype;
564 dev = pool->qpi_qmt->qmt_child;
566 /* allocate directory for this pool */
567 snprintf(qti->qti_buf, LQUOTA_NAME_MAX, "%s-%s",
568 RES_NAME(rtype), pool_name);
569 obj = lquota_disk_dir_find_create(env, qmt->qmt_child, qmt_root,
572 RETURN(PTR_ERR(obj));
573 pool->qpi_root = obj;
575 for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
576 /* Generating FID of global index in charge of storing
577 * settings for this quota type */
578 lquota_generate_fid(&qti->qti_fid, rtype, qtype);
580 /* open/create the global index file for this quota
581 * type. If name is set, it means we came here from
582 * qmt_pool_new and can create glb index with a
583 * local generated FID. */
584 obj = lquota_disk_glb_find_create(env, dev,
587 name ? true : false);
590 CERROR("%s: failed to create glb index copy for %s type: rc = %d\n",
591 qmt->qmt_svname, qtype_name(qtype), rc);
595 pool->qpi_glb_obj[qtype] = obj;
597 version = dt_version_get(env, obj);
598 /* set default grace time for newly created index */
600 rec->qbr_hardlimit = 0;
601 rec->qbr_softlimit = 0;
602 rec->qbr_granted = 0;
603 rec->qbr_time = rtype == LQUOTA_RES_MD ?
604 MAX_IQ_TIME : MAX_DQ_TIME;
606 rc = lquota_disk_write_glb(env, obj, 0, rec);
608 CERROR("%s: failed to set default grace time for %s type: rc = %d\n",
609 qmt->qmt_svname, qtype_name(qtype), rc);
613 rc = lquota_disk_update_ver(env, dev, obj, 1);
615 CERROR("%s: failed to set initial version for %s type: rc = %d\n",
616 qmt->qmt_svname, qtype_name(qtype), rc);
621 /* create quota entry site for this quota type */
622 pool->qpi_site[qtype] = lquota_site_alloc(env, pool,
625 if (IS_ERR(pool->qpi_site[qtype])) {
626 rc = PTR_ERR(pool->qpi_site[qtype]);
627 CERROR("%s: failed to create site for %s type: rc = %d\n",
628 qmt->qmt_svname, qtype_name(qtype), rc);
632 /* count number of slaves which already connected to
633 * the master in the past */
634 for (i = 0; i < QMT_STYPE_CNT; i++)
635 pool->qpi_slv_nr[i][qtype] = 0;
637 rc = lquota_disk_for_each_slv(env, pool->qpi_root,
642 CERROR("%s: failed to scan & count slave indexes for %s type: rc = %d\n",
643 qmt->qmt_svname, qtype_name(qtype), rc);
647 /* Global grace time is stored in quota settings of
649 qti->qti_id.qid_uid = 0;
651 /* look-up quota entry storing grace time */
652 lqe = lqe_locate(env, pool->qpi_site[qtype],
655 RETURN(PTR_ERR(lqe));
656 pool->qpi_grace_lqe[qtype] = lqe;
657 #ifdef CONFIG_PROC_FS
658 /* add procfs file to dump the global index, mostly for
659 * debugging purpose */
660 snprintf(qti->qti_buf, MTI_NAME_MAXLEN,
661 "glb-%s", qtype_name(qtype));
662 rc = lprocfs_seq_create(pool->qpi_proc, qti->qti_buf,
663 0444, &lprocfs_quota_seq_fops,
666 CWARN("%s: Error adding procfs file for global quota index "DFID": rc = %d\n",
667 qmt->qmt_svname, PFID(&qti->qti_fid), rc);
678 * Handle new slave connection. Called when a slave enqueues the global quota
679 * lock at the beginning of the reintegration procedure.
681 * \param env - is the environment passed by the caller
682 * \parap qmt - is the quota master target handling this request
683 * \param glb_fid - is the fid of the global index file
684 * \param slv_fid - is the fid of the newly created slave index file
685 * \param slv_ver - is the current version of the slave index file
686 * \param uuid - is the uuid of slave which is (re)connecting to the master
689 * \retval - 0 on success, appropriate error on failure
691 int qmt_pool_new_conn(const struct lu_env *env, struct qmt_device *qmt,
692 struct lu_fid *glb_fid, struct lu_fid *slv_fid,
693 __u64 *slv_ver, struct obd_uuid *uuid)
695 struct qmt_pool_info *pool;
696 struct dt_object *slv_obj;
697 int pool_type, qtype, stype;
698 bool created = false;
701 stype = qmt_uuid2idx(uuid, &idx);
705 /* extract pool info from global index FID */
706 rc = lquota_extract_fid(glb_fid, &pool_type, &qtype);
710 /* look-up pool in charge of this global index FID */
712 pool = qmt_pool_lookup_arr(env, qmt, pool_type, idx);
714 RETURN(PTR_ERR(pool));
716 /* look-up slave index file */
717 slv_obj = lquota_disk_slv_find(env, qmt->qmt_child, pool->qpi_root,
719 if (IS_ERR(slv_obj) && PTR_ERR(slv_obj) == -ENOENT) {
720 /* create slave index file */
721 slv_obj = lquota_disk_slv_find_create(env, qmt->qmt_child,
722 pool->qpi_root, glb_fid,
726 if (IS_ERR(slv_obj)) {
727 rc = PTR_ERR(slv_obj);
728 CERROR("%s: failed to create quota slave index file for %s (%d)"
729 "\n", qmt->qmt_svname, obd_uuid2str(uuid), rc);
733 /* retrieve slave fid & current object version */
734 memcpy(slv_fid, lu_object_fid(&slv_obj->do_lu), sizeof(*slv_fid));
735 *slv_ver = dt_version_get(env, slv_obj);
736 dt_object_put(env, slv_obj);
738 for (i = 0; i < qti_pools_cnt(env); i++)
739 qti_pools_env(env)[i]->qpi_slv_nr[stype][qtype]++;
746 * Look-up a lquota_entry in the pool hash and allocate it if not found.
748 * \param env - is the environment passed by the caller
749 * \param qmt - is the quota master target for which we have to initialize the
751 * \param pool_type - is the pool type, either LQUOTA_RES_MD or LQUOTA_RES_DT.
752 * \param qtype - is the quota type, either user or group.
753 * \param qid - is the quota ID to look-up
755 * \retval - valid pointer to lquota entry on success, appropriate error on
758 struct lquota_entry *qmt_pool_lqe_lookup(const struct lu_env *env,
759 struct qmt_device *qmt,
760 int pool_type, int qtype,
761 union lquota_id *qid,
764 struct qmt_pool_info *pool;
765 struct lquota_entry *lqe;
768 /* look-up pool responsible for this global index FID */
769 pool = qmt_pool_lookup_name(env, qmt, pool_type, pool_name);
771 RETURN(ERR_CAST(pool));
773 if (qid->qid_uid == 0) {
774 /* caller wants to access grace time, no need to look up the
775 * entry since we keep a reference on ID 0 all the time */
776 lqe = pool->qpi_grace_lqe[qtype];
781 /* now that we have the pool, let's look-up the quota entry in the
782 * right quota site */
783 lqe = lqe_locate(env, pool->qpi_site[qtype], qid);
785 qpi_putref(env, pool);
789 int qmt_pool_lqes_lookup(const struct lu_env *env,
790 struct qmt_device *qmt,
791 int rtype, int stype,
792 int qtype, union lquota_id *qid,
793 char *pool_name, int idx)
795 struct qmt_pool_info *pool;
796 struct lquota_entry *lqe;
800 /* Until MDT pools are not emplemented, all MDTs belong to
801 * global pool, thus lookup lqes only from global pool. */
802 if (rtype == LQUOTA_RES_DT && stype == QMT_STYPE_MDT)
807 /* look-up pool responsible for this global index FID */
808 pool = qmt_pool_lookup_arr(env, qmt, rtype, idx);
811 RETURN(PTR_ERR(pool));
814 /* now that we have the pool, let's look-up the quota entry in the
815 * right quota site */
817 for (i = 0; i < qti_pools_cnt(env); i++) {
818 pool = qti_pools_env(env)[i];
819 lqe = lqe_locate(env, pool->qpi_site[qtype], qid);
822 GOTO(out, rc = PTR_ERR(lqe));
824 /* Only release could be done for not enforced lqe
825 * (see qmt_dqacq0). However slave could request to
826 * release more than not global lqe had granted before
827 * lqe_enforced was cleared. It is legal case,
828 * because even if current lqe is not enforced,
829 * lqes from other pools are still active and avilable
830 * for acquiring. Furthermore, skip not enforced lqe
831 * to don't make extra allocations. */
832 /*if (!lqe_is_glbl(lqe) && !lqe->lqe_enforced) {
836 qti_lqes_add(env, lqe);
838 LASSERT(qti_lqes_glbl(env)->lqe_is_global);
845 static int lqes_cmp(const void *arg1, const void *arg2)
847 const struct lquota_entry *lqe1, *lqe2;
850 return lqe1->lqe_qunit > lqe2->lqe_qunit;
853 void qmt_lqes_sort(const struct lu_env *env)
855 sort(qti_lqes(env), qti_lqes_cnt(env), sizeof(void *), lqes_cmp, NULL);
856 /* global lqe was moved during sorting */
857 if (!qti_lqes_glbl(env)->lqe_is_global) {
859 for (i = 0; i < qti_lqes_cnt(env); i++) {
860 if (qti_lqes(env)[i]->lqe_is_global) {
861 qti_glbl_lqe_idx(env) = i;
868 int qmt_pool_lqes_lookup_spec(const struct lu_env *env, struct qmt_device *qmt,
869 int rtype, int qtype, union lquota_id *qid)
871 struct qmt_pool_info *pos;
872 struct lquota_entry *lqe;
876 down_read(&qmt->qmt_pool_lock);
877 if (list_empty(&qmt->qmt_pool_list)) {
878 up_read(&qmt->qmt_pool_lock);
882 list_for_each_entry(pos, &qmt->qmt_pool_list, qpi_linkage) {
883 if (pos->qpi_rtype != rtype)
885 /* Don't take into account pools without slaves */
886 if (!qpi_slv_nr(pos, qtype))
888 lqe = lqe_find(env, pos->qpi_site[qtype], qid);
889 /* ENOENT is valid case for lqe from non global pool
890 * that hasn't limits, i.e. not enforced. Continue even
891 * in case of error - we can handle already found lqes */
892 if (IS_ERR_OR_NULL(lqe)) {
893 /* let know that something went wrong */
894 rc = lqe ? PTR_ERR(lqe) : -ENOENT;
897 if (!lqe->lqe_enforced) {
898 /* no settings for this qid_uid */
902 qti_lqes_add(env, lqe);
903 CDEBUG(D_QUOTA, "adding lqe %p from pool %s\n",
906 up_read(&qmt->qmt_pool_lock);
911 * Allocate a new pool for the specified device.
913 * Allocate a new pool_desc structure for the specified \a new_pool
914 * device to create a pool with the given \a poolname. The new pool
915 * structure is created with a single reference, and is freed when the
916 * reference count drops to zero.
918 * \param[in] obd Lustre OBD device on which to add a pool iterator
919 * \param[in] poolname the name of the pool to be created
921 * \retval 0 in case of success
922 * \retval negative error code in case of error
924 int qmt_pool_new(struct obd_device *obd, char *poolname)
926 struct qmt_device *qmt = lu2qmt_dev(obd->obd_lu_dev);
927 struct qmt_pool_info *qpi;
932 if (strnlen(poolname, LOV_MAXPOOLNAME + 1) > LOV_MAXPOOLNAME)
933 RETURN(-ENAMETOOLONG);
935 rc = lu_env_init(&env, LCT_MD_THREAD);
937 CERROR("%s: can't init env: rc = %d\n", obd->obd_name, rc);
941 qpi = qmt_pool_lookup_name(&env, qmt, LQUOTA_RES_DT, poolname);
943 /* Valid case when several MDTs are mounted
944 * at the same node. */
945 CDEBUG(D_QUOTA, "pool %s already exists\n", poolname);
946 qpi_putref(&env, qpi);
947 GOTO(out_env, rc = -EEXIST);
949 if (PTR_ERR(qpi) != -ENOENT) {
950 CWARN("%s: pool %s lookup failed: rc = %ld\n",
951 obd->obd_name, poolname, PTR_ERR(qpi));
952 GOTO(out_env, rc = PTR_ERR(qpi));
955 /* Now allocate and prepare only DATA pool.
956 * Further when MDT pools will be ready we need to add
957 * a cycle here and setup pools of both types. Another
958 * approach is to find out pool of which type should be
960 rc = qmt_pool_alloc(&env, qmt, poolname, LQUOTA_RES_DT);
962 CERROR("%s: can't alloc pool %s: rc = %d\n",
963 obd->obd_name, poolname, rc);
967 rc = qmt_pool_prepare(&env, qmt, qmt->qmt_root, poolname);
969 CERROR("%s: can't prepare pool for %s: rc = %d\n",
970 obd->obd_name, poolname, rc);
974 CDEBUG(D_QUOTA, "Quota pool "LOV_POOLNAMEF" added\n",
979 qpi = qmt_pool_lookup_name(&env, qmt, LQUOTA_RES_DT, poolname);
981 qpi_putref(&env, qpi);
982 qpi_putref(&env, qpi);
990 qmt_obj_recalc(const struct lu_env *env, struct dt_object *obj,
991 struct lquota_site *site)
993 struct qmt_thread_info *qti = qmt_info(env);
994 union lquota_id *qid = &qti->qti_id;
995 const struct dt_it_ops *iops;
1002 iops = &obj->do_index_ops->dio_it;
1004 it = iops->init(env, obj, 0);
1006 CWARN("quota: initialize it for "DFID" failed: rc = %ld\n",
1007 PFID(&qti->qti_fid), PTR_ERR(it));
1008 RETURN(PTR_ERR(it));
1011 rc = iops->load(env, it, 0);
1013 CWARN("quota: load first entry for "DFID" failed: rc = %d\n",
1014 PFID(&qti->qti_fid), rc);
1016 } else if (rc == 0) {
1017 rc = iops->next(env, it);
1019 GOTO(out, rc = (rc < 0) ? rc : 0);
1023 struct lquota_entry *lqe;
1025 key = iops->key(env, it);
1027 CWARN("quota: error key for "DFID": rc = %ld\n",
1028 PFID(&qti->qti_fid), PTR_ERR(key));
1029 GOTO(out, rc = PTR_ERR(key));
1032 /* skip the root user/group */
1033 if (*((__u64 *)key) == 0)
1036 qid->qid_uid = *((__u64 *)key);
1038 rc = qmt_slv_read(env, qid, obj, &granted);
1042 lqe = lqe_locate(env, site, qid);
1044 GOTO(out, rc = PTR_ERR(lqe));
1045 lqe_write_lock(lqe);
1046 lqe->lqe_recalc_granted += granted;
1047 lqe_write_unlock(lqe);
1050 rc = iops->next(env, it);
1052 CWARN("quota: failed to parse index "DFID
1053 ", ->next error: rc = %d\n",
1054 PFID(&qti->qti_fid), rc);
1055 } while (rc == 0 && !kthread_should_stop());
1059 iops->fini(env, it);
1063 static int qmt_site_recalc_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1064 struct hlist_node *hnode, void *data)
1066 struct lquota_entry *lqe;
1067 struct lu_env *env = data;
1069 lqe = hlist_entry(hnode, struct lquota_entry, lqe_hash);
1070 LASSERT(atomic_read(&lqe->lqe_ref) > 0);
1072 lqe_write_lock(lqe);
1073 if (lqe->lqe_granted != lqe->lqe_recalc_granted) {
1074 struct qmt_device *qmt = lqe2qpi(lqe)->qpi_qmt;
1076 bool need_notify = false;
1079 LQUOTA_DEBUG(lqe, "lqe_recalc_granted %llu\n",
1080 lqe->lqe_recalc_granted);
1081 lqe->lqe_granted = lqe->lqe_recalc_granted;
1082 /* Always returns true, if there is no slaves in a pool */
1083 need_notify |= qmt_adjust_qunit(env, lqe);
1084 need_notify |= qmt_adjust_edquot(lqe, ktime_get_real_seconds());
1086 /* Find all lqes with lqe_id to reseed lgd array */
1087 rc = qmt_pool_lqes_lookup_spec(env, qmt, lqe_rtype(lqe),
1088 lqe_qtype(lqe), &lqe->lqe_id);
1089 if (!rc && qti_lqes_glbl(env)->lqe_glbl_data) {
1091 qti_lqes_glbl(env)->lqe_glbl_data);
1092 qmt_id_lock_notify(qmt, qti_lqes_glbl(env));
1096 th = dt_trans_create(env, qmt->qmt_child);
1100 rc = lquota_disk_declare_write(env, th,
1106 rc = dt_trans_start_local(env, qmt->qmt_child, th);
1110 qmt_glb_write(env, th, lqe, 0, NULL);
1112 dt_trans_stop(env, qmt->qmt_child, th);
1115 lqe->lqe_recalc_granted = 0;
1116 lqe_write_unlock(lqe);
1121 #define MDT_DEV_NAME_LEN (LUSTRE_MAXFSNAME + sizeof("-MDT0000"))
1122 static struct obd_device *qmt_get_mgc(struct qmt_device *qmt)
1124 char mdt_name[MDT_DEV_NAME_LEN];
1125 struct lustre_mount_info *lmi;
1126 struct obd_device *obd;
1130 rc = server_name2fsname(qmt->qmt_svname, mdt_name, NULL);
1132 CERROR("quota: cannot get server name from %s: rc = %d\n",
1133 qmt->qmt_svname, rc);
1134 RETURN(ERR_PTR(rc));
1137 strlcat(mdt_name, "-MDT0000", MDT_DEV_NAME_LEN);
1138 lmi = server_get_mount(mdt_name);
1141 CERROR("%s: cannot get mount info from %s: rc = %d\n",
1142 qmt->qmt_svname, mdt_name, rc);
1143 RETURN(ERR_PTR(rc));
1145 obd = s2lsi(lmi->lmi_sb)->lsi_mgc;
1146 lustre_put_lsi(lmi->lmi_sb);
1151 static int qmt_pool_recalc(void *args)
1153 struct qmt_pool_info *pool, *glbl_pool;
1154 struct rw_semaphore *sem = NULL;
1155 struct obd_device *obd;
1157 int i, rc, qtype, slaves_cnt;
1162 obd = qmt_get_mgc(pool->qpi_qmt);
1164 GOTO(out, rc = PTR_ERR(obd));
1166 /* Waiting for the end of processing mgs config.
1167 * It is needed to be sure all pools are configured. */
1168 while (obd->obd_process_conf)
1169 schedule_timeout_uninterruptible(cfs_time_seconds(1));
1171 sem = qmt_sarr_rwsem(pool);
1174 /* Hold this to be sure that OSTs from this pool
1175 * can't do acquire/release.
1177 * I guess below write semaphore could be a bottleneck
1178 * as qmt_dqacq would be blocked trying to hold
1179 * read_lock at qmt_pool_lookup->qti_pools_add.
1180 * But on the other hand adding/removing OSTs to the pool is
1181 * a rare operation. If finally this would be a problem,
1182 * we can consider another approach. For example we can
1183 * iterate through the POOL's lqes. Take lqe, hold lqe_write_lock
1184 * and go through appropriate OSTs. I don't use this approach now
1185 * as newly created pool hasn't lqes entries. So firstly we need
1186 * to get this lqes from the global pool index file. This
1187 * solution looks more complex, so leave it as it is. */
1188 down_write(&pool->qpi_recalc_sem);
1190 rc = lu_env_init(&env, LCT_MD_THREAD);
1192 CERROR("%s: cannot init env: rc = %d\n", obd->obd_name, rc);
1196 glbl_pool = qmt_pool_lookup_glb(&env, pool->qpi_qmt, pool->qpi_rtype);
1197 if (IS_ERR(glbl_pool))
1198 GOTO(out_env, rc = PTR_ERR(glbl_pool));
1200 slaves_cnt = qmt_sarr_count(pool);
1201 CDEBUG(D_QUOTA, "Starting pool recalculation for %d slaves in %s\n",
1202 slaves_cnt, pool->qpi_name);
1204 for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
1205 for (i = 0; i < slaves_cnt; i++) {
1206 struct qmt_thread_info *qti = qmt_info(&env);
1207 struct dt_object *slv_obj;
1208 struct obd_uuid uuid;
1211 if (kthread_should_stop())
1212 GOTO(out_stop, rc = 0);
1213 idx = qmt_sarr_get_idx(pool, i);
1216 /* We don't need fsname here - anyway
1217 * lquota_disk_slv_filename ignores it. */
1218 snprintf(uuid.uuid, UUID_MAX, "-OST%04x_UUID", idx);
1219 lquota_generate_fid(&qti->qti_fid, pool->qpi_rtype,
1221 /* look-up index file associated with acquiring slave */
1222 slv_obj = lquota_disk_slv_find(&env,
1223 glbl_pool->qpi_qmt->qmt_child,
1224 glbl_pool->qpi_root,
1227 if (IS_ERR(slv_obj))
1228 GOTO(out_stop, rc = PTR_ERR(slv_obj));
1230 CDEBUG(D_QUOTA, "slv_obj is found %p for uuid %s\n",
1231 slv_obj, uuid.uuid);
1232 qmt_obj_recalc(&env, slv_obj, pool->qpi_site[qtype]);
1233 dt_object_put(&env, slv_obj);
1235 /* Now go trough the site hash and compare lqe_granted
1236 * with lqe_calc_granted. Write new value if disagree */
1238 cfs_hash_for_each(pool->qpi_site[qtype]->lqs_hash,
1239 qmt_site_recalc_cb, &env);
1243 qpi_putref(&env, glbl_pool);
1247 if (xchg(&pool->qpi_recalc_task, NULL) == NULL)
1249 * Someone is waiting for us to stop - be sure not to exit
1250 * before kthread_stop() gets a ref on the task. No event
1251 * will happen on 'pool, this is just a convenient way to
1254 wait_var_event(pool, kthread_should_stop());
1256 clear_bit(QPI_FLAG_RECALC_OFFSET, &pool->qpi_flags);
1257 /* Pool can't be changed, since sem has been down.
1258 * Thus until up_read, no one can restart recalc thread. */
1261 up_write(&pool->qpi_recalc_sem);
1263 qpi_putref(&env, pool);
1268 static int qmt_start_pool_recalc(struct lu_env *env, struct qmt_pool_info *qpi)
1270 struct task_struct *task;
1273 if (!test_and_set_bit(QPI_FLAG_RECALC_OFFSET, &qpi->qpi_flags)) {
1274 LASSERT(!qpi->qpi_recalc_task);
1277 task = kthread_create(qmt_pool_recalc, qpi,
1278 "qsd_reint_%s", qpi->qpi_name);
1280 clear_bit(QPI_FLAG_RECALC_OFFSET, &qpi->qpi_flags);
1282 qpi_putref(env, qpi);
1284 qpi->qpi_recalc_task = task;
1285 /* Using park/unpark to start the thread ensures that
1286 * the thread function does get calls, so the
1287 * ref on qpi will be dropped
1290 kthread_unpark(task);
1297 static inline void qmt_stop_pool_recalc(struct qmt_pool_info *qpi)
1299 struct task_struct *task;
1301 task = xchg(&qpi->qpi_recalc_task, NULL);
1306 static int qmt_pool_slv_nr_change(const struct lu_env *env,
1307 struct qmt_pool_info *pool,
1310 struct qmt_pool_info *glbl_pool;
1313 glbl_pool = qmt_pool_lookup_glb(env, pool->qpi_qmt, LQUOTA_RES_DT);
1314 if (IS_ERR(glbl_pool))
1315 RETURN(PTR_ERR(glbl_pool));
1317 for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
1318 struct qmt_thread_info *qti = qmt_info(env);
1319 struct dt_object *slv_obj;
1320 struct obd_uuid uuid;
1322 /* We don't need fsname here - anyway
1323 * lquota_disk_slv_filename ignores it. */
1324 snprintf(uuid.uuid, UUID_MAX, "-OST%04x_UUID", idx);
1325 lquota_generate_fid(&qti->qti_fid, pool->qpi_rtype,
1327 /* look-up index file associated with acquiring slave */
1328 slv_obj = lquota_disk_slv_find(env,
1329 glbl_pool->qpi_qmt->qmt_child,
1330 glbl_pool->qpi_root,
1333 if (IS_ERR(slv_obj))
1337 pool->qpi_slv_nr[QMT_STYPE_OST][qtype]++;
1339 pool->qpi_slv_nr[QMT_STYPE_OST][qtype]--;
1340 dt_object_put(env, slv_obj);
1342 qpi_putref(env, glbl_pool);
1347 static int qmt_pool_add_rem(struct obd_device *obd, char *poolname,
1348 char *slavename, bool add)
1350 struct qmt_device *qmt = lu2qmt_dev(obd->obd_lu_dev);
1351 struct qmt_pool_info *qpi;
1356 if (strnlen(poolname, LOV_MAXPOOLNAME + 1) > LOV_MAXPOOLNAME)
1357 RETURN(-ENAMETOOLONG);
1359 CDEBUG(D_QUOTA, add ? "%s: pool %s, adding %s\n" :
1360 "%s: pool %s, removing %s\n",
1361 obd->obd_name, poolname, slavename);
1363 rc = server_name2index(slavename, &idx, NULL);
1364 if (rc != LDD_F_SV_TYPE_OST)
1367 rc = lu_env_init(&env, LCT_MD_THREAD);
1369 CERROR("%s: cannot init env: rc = %d\n", obd->obd_name, rc);
1373 qpi = qmt_pool_lookup_name(&env, qmt, LQUOTA_RES_DT, poolname);
1375 CWARN("%s: can't find pool %s: rc = %long\n",
1376 obd->obd_name, poolname, PTR_ERR(qpi));
1377 GOTO(out, rc = PTR_ERR(qpi));
1380 rc = add ? qmt_sarr_pool_add(qpi, idx, 32) :
1381 qmt_sarr_pool_rem(qpi, idx);
1383 CERROR("%s: can't %s %s pool %s: rc = %d\n",
1384 add ? "add to" : "remove", obd->obd_name,
1385 slavename, poolname, rc);
1386 GOTO(out_putref, rc);
1388 qmt_pool_slv_nr_change(&env, qpi, idx, add);
1389 qmt_start_pool_recalc(&env, qpi);
1392 qpi_putref(&env, qpi);
1401 * Add a single target device to the named pool.
1403 * \param[in] obd OBD device on which to add the pool
1404 * \param[in] poolname name of the pool to which to add the target \a slavename
1405 * \param[in] slavename name of the target device to be added
1407 * \retval 0 if \a slavename was (previously) added to the pool
1408 * \retval negative error number on failure
1410 int qmt_pool_add(struct obd_device *obd, char *poolname, char *slavename)
1412 return qmt_pool_add_rem(obd, poolname, slavename, true);
1416 * Remove the named target from the specified pool.
1418 * \param[in] obd OBD device from which to remove \a poolname
1419 * \param[in] poolname name of the pool to be changed
1420 * \param[in] slavename name of the target to remove from \a poolname
1422 * \retval 0 on successfully removing \a slavename from the pool
1423 * \retval negative number on error (e.g. \a slavename not in pool)
1425 int qmt_pool_rem(struct obd_device *obd, char *poolname, char *slavename)
1427 return qmt_pool_add_rem(obd, poolname, slavename, false);
1431 * Remove the named pool from the QMT device.
1433 * \param[in] obd OBD device on which pool was previously created
1434 * \param[in] poolname name of pool to remove from \a obd
1436 * \retval 0 on successfully removing the pool
1437 * \retval negative error numbers for failures
1439 int qmt_pool_del(struct obd_device *obd, char *poolname)
1441 struct qmt_device *qmt = lu2qmt_dev(obd->obd_lu_dev);
1442 struct qmt_pool_info *qpi;
1444 char buf[LQUOTA_NAME_MAX];
1450 if (strnlen(poolname, LOV_MAXPOOLNAME + 1) > LOV_MAXPOOLNAME)
1451 RETURN(-ENAMETOOLONG);
1453 CDEBUG(D_QUOTA, "Removing quota pool "LOV_POOLNAMEF"\n",
1456 rc = lu_env_init(&env, LCT_MD_THREAD);
1458 CERROR("%s: cannot init env: rc = %d\n", obd->obd_name, rc);
1462 /* look-up pool in charge of this global index FID */
1463 qpi = qmt_pool_lookup_name(&env, qmt, LQUOTA_RES_DT, poolname);
1465 /* Valid case for several MDTs at the same node -
1466 * pool removed by the 1st MDT in config */
1467 CDEBUG(D_QUOTA, "Cannot find pool %s\n", poolname);
1469 RETURN(PTR_ERR(qpi));
1472 for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
1473 lquota_generate_fid(&fid, LQUOTA_RES_DT, qtype);
1474 snprintf(buf, LQUOTA_NAME_MAX, "0x%x", fid.f_oid);
1475 rc = local_object_unlink(&env, qmt->qmt_child,
1476 qpi->qpi_root, buf);
1478 CWARN("%s: cannot unlink %s from pool %s: rc = %d\n",
1479 obd->obd_name, buf, poolname, rc);
1482 /* put ref from look-up */
1483 qpi_putref(&env, qpi);
1484 /* put last ref to free qpi */
1485 qpi_putref(&env, qpi);
1487 snprintf(buf, LQUOTA_NAME_MAX, "%s-%s",
1488 RES_NAME(LQUOTA_RES_DT), poolname);
1489 rc = local_object_unlink(&env, qmt->qmt_child, qmt->qmt_root, buf);
1491 CWARN("%s: cannot unlink dir %s: rc = %d\n",
1492 obd->obd_name, poolname, rc);
1498 static inline int qmt_sarr_pool_init(struct qmt_pool_info *qpi)
1501 /* No need to initialize sarray for global pool
1502 * as it always includes all slaves */
1503 if (qmt_pool_global(qpi))
1506 switch (qpi->qpi_rtype) {
1508 return tgt_pool_init(&qpi->qpi_sarr.osts, 0);
1515 static inline int qmt_sarr_pool_add(struct qmt_pool_info *qpi, int idx, int min)
1517 switch (qpi->qpi_rtype) {
1519 return tgt_pool_add(&qpi->qpi_sarr.osts, idx, min);
1526 static inline int qmt_sarr_pool_rem(struct qmt_pool_info *qpi, int idx)
1528 switch (qpi->qpi_rtype) {
1530 return tgt_pool_remove(&qpi->qpi_sarr.osts, idx);
1537 static inline int qmt_sarr_pool_free(struct qmt_pool_info *qpi)
1539 if (qmt_pool_global(qpi))
1542 switch (qpi->qpi_rtype) {
1544 if (!qpi->qpi_sarr.osts.op_array)
1546 return tgt_pool_free(&qpi->qpi_sarr.osts);
1553 static inline int qmt_sarr_check_idx(struct qmt_pool_info *qpi, int idx)
1555 if (qmt_pool_global(qpi))
1558 switch (qpi->qpi_rtype) {
1560 return tgt_check_index(idx, &qpi->qpi_sarr.osts);
1567 inline struct rw_semaphore *qmt_sarr_rwsem(struct qmt_pool_info *qpi)
1569 switch (qpi->qpi_rtype) {
1571 /* to protect ost_pool use */
1572 return &qpi->qpi_sarr.osts.op_rw_sem;
1579 inline int qmt_sarr_get_idx(struct qmt_pool_info *qpi, int arr_idx)
1582 if (qmt_pool_global(qpi))
1585 switch (qpi->qpi_rtype) {
1587 LASSERTF(arr_idx < qpi->qpi_sarr.osts.op_count && arr_idx >= 0,
1588 "idx invalid %d op_count %d\n", arr_idx,
1589 qpi->qpi_sarr.osts.op_count);
1590 return qpi->qpi_sarr.osts.op_array[arr_idx];
1597 /* Number of slaves in a pool */
1598 inline unsigned int qmt_sarr_count(struct qmt_pool_info *qpi)
1600 switch (qpi->qpi_rtype) {
1602 return qpi->qpi_sarr.osts.op_count;