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,
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.
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
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved
24 * Use is subject to license terms.
27 * lustre/lod/lod_lov.c
29 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
33 # define EXPORT_SYMTAB
35 #define DEBUG_SUBSYSTEM S_MDS
37 #include <obd_class.h>
40 #include "lod_internal.h"
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
47 * \param lod - is the lod device from which we want to grab a reference
49 void lod_getref(struct lod_device *lod)
51 cfs_down_read(&lod->lod_rw_sem);
52 cfs_mutex_lock(&lod->lod_mutex);
54 cfs_mutex_unlock(&lod->lod_mutex);
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.
62 * \param lod - is the lod device from which we release a reference
64 void lod_putref(struct lod_device *lod)
66 cfs_mutex_lock(&lod->lod_mutex);
68 if (lod->lod_refcount == 0 && lod->lod_death_row) {
69 struct lod_ost_desc *ost_desc, *tmp;
73 CDEBUG(D_CONFIG, "destroying %d lod desc\n",
76 cfs_foreach_bit(lod->lod_ost_bitmap, idx) {
77 ost_desc = OST_TGT(lod, idx);
80 if (!ost_desc->ltd_reap)
83 cfs_list_add(&ost_desc->ltd_kill, &kill);
84 /* XXX: remove from the pool */
85 OST_TGT(lod, idx) = NULL;
87 cfs_bitmap_clear(lod->lod_ost_bitmap, idx);
88 if (ost_desc->ltd_active)
89 lod->lod_desc.ld_active_tgt_count--;
92 cfs_mutex_unlock(&lod->lod_mutex);
93 cfs_up_read(&lod->lod_rw_sem);
95 cfs_list_for_each_entry_safe(ost_desc, tmp, &kill, ltd_kill) {
97 cfs_list_del(&ost_desc->ltd_kill);
98 /* XXX: remove from QoS structures */
99 /* disconnect from OSP */
100 rc = obd_disconnect(ost_desc->ltd_exp);
102 CERROR("%s: failed to disconnect %s (%d)\n",
103 lod2obd(lod)->obd_name,
104 obd_uuid2str(&ost_desc->ltd_uuid), rc);
105 OBD_FREE_PTR(ost_desc);
108 cfs_mutex_unlock(&lod->lod_mutex);
109 cfs_up_read(&lod->lod_rw_sem);