Whamcloud - gitweb
LU-1303 lod: methods to manage pools
[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 /*
27  * lustre/lod/lod_lov.c
28  *
29  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com> 
30  */
31
32 #ifndef EXPORT_SYMTAB
33 # define EXPORT_SYMTAB
34 #endif
35 #define DEBUG_SUBSYSTEM S_MDS
36
37 #include <obd_class.h>
38 #include <obd_lov.h>
39
40 #include "lod_internal.h"
41
42 /*
43  * Keep a refcount of lod->lod_osts usage to prevent racing with
44  * addition/deletion. Any function that expects lov_tgts to remain stationary
45  * must take a ref.
46  *
47  * \param lod - is the lod device from which we want to grab a reference
48  */
49 void lod_getref(struct lod_device *lod)
50 {
51         cfs_down_read(&lod->lod_rw_sem);
52         cfs_mutex_lock(&lod->lod_mutex);
53         lod->lod_refcount++;
54         cfs_mutex_unlock(&lod->lod_mutex);
55 }
56
57 /*
58  * Companion of lod_getref() to release a reference on the lod table.
59  * If this is the last reference and the ost entry was scheduled for deletion,
60  * the descriptor is removed from the array.
61  *
62  * \param lod - is the lod device from which we release a reference
63  */
64 void lod_putref(struct lod_device *lod)
65 {
66         cfs_mutex_lock(&lod->lod_mutex);
67         lod->lod_refcount--;
68         if (lod->lod_refcount == 0 && lod->lod_death_row) {
69                 struct lod_ost_desc *ost_desc, *tmp;
70                 int                  idx;
71                 CFS_LIST_HEAD(kill);
72
73                 CDEBUG(D_CONFIG, "destroying %d lod desc\n",
74                        lod->lod_death_row);
75
76                 cfs_foreach_bit(lod->lod_ost_bitmap, idx) {
77                         ost_desc = OST_TGT(lod, idx);
78                         LASSERT(ost_desc);
79
80                         if (!ost_desc->ltd_reap)
81                                 continue;
82
83                         cfs_list_add(&ost_desc->ltd_kill, &kill);
84
85                         lod_ost_pool_remove(&lod->lod_pool_info, idx);
86                         OST_TGT(lod, idx) = NULL;
87                         lod->lod_ostnr--;
88                         cfs_bitmap_clear(lod->lod_ost_bitmap, idx);
89                         if (ost_desc->ltd_active)
90                                 lod->lod_desc.ld_active_tgt_count--;
91                         lod->lod_death_row--;
92                 }
93                 cfs_mutex_unlock(&lod->lod_mutex);
94                 cfs_up_read(&lod->lod_rw_sem);
95
96                 cfs_list_for_each_entry_safe(ost_desc, tmp, &kill, ltd_kill) {
97                         int rc;
98                         cfs_list_del(&ost_desc->ltd_kill);
99                         /* XXX: remove from QoS structures */
100                         /* disconnect from OSP */
101                         rc = obd_disconnect(ost_desc->ltd_exp);
102                         if (rc)
103                                 CERROR("%s: failed to disconnect %s (%d)\n",
104                                        lod2obd(lod)->obd_name,
105                                        obd_uuid2str(&ost_desc->ltd_uuid), rc);
106                         OBD_FREE_PTR(ost_desc);
107                 }
108         } else {
109                 cfs_mutex_unlock(&lod->lod_mutex);
110                 cfs_up_read(&lod->lod_rw_sem);
111         }
112 }
113