Whamcloud - gitweb
a9d87e38cb044065d77ade5c9279e53e54ca9c53
[fs/lustre-release.git] / lustre / lod / lod_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, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 /*
33  * lustre/lod/lod_pool.c
34  *
35  * OST pool methods
36  *
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.
47  *
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.
52  *
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>
56  */
57
58 #define DEBUG_SUBSYSTEM S_LOV
59
60 #include <libcfs/libcfs.h>
61 #include <libcfs/linux/linux-hash.h>
62 #include <libcfs/linux/linux-fs.h>
63 #include <obd.h>
64 #include "lod_internal.h"
65
66 #define pool_tgt(_p, _i) OST_TGT(lu2lod_dev((_p)->pool_lobd->obd_lu_dev), \
67                                  (_p)->pool_obds.op_array[_i])
68
69 /**
70  * Get a reference on the specified pool.
71  *
72  * To ensure the pool descriptor is not freed before the caller is finished
73  * with it.  Any process that is accessing \a pool directly needs to hold
74  * reference on it, including /proc since a userspace thread may be holding
75  * the /proc file open and busy in the kernel.
76  *
77  * \param[in] pool      pool descriptor on which to gain reference
78  */
79 static void pool_getref(struct pool_desc *pool)
80 {
81         CDEBUG(D_INFO, "pool %p\n", pool);
82         atomic_inc(&pool->pool_refcount);
83 }
84
85 /**
86  * Drop a reference on the specified pool and free its memory if needed.
87  *
88  * One reference is held by the LOD OBD device while it is configured, from
89  * the time the configuration log defines the pool until the time when it is
90  * dropped when the LOD OBD is cleaned up or the pool is deleted.  This means
91  * that the pool will not be freed while the LOD device is configured, unless
92  * it is explicitly destroyed by the sysadmin.  The pool structure is freed
93  * after the last reference on the structure is released.
94  *
95  * \param[in] pool      pool descriptor to drop reference on and possibly free
96  */
97 void lod_pool_putref(struct pool_desc *pool)
98 {
99         CDEBUG(D_INFO, "pool %p\n", pool);
100         if (atomic_dec_and_test(&pool->pool_refcount)) {
101                 LASSERT(list_empty(&pool->pool_list));
102                 LASSERT(pool->pool_proc_entry == NULL);
103                 tgt_pool_free(&(pool->pool_rr.lqr_pool));
104                 tgt_pool_free(&(pool->pool_obds));
105                 kfree_rcu(pool, pool_rcu);
106                 EXIT;
107         }
108 }
109
110 static u32 pool_hashfh(const void *data, u32 len, u32 seed)
111 {
112         const char *pool_name = data;
113
114         return hashlen_hash(cfs_hashlen_string((void *)(unsigned long)seed,
115                                                pool_name));
116 }
117
118 static int pool_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
119 {
120         const struct pool_desc *pool = obj;
121         const char *pool_name = arg->key;
122
123         return strcmp(pool_name, pool->pool_name);
124 }
125
126 static const struct rhashtable_params pools_hash_params = {
127         .key_len        = 1, /* actually variable */
128         .key_offset     = offsetof(struct pool_desc, pool_name),
129         .head_offset    = offsetof(struct pool_desc, pool_hash),
130         .hashfn         = pool_hashfh,
131         .obj_cmpfn      = pool_cmpfn,
132         .automatic_shrinking = true,
133 };
134
135 /*
136  * Methods for /proc seq_file iteration of the defined pools.
137  */
138
139 #define POOL_IT_MAGIC 0xB001CEA0
140 struct lod_pool_iterator {
141         unsigned int      lpi_magic;    /* POOL_IT_MAGIC */
142         unsigned int      lpi_idx;      /* from 0 to pool_tgt_size - 1 */
143         struct pool_desc *lpi_pool;
144 };
145
146 /**
147  * Return the next configured target within one pool for seq_file iteration.
148  *
149  * Iterator is used to go through the target entries of a single pool
150  * (i.e. the list of OSTs configured for a named pool).
151  * lpi_idx is the current target index in the pool's op_array[].
152  *
153  * The return type is a void * because this function is one of the
154  * struct seq_operations methods and must match the function template.
155  *
156  * \param[in] seq       /proc sequence file iteration tracking structure
157  * \param[in] v         unused
158  * \param[in] pos       position within iteration; 0 to number of targets - 1
159  *
160  * \retval      struct pool_iterator of the next pool descriptor
161  */
162 static void *pool_proc_next(struct seq_file *seq, void *v, loff_t *pos)
163 {
164         struct lod_pool_iterator *iter = seq->private;
165         int prev_idx;
166
167         LASSERTF(iter->lpi_magic == POOL_IT_MAGIC, "%08X\n", iter->lpi_magic);
168
169         (*pos)++;
170         /* test if end of file */
171         if (*pos > pool_tgt_count(iter->lpi_pool))
172                 return NULL;
173
174         OBD_FAIL_TIMEOUT(OBD_FAIL_OST_LIST_ASSERT, cfs_fail_val);
175
176         /* iterate to find a non empty entry */
177         prev_idx = iter->lpi_idx;
178         iter->lpi_idx++;
179         if (iter->lpi_idx >= pool_tgt_count(iter->lpi_pool)) {
180                 iter->lpi_idx = prev_idx; /* we stay on the last entry */
181                 return NULL;
182         }
183
184         /* return != NULL to continue */
185         return iter;
186 }
187
188 /**
189  * Start seq_file iteration via /proc for a single pool.
190  *
191  * The \a pos parameter may be non-zero, indicating that the iteration
192  * is starting at some offset in the target list.  Use the seq_file
193  * private field to memorize the iterator so we can free it at stop().
194  * Need to restore the private pointer to the pool before freeing it.
195  *
196  * \param[in] seq       new sequence file structure to initialize
197  * \param[in] pos       initial target number at which to start iteration
198  *
199  * \retval              initialized pool iterator private structure
200  * \retval              NULL if \a pos exceeds the number of targets in \a pool
201  * \retval              negative error number on failure
202  */
203 static void *pool_proc_start(struct seq_file *seq, loff_t *pos)
204 {
205         struct pool_desc *pool = seq->private;
206         struct lod_pool_iterator *iter;
207
208         pool_getref(pool);
209         if ((pool_tgt_count(pool) == 0) ||
210             (*pos >= pool_tgt_count(pool))) {
211                 /* iter is not created, so stop() has no way to
212                  * find pool to dec ref */
213                 lod_pool_putref(pool);
214                 return NULL;
215         }
216
217         OBD_ALLOC_PTR(iter);
218         if (iter == NULL)
219                 return ERR_PTR(-ENOMEM);
220         iter->lpi_magic = POOL_IT_MAGIC;
221         iter->lpi_pool = pool;
222         iter->lpi_idx = 0;
223
224         seq->private = iter;
225         down_read(&pool_tgt_rw_sem(pool));
226         if (*pos > 0) {
227                 loff_t i;
228                 void *ptr;
229
230                 i = 0;
231                 do {
232                         ptr = pool_proc_next(seq, &iter, &i);
233                 } while ((i < *pos) && (ptr != NULL));
234
235                 return ptr;
236         }
237
238         return iter;
239 }
240
241 /**
242  * Finish seq_file iteration for a single pool.
243  *
244  * Once iteration has been completed, the pool_iterator struct must be
245  * freed, and the seq_file private pointer restored to the pool, as it
246  * was initially when pool_proc_start() was called.
247  *
248  * In some cases the stop() method may be called 2 times, without calling
249  * the start() method (see seq_read() from fs/seq_file.c). We have to free
250  * the private iterator struct only if seq->private points to the iterator.
251  *
252  * \param[in] seq       sequence file structure to clean up
253  * \param[in] v         (unused)
254  */
255 static void pool_proc_stop(struct seq_file *seq, void *v)
256 {
257         struct lod_pool_iterator *iter = seq->private;
258
259         if (iter != NULL && iter->lpi_magic == POOL_IT_MAGIC) {
260                 up_read(&pool_tgt_rw_sem(iter->lpi_pool));
261                 seq->private = iter->lpi_pool;
262                 lod_pool_putref(iter->lpi_pool);
263                 OBD_FREE_PTR(iter);
264         }
265 }
266
267 /**
268  * Print out one target entry from the pool for seq_file iteration.
269  *
270  * The currently referenced pool target is given by op_array[lpi_idx].
271  *
272  * \param[in] seq       new sequence file structure to initialize
273  * \param[in] v         (unused)
274  */
275 static int pool_proc_show(struct seq_file *seq, void *v)
276 {
277         struct lod_pool_iterator *iter = v;
278         struct lod_tgt_desc  *tgt;
279
280         LASSERTF(iter->lpi_magic == POOL_IT_MAGIC, "%08X\n", iter->lpi_magic);
281         LASSERT(iter->lpi_pool != NULL);
282         LASSERT(iter->lpi_idx <= pool_tgt_count(iter->lpi_pool));
283
284         tgt = pool_tgt(iter->lpi_pool, iter->lpi_idx);
285         if (tgt != NULL)
286                 seq_printf(seq, "%s\n", obd_uuid2str(&(tgt->ltd_uuid)));
287
288         return 0;
289 }
290
291 static const struct seq_operations pool_proc_ops = {
292         .start  = pool_proc_start,
293         .next   = pool_proc_next,
294         .stop   = pool_proc_stop,
295         .show   = pool_proc_show,
296 };
297
298 /**
299  * Open a new /proc file for seq_file iteration of targets in one pool.
300  *
301  * Initialize the seq_file private pointer to reference the pool.
302  *
303  * \param inode inode to store iteration state for /proc
304  * \param file  file descriptor to store iteration methods
305  *
306  * \retval      0 for success
307  * \retval      negative error number on failure
308  */
309 static int pool_proc_open(struct inode *inode, struct file *file)
310 {
311         int rc;
312
313         rc = seq_open(file, &pool_proc_ops);
314         if (!rc) {
315                 struct seq_file *seq = file->private_data;
316                 seq->private = PDE_DATA(inode);
317         }
318         return rc;
319 }
320
321 const static struct proc_ops pool_proc_operations = {
322         .open           = pool_proc_open,
323         .read           = seq_read,
324         .llseek         = seq_lseek,
325         .release        = seq_release,
326 };
327
328 /**
329  * Dump the pool target list into the Lustre debug log.
330  *
331  * This is a debugging function to allow dumping the list of targets
332  * in \a pool to the Lustre kernel debug log at the given \a level.
333  *
334  * This is not currently called by any existing code, but can be called
335  * from within gdb/crash to display the contents of the pool, or from
336  * code under development.
337  *
338  * \param[in] level     Lustre debug level (D_INFO, D_WARN, D_ERROR, etc)
339  * \param[in] pool      pool descriptor to be dumped
340  */
341 void lod_dump_pool(int level, struct pool_desc *pool)
342 {
343         unsigned int i;
344
345         pool_getref(pool);
346
347         CDEBUG(level, "pool "LOV_POOLNAMEF" has %d members\n",
348                pool->pool_name, pool->pool_obds.op_count);
349         down_read(&pool_tgt_rw_sem(pool));
350
351         for (i = 0; i < pool_tgt_count(pool) ; i++) {
352                 if (!pool_tgt(pool, i) || !(pool_tgt(pool, i))->ltd_exp)
353                         continue;
354                 CDEBUG(level, "pool "LOV_POOLNAMEF"[%d] = %s\n",
355                        pool->pool_name, i,
356                        obd_uuid2str(&((pool_tgt(pool, i))->ltd_uuid)));
357         }
358
359         up_read(&pool_tgt_rw_sem(pool));
360         lod_pool_putref(pool);
361 }
362
363 static void pools_hash_exit(void *vpool, void *data)
364 {
365         struct pool_desc *pool = vpool;
366
367         lod_pool_putref(pool);
368 }
369
370 int lod_pool_hash_init(struct rhashtable *tbl)
371 {
372         return rhashtable_init(tbl, &pools_hash_params);
373 }
374
375 void lod_pool_hash_destroy(struct rhashtable *tbl)
376 {
377         rhashtable_free_and_destroy(tbl, pools_hash_exit, NULL);
378 }
379
380 /**
381  * Allocate a new pool for the specified device.
382  *
383  * Allocate a new pool_desc structure for the specified \a new_pool
384  * device to create a pool with the given \a poolname.  The new pool
385  * structure is created with a single reference, and is freed when the
386  * reference count drops to zero.
387  *
388  * \param[in] obd       Lustre OBD device on which to add a pool iterator
389  * \param[in] poolname  the name of the pool to be created
390  *
391  * \retval              0 in case of success
392  * \retval              negative error code in case of error
393  */
394 int lod_pool_new(struct obd_device *obd, char *poolname)
395 {
396         struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
397         struct pool_desc  *new_pool;
398         int rc;
399         ENTRY;
400
401         if (strlen(poolname) > LOV_MAXPOOLNAME)
402                 RETURN(-ENAMETOOLONG);
403
404         /* OBD_ALLOC_* doesn't work with direct kfree_rcu use */
405         new_pool = kmalloc(sizeof(*new_pool), GFP_KERNEL);
406         if (new_pool == NULL)
407                 RETURN(-ENOMEM);
408
409         strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name));
410         new_pool->pool_lobd = obd;
411         atomic_set(&new_pool->pool_refcount, 1);
412         rc = tgt_pool_init(&new_pool->pool_obds, 0);
413         if (rc)
414                 GOTO(out_err, rc);
415
416         lu_qos_rr_init(&new_pool->pool_rr);
417
418         rc = tgt_pool_init(&new_pool->pool_rr.lqr_pool, 0);
419         if (rc)
420                 GOTO(out_free_pool_obds, rc);
421
422 #ifdef CONFIG_PROC_FS
423         pool_getref(new_pool);
424         new_pool->pool_proc_entry = lprocfs_add_simple(lod->lod_pool_proc_entry,
425                                                        poolname, new_pool,
426                                                        &pool_proc_operations);
427         if (IS_ERR(new_pool->pool_proc_entry)) {
428                 CDEBUG(D_CONFIG, "%s: cannot add proc entry "LOV_POOLNAMEF"\n",
429                        obd->obd_name, poolname);
430                 new_pool->pool_proc_entry = NULL;
431                 lod_pool_putref(new_pool);
432         }
433         CDEBUG(D_INFO, "pool %p - proc %p\n", new_pool,
434                new_pool->pool_proc_entry);
435 #endif
436
437         spin_lock(&obd->obd_dev_lock);
438         list_add_tail(&new_pool->pool_list, &lod->lod_pool_list);
439         lod->lod_pool_count++;
440         spin_unlock(&obd->obd_dev_lock);
441
442         /* Add to hash table only when it is fully ready. */
443         rc = rhashtable_lookup_insert_fast(&lod->lod_pools_hash_body,
444                                            &new_pool->pool_hash,
445                                            pools_hash_params);
446         if (rc) {
447                 if (rc != -EEXIST)
448                         /*
449                          * Hide -E2BIG and -EBUSY which
450                          * are not helpful.
451                          */
452                         rc = -ENOMEM;
453                 GOTO(out_err, rc);
454         }
455
456         CDEBUG(D_CONFIG, LOV_POOLNAMEF" is pool #%d\n",
457                         poolname, lod->lod_pool_count);
458
459         RETURN(0);
460
461 out_err:
462         spin_lock(&obd->obd_dev_lock);
463         list_del_init(&new_pool->pool_list);
464         lod->lod_pool_count--;
465         spin_unlock(&obd->obd_dev_lock);
466
467         lprocfs_remove(&new_pool->pool_proc_entry);
468
469         tgt_pool_free(&new_pool->pool_rr.lqr_pool);
470 out_free_pool_obds:
471         tgt_pool_free(&new_pool->pool_obds);
472         OBD_FREE_PTR(new_pool);
473         return rc;
474 }
475
476 /**
477  * Remove the named pool from the OBD device.
478  *
479  * \param[in] obd       OBD device on which pool was previously created
480  * \param[in] poolname  name of pool to remove from \a obd
481  *
482  * \retval              0 on successfully removing the pool
483  * \retval              negative error numbers for failures
484  */
485 int lod_pool_del(struct obd_device *obd, char *poolname)
486 {
487         struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
488         struct pool_desc  *pool;
489         ENTRY;
490
491         /* lookup and kill hash reference */
492         rcu_read_lock();
493         pool = rhashtable_lookup(&lod->lod_pools_hash_body, poolname,
494                                  pools_hash_params);
495         if (pool && rhashtable_remove_fast(&lod->lod_pools_hash_body,
496                                            &pool->pool_hash,
497                                            pools_hash_params) != 0)
498                 pool = NULL;
499         rcu_read_unlock();
500         if (!pool)
501                 RETURN(-ENOENT);
502
503         if (pool->pool_proc_entry != NULL) {
504                 CDEBUG(D_INFO, "proc entry %p\n", pool->pool_proc_entry);
505                 lprocfs_remove(&pool->pool_proc_entry);
506                 lod_pool_putref(pool);
507         }
508
509         spin_lock(&obd->obd_dev_lock);
510         list_del_init(&pool->pool_list);
511         lod->lod_pool_count--;
512         spin_unlock(&obd->obd_dev_lock);
513
514         /* release last reference */
515         lod_pool_putref(pool);
516
517         RETURN(0);
518 }
519
520 /**
521  * Add a single target device to the named pool.
522  *
523  * Add the target specified by \a ostname to the specified \a poolname.
524  *
525  * \param[in] obd       OBD device on which to add the pool
526  * \param[in] poolname  name of the pool to which to add the target \a ostname
527  * \param[in] ostname   name of the target device to be added
528  *
529  * \retval              0 if \a ostname was (previously) added to the named pool
530  * \retval              negative error number on failure
531  */
532 int lod_pool_add(struct obd_device *obd, char *poolname, char *ostname)
533 {
534         struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
535         struct obd_uuid ost_uuid;
536         struct pool_desc *pool;
537         struct lu_tgt_desc *tgt;
538         int rc = -EINVAL;
539         ENTRY;
540
541         rcu_read_lock();
542         pool = rhashtable_lookup(&lod->lod_pools_hash_body, poolname,
543                                  pools_hash_params);
544         if (pool && !atomic_inc_not_zero(&pool->pool_refcount))
545                 pool = NULL;
546         rcu_read_unlock();
547         if (!pool)
548                 RETURN(-ENOENT);
549
550         obd_str2uuid(&ost_uuid, ostname);
551
552         /* search ost in lod array */
553         lod_getref(&lod->lod_ost_descs);
554         lod_foreach_ost(lod, tgt) {
555                 if (obd_uuid_equals(&ost_uuid, &tgt->ltd_uuid)) {
556                         rc = 0;
557                         break;
558                 }
559         }
560
561         if (rc)
562                 GOTO(out, rc);
563
564         rc = tgt_pool_add(&pool->pool_obds, tgt->ltd_index,
565                               lod->lod_ost_count);
566         if (rc)
567                 GOTO(out, rc);
568
569         set_bit(LQ_DIRTY, &pool->pool_rr.lqr_flags);
570
571         CDEBUG(D_CONFIG, "Added %s to "LOV_POOLNAMEF" as member %d\n",
572                         ostname, poolname,  pool_tgt_count(pool));
573
574         EXIT;
575 out:
576         lod_putref(lod, &lod->lod_ost_descs);
577         lod_pool_putref(pool);
578         return rc;
579 }
580
581 /**
582  * Remove the named target from the specified pool.
583  *
584  * Remove one target named \a ostname from \a poolname.  The \a ostname
585  * is searched for in the lod_device lod_ost_bitmap array, to ensure the
586  * specified name actually exists in the pool.
587  *
588  * \param[in] obd       OBD device from which to remove \a poolname
589  * \param[in] poolname  name of the pool to be changed
590  * \param[in] ostname   name of the target to remove from \a poolname
591  *
592  * \retval              0 on successfully removing \a ostname from the pool
593  * \retval              negative number on error (e.g. \a ostname not in pool)
594  */
595 int lod_pool_remove(struct obd_device *obd, char *poolname, char *ostname)
596 {
597         struct lod_device *lod = lu2lod_dev(obd->obd_lu_dev);
598         struct lu_tgt_desc *ost;
599         struct obd_uuid ost_uuid;
600         struct pool_desc *pool;
601         int rc = -EINVAL;
602         ENTRY;
603
604         /* lookup and kill hash reference */
605         rcu_read_lock();
606         pool = rhashtable_lookup(&lod->lod_pools_hash_body, poolname,
607                                  pools_hash_params);
608         if (pool && !atomic_inc_not_zero(&pool->pool_refcount))
609                 pool = NULL;
610         rcu_read_unlock();
611         if (!pool)
612                 RETURN(-ENOENT);
613
614         obd_str2uuid(&ost_uuid, ostname);
615
616         lod_getref(&lod->lod_ost_descs);
617         lod_foreach_ost(lod, ost) {
618                 if (obd_uuid_equals(&ost_uuid, &ost->ltd_uuid)) {
619                         rc = 0;
620                         break;
621                 }
622         }
623
624         /* test if ost found in lod array */
625         if (rc)
626                 GOTO(out, rc);
627
628         tgt_pool_remove(&pool->pool_obds, ost->ltd_index);
629         set_bit(LQ_DIRTY, &pool->pool_rr.lqr_flags);
630
631         CDEBUG(D_CONFIG, "%s removed from "LOV_POOLNAMEF"\n", ostname,
632                poolname);
633
634         EXIT;
635 out:
636         lod_putref(lod, &lod->lod_ost_descs);
637         lod_pool_putref(pool);
638         return rc;
639 }
640
641 /**
642  * Check if the specified target exists in the pool.
643  *
644  * The caller may not have a reference on \a pool if it got the pool without
645  * calling lod_find_pool() (e.g. directly from the lod pool list)
646  *
647  * \param[in] idx       Target index to check
648  * \param[in] pool      Pool in which to check if target is added.
649  *
650  * \retval              0 successfully found index in \a pool
651  * \retval              negative error if device not found in \a pool
652  */
653 int lod_check_index_in_pool(__u32 idx, struct pool_desc *pool)
654 {
655         int rc;
656
657         pool_getref(pool);
658         rc = tgt_check_index(idx, &pool->pool_obds);
659         lod_pool_putref(pool);
660         return rc;
661 }
662
663 /**
664  * Find the pool descriptor for the specified pool and return it with a
665  * reference to the caller if found.
666  *
667  * \param[in] lod       LOD on which the pools are configured
668  * \param[in] poolname  NUL-terminated name of the pool
669  *
670  * \retval      pointer to pool descriptor on success
671  * \retval      NULL if \a poolname could not be found or poolname is empty
672  */
673 struct pool_desc *lod_find_pool(struct lod_device *lod, char *poolname)
674 {
675         struct pool_desc *pool;
676
677         pool = NULL;
678         if (poolname[0] != '\0') {
679                 rcu_read_lock();
680                 pool = rhashtable_lookup(&lod->lod_pools_hash_body, poolname,
681                                          pools_hash_params);
682                 if (pool && !atomic_inc_not_zero(&pool->pool_refcount))
683                         pool = NULL;
684                 rcu_read_unlock();
685                 if (!pool)
686                         CDEBUG(D_CONFIG,
687                                "%s: request for an unknown pool (" LOV_POOLNAMEF ")\n",
688                                lod->lod_child_exp->exp_obd->obd_name, poolname);
689                 if (pool != NULL && pool_tgt_count(pool) == 0) {
690                         CDEBUG(D_CONFIG, "%s: request for an empty pool ("
691                                LOV_POOLNAMEF")\n",
692                                lod->lod_child_exp->exp_obd->obd_name, poolname);
693                         /* pool is ignored, so we remove ref on it */
694                         lod_pool_putref(pool);
695                         pool = NULL;
696                 }
697         }
698         return pool;
699 }
700