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(cfs_hlist_unhashed(&pool->pool_hash));
100 LASSERT(cfs_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(cfs_hash_t *hash_body, const void *key, unsigned mask)
145 return cfs_hash_djb2_hash(key, strnlen(key, LOV_MAXPOOLNAME), mask);
149 * Return the actual key (pool name) from the hashed \a hnode.
151 * Allows extracting the key name when iterating over all hash entries.
153 * \param[in] hnode hash node found by lookup or iteration
155 * \retval char array referencing the pool name (no refcount)
157 static void *pool_key(cfs_hlist_node_t *hnode)
159 struct pool_desc *pool;
161 pool = cfs_hlist_entry(hnode, struct pool_desc, pool_hash);
162 return pool->pool_name;
166 * Check if the specified hash key matches the hash node.
168 * This is needed in case there is a hash key collision, allowing the hash
169 * table lookup/iteration to distinguish between the two entries.
171 * \param[in] key key (pool name) being searched for
172 * \param[in] compared current entry being compared
174 * \retval 0 if \a key is the same as the key of \a compared
175 * \retval 1 if \a key is different from the key of \a compared
177 static int pool_hashkey_keycmp(const void *key, cfs_hlist_node_t *compared_hnode)
180 struct pool_desc *pool;
182 pool_name = (char *)key;
183 pool = cfs_hlist_entry(compared_hnode, struct pool_desc, pool_hash);
184 return !strncmp(pool_name, pool->pool_name, LOV_MAXPOOLNAME);
188 * Return the actual pool data structure from the hash table entry.
190 * Once the hash table entry is found, extract the pool data from it.
191 * The return type of this function is void * because it needs to be
192 * assigned to the generic hash operations table.
194 * \param[in] hnode hash table entry
196 * \retval struct pool_desc for the specified \a hnode
198 static void *pool_hashobject(cfs_hlist_node_t *hnode)
200 return cfs_hlist_entry(hnode, struct pool_desc, pool_hash);
203 static void pool_hashrefcount_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
205 struct pool_desc *pool;
207 pool = cfs_hlist_entry(hnode, struct pool_desc, pool_hash);
211 static void pool_hashrefcount_put_locked(cfs_hash_t *hs,
212 cfs_hlist_node_t *hnode)
214 struct pool_desc *pool;
216 pool = cfs_hlist_entry(hnode, struct pool_desc, pool_hash);
217 pool_putref_locked(pool);
220 cfs_hash_ops_t pool_hash_operations = {
221 .hs_hash = pool_hashfn,
223 .hs_keycmp = pool_hashkey_keycmp,
224 .hs_object = pool_hashobject,
225 .hs_get = pool_hashrefcount_get,
226 .hs_put_locked = pool_hashrefcount_put_locked,
230 * Methods for /proc seq_file iteration of the defined pools.
233 #define POOL_IT_MAGIC 0xB001CEA0
234 struct lod_pool_iterator {
235 int lpi_magic; /* POOL_IT_MAGIC */
236 int lpi_idx; /* from 0 to pool_tgt_size - 1 */
237 struct pool_desc *lpi_pool;
241 * Return the next configured target within one pool for seq_file iteration.
243 * Iterator is used to go through the target entries of a single pool
244 * (i.e. the list of OSTs configured for a named pool).
245 * lpi_idx is the current target index in the pool's op_array[].
247 * The return type is a void * because this function is one of the
248 * struct seq_operations methods and must match the function template.
250 * \param[in] seq /proc sequence file iteration tracking structure
251 * \param[in] v unused
252 * \param[in] pos position within iteration; 0 to number of targets - 1
254 * \retval struct pool_iterator of the next pool descriptor
256 static void *pool_proc_next(struct seq_file *seq, void *v, loff_t *pos)
258 struct lod_pool_iterator *iter = seq->private;
261 LASSERTF(iter->lpi_magic == POOL_IT_MAGIC, "%08X\n", iter->lpi_magic);
263 /* test if end of file */
264 if (*pos >= pool_tgt_count(iter->lpi_pool))
267 /* iterate to find a non empty entry */
268 prev_idx = iter->lpi_idx;
269 down_read(&pool_tgt_rw_sem(iter->lpi_pool));
271 if (iter->lpi_idx == pool_tgt_count(iter->lpi_pool)) {
272 iter->lpi_idx = prev_idx; /* we stay on the last entry */
273 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
276 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
278 /* return != NULL to continue */
283 * Start seq_file iteration via /proc for a single pool.
285 * The \a pos parameter may be non-zero, indicating that the iteration
286 * is starting at some offset in the target list. Use the seq_file
287 * private field to memorize the iterator so we can free it at stop().
288 * Need to restore the private pointer to the pool before freeing it.
290 * \param[in] seq new sequence file structure to initialize
291 * \param[in] pos initial target number at which to start iteration
293 * \retval initialized pool iterator private structure
294 * \retval NULL if \a pos exceeds the number of targets in \a pool
295 * \retval negative error number on failure
297 static void *pool_proc_start(struct seq_file *seq, loff_t *pos)
299 struct pool_desc *pool = seq->private;
300 struct lod_pool_iterator *iter;
303 if ((pool_tgt_count(pool) == 0) ||
304 (*pos >= pool_tgt_count(pool))) {
305 /* iter is not created, so stop() has no way to
306 * find pool to dec ref */
307 lod_pool_putref(pool);
313 return ERR_PTR(-ENOMEM);
314 iter->lpi_magic = POOL_IT_MAGIC;
315 iter->lpi_pool = pool;
325 ptr = pool_proc_next(seq, &iter, &i);
326 } while ((i < *pos) && (ptr != NULL));
335 * Finish seq_file iteration for a single pool.
337 * Once iteration has been completed, the pool_iterator struct must be
338 * freed, and the seq_file private pointer restored to the pool, as it
339 * was initially when pool_proc_start() was called.
341 * In some cases the stop() method may be called 2 times, without calling
342 * the start() method (see seq_read() from fs/seq_file.c). We have to free
343 * the private iterator struct only if seq->private points to the iterator.
345 * \param[in] seq sequence file structure to clean up
346 * \param[in] v (unused)
348 static void pool_proc_stop(struct seq_file *seq, void *v)
350 struct lod_pool_iterator *iter = seq->private;
352 if (iter != NULL && iter->lpi_magic == POOL_IT_MAGIC) {
353 seq->private = iter->lpi_pool;
354 lod_pool_putref(iter->lpi_pool);
360 * Print out one target entry from the pool for seq_file iteration.
362 * The currently referenced pool target is given by op_array[lpi_idx].
364 * \param[in] seq new sequence file structure to initialize
365 * \param[in] v (unused)
367 static int pool_proc_show(struct seq_file *seq, void *v)
369 struct lod_pool_iterator *iter = v;
370 struct lod_tgt_desc *tgt;
372 LASSERTF(iter->lpi_magic == POOL_IT_MAGIC, "%08X\n", iter->lpi_magic);
373 LASSERT(iter->lpi_pool != NULL);
374 LASSERT(iter->lpi_idx <= pool_tgt_count(iter->lpi_pool));
376 down_read(&pool_tgt_rw_sem(iter->lpi_pool));
377 tgt = pool_tgt(iter->lpi_pool, iter->lpi_idx);
378 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
380 seq_printf(seq, "%s\n", obd_uuid2str(&(tgt->ltd_uuid)));
385 static const struct seq_operations pool_proc_ops = {
386 .start = pool_proc_start,
387 .next = pool_proc_next,
388 .stop = pool_proc_stop,
389 .show = pool_proc_show,
393 * Open a new /proc file for seq_file iteration of targets in one pool.
395 * Initialize the seq_file private pointer to reference the pool.
397 * \param inode inode to store iteration state for /proc
398 * \param file file descriptor to store iteration methods
400 * \retval 0 for success
401 * \retval negative error number on failure
403 static int pool_proc_open(struct inode *inode, struct file *file)
407 rc = seq_open(file, &pool_proc_ops);
409 struct seq_file *seq = file->private_data;
410 seq->private = PDE_DATA(inode);
415 static struct file_operations pool_proc_operations = {
416 .open = pool_proc_open,
419 .release = seq_release,
423 * Dump the pool target list into the Lustre debug log.
425 * This is a debugging function to allow dumping the list of targets
426 * in \a pool to the Lustre kernel debug log at the given \a level.
428 * This is not currently called by any existing code, but can be called
429 * from within gdb/crash to display the contents of the pool, or from
430 * code under development.
432 * \param[in] level Lustre debug level (D_INFO, D_WARN, D_ERROR, etc)
433 * \param[in] pool pool descriptor to be dumped
435 void lod_dump_pool(int level, struct pool_desc *pool)
441 CDEBUG(level, "pool "LOV_POOLNAMEF" has %d members\n",
442 pool->pool_name, pool->pool_obds.op_count);
443 down_read(&pool_tgt_rw_sem(pool));
445 for (i = 0; i < pool_tgt_count(pool) ; i++) {
446 if (!pool_tgt(pool, i) || !(pool_tgt(pool, i))->ltd_exp)
448 CDEBUG(level, "pool "LOV_POOLNAMEF"[%d] = %s\n",
450 obd_uuid2str(&((pool_tgt(pool, i))->ltd_uuid)));
453 up_read(&pool_tgt_rw_sem(pool));
454 lod_pool_putref(pool);
458 * Initialize the pool data structures at startup.
460 * Allocate and initialize the pool data structures with the specified
461 * array size. If pool count is not specified (\a count == 0), then
462 * POOL_INIT_COUNT will be used. Allocating a non-zero initial array
463 * size avoids the need to reallocate as new pools are added.
465 * \param[in] op pool structure
466 * \param[in] count initial size of the target op_array[] array
468 * \retval 0 indicates successful pool initialization
469 * \retval negative error number on failure
471 #define POOL_INIT_COUNT 2
472 int lod_ost_pool_init(struct ost_pool *op, unsigned int count)
477 count = POOL_INIT_COUNT;
480 init_rwsem(&op->op_rw_sem);
482 OBD_ALLOC(op->op_array, op->op_size * sizeof(op->op_array[0]));
483 if (op->op_array == NULL) {
492 * Increase the op_array size to hold more targets in this pool.
494 * The size is increased to at least \a min_count, but may be larger
495 * for an existing pool since ->op_array[] is growing exponentially.
496 * Caller must hold write op_rwlock.
498 * \param[in] op pool structure
499 * \param[in] min_count minimum number of entries to handle
501 * \retval 0 on success
502 * \retval negative error number on failure.
504 int lod_ost_pool_extend(struct ost_pool *op, unsigned int min_count)
509 LASSERT(min_count != 0);
511 if (op->op_count < op->op_size)
514 new_size = max(min_count, 2 * op->op_size);
515 OBD_ALLOC(new, new_size * sizeof(op->op_array[0]));
519 /* copy old array to new one */
520 memcpy(new, op->op_array, op->op_size * sizeof(op->op_array[0]));
521 OBD_FREE(op->op_array, op->op_size * sizeof(op->op_array[0]));
523 op->op_size = new_size;
529 * Add a new target to an existing pool.
531 * Add a new target device to the pool previously created and returned by
532 * lod_pool_new(). Each target can only be in each pool at most one time.
534 * \param[in] op target pool to add new entry
535 * \param[in] idx pool index number to add to the \a op array
536 * \param[in] min_count minimum number of entries to expect in the pool
538 * \retval 0 if target could be added to the pool
539 * \retval negative error if target \a idx was not added
541 int lod_ost_pool_add(struct ost_pool *op, __u32 idx, unsigned int min_count)
546 down_write(&op->op_rw_sem);
548 rc = lod_ost_pool_extend(op, min_count);
552 /* search ost in pool array */
553 for (i = 0; i < op->op_count; i++) {
554 if (op->op_array[i] == idx)
555 GOTO(out, rc = -EEXIST);
557 /* ost not found we add it */
558 op->op_array[op->op_count] = idx;
562 up_write(&op->op_rw_sem);
567 * Remove an existing pool from the system.
569 * The specified pool must have previously been allocated by
570 * lod_pool_new() and not have any target members in the pool.
571 * If the removed target is not the last, compact the array
572 * to remove empty spaces.
574 * \param[in] op pointer to the original data structure
575 * \param[in] idx target index to be removed
577 * \retval 0 on success
578 * \retval negative error number on failure
580 int lod_ost_pool_remove(struct ost_pool *op, __u32 idx)
585 down_write(&op->op_rw_sem);
587 for (i = 0; i < op->op_count; i++) {
588 if (op->op_array[i] == idx) {
589 memmove(&op->op_array[i], &op->op_array[i + 1],
590 (op->op_count - i - 1) *
591 sizeof(op->op_array[0]));
593 up_write(&op->op_rw_sem);
599 up_write(&op->op_rw_sem);
604 * Free the pool after it was emptied and removed from /proc.
606 * Note that all of the child/target entries referenced by this pool
607 * must have been removed by lod_ost_pool_remove() before it can be
608 * deleted from memory.
610 * \param[in] op pool to be freed.
612 * \retval 0 on success or if pool was already freed
614 int lod_ost_pool_free(struct ost_pool *op)
618 if (op->op_size == 0)
621 down_write(&op->op_rw_sem);
623 OBD_FREE(op->op_array, op->op_size * sizeof(op->op_array[0]));
628 up_write(&op->op_rw_sem);
633 * Allocate a new pool for the specified device.
635 * Allocate a new pool_desc structure for the specified \a new_pool
636 * device to create a pool with the given \a poolname. The new pool
637 * structure is created with a single reference, and is freed when the
638 * reference count drops to zero.
640 * \param[in] obd Lustre OBD device on which to add a pool iterator
641 * \param[in] poolname the name of the pool to be created
643 * \retval 0 in case of success
644 * \retval negative error code in case of error
646 int lod_pool_new(struct obd_device *obd, char *poolname)
648 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
649 struct pool_desc *new_pool;
653 if (strlen(poolname) > LOV_MAXPOOLNAME)
654 RETURN(-ENAMETOOLONG);
656 OBD_ALLOC_PTR(new_pool);
657 if (new_pool == NULL)
660 strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name));
661 new_pool->pool_lobd = obd;
662 atomic_set(&new_pool->pool_refcount, 1);
663 rc = lod_ost_pool_init(&new_pool->pool_obds, 0);
667 memset(&new_pool->pool_rr, 0, sizeof(new_pool->pool_rr));
668 rc = lod_ost_pool_init(&new_pool->pool_rr.lqr_pool, 0);
670 GOTO(out_free_pool_obds, rc);
672 INIT_HLIST_NODE(&new_pool->pool_hash);
675 pool_getref(new_pool);
676 new_pool->pool_proc_entry = lprocfs_add_simple(lod->lod_pool_proc_entry,
678 #ifndef HAVE_ONLY_PROCFS_SEQ
682 &pool_proc_operations);
683 if (IS_ERR(new_pool->pool_proc_entry)) {
684 CDEBUG(D_CONFIG, "%s: cannot add proc entry "LOV_POOLNAMEF"\n",
685 obd->obd_name, poolname);
686 new_pool->pool_proc_entry = NULL;
687 lod_pool_putref(new_pool);
689 CDEBUG(D_INFO, "pool %p - proc %p\n", new_pool,
690 new_pool->pool_proc_entry);
693 spin_lock(&obd->obd_dev_lock);
694 cfs_list_add_tail(&new_pool->pool_list, &lod->lod_pool_list);
695 lod->lod_pool_count++;
696 spin_unlock(&obd->obd_dev_lock);
698 /* add to find only when it fully ready */
699 rc = cfs_hash_add_unique(lod->lod_pools_hash_body, poolname,
700 &new_pool->pool_hash);
702 GOTO(out_err, rc = -EEXIST);
704 CDEBUG(D_CONFIG, LOV_POOLNAMEF" is pool #%d\n",
705 poolname, lod->lod_pool_count);
710 spin_lock(&obd->obd_dev_lock);
711 cfs_list_del_init(&new_pool->pool_list);
712 lod->lod_pool_count--;
713 spin_unlock(&obd->obd_dev_lock);
715 lprocfs_remove(&new_pool->pool_proc_entry);
717 lod_ost_pool_free(&new_pool->pool_rr.lqr_pool);
719 lod_ost_pool_free(&new_pool->pool_obds);
720 OBD_FREE_PTR(new_pool);
725 * Remove the named pool from the OBD device.
727 * \param[in] obd OBD device on which pool was previously created
728 * \param[in] poolname name of pool to remove from \a obd
730 * \retval 0 on successfully removing the pool
731 * \retval negative error numbers for failures
733 int lod_pool_del(struct obd_device *obd, char *poolname)
735 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
736 struct pool_desc *pool;
739 /* lookup and kill hash reference */
740 pool = cfs_hash_del_key(lod->lod_pools_hash_body, poolname);
744 if (pool->pool_proc_entry != NULL) {
745 CDEBUG(D_INFO, "proc entry %p\n", pool->pool_proc_entry);
746 lprocfs_remove(&pool->pool_proc_entry);
747 lod_pool_putref(pool);
750 spin_lock(&obd->obd_dev_lock);
751 cfs_list_del_init(&pool->pool_list);
752 lod->lod_pool_count--;
753 spin_unlock(&obd->obd_dev_lock);
755 /* release last reference */
756 lod_pool_putref(pool);
762 * Add a single target device to the named pool.
764 * Add the target specified by \a ostname to the specified \a poolname.
766 * \param[in] obd OBD device on which to add the pool
767 * \param[in] poolname name of the pool to which to add the target \a ostname
768 * \param[in] ostname name of the target device to be added
770 * \retval 0 if \a ostname was (previously) added to the named pool
771 * \retval negative error number on failure
773 int lod_pool_add(struct obd_device *obd, char *poolname, char *ostname)
775 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
776 struct obd_uuid ost_uuid;
777 struct pool_desc *pool;
782 pool = cfs_hash_lookup(lod->lod_pools_hash_body, poolname);
786 obd_str2uuid(&ost_uuid, ostname);
788 /* search ost in lod array */
789 lod_getref(&lod->lod_ost_descs);
790 lod_foreach_ost(lod, idx) {
791 if (obd_uuid_equals(&ost_uuid, &OST_TGT(lod, idx)->ltd_uuid)) {
800 rc = lod_ost_pool_add(&pool->pool_obds, idx, lod->lod_osts_size);
804 pool->pool_rr.lqr_dirty = 1;
806 CDEBUG(D_CONFIG, "Added %s to "LOV_POOLNAMEF" as member %d\n",
807 ostname, poolname, pool_tgt_count(pool));
811 lod_putref(lod, &lod->lod_ost_descs);
812 lod_pool_putref(pool);
817 * Remove the named target from the specified pool.
819 * Remove one target named \a ostname from \a poolname. The \a ostname
820 * is searched for in the lod_device lod_ost_bitmap array, to ensure the
821 * specified name actually exists in the pool.
823 * \param[in] obd OBD device from which to remove \a poolname
824 * \param[in] poolname name of the pool to be changed
825 * \param[in] ostname name of the target to remove from \a poolname
827 * \retval 0 on successfully removing \a ostname from the pool
828 * \retval negative number on error (e.g. \a ostname not in pool)
830 int lod_pool_remove(struct obd_device *obd, char *poolname, char *ostname)
832 struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
833 struct obd_uuid ost_uuid;
834 struct pool_desc *pool;
839 pool = cfs_hash_lookup(lod->lod_pools_hash_body, poolname);
843 obd_str2uuid(&ost_uuid, ostname);
845 lod_getref(&lod->lod_ost_descs);
846 cfs_foreach_bit(lod->lod_ost_bitmap, idx) {
847 if (obd_uuid_equals(&ost_uuid, &OST_TGT(lod, idx)->ltd_uuid)) {
853 /* test if ost found in lod array */
857 lod_ost_pool_remove(&pool->pool_obds, idx);
859 pool->pool_rr.lqr_dirty = 1;
861 CDEBUG(D_CONFIG, "%s removed from "LOV_POOLNAMEF"\n", ostname,
866 lod_putref(lod, &lod->lod_ost_descs);
867 lod_pool_putref(pool);
872 * Check if the specified target exists in the pool.
874 * The caller may not have a reference on \a pool if it got the pool without
875 * calling lod_find_pool() (e.g. directly from the lod pool list)
877 * \param[in] idx Target index to check
878 * \param[in] pool Pool in which to check if target is added.
880 * \retval 0 successfully found index in \a pool
881 * \retval negative error if device not found in \a pool
883 int lod_check_index_in_pool(__u32 idx, struct pool_desc *pool)
890 down_read(&pool_tgt_rw_sem(pool));
892 for (i = 0; i < pool_tgt_count(pool); i++) {
893 if (pool_tgt_array(pool)[i] == idx)
899 up_read(&pool_tgt_rw_sem(pool));
901 lod_pool_putref(pool);
906 * Find the pool descriptor for the specified pool and return it with a
907 * reference to the caller if found.
909 * \param[in] lod LOD on which the pools are configured
910 * \param[in] poolname NUL-terminated name of the pool
912 * \retval pointer to pool descriptor on success
913 * \retval NULL if \a poolname could not be found or poolname is empty
915 struct pool_desc *lod_find_pool(struct lod_device *lod, char *poolname)
917 struct pool_desc *pool;
920 if (poolname[0] != '\0') {
921 pool = cfs_hash_lookup(lod->lod_pools_hash_body, poolname);
923 CDEBUG(D_CONFIG, "%s: request for an unknown pool ("
925 lod->lod_child_exp->exp_obd->obd_name, poolname);
926 if (pool != NULL && pool_tgt_count(pool) == 0) {
927 CDEBUG(D_CONFIG, "%s: request for an empty pool ("
929 lod->lod_child_exp->exp_obd->obd_name, poolname);
930 /* pool is ignored, so we remove ref on it */
931 lod_pool_putref(pool);