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, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2014 Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 * lustre/lod/lod_pool.c
37 * This file provides code related to the Logical Object Device (LOD)
38 * handling of OST Pools on the MDT. Pools are named lists of targets
39 * that allow userspace to group targets that share a particlar property
40 * together so that users or kernel helpers can make decisions about file
41 * allocation based on these properties. For example, pools could be
42 * defined based on fault domains (e.g. separate racks of server nodes) so
43 * that RAID-1 mirroring could select targets from independent fault
44 * domains, or pools could define target performance characteristics so
45 * that applicatins could select IOP-optimized storage or stream-optimized
46 * storage for a particular output file.
48 * This file handles creation, lookup, and removal of pools themselves, as
49 * well as adding and removing targets to pools. It also handles lprocfs
50 * display of configured pool. The pools are accessed by name in the pool
51 * hash, and are refcounted to ensure proper pool structure lifetimes.
53 * Author: Jacques-Charles LAFOUCRIERE <jc.lafoucriere@cea.fr>
54 * Author: Alex Lyashkov <Alexey.Lyashkov@Sun.COM>
55 * Author: Nathaniel Rutman <Nathan.Rutman@Sun.COM>
58 #define DEBUG_SUBSYSTEM S_LOV
60 #include <libcfs/libcfs.h>
62 #include "lod_internal.h"
64 #define pool_tgt(_p, _i) OST_TGT(lu2lod_dev((_p)->pool_lobd->obd_lu_dev), \
65 (_p)->pool_obds.op_array[_i])
68 * Get a reference on the specified pool.
70 * To ensure the pool descriptor is not freed before the caller is finished
71 * with it. Any process that is accessing \a pool directly needs to hold
72 * reference on it, including /proc since a userspace thread may be holding
73 * the /proc file open and busy in the kernel.
75 * \param[in] pool pool descriptor on which to gain reference
77 static void pool_getref(struct pool_desc *pool)
79 CDEBUG(D_INFO, "pool %p\n", pool);
80 atomic_inc(&pool->pool_refcount);
84 * Drop a reference on the specified pool and free its memory if needed.
86 * One reference is held by the LOD OBD device while it is configured, from
87 * the time the configuration log defines the pool until the time when it is
88 * dropped when the LOD OBD is cleaned up or the pool is deleted. This means
89 * that the pool will not be freed while the LOD device is configured, unless
90 * it is explicitly destroyed by the sysadmin. The pool structure is freed
91 * after the last reference on the structure is released.
93 * \param[in] pool pool descriptor to drop reference on and possibly free
95 void lod_pool_putref(struct pool_desc *pool)
97 CDEBUG(D_INFO, "pool %p\n", pool);
98 if (atomic_dec_and_test(&pool->pool_refcount)) {
99 LASSERT(hlist_unhashed(&pool->pool_hash));
100 LASSERT(list_empty(&pool->pool_list));
101 LASSERT(pool->pool_proc_entry == NULL);
102 lod_ost_pool_free(&(pool->pool_rr.lqr_pool));
103 lod_ost_pool_free(&(pool->pool_obds));
110 * Drop the refcount in cases where the caller holds a spinlock.
112 * This is needed if the caller cannot be blocked while freeing memory.
113 * It assumes that there is some other known refcount held on the \a pool
114 * and the memory cannot actually be freed, but the refcounting needs to
117 * \param[in] pool pool descriptor on which to drop reference
119 static void pool_putref_locked(struct pool_desc *pool)
121 CDEBUG(D_INFO, "pool %p\n", pool);
122 LASSERT(atomic_read(&pool->pool_refcount) > 1);
124 atomic_dec(&pool->pool_refcount);
128 * Group of functions needed for cfs_hash implementation. This
129 * includes pool lookup, refcounting, and cleanup.
133 * Hash the pool name for use by the cfs_hash handlers.
135 * Use the standard DJB2 hash function for ASCII strings in Lustre.
137 * \param[in] hash_body hash structure where this key is embedded (unused)
138 * \param[in] key key to be hashed (in this case the pool name)
139 * \param[in] mask bitmask to limit the hash value to the desired size
141 * \retval computed hash value from \a key and limited by \a mask
143 static __u32 pool_hashfn(struct cfs_hash *hash_body, const void *key,
146 return cfs_hash_djb2_hash(key, strnlen(key, LOV_MAXPOOLNAME), mask);
150 * Return the actual key (pool name) from the hashed \a hnode.
152 * Allows extracting the key name when iterating over all hash entries.
154 * \param[in] hnode hash node found by lookup or iteration
156 * \retval char array referencing the pool name (no refcount)
158 static void *pool_key(struct hlist_node *hnode)
160 struct pool_desc *pool;
162 pool = hlist_entry(hnode, struct pool_desc, pool_hash);
163 return pool->pool_name;
167 * Check if the specified hash key matches the hash node.
169 * This is needed in case there is a hash key collision, allowing the hash
170 * table lookup/iteration to distinguish between the two entries.
172 * \param[in] key key (pool name) being searched for
173 * \param[in] compared current entry being compared
175 * \retval 0 if \a key is the same as the key of \a compared
176 * \retval 1 if \a key is different from the key of \a compared
178 static int pool_hashkey_keycmp(const void *key, struct hlist_node *compared)
180 return !strncmp(key, pool_key(compared), LOV_MAXPOOLNAME);
184 * Return the actual pool data structure from the hash table entry.
186 * Once the hash table entry is found, extract the pool data from it.
187 * The return type of this function is void * because it needs to be
188 * assigned to the generic hash operations table.
190 * \param[in] hnode hash table entry
192 * \retval struct pool_desc for the specified \a hnode
194 static void *pool_hashobject(struct hlist_node *hnode)
196 return hlist_entry(hnode, struct pool_desc, pool_hash);
199 static void pool_hashrefcount_get(struct cfs_hash *hs, struct hlist_node *hnode)
201 struct pool_desc *pool;
203 pool = hlist_entry(hnode, struct pool_desc, pool_hash);
207 static void pool_hashrefcount_put_locked(struct cfs_hash *hs,
208 struct hlist_node *hnode)
210 struct pool_desc *pool;
212 pool = hlist_entry(hnode, struct pool_desc, pool_hash);
213 pool_putref_locked(pool);
216 struct cfs_hash_ops pool_hash_operations = {
217 .hs_hash = pool_hashfn,
219 .hs_keycmp = pool_hashkey_keycmp,
220 .hs_object = pool_hashobject,
221 .hs_get = pool_hashrefcount_get,
222 .hs_put_locked = pool_hashrefcount_put_locked,
226 * Methods for /proc seq_file iteration of the defined pools.
229 #define POOL_IT_MAGIC 0xB001CEA0
230 struct lod_pool_iterator {
231 unsigned int lpi_magic; /* POOL_IT_MAGIC */
232 unsigned int lpi_idx; /* from 0 to pool_tgt_size - 1 */
233 struct pool_desc *lpi_pool;
237 * Return the next configured target within one pool for seq_file iteration.
239 * Iterator is used to go through the target entries of a single pool
240 * (i.e. the list of OSTs configured for a named pool).
241 * lpi_idx is the current target index in the pool's op_array[].
243 * The return type is a void * because this function is one of the
244 * struct seq_operations methods and must match the function template.
246 * \param[in] seq /proc sequence file iteration tracking structure
247 * \param[in] v unused
248 * \param[in] pos position within iteration; 0 to number of targets - 1
250 * \retval struct pool_iterator of the next pool descriptor
252 static void *pool_proc_next(struct seq_file *seq, void *v, loff_t *pos)
254 struct lod_pool_iterator *iter = seq->private;
257 LASSERTF(iter->lpi_magic == POOL_IT_MAGIC, "%08X\n", iter->lpi_magic);
259 /* test if end of file */
260 if (*pos >= pool_tgt_count(iter->lpi_pool))
263 /* iterate to find a non empty entry */
264 prev_idx = iter->lpi_idx;
265 down_read(&pool_tgt_rw_sem(iter->lpi_pool));
267 if (iter->lpi_idx == pool_tgt_count(iter->lpi_pool)) {
268 iter->lpi_idx = prev_idx; /* we stay on the last entry */
269 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
272 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
274 /* return != NULL to continue */
279 * Start seq_file iteration via /proc for a single pool.
281 * The \a pos parameter may be non-zero, indicating that the iteration
282 * is starting at some offset in the target list. Use the seq_file
283 * private field to memorize the iterator so we can free it at stop().
284 * Need to restore the private pointer to the pool before freeing it.
286 * \param[in] seq new sequence file structure to initialize
287 * \param[in] pos initial target number at which to start iteration
289 * \retval initialized pool iterator private structure
290 * \retval NULL if \a pos exceeds the number of targets in \a pool
291 * \retval negative error number on failure
293 static void *pool_proc_start(struct seq_file *seq, loff_t *pos)
295 struct pool_desc *pool = seq->private;
296 struct lod_pool_iterator *iter;
299 if ((pool_tgt_count(pool) == 0) ||
300 (*pos >= pool_tgt_count(pool))) {
301 /* iter is not created, so stop() has no way to
302 * find pool to dec ref */
303 lod_pool_putref(pool);
309 return ERR_PTR(-ENOMEM);
310 iter->lpi_magic = POOL_IT_MAGIC;
311 iter->lpi_pool = pool;
321 ptr = pool_proc_next(seq, &iter, &i);
322 } while ((i < *pos) && (ptr != NULL));
331 * Finish seq_file iteration for a single pool.
333 * Once iteration has been completed, the pool_iterator struct must be
334 * freed, and the seq_file private pointer restored to the pool, as it
335 * was initially when pool_proc_start() was called.
337 * In some cases the stop() method may be called 2 times, without calling
338 * the start() method (see seq_read() from fs/seq_file.c). We have to free
339 * the private iterator struct only if seq->private points to the iterator.
341 * \param[in] seq sequence file structure to clean up
342 * \param[in] v (unused)
344 static void pool_proc_stop(struct seq_file *seq, void *v)
346 struct lod_pool_iterator *iter = seq->private;
348 if (iter != NULL && iter->lpi_magic == POOL_IT_MAGIC) {
349 seq->private = iter->lpi_pool;
350 lod_pool_putref(iter->lpi_pool);
356 * Print out one target entry from the pool for seq_file iteration.
358 * The currently referenced pool target is given by op_array[lpi_idx].
360 * \param[in] seq new sequence file structure to initialize
361 * \param[in] v (unused)
363 static int pool_proc_show(struct seq_file *seq, void *v)
365 struct lod_pool_iterator *iter = v;
366 struct lod_tgt_desc *tgt;
368 LASSERTF(iter->lpi_magic == POOL_IT_MAGIC, "%08X\n", iter->lpi_magic);
369 LASSERT(iter->lpi_pool != NULL);
370 LASSERT(iter->lpi_idx <= pool_tgt_count(iter->lpi_pool));
372 down_read(&pool_tgt_rw_sem(iter->lpi_pool));
373 tgt = pool_tgt(iter->lpi_pool, iter->lpi_idx);
374 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
376 seq_printf(seq, "%s\n", obd_uuid2str(&(tgt->ltd_uuid)));
381 static const struct seq_operations pool_proc_ops = {
382 .start = pool_proc_start,
383 .next = pool_proc_next,
384 .stop = pool_proc_stop,
385 .show = pool_proc_show,
389 * Open a new /proc file for seq_file iteration of targets in one pool.
391 * Initialize the seq_file private pointer to reference the pool.
393 * \param inode inode to store iteration state for /proc
394 * \param file file descriptor to store iteration methods
396 * \retval 0 for success
397 * \retval negative error number on failure
399 static int pool_proc_open(struct inode *inode, struct file *file)
403 rc = seq_open(file, &pool_proc_ops);
405 struct seq_file *seq = file->private_data;
406 seq->private = PDE_DATA(inode);
411 static struct file_operations pool_proc_operations = {
412 .open = pool_proc_open,
415 .release = seq_release,
419 * Dump the pool target list into the Lustre debug log.
421 * This is a debugging function to allow dumping the list of targets
422 * in \a pool to the Lustre kernel debug log at the given \a level.
424 * This is not currently called by any existing code, but can be called
425 * from within gdb/crash to display the contents of the pool, or from
426 * code under development.
428 * \param[in] level Lustre debug level (D_INFO, D_WARN, D_ERROR, etc)
429 * \param[in] pool pool descriptor to be dumped
431 void lod_dump_pool(int level, struct pool_desc *pool)
437 CDEBUG(level, "pool "LOV_POOLNAMEF" has %d members\n",
438 pool->pool_name, pool->pool_obds.op_count);
439 down_read(&pool_tgt_rw_sem(pool));
441 for (i = 0; i < pool_tgt_count(pool) ; i++) {
442 if (!pool_tgt(pool, i) || !(pool_tgt(pool, i))->ltd_exp)
444 CDEBUG(level, "pool "LOV_POOLNAMEF"[%d] = %s\n",
446 obd_uuid2str(&((pool_tgt(pool, i))->ltd_uuid)));
449 up_read(&pool_tgt_rw_sem(pool));
450 lod_pool_putref(pool);
454 * Initialize the pool data structures at startup.
456 * Allocate and initialize the pool data structures with the specified
457 * array size. If pool count is not specified (\a count == 0), then
458 * POOL_INIT_COUNT will be used. Allocating a non-zero initial array
459 * size avoids the need to reallocate as new pools are added.
461 * \param[in] op pool structure
462 * \param[in] count initial size of the target op_array[] array
464 * \retval 0 indicates successful pool initialization
465 * \retval negative error number on failure
467 #define POOL_INIT_COUNT 2
468 int lod_ost_pool_init(struct ost_pool *op, unsigned int count)
473 count = POOL_INIT_COUNT;
476 init_rwsem(&op->op_rw_sem);
478 OBD_ALLOC(op->op_array, op->op_size * sizeof(op->op_array[0]));
479 if (op->op_array == NULL) {
488 * Increase the op_array size to hold more targets in this pool.
490 * The size is increased to at least \a min_count, but may be larger
491 * for an existing pool since ->op_array[] is growing exponentially.
492 * Caller must hold write op_rwlock.
494 * \param[in] op pool structure
495 * \param[in] min_count minimum number of entries to handle
497 * \retval 0 on success
498 * \retval negative error number on failure.
500 int lod_ost_pool_extend(struct ost_pool *op, unsigned int min_count)
505 LASSERT(min_count != 0);
507 if (op->op_count < op->op_size)
510 new_size = max(min_count, 2 * op->op_size);
511 OBD_ALLOC(new, new_size * sizeof(op->op_array[0]));
515 /* copy old array to new one */
516 memcpy(new, op->op_array, op->op_size * sizeof(op->op_array[0]));
517 OBD_FREE(op->op_array, op->op_size * sizeof(op->op_array[0]));
519 op->op_size = new_size;
525 * Add a new target to an existing pool.
527 * Add a new target device to the pool previously created and returned by
528 * lod_pool_new(). Each target can only be in each pool at most one time.
530 * \param[in] op target pool to add new entry
531 * \param[in] idx pool index number to add to the \a op array
532 * \param[in] min_count minimum number of entries to expect in the pool
534 * \retval 0 if target could be added to the pool
535 * \retval negative error if target \a idx was not added
537 int lod_ost_pool_add(struct ost_pool *op, __u32 idx, unsigned int min_count)
543 down_write(&op->op_rw_sem);
545 rc = lod_ost_pool_extend(op, min_count);
549 /* search ost in pool array */
550 for (i = 0; i < op->op_count; i++) {
551 if (op->op_array[i] == idx)
552 GOTO(out, rc = -EEXIST);
554 /* ost not found we add it */
555 op->op_array[op->op_count] = idx;
559 up_write(&op->op_rw_sem);
564 * Remove an existing pool from the system.
566 * The specified pool must have previously been allocated by
567 * lod_pool_new() and not have any target members in the pool.
568 * If the removed target is not the last, compact the array
569 * to remove empty spaces.
571 * \param[in] op pointer to the original data structure
572 * \param[in] idx target index to be removed
574 * \retval 0 on success
575 * \retval negative error number on failure
577 int lod_ost_pool_remove(struct ost_pool *op, __u32 idx)
582 down_write(&op->op_rw_sem);
584 for (i = 0; i < op->op_count; i++) {
585 if (op->op_array[i] == idx) {
586 memmove(&op->op_array[i], &op->op_array[i + 1],
587 (op->op_count - i - 1) *
588 sizeof(op->op_array[0]));
590 up_write(&op->op_rw_sem);
596 up_write(&op->op_rw_sem);
601 * Free the pool after it was emptied and removed from /proc.
603 * Note that all of the child/target entries referenced by this pool
604 * must have been removed by lod_ost_pool_remove() before it can be
605 * deleted from memory.
607 * \param[in] op pool to be freed.
609 * \retval 0 on success or if pool was already freed
611 int lod_ost_pool_free(struct ost_pool *op)
615 if (op->op_size == 0)
618 down_write(&op->op_rw_sem);
620 OBD_FREE(op->op_array, op->op_size * sizeof(op->op_array[0]));
625 up_write(&op->op_rw_sem);
630 * Allocate a new pool for the specified device.
632 * Allocate a new pool_desc structure for the specified \a new_pool
633 * device to create a pool with the given \a poolname. The new pool
634 * structure is created with a single reference, and is freed when the
635 * reference count drops to zero.
637 * \param[in] obd Lustre OBD device on which to add a pool iterator
638 * \param[in] poolname the name of the pool to be created
640 * \retval 0 in case of success
641 * \retval negative error code in case of error
643 int lod_pool_new(struct obd_device *obd, char *poolname)
645 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
646 struct pool_desc *new_pool;
650 if (strlen(poolname) > LOV_MAXPOOLNAME)
651 RETURN(-ENAMETOOLONG);
653 OBD_ALLOC_PTR(new_pool);
654 if (new_pool == NULL)
657 strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name));
658 new_pool->pool_lobd = obd;
659 atomic_set(&new_pool->pool_refcount, 1);
660 rc = lod_ost_pool_init(&new_pool->pool_obds, 0);
664 lod_qos_rr_init(&new_pool->pool_rr);
665 rc = lod_ost_pool_init(&new_pool->pool_rr.lqr_pool, 0);
667 GOTO(out_free_pool_obds, rc);
669 INIT_HLIST_NODE(&new_pool->pool_hash);
671 #ifdef CONFIG_PROC_FS
672 pool_getref(new_pool);
673 new_pool->pool_proc_entry = lprocfs_add_simple(lod->lod_pool_proc_entry,
675 &pool_proc_operations);
676 if (IS_ERR(new_pool->pool_proc_entry)) {
677 CDEBUG(D_CONFIG, "%s: cannot add proc entry "LOV_POOLNAMEF"\n",
678 obd->obd_name, poolname);
679 new_pool->pool_proc_entry = NULL;
680 lod_pool_putref(new_pool);
682 CDEBUG(D_INFO, "pool %p - proc %p\n", new_pool,
683 new_pool->pool_proc_entry);
686 spin_lock(&obd->obd_dev_lock);
687 list_add_tail(&new_pool->pool_list, &lod->lod_pool_list);
688 lod->lod_pool_count++;
689 spin_unlock(&obd->obd_dev_lock);
691 /* add to find only when it fully ready */
692 rc = cfs_hash_add_unique(lod->lod_pools_hash_body, poolname,
693 &new_pool->pool_hash);
695 GOTO(out_err, rc = -EEXIST);
697 CDEBUG(D_CONFIG, LOV_POOLNAMEF" is pool #%d\n",
698 poolname, lod->lod_pool_count);
703 spin_lock(&obd->obd_dev_lock);
704 list_del_init(&new_pool->pool_list);
705 lod->lod_pool_count--;
706 spin_unlock(&obd->obd_dev_lock);
708 lprocfs_remove(&new_pool->pool_proc_entry);
710 lod_ost_pool_free(&new_pool->pool_rr.lqr_pool);
712 lod_ost_pool_free(&new_pool->pool_obds);
713 OBD_FREE_PTR(new_pool);
718 * Remove the named pool from the OBD device.
720 * \param[in] obd OBD device on which pool was previously created
721 * \param[in] poolname name of pool to remove from \a obd
723 * \retval 0 on successfully removing the pool
724 * \retval negative error numbers for failures
726 int lod_pool_del(struct obd_device *obd, char *poolname)
728 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
729 struct pool_desc *pool;
732 /* lookup and kill hash reference */
733 pool = cfs_hash_del_key(lod->lod_pools_hash_body, poolname);
737 if (pool->pool_proc_entry != NULL) {
738 CDEBUG(D_INFO, "proc entry %p\n", pool->pool_proc_entry);
739 lprocfs_remove(&pool->pool_proc_entry);
740 lod_pool_putref(pool);
743 spin_lock(&obd->obd_dev_lock);
744 list_del_init(&pool->pool_list);
745 lod->lod_pool_count--;
746 spin_unlock(&obd->obd_dev_lock);
748 /* release last reference */
749 lod_pool_putref(pool);
755 * Add a single target device to the named pool.
757 * Add the target specified by \a ostname to the specified \a poolname.
759 * \param[in] obd OBD device on which to add the pool
760 * \param[in] poolname name of the pool to which to add the target \a ostname
761 * \param[in] ostname name of the target device to be added
763 * \retval 0 if \a ostname was (previously) added to the named pool
764 * \retval negative error number on failure
766 int lod_pool_add(struct obd_device *obd, char *poolname, char *ostname)
768 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
769 struct obd_uuid ost_uuid;
770 struct pool_desc *pool;
775 pool = cfs_hash_lookup(lod->lod_pools_hash_body, poolname);
779 obd_str2uuid(&ost_uuid, ostname);
781 /* search ost in lod array */
782 lod_getref(&lod->lod_ost_descs);
783 lod_foreach_ost(lod, idx) {
784 if (obd_uuid_equals(&ost_uuid, &OST_TGT(lod, idx)->ltd_uuid)) {
793 rc = lod_ost_pool_add(&pool->pool_obds, idx, lod->lod_osts_size);
797 pool->pool_rr.lqr_dirty = 1;
799 CDEBUG(D_CONFIG, "Added %s to "LOV_POOLNAMEF" as member %d\n",
800 ostname, poolname, pool_tgt_count(pool));
804 lod_putref(lod, &lod->lod_ost_descs);
805 lod_pool_putref(pool);
810 * Remove the named target from the specified pool.
812 * Remove one target named \a ostname from \a poolname. The \a ostname
813 * is searched for in the lod_device lod_ost_bitmap array, to ensure the
814 * specified name actually exists in the pool.
816 * \param[in] obd OBD device from which to remove \a poolname
817 * \param[in] poolname name of the pool to be changed
818 * \param[in] ostname name of the target to remove from \a poolname
820 * \retval 0 on successfully removing \a ostname from the pool
821 * \retval negative number on error (e.g. \a ostname not in pool)
823 int lod_pool_remove(struct obd_device *obd, char *poolname, char *ostname)
825 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
826 struct obd_uuid ost_uuid;
827 struct pool_desc *pool;
832 pool = cfs_hash_lookup(lod->lod_pools_hash_body, poolname);
836 obd_str2uuid(&ost_uuid, ostname);
838 lod_getref(&lod->lod_ost_descs);
839 cfs_foreach_bit(lod->lod_ost_bitmap, idx) {
840 if (obd_uuid_equals(&ost_uuid, &OST_TGT(lod, idx)->ltd_uuid)) {
846 /* test if ost found in lod array */
850 lod_ost_pool_remove(&pool->pool_obds, idx);
852 pool->pool_rr.lqr_dirty = 1;
854 CDEBUG(D_CONFIG, "%s removed from "LOV_POOLNAMEF"\n", ostname,
859 lod_putref(lod, &lod->lod_ost_descs);
860 lod_pool_putref(pool);
865 * Check if the specified target exists in the pool.
867 * The caller may not have a reference on \a pool if it got the pool without
868 * calling lod_find_pool() (e.g. directly from the lod pool list)
870 * \param[in] idx Target index to check
871 * \param[in] pool Pool in which to check if target is added.
873 * \retval 0 successfully found index in \a pool
874 * \retval negative error if device not found in \a pool
876 int lod_check_index_in_pool(__u32 idx, struct pool_desc *pool)
884 down_read(&pool_tgt_rw_sem(pool));
886 for (i = 0; i < pool_tgt_count(pool); i++) {
887 if (pool_tgt_array(pool)[i] == idx)
893 up_read(&pool_tgt_rw_sem(pool));
895 lod_pool_putref(pool);
900 * Find the pool descriptor for the specified pool and return it with a
901 * reference to the caller if found.
903 * \param[in] lod LOD on which the pools are configured
904 * \param[in] poolname NUL-terminated name of the pool
906 * \retval pointer to pool descriptor on success
907 * \retval NULL if \a poolname could not be found or poolname is empty
909 struct pool_desc *lod_find_pool(struct lod_device *lod, char *poolname)
911 struct pool_desc *pool;
914 if (poolname[0] != '\0') {
915 pool = cfs_hash_lookup(lod->lod_pools_hash_body, poolname);
917 CDEBUG(D_CONFIG, "%s: request for an unknown pool ("
919 lod->lod_child_exp->exp_obd->obd_name, poolname);
920 if (pool != NULL && pool_tgt_count(pool) == 0) {
921 CDEBUG(D_CONFIG, "%s: request for an empty pool ("
923 lod->lod_child_exp->exp_obd->obd_name, poolname);
924 /* pool is ignored, so we remove ref on it */
925 lod_pool_putref(pool);