Whamcloud - gitweb
148020a8cfe4ce16df2fd62dcba70bc47f7d9182
[fs/lustre-release.git] / lustre / lod / lod_lov.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,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright  2009 Sun Microsystems, Inc. All rights reserved
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, 2013, Intel Corporation.
27  */
28 /*
29  * lustre/lod/lod_lov.c
30  *
31  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com> 
32  */
33
34 #define DEBUG_SUBSYSTEM S_MDS
35
36 #include <obd_class.h>
37 #include <lustre_lfsck.h>
38
39 #include "lod_internal.h"
40
41 /*
42  * Keep a refcount of lod->ltd_tgts usage to prevent racing with
43  * addition/deletion. Any function that expects lov_tgts to remain stationary
44  * must take a ref.
45  *
46  * \param lod - is the lod device from which we want to grab a reference
47  */
48 void lod_getref(struct lod_tgt_descs *ltd)
49 {
50         down_read(&ltd->ltd_rw_sem);
51         mutex_lock(&ltd->ltd_mutex);
52         ltd->ltd_refcount++;
53         mutex_unlock(&ltd->ltd_mutex);
54 }
55
56 /*
57  * Companion of lod_getref() to release a reference on the lod table.
58  * If this is the last reference and the ost entry was scheduled for deletion,
59  * the descriptor is removed from the array.
60  *
61  * \param lod - is the lod device from which we release a reference
62  */
63 void lod_putref(struct lod_device *lod, struct lod_tgt_descs *ltd)
64 {
65         mutex_lock(&ltd->ltd_mutex);
66         ltd->ltd_refcount--;
67         if (ltd->ltd_refcount == 0 && ltd->ltd_death_row) {
68                 struct lod_tgt_desc *tgt_desc, *tmp;
69                 int                  idx;
70                 CFS_LIST_HEAD(kill);
71
72                 CDEBUG(D_CONFIG, "destroying %d ltd desc\n",
73                        ltd->ltd_death_row);
74
75                 cfs_foreach_bit(ltd->ltd_tgt_bitmap, idx) {
76                         tgt_desc = LTD_TGT(ltd, idx);
77                         LASSERT(tgt_desc);
78
79                         if (!tgt_desc->ltd_reap)
80                                 continue;
81
82                         cfs_list_add(&tgt_desc->ltd_kill, &kill);
83                         LTD_TGT(ltd, idx) = NULL;
84                         /*FIXME: only support ost pool for now */
85                         if (ltd == &lod->lod_ost_descs) {
86                                 lod_ost_pool_remove(&lod->lod_pool_info, idx);
87                                 if (tgt_desc->ltd_active)
88                                         lod->lod_desc.ld_active_tgt_count--;
89                         }
90                         ltd->ltd_tgtnr--;
91                         cfs_bitmap_clear(ltd->ltd_tgt_bitmap, idx);
92                         ltd->ltd_death_row--;
93                 }
94                 mutex_unlock(&ltd->ltd_mutex);
95                 up_read(&ltd->ltd_rw_sem);
96
97                 cfs_list_for_each_entry_safe(tgt_desc, tmp, &kill, ltd_kill) {
98                         int rc;
99                         cfs_list_del(&tgt_desc->ltd_kill);
100                         if (ltd == &lod->lod_ost_descs) {
101                                 /* remove from QoS structures */
102                                 rc = qos_del_tgt(lod, tgt_desc);
103                                 if (rc)
104                                         CERROR("%s: qos_del_tgt(%s) failed:"
105                                                "rc = %d\n",
106                                                lod2obd(lod)->obd_name,
107                                               obd_uuid2str(&tgt_desc->ltd_uuid),
108                                                rc);
109                         }
110                         rc = obd_disconnect(tgt_desc->ltd_exp);
111                         if (rc)
112                                 CERROR("%s: failed to disconnect %s: rc = %d\n",
113                                        lod2obd(lod)->obd_name,
114                                        obd_uuid2str(&tgt_desc->ltd_uuid), rc);
115                         OBD_FREE_PTR(tgt_desc);
116                 }
117         } else {
118                 mutex_unlock(&ltd->ltd_mutex);
119                 up_read(&ltd->ltd_rw_sem);
120         }
121 }
122
123 static int ltd_bitmap_resize(struct lod_tgt_descs *ltd, __u32 newsize)
124 {
125         cfs_bitmap_t *new_bitmap, *old_bitmap = NULL;
126         int           rc = 0;
127         ENTRY;
128
129         /* grab write reference on the lod. Relocating the array requires
130          * exclusive access */
131
132         down_write(&ltd->ltd_rw_sem);
133         if (newsize <= ltd->ltd_tgts_size)
134                 /* someone else has already resize the array */
135                 GOTO(out, rc = 0);
136
137         /* allocate new bitmap */
138         new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
139         if (!new_bitmap)
140                 GOTO(out, rc = -ENOMEM);
141
142         if (ltd->ltd_tgts_size > 0) {
143                 /* the bitmap already exists, we need
144                  * to copy data from old one */
145                 cfs_bitmap_copy(new_bitmap, ltd->ltd_tgt_bitmap);
146                 old_bitmap = ltd->ltd_tgt_bitmap;
147         }
148
149         ltd->ltd_tgts_size  = newsize;
150         ltd->ltd_tgt_bitmap = new_bitmap;
151
152         if (old_bitmap)
153                 CFS_FREE_BITMAP(old_bitmap);
154
155         CDEBUG(D_CONFIG, "tgt size: %d\n", ltd->ltd_tgts_size);
156
157         EXIT;
158 out:
159         up_write(&ltd->ltd_rw_sem);
160         return rc;
161 }
162
163 /*
164  * Connect LOD to a new OSP and add it to the device table.
165  *
166  * \param env - is the environment passed by the caller
167  * \param lod - is the LOD device to be connected to the new OSP
168  * \param osp - is the name of OSP device name about to be added
169  * \param index - is the OSP index
170  * \param gen - is the generation number
171  * \param tgt_index - is the group of the OSP.
172  * \param type - is the type of device (mdc or osc)
173  */
174 int lod_add_device(const struct lu_env *env, struct lod_device *lod,
175                    char *osp, unsigned index, unsigned gen, int tgt_index,
176                    char *type, int active)
177 {
178         struct obd_connect_data *data = NULL;
179         struct obd_export       *exp = NULL;
180         struct obd_device       *obd;
181         struct lu_device        *ldev;
182         struct dt_device        *d;
183         int                      rc;
184         struct lod_tgt_desc     *tgt_desc;
185         struct lod_tgt_descs    *ltd;
186         struct obd_uuid         obd_uuid;
187         bool                    for_ost;
188         ENTRY;
189
190         CDEBUG(D_CONFIG, "osp:%s idx:%d gen:%d\n", osp, index, gen);
191
192         if (gen <= 0) {
193                 CERROR("request to add OBD %s with invalid generation: %d\n",
194                        osp, gen);
195                 RETURN(-EINVAL);
196         }
197
198         obd_str2uuid(&obd_uuid, osp);
199
200         obd = class_find_client_obd(&obd_uuid, LUSTRE_OSP_NAME,
201                                 &lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_uuid);
202         if (obd == NULL) {
203                 CERROR("can't find %s device\n", osp);
204                 RETURN(-EINVAL);
205         }
206
207         OBD_ALLOC_PTR(data);
208         if (data == NULL)
209                 RETURN(-ENOMEM);
210
211         data->ocd_connect_flags = OBD_CONNECT_INDEX | OBD_CONNECT_VERSION;
212         data->ocd_version = LUSTRE_VERSION_CODE;
213         data->ocd_index = index;
214
215         if (strcmp(LUSTRE_OSC_NAME, type) == 0) {
216                 for_ost = true;
217                 data->ocd_connect_flags |= OBD_CONNECT_AT |
218                                            OBD_CONNECT_FULL20 |
219                                            OBD_CONNECT_INDEX |
220 #ifdef HAVE_LRU_RESIZE_SUPPORT
221                                            OBD_CONNECT_LRU_RESIZE |
222 #endif
223                                            OBD_CONNECT_MDS |
224                                            OBD_CONNECT_OSS_CAPA |
225                                            OBD_CONNECT_REQPORTAL |
226                                            OBD_CONNECT_SKIP_ORPHAN |
227                                            OBD_CONNECT_FID |
228                                            OBD_CONNECT_LVB_TYPE |
229                                            OBD_CONNECT_VERSION |
230                                            OBD_CONNECT_PINGLESS |
231                                            OBD_CONNECT_LFSCK;
232
233                 data->ocd_group = tgt_index;
234                 ltd = &lod->lod_ost_descs;
235         } else {
236                 struct obd_import *imp = obd->u.cli.cl_import;
237
238                 for_ost = false;
239                 data->ocd_ibits_known = MDS_INODELOCK_UPDATE;
240                 data->ocd_connect_flags |= OBD_CONNECT_ACL |
241                                            OBD_CONNECT_MDS_CAPA |
242                                            OBD_CONNECT_OSS_CAPA |
243                                            OBD_CONNECT_IBITS |
244                                            OBD_CONNECT_MDS_MDS |
245                                            OBD_CONNECT_FID |
246                                            OBD_CONNECT_AT |
247                                            OBD_CONNECT_FULL20 |
248                                            OBD_CONNECT_LFSCK;
249                 /* XXX set MDS-MDS flags, remove this when running this
250                  * on client*/
251                 data->ocd_connect_flags |= OBD_CONNECT_MDS_MDS;
252                 spin_lock(&imp->imp_lock);
253                 imp->imp_server_timeout = 1;
254                 spin_unlock(&imp->imp_lock);
255                 imp->imp_client->cli_request_portal = OUT_PORTAL;
256                 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
257                       obd->obd_name);
258                 ltd = &lod->lod_mdt_descs;
259         }
260
261         rc = obd_connect(env, &exp, obd, &obd->obd_uuid, data, NULL);
262         OBD_FREE_PTR(data);
263         if (rc) {
264                 CERROR("%s: cannot connect to next dev %s (%d)\n",
265                        obd->obd_name, osp, rc);
266                 GOTO(out_free, rc);
267         }
268
269         LASSERT(obd->obd_lu_dev);
270         LASSERT(obd->obd_lu_dev->ld_site == lod->lod_dt_dev.dd_lu_dev.ld_site);
271
272         ldev = obd->obd_lu_dev;
273         d = lu2dt_dev(ldev);
274
275         /* Allocate ost descriptor and fill it */
276         OBD_ALLOC_PTR(tgt_desc);
277         if (!tgt_desc)
278                 GOTO(out_conn, rc = -ENOMEM);
279
280         tgt_desc->ltd_tgt    = d;
281         tgt_desc->ltd_exp    = exp;
282         tgt_desc->ltd_uuid   = obd->u.cli.cl_target_uuid;
283         tgt_desc->ltd_gen    = gen;
284         tgt_desc->ltd_index  = index;
285         tgt_desc->ltd_active = active;
286
287         lod_getref(ltd);
288         if (index >= ltd->ltd_tgts_size) {
289                 /* we have to increase the size of the lod_osts array */
290                 __u32  newsize;
291
292                 newsize = max(ltd->ltd_tgts_size, (__u32)2);
293                 while (newsize < index + 1)
294                         newsize = newsize << 1;
295
296                 /* lod_bitmap_resize() needs lod_rw_sem
297                  * which we hold with th reference */
298                 lod_putref(lod, ltd);
299
300                 rc = ltd_bitmap_resize(ltd, newsize);
301                 if (rc)
302                         GOTO(out_desc, rc);
303
304                 lod_getref(ltd);
305         }
306
307         mutex_lock(&ltd->ltd_mutex);
308         if (cfs_bitmap_check(ltd->ltd_tgt_bitmap, index)) {
309                 CERROR("%s: device %d is registered already\n", obd->obd_name,
310                        index);
311                 GOTO(out_mutex, rc = -EEXIST);
312         }
313
314         if (ltd->ltd_tgt_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
315                 OBD_ALLOC_PTR(ltd->ltd_tgt_idx[index / TGT_PTRS_PER_BLOCK]);
316                 if (ltd->ltd_tgt_idx[index / TGT_PTRS_PER_BLOCK] == NULL) {
317                         CERROR("can't allocate index to add %s\n",
318                                obd->obd_name);
319                         GOTO(out_mutex, rc = -ENOMEM);
320                 }
321         }
322
323         if (!strcmp(LUSTRE_OSC_NAME, type)) {
324                 /* pool and qos are not supported for MDS stack yet */
325                 rc = lod_ost_pool_add(&lod->lod_pool_info, index,
326                                       lod->lod_osts_size);
327                 if (rc) {
328                         CERROR("%s: can't set up pool, failed with %d\n",
329                                obd->obd_name, rc);
330                         GOTO(out_mutex, rc);
331                 }
332
333                 rc = qos_add_tgt(lod, tgt_desc);
334                 if (rc) {
335                         CERROR("%s: qos_add_tgt failed with %d\n",
336                                 obd->obd_name, rc);
337                         GOTO(out_pool, rc);
338                 }
339
340                 /* The new OST is now a full citizen */
341                 if (index >= lod->lod_desc.ld_tgt_count)
342                         lod->lod_desc.ld_tgt_count = index + 1;
343                 if (active)
344                         lod->lod_desc.ld_active_tgt_count++;
345         }
346
347         LTD_TGT(ltd, index) = tgt_desc;
348         cfs_bitmap_set(ltd->ltd_tgt_bitmap, index);
349         ltd->ltd_tgtnr++;
350         mutex_unlock(&ltd->ltd_mutex);
351         lod_putref(lod, ltd);
352         if (lod->lod_recovery_completed)
353                 ldev->ld_ops->ldo_recovery_complete(env, ldev);
354
355         rc = lfsck_add_target(env, lod->lod_child, d, exp, index, for_ost);
356         if (rc != 0)
357                 CERROR("Fail to add LFSCK target: name = %s, type = %s, "
358                        "index = %u, rc = %d\n", osp, type, index, rc);
359
360         RETURN(rc);
361
362 out_pool:
363         lod_ost_pool_remove(&lod->lod_pool_info, index);
364 out_mutex:
365         mutex_unlock(&ltd->ltd_mutex);
366         lod_putref(lod, ltd);
367 out_desc:
368         OBD_FREE_PTR(tgt_desc);
369 out_conn:
370         obd_disconnect(exp);
371 out_free:
372         return rc;
373 }
374
375 /*
376  * helper function to schedule OST removal from the device table
377  */
378 static void __lod_del_device(const struct lu_env *env, struct lod_device *lod,
379                              struct lod_tgt_descs *ltd, unsigned idx,
380                              bool for_ost)
381 {
382         LASSERT(LTD_TGT(ltd, idx));
383
384         lfsck_del_target(env, lod->lod_child, LTD_TGT(ltd, idx)->ltd_tgt,
385                          idx, for_ost);
386
387         if (LTD_TGT(ltd, idx)->ltd_reap == 0) {
388                 LTD_TGT(ltd, idx)->ltd_reap = 1;
389                 ltd->ltd_death_row++;
390         }
391 }
392
393 int lod_fini_tgt(const struct lu_env *env, struct lod_device *lod,
394                  struct lod_tgt_descs *ltd, bool for_ost)
395 {
396         int idx;
397
398         if (ltd->ltd_tgts_size <= 0)
399                 return 0;
400         lod_getref(ltd);
401         mutex_lock(&ltd->ltd_mutex);
402         cfs_foreach_bit(ltd->ltd_tgt_bitmap, idx)
403                 __lod_del_device(env, lod, ltd, idx, for_ost);
404         mutex_unlock(&ltd->ltd_mutex);
405         lod_putref(lod, ltd);
406         CFS_FREE_BITMAP(ltd->ltd_tgt_bitmap);
407         for (idx = 0; idx < TGT_PTRS; idx++) {
408                 if (ltd->ltd_tgt_idx[idx])
409                         OBD_FREE_PTR(ltd->ltd_tgt_idx[idx]);
410         }
411         ltd->ltd_tgts_size = 0;
412         return 0;
413 }
414
415 /*
416  * Add support for administratively disabled OST (through the MGS).
417  * Schedule a target for deletion.  Disconnection and real removal from the
418  * table takes place in lod_putref() once the last table user release its
419  * reference.
420  *
421  * \param env - is the environment passed by the caller
422  * \param lod - is the lod device currently connected to the OSP about to be
423  *              removed
424  * \param osp - is the name of OSP device about to be removed
425  * \param idx - is the OSP index
426  * \param gen - is the generation number, not used currently
427  */
428 int lod_del_device(const struct lu_env *env, struct lod_device *lod,
429                    struct lod_tgt_descs *ltd, char *osp, unsigned idx,
430                    unsigned gen, bool for_ost)
431 {
432         struct obd_device *obd;
433         int                rc = 0;
434         struct obd_uuid    uuid;
435         ENTRY;
436
437         CDEBUG(D_CONFIG, "osp:%s idx:%d gen:%d\n", osp, idx, gen);
438
439         obd_str2uuid(&uuid, osp);
440
441         obd = class_find_client_obd(&uuid, LUSTRE_OSP_NAME,
442                                    &lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_uuid);
443         if (obd == NULL) {
444                 CERROR("can't find %s device\n", osp);
445                 RETURN(-EINVAL);
446         }
447
448         if (gen <= 0) {
449                 CERROR("%s: request to remove OBD %s with invalid generation %d"
450                        "\n", obd->obd_name, osp, gen);
451                 RETURN(-EINVAL);
452         }
453
454         obd_str2uuid(&uuid,  osp);
455
456         lod_getref(ltd);
457         mutex_lock(&ltd->ltd_mutex);
458         /* check that the index is allocated in the bitmap */
459         if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, idx) ||
460             !LTD_TGT(ltd, idx)) {
461                 CERROR("%s: device %d is not set up\n", obd->obd_name, idx);
462                 GOTO(out, rc = -EINVAL);
463         }
464
465         /* check that the UUID matches */
466         if (!obd_uuid_equals(&uuid, &LTD_TGT(ltd, idx)->ltd_uuid)) {
467                 CERROR("%s: LOD target UUID %s at index %d does not match %s\n",
468                        obd->obd_name, obd_uuid2str(&LTD_TGT(ltd,idx)->ltd_uuid),
469                        idx, osp);
470                 GOTO(out, rc = -EINVAL);
471         }
472
473         __lod_del_device(env, lod, ltd, idx, for_ost);
474         EXIT;
475 out:
476         mutex_unlock(&ltd->ltd_mutex);
477         lod_putref(lod, ltd);
478         return(rc);
479 }
480
481 int lod_ea_store_resize(struct lod_thread_info *info, int size)
482 {
483         int round = size_roundup_power2(size);
484
485         LASSERT(round <=
486                 lov_mds_md_size(LOV_MAX_STRIPE_COUNT, LOV_MAGIC_V3));
487         if (info->lti_ea_store) {
488                 LASSERT(info->lti_ea_store_size);
489                 LASSERT(info->lti_ea_store_size < round);
490                 CDEBUG(D_INFO, "EA store size %d is not enough, need %d\n",
491                        info->lti_ea_store_size, round);
492                 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
493                 info->lti_ea_store = NULL;
494                 info->lti_ea_store_size = 0;
495         }
496
497         OBD_ALLOC_LARGE(info->lti_ea_store, round);
498         if (info->lti_ea_store == NULL)
499                 RETURN(-ENOMEM);
500         info->lti_ea_store_size = round;
501         RETURN(0);
502 }
503
504 /*
505  * generate and write LOV EA for given striped object
506  */
507 int lod_generate_and_set_lovea(const struct lu_env *env,
508                                struct lod_object *lo, struct thandle *th)
509 {
510         struct lod_thread_info  *info = lod_env_info(env);
511         struct dt_object        *next = dt_object_child(&lo->ldo_obj);
512         const struct lu_fid     *fid  = lu_object_fid(&lo->ldo_obj.do_lu);
513         struct lov_mds_md_v1    *lmm;
514         struct lov_ost_data_v1  *objs;
515         __u32                    magic;
516         int                      i, rc, lmm_size;
517         int                      cplen = 0;
518         ENTRY;
519
520         LASSERT(lo);
521
522         magic = lo->ldo_pool != NULL ? LOV_MAGIC_V3 : LOV_MAGIC_V1;
523         lmm_size = lov_mds_md_size(lo->ldo_stripenr, magic);
524         if (info->lti_ea_store_size < lmm_size) {
525                 rc = lod_ea_store_resize(info, lmm_size);
526                 if (rc)
527                         RETURN(rc);
528         }
529
530         if (lo->ldo_pattern == 0) /* default striping */
531                 lo->ldo_pattern = LOV_PATTERN_RAID0;
532
533         lmm = info->lti_ea_store;
534
535         lmm->lmm_magic = cpu_to_le32(magic);
536         lmm->lmm_pattern = cpu_to_le32(lo->ldo_pattern);
537         fid_to_lmm_oi(fid, &lmm->lmm_oi);
538         if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_LMMOI))
539                 lmm->lmm_oi.oi.oi_id++;
540         lmm_oi_cpu_to_le(&lmm->lmm_oi, &lmm->lmm_oi);
541         lmm->lmm_stripe_size = cpu_to_le32(lo->ldo_stripe_size);
542         lmm->lmm_stripe_count = cpu_to_le16(lo->ldo_stripenr);
543         if (lo->ldo_pattern & LOV_PATTERN_F_RELEASED)
544                 lmm->lmm_stripe_count = cpu_to_le16(lo->ldo_released_stripenr);
545         lmm->lmm_layout_gen = 0;
546         if (magic == LOV_MAGIC_V1) {
547                 objs = &lmm->lmm_objects[0];
548         } else {
549                 struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm;
550                 cplen = strlcpy(v3->lmm_pool_name, lo->ldo_pool,
551                                 sizeof(v3->lmm_pool_name));
552                 if (cplen >= sizeof(v3->lmm_pool_name))
553                         RETURN(-E2BIG);
554                 objs = &v3->lmm_objects[0];
555         }
556
557         for (i = 0; i < lo->ldo_stripenr; i++) {
558                 struct lu_fid           *fid    = &info->lti_fid;
559                 struct lod_device       *lod;
560                 __u32                   index;
561                 int                     type    = LU_SEQ_RANGE_OST;
562
563                 lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
564                 LASSERT(lo->ldo_stripe[i]);
565
566                 *fid = *lu_object_fid(&lo->ldo_stripe[i]->do_lu);
567                 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MULTIPLE_REF)) {
568                         if (cfs_fail_val == 0)
569                                 cfs_fail_val = fid->f_oid;
570                         else
571                                 fid->f_oid = cfs_fail_val;
572                 }
573
574                 rc = fid_to_ostid(fid, &info->lti_ostid);
575                 LASSERT(rc == 0);
576
577                 ostid_cpu_to_le(&info->lti_ostid, &objs[i].l_ost_oi);
578                 objs[i].l_ost_gen    = cpu_to_le32(0);
579                 rc = lod_fld_lookup(env, lod, fid, &index, &type);
580                 if (rc < 0) {
581                         CERROR("%s: Can not locate "DFID": rc = %d\n",
582                                lod2obd(lod)->obd_name, PFID(fid), rc);
583                         lod_object_free_striping(env, lo);
584                         RETURN(rc);
585                 }
586                 objs[i].l_ost_idx = cpu_to_le32(index);
587         }
588
589         info->lti_buf.lb_buf = lmm;
590         info->lti_buf.lb_len = lmm_size;
591         rc = dt_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV, 0,
592                           th, BYPASS_CAPA);
593         if (rc < 0)
594                 lod_object_free_striping(env, lo);
595
596         RETURN(rc);
597 }
598
599 int lod_get_ea(const struct lu_env *env, struct lod_object *lo,
600                const char *name)
601 {
602         struct lod_thread_info  *info = lod_env_info(env);
603         struct dt_object        *next = dt_object_child(&lo->ldo_obj);
604         int                     rc;
605         ENTRY;
606
607         LASSERT(info);
608
609         if (unlikely(info->lti_ea_store == NULL)) {
610                 /* just to enter in allocation block below */
611                 rc = -ERANGE;
612         } else {
613 repeat:
614                 info->lti_buf.lb_buf = info->lti_ea_store;
615                 info->lti_buf.lb_len = info->lti_ea_store_size;
616                 rc = dt_xattr_get(env, next, &info->lti_buf, name, BYPASS_CAPA);
617         }
618
619         /* if object is not striped or inaccessible */
620         if (rc == -ENODATA || rc == -ENOENT)
621                 RETURN(0);
622
623         if (rc == -ERANGE) {
624                 /* EA doesn't fit, reallocate new buffer */
625                 rc = dt_xattr_get(env, next, &LU_BUF_NULL, name,
626                                   BYPASS_CAPA);
627                 if (rc == -ENODATA || rc == -ENOENT)
628                         RETURN(0);
629                 else if (rc < 0)
630                         RETURN(rc);
631
632                 LASSERT(rc > 0);
633                 rc = lod_ea_store_resize(info, rc);
634                 if (rc)
635                         RETURN(rc);
636                 goto repeat;
637         }
638
639         RETURN(rc);
640 }
641
642 int lod_store_def_striping(const struct lu_env *env, struct dt_object *dt,
643                            struct thandle *th)
644 {
645         struct lod_thread_info  *info = lod_env_info(env);
646         struct lod_object       *lo = lod_dt_obj(dt);
647         struct dt_object        *next = dt_object_child(dt);
648         struct lov_user_md_v3   *v3;
649         int                      rc;
650         ENTRY;
651
652         if (S_ISDIR(dt->do_lu.lo_header->loh_attr))
653                 RETURN(-ENOTDIR);
654         /*
655          * store striping defaults into new directory
656          * used to implement defaults inheritance
657          */
658
659         /* probably nothing to inherite */
660         if (lo->ldo_striping_cached == 0)
661                 RETURN(0);
662
663         if (LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size, lo->ldo_def_stripenr,
664                                 lo->ldo_def_stripe_offset))
665                 RETURN(0);
666
667         v3 = info->lti_ea_store;
668         if (info->lti_ea_store_size < sizeof(*v3)) {
669                 rc = lod_ea_store_resize(info, sizeof(*v3));
670                 if (rc != 0)
671                         RETURN(rc);
672                 v3 = info->lti_ea_store;
673         }
674         memset(v3, 0, sizeof(*v3));
675         v3->lmm_magic = cpu_to_le32(LOV_USER_MAGIC_V3);
676         v3->lmm_stripe_count = cpu_to_le16(lo->ldo_def_stripenr);
677         v3->lmm_stripe_offset = cpu_to_le16(lo->ldo_def_stripe_offset);
678         v3->lmm_stripe_size = cpu_to_le32(lo->ldo_def_stripe_size);
679         if (lo->ldo_pool != NULL)
680                 strlcpy(v3->lmm_pool_name, lo->ldo_pool,
681                         sizeof(v3->lmm_pool_name));
682         info->lti_buf.lb_buf = v3;
683         info->lti_buf.lb_len = sizeof(*v3);
684         rc = dt_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV, 0, th,
685                         BYPASS_CAPA);
686
687         RETURN(rc);
688 }
689
690 static int validate_lod_and_idx(struct lod_device *md, int idx)
691 {
692         if (unlikely(idx >= md->lod_ost_descs.ltd_tgts_size ||
693                      !cfs_bitmap_check(md->lod_ost_bitmap, idx))) {
694                 CERROR("%s: bad idx: %d of %d\n", lod2obd(md)->obd_name, idx,
695                        md->lod_ost_descs.ltd_tgts_size);
696                 return -EINVAL;
697         }
698
699         if (unlikely(OST_TGT(md, idx) == NULL)) {
700                 CERROR("%s: bad lod_tgt_desc for idx: %d\n",
701                        lod2obd(md)->obd_name, idx);
702                 return -EINVAL;
703         }
704
705         if (unlikely(OST_TGT(md, idx)->ltd_ost == NULL)) {
706                 CERROR("%s: invalid lod device, for idx: %d\n",
707                        lod2obd(md)->obd_name , idx);
708                 return -EINVAL;
709         }
710
711         return 0;
712 }
713
714 /*
715  * allocate array of objects pointers, find/create objects
716  * stripenr and other fields should be initialized by this moment
717  */
718 int lod_initialize_objects(const struct lu_env *env, struct lod_object *lo,
719                            struct lov_ost_data_v1 *objs)
720 {
721         struct lod_thread_info  *info = lod_env_info(env);
722         struct lod_device       *md;
723         struct lu_object        *o, *n;
724         struct lu_device        *nd;
725         struct dt_object       **stripe;
726         int                      stripe_len;
727         int                      i, idx, rc = 0;
728         ENTRY;
729
730         LASSERT(lo != NULL);
731         md = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
732         LASSERT(lo->ldo_stripe == NULL);
733         LASSERT(lo->ldo_stripenr > 0);
734         LASSERT(lo->ldo_stripe_size > 0);
735
736         stripe_len = lo->ldo_stripenr;
737         OBD_ALLOC(stripe, sizeof(stripe[0]) * stripe_len);
738         if (stripe == NULL)
739                 RETURN(-ENOMEM);
740
741         for (i = 0; i < lo->ldo_stripenr; i++) {
742                 if (unlikely(lovea_slot_is_dummy(&objs[i])))
743                         continue;
744
745                 ostid_le_to_cpu(&objs[i].l_ost_oi, &info->lti_ostid);
746                 idx = le32_to_cpu(objs[i].l_ost_idx);
747                 rc = ostid_to_fid(&info->lti_fid, &info->lti_ostid, idx);
748                 if (rc != 0)
749                         GOTO(out, rc);
750                 LASSERTF(fid_is_sane(&info->lti_fid), ""DFID" insane!\n",
751                          PFID(&info->lti_fid));
752                 lod_getref(&md->lod_ost_descs);
753
754                 rc = validate_lod_and_idx(md, idx);
755                 if (unlikely(rc != 0)) {
756                         lod_putref(md, &md->lod_ost_descs);
757                         GOTO(out, rc);
758                 }
759
760                 nd = &OST_TGT(md,idx)->ltd_ost->dd_lu_dev;
761                 lod_putref(md, &md->lod_ost_descs);
762
763                 /* In the function below, .hs_keycmp resolves to
764                  * u_obj_hop_keycmp() */
765                 /* coverity[overrun-buffer-val] */
766                 o = lu_object_find_at(env, nd, &info->lti_fid, NULL);
767                 if (IS_ERR(o))
768                         GOTO(out, rc = PTR_ERR(o));
769
770                 n = lu_object_locate(o->lo_header, nd->ld_type);
771                 LASSERT(n);
772
773                 stripe[i] = container_of(n, struct dt_object, do_lu);
774         }
775
776 out:
777         if (rc != 0) {
778                 for (i = 0; i < stripe_len; i++)
779                         if (stripe[i] != NULL)
780                                 lu_object_put(env, &stripe[i]->do_lu);
781
782                 OBD_FREE(stripe, sizeof(stripe[0]) * stripe_len);
783         } else {
784                 lo->ldo_stripe = stripe;
785                 lo->ldo_stripes_allocated = stripe_len;
786         }
787
788         RETURN(rc);
789 }
790
791 /*
792  * Parse striping information stored in lti_ea_store
793  */
794 int lod_parse_striping(const struct lu_env *env, struct lod_object *lo,
795                        const struct lu_buf *buf)
796 {
797         struct lov_mds_md_v1    *lmm;
798         struct lov_ost_data_v1  *objs;
799         __u32                    magic;
800         __u32                    pattern;
801         int                      rc = 0;
802         ENTRY;
803
804         LASSERT(buf);
805         LASSERT(buf->lb_buf);
806         LASSERT(buf->lb_len);
807
808         lmm = (struct lov_mds_md_v1 *) buf->lb_buf;
809         magic = le32_to_cpu(lmm->lmm_magic);
810         pattern = le32_to_cpu(lmm->lmm_pattern);
811
812         if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
813                 GOTO(out, rc = -EINVAL);
814         if (lov_pattern(pattern) != LOV_PATTERN_RAID0)
815                 GOTO(out, rc = -EINVAL);
816
817         lo->ldo_pattern = pattern;
818         lo->ldo_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
819         lo->ldo_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
820         lo->ldo_stripenr = le16_to_cpu(lmm->lmm_stripe_count);
821         /* released file stripenr fixup. */
822         if (pattern & LOV_PATTERN_F_RELEASED)
823                 lo->ldo_stripenr = 0;
824
825         LASSERT(buf->lb_len >= lov_mds_md_size(lo->ldo_stripenr, magic));
826
827         if (magic == LOV_MAGIC_V3) {
828                 struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm;
829                 objs = &v3->lmm_objects[0];
830                 lod_object_set_pool(lo, v3->lmm_pool_name);
831         } else {
832                 objs = &lmm->lmm_objects[0];
833         }
834
835         if (lo->ldo_stripenr > 0)
836                 rc = lod_initialize_objects(env, lo, objs);
837
838 out:
839         RETURN(rc);
840 }
841
842 int lod_load_striping_locked(const struct lu_env *env, struct lod_object *lo)
843 {
844         struct lod_thread_info  *info = lod_env_info(env);
845         struct dt_object        *next = dt_object_child(&lo->ldo_obj);
846         int                      rc = 0;
847         ENTRY;
848
849         /* already initialized? */
850         if (lo->ldo_stripe != NULL)
851                 GOTO(out, rc = 0);
852
853         if (!dt_object_exists(next))
854                 GOTO(out, rc = 0);
855
856         /* Do not load stripe for slaves of striped dir */
857         if (lo->ldo_dir_slave_stripe)
858                 GOTO(out, rc = 0);
859
860         if (S_ISREG(lu_object_attr(lod2lu_obj(lo)))) {
861                 rc = lod_get_lov_ea(env, lo);
862                 if (rc <= 0)
863                         GOTO(out, rc);
864                 /*
865                  * there is LOV EA (striping information) in this object
866                  * let's parse it and create in-core objects for the stripes
867                  */
868                 info->lti_buf.lb_buf = info->lti_ea_store;
869                 info->lti_buf.lb_len = info->lti_ea_store_size;
870                 rc = lod_parse_striping(env, lo, &info->lti_buf);
871         } else if (S_ISDIR(lu_object_attr(lod2lu_obj(lo)))) {
872                 rc = lod_get_lmv_ea(env, lo);
873                 if (rc <= 0)
874                         GOTO(out, rc);
875                 /*
876                  * there is LOV EA (striping information) in this object
877                  * let's parse it and create in-core objects for the stripes
878                  */
879                 info->lti_buf.lb_buf = info->lti_ea_store;
880                 info->lti_buf.lb_len = info->lti_ea_store_size;
881                 rc = lod_parse_dir_striping(env, lo, &info->lti_buf);
882         }
883 out:
884         RETURN(rc);
885 }
886
887 /**
888  * Load and parse striping information, create in-core representation for the
889  * stripes
890  **/
891 int lod_load_striping(const struct lu_env *env, struct lod_object *lo)
892 {
893         struct dt_object        *next = dt_object_child(&lo->ldo_obj);
894         int                     rc = 0;
895
896         /* currently this code is supposed to be called from declaration
897          * phase only, thus the object is not expected to be locked by caller */
898         dt_write_lock(env, next, 0);
899         rc = lod_load_striping_locked(env, lo);
900         dt_write_unlock(env, next);
901         return rc;
902 }
903
904 /* verify the striping information for directory */
905 int lod_verify_striping(struct lod_device *d, const struct lu_buf *buf,
906                         bool is_from_disk)
907 {
908         struct lov_user_md_v1   *lum;
909         struct lov_user_md_v3   *lum3;
910         struct pool_desc        *pool = NULL;
911         __u32                    magic;
912         __u32                    stripe_size;
913         __u16                    stripe_count;
914         __u16                    stripe_offset;
915         size_t                   lum_size;
916         int                      rc = 0;
917         ENTRY;
918
919         lum = buf->lb_buf;
920
921         LASSERT(sizeof(*lum) < sizeof(*lum3));
922
923         if (buf->lb_len < sizeof(*lum)) {
924                 CDEBUG(D_IOCTL, "buf len %zd too small for lov_user_md\n",
925                        buf->lb_len);
926                 GOTO(out, rc = -EINVAL);
927         }
928
929         magic = le32_to_cpu(lum->lmm_magic);
930         if (magic != LOV_USER_MAGIC_V1 &&
931             magic != LOV_USER_MAGIC_V3 &&
932             magic != LOV_MAGIC_V1_DEF &&
933             magic != LOV_MAGIC_V3_DEF) {
934                 CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#x\n", magic);
935                 GOTO(out, rc = -EINVAL);
936         }
937
938         /* the user uses "0" for default stripe pattern normally. */
939         if (!is_from_disk && lum->lmm_pattern == 0)
940                 lum->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
941
942         if (le32_to_cpu(lum->lmm_pattern) != LOV_PATTERN_RAID0) {
943                 CDEBUG(D_IOCTL, "bad userland stripe pattern: %#x\n",
944                        le32_to_cpu(lum->lmm_pattern));
945                 GOTO(out, rc = -EINVAL);
946         }
947
948         /* 64kB is the largest common page size we see (ia64), and matches the
949          * check in lfs */
950         stripe_size = le32_to_cpu(lum->lmm_stripe_size);
951         if (stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
952                 CDEBUG(D_IOCTL, "stripe size %u not a multiple of %u\n",
953                        stripe_size, LOV_MIN_STRIPE_SIZE);
954                 GOTO(out, rc = -EINVAL);
955         }
956
957         /* an offset of -1 is treated as a "special" valid offset */
958         stripe_offset = le16_to_cpu(lum->lmm_stripe_offset);
959         if (stripe_offset != (typeof(stripe_offset))-1) {
960                 /* if offset is not within valid range [0, osts_size) */
961                 if (stripe_offset >= d->lod_osts_size) {
962                         CDEBUG(D_IOCTL, "stripe offset %u >= bitmap size %u\n",
963                                stripe_offset, d->lod_osts_size);
964                         GOTO(out, rc = -EINVAL);
965                 }
966
967                 /* if lmm_stripe_offset is *not* in bitmap */
968                 if (!cfs_bitmap_check(d->lod_ost_bitmap, stripe_offset)) {
969                         CDEBUG(D_IOCTL, "stripe offset %u not in bitmap\n",
970                                stripe_offset);
971                         GOTO(out, rc = -EINVAL);
972                 }
973         }
974
975         if (magic == LOV_USER_MAGIC_V1 || magic == LOV_MAGIC_V1_DEF)
976                 lum_size = offsetof(struct lov_user_md_v1,
977                                     lmm_objects[0]);
978         else if (magic == LOV_USER_MAGIC_V3 || magic == LOV_MAGIC_V3_DEF)
979                 lum_size = offsetof(struct lov_user_md_v3,
980                                     lmm_objects[0]);
981         else
982                 GOTO(out, rc = -EINVAL);
983
984         stripe_count = le16_to_cpu(lum->lmm_stripe_count);
985         if (buf->lb_len != lum_size) {
986                 CDEBUG(D_IOCTL, "invalid buf len %zd for lov_user_md with "
987                        "magic %#x and stripe_count %u\n",
988                        buf->lb_len, magic, stripe_count);
989                 GOTO(out, rc = -EINVAL);
990         }
991
992         if (!(magic == LOV_USER_MAGIC_V3 || magic == LOV_MAGIC_V3_DEF))
993                 goto out;
994
995         lum3 = buf->lb_buf;
996         if (buf->lb_len < sizeof(*lum3)) {
997                 CDEBUG(D_IOCTL, "buf len %zd too small for lov_user_md_v3\n",
998                        buf->lb_len);
999                 GOTO(out, rc = -EINVAL);
1000         }
1001
1002         /* In the function below, .hs_keycmp resolves to
1003          * pool_hashkey_keycmp() */
1004         /* coverity[overrun-buffer-val] */
1005         pool = lod_find_pool(d, lum3->lmm_pool_name);
1006         if (pool == NULL)
1007                 goto out;
1008
1009         if (stripe_offset != (typeof(stripe_offset))-1) {
1010                 rc = lod_check_index_in_pool(stripe_offset, pool);
1011                 if (rc < 0)
1012                         GOTO(out, rc = -EINVAL);
1013         }
1014
1015         if (is_from_disk && stripe_count > pool_tgt_count(pool)) {
1016                 CDEBUG(D_IOCTL,
1017                        "stripe count %u > # OSTs %u in the pool\n",
1018                        stripe_count, pool_tgt_count(pool));
1019                 GOTO(out, rc = -EINVAL);
1020         }
1021
1022 out:
1023         if (pool != NULL)
1024                 lod_pool_putref(pool);
1025
1026         RETURN(rc);
1027 }
1028
1029 void lod_fix_desc_stripe_size(__u64 *val)
1030 {
1031         if (*val < LOV_MIN_STRIPE_SIZE) {
1032                 if (*val != 0)
1033                         LCONSOLE_INFO("Increasing default stripe size to "
1034                                       "minimum value %u\n",
1035                                       LOV_DESC_STRIPE_SIZE_DEFAULT);
1036                 *val = LOV_DESC_STRIPE_SIZE_DEFAULT;
1037         } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
1038                 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
1039                 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
1040                               "multiple of %u)\n",
1041                               *val, LOV_MIN_STRIPE_SIZE);
1042         }
1043 }
1044
1045 void lod_fix_desc_stripe_count(__u32 *val)
1046 {
1047         if (*val == 0)
1048                 *val = 1;
1049 }
1050
1051 void lod_fix_desc_pattern(__u32 *val)
1052 {
1053         /* from lov_setstripe */
1054         if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
1055                 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
1056                 *val = 0;
1057         }
1058 }
1059
1060 void lod_fix_desc_qos_maxage(__u32 *val)
1061 {
1062         /* fix qos_maxage */
1063         if (*val == 0)
1064                 *val = LOV_DESC_QOS_MAXAGE_DEFAULT;
1065 }
1066
1067 void lod_fix_desc(struct lov_desc *desc)
1068 {
1069         lod_fix_desc_stripe_size(&desc->ld_default_stripe_size);
1070         lod_fix_desc_stripe_count(&desc->ld_default_stripe_count);
1071         lod_fix_desc_pattern(&desc->ld_pattern);
1072         lod_fix_desc_qos_maxage(&desc->ld_qos_maxage);
1073 }
1074
1075 int lod_pools_init(struct lod_device *lod, struct lustre_cfg *lcfg)
1076 {
1077         struct obd_device          *obd;
1078         struct lov_desc            *desc;
1079         int                         rc;
1080         ENTRY;
1081
1082         obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1083         LASSERT(obd != NULL);
1084         obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
1085
1086         if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1087                 CERROR("LOD setup requires a descriptor\n");
1088                 RETURN(-EINVAL);
1089         }
1090
1091         desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
1092
1093         if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1094                 CERROR("descriptor size wrong: %d > %d\n",
1095                        (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1096                 RETURN(-EINVAL);
1097         }
1098
1099         if (desc->ld_magic != LOV_DESC_MAGIC) {
1100                 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
1101                         CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
1102                                obd->obd_name, desc);
1103                         lustre_swab_lov_desc(desc);
1104                 } else {
1105                         CERROR("%s: Bad lov desc magic: %#x\n",
1106                                obd->obd_name, desc->ld_magic);
1107                         RETURN(-EINVAL);
1108                 }
1109         }
1110
1111         lod_fix_desc(desc);
1112
1113         desc->ld_active_tgt_count = 0;
1114         lod->lod_desc = *desc;
1115
1116         lod->lod_sp_me = LUSTRE_SP_CLI;
1117
1118         /* Set up allocation policy (QoS and RR) */
1119         CFS_INIT_LIST_HEAD(&lod->lod_qos.lq_oss_list);
1120         init_rwsem(&lod->lod_qos.lq_rw_sem);
1121         lod->lod_qos.lq_dirty = 1;
1122         lod->lod_qos.lq_rr.lqr_dirty = 1;
1123         lod->lod_qos.lq_reset = 1;
1124         /* Default priority is toward free space balance */
1125         lod->lod_qos.lq_prio_free = 232;
1126         /* Default threshold for rr (roughly 17%) */
1127         lod->lod_qos.lq_threshold_rr = 43;
1128
1129         /* Set up OST pool environment */
1130         lod->lod_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
1131                                                    HASH_POOLS_MAX_BITS,
1132                                                    HASH_POOLS_BKT_BITS, 0,
1133                                                    CFS_HASH_MIN_THETA,
1134                                                    CFS_HASH_MAX_THETA,
1135                                                    &pool_hash_operations,
1136                                                    CFS_HASH_DEFAULT);
1137         if (lod->lod_pools_hash_body == NULL)
1138                 RETURN(-ENOMEM);
1139
1140         CFS_INIT_LIST_HEAD(&lod->lod_pool_list);
1141         lod->lod_pool_count = 0;
1142         rc = lod_ost_pool_init(&lod->lod_pool_info, 0);
1143         if (rc)
1144                 GOTO(out_hash, rc);
1145         rc = lod_ost_pool_init(&lod->lod_qos.lq_rr.lqr_pool, 0);
1146         if (rc)
1147                 GOTO(out_pool_info, rc);
1148
1149         RETURN(0);
1150
1151 out_pool_info:
1152         lod_ost_pool_free(&lod->lod_pool_info);
1153 out_hash:
1154         cfs_hash_putref(lod->lod_pools_hash_body);
1155
1156         return rc;
1157 }
1158
1159 int lod_pools_fini(struct lod_device *lod)
1160 {
1161         struct obd_device   *obd = lod2obd(lod);
1162         cfs_list_t          *pos, *tmp;
1163         struct pool_desc    *pool;
1164         ENTRY;
1165
1166         cfs_list_for_each_safe(pos, tmp, &lod->lod_pool_list) {
1167                 pool = cfs_list_entry(pos, struct pool_desc, pool_list);
1168                 /* free pool structs */
1169                 CDEBUG(D_INFO, "delete pool %p\n", pool);
1170                 /* In the function below, .hs_keycmp resolves to
1171                  * pool_hashkey_keycmp() */
1172                 /* coverity[overrun-buffer-val] */
1173                 lod_pool_del(obd, pool->pool_name);
1174         }
1175
1176         cfs_hash_putref(lod->lod_pools_hash_body);
1177         lod_ost_pool_free(&(lod->lod_qos.lq_rr.lqr_pool));
1178         lod_ost_pool_free(&lod->lod_pool_info);
1179
1180         RETURN(0);
1181 }
1182