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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mgs/mgs_nids.c
38 * NID table management for lustre.
40 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_MGS
44 #define D_MGS D_CONFIG
47 #include <linux/module.h>
48 #include <linux/pagemap.h>
54 #include <obd_class.h>
55 #include <lustre_log.h>
57 #include <libcfs/list.h>
58 #include <linux/lvfs.h>
59 #include <lustre_fsfilt.h>
60 #include <lustre_disk.h>
61 #include <lustre_param.h>
62 #include "mgs_internal.h"
64 static unsigned int ir_timeout;
66 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
68 struct mgs_nidtbl_target *tgt;
71 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
72 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
73 if (!tgt->mnt_version)
76 if (version >= tgt->mnt_version)
79 version = tgt->mnt_version;
85 * Fetch nidtbl entries whose version are not less than @version
86 * nidtbl entries will be packed in @pages by @unit_size units - entries
87 * shouldn't cross unit boundaries.
89 static int mgs_nidtbl_read(struct obd_device *unused, struct mgs_nidtbl *tbl,
90 struct mgs_config_res *res, cfs_page_t **pages,
91 int nrpages, int units_total, int unit_size)
93 struct mgs_nidtbl_target *tgt;
94 struct mgs_nidtbl_entry *entry;
95 struct mgs_nidtbl_entry *last_in_unit = NULL;
96 struct mgs_target_info *mti;
97 __u64 version = res->mcr_offset;
100 int bytes_in_unit = 0;
101 int units_in_page = 0;
106 /* make sure unit_size is power 2 */
107 LASSERT((unit_size & (unit_size - 1)) == 0);
108 LASSERT(nrpages << CFS_PAGE_SHIFT >= units_total * unit_size);
110 cfs_mutex_lock(&tbl->mn_lock);
111 LASSERT(nidtbl_is_sane(tbl));
113 /* no more entries ? */
114 if (version > tbl->mn_version) {
115 version = tbl->mn_version;
119 /* iterate over all targets to compose a bitmap by the type of llog.
120 * If the llog is for MDTs, llog entries for OSTs will be returned;
121 * otherwise, it's for clients, then llog entries for both OSTs and
122 * MDTs will be returned.
124 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
125 int entry_len = sizeof(*entry);
127 if (tgt->mnt_version < version)
130 /* write target recover information */
132 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
133 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
135 if (entry_len > unit_size) {
136 CWARN("nidtbl: too large entry: entry length %d,"
137 "unit size: %d\n", entry_len, unit_size);
138 GOTO(out, rc = -EOVERFLOW);
141 if (bytes_in_unit < entry_len) {
142 if (units_total == 0) {
147 /* check if we need to consume remaining bytes. */
148 if (last_in_unit != NULL && bytes_in_unit) {
149 last_in_unit->mne_length += bytes_in_unit;
151 buf += bytes_in_unit;
154 LASSERT((rc & (unit_size - 1)) == 0);
156 if (units_in_page == 0) {
157 /* allocate a new page */
158 pages[index] = cfs_alloc_page(CFS_ALLOC_STD);
159 if (pages[index] == NULL) {
164 /* destroy previous map */
166 cfs_kunmap(pages[index - 1]);
168 /* reassign buffer */
169 buf = cfs_kmap(pages[index]);
172 units_in_page = CFS_PAGE_SIZE / unit_size;
173 LASSERT(units_in_page > 0);
176 /* allocate an unit */
177 LASSERT(((long)buf & (unit_size - 1)) == 0);
178 bytes_in_unit = unit_size;
184 entry = (struct mgs_nidtbl_entry *)buf;
185 entry->mne_version = tgt->mnt_version;
186 entry->mne_instance = mti->mti_instance;
187 entry->mne_index = mti->mti_stripe_index;
188 entry->mne_length = entry_len;
189 entry->mne_type = tgt->mnt_type;
190 entry->mne_nid_type = 0;
191 entry->mne_nid_size = sizeof(lnet_nid_t);
192 entry->mne_nid_count = mti->mti_nid_count;
193 memcpy(entry->u.nids, mti->mti_nids,
194 mti->mti_nid_count * sizeof(lnet_nid_t));
196 version = tgt->mnt_version;
200 bytes_in_unit -= entry_len;
201 last_in_unit = entry;
203 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
204 tbl->mn_fsdb->fsdb_name, entry_len,
205 bytes_in_unit, index, nrpages, units_total);
208 cfs_kunmap(pages[index - 1]);
210 LASSERT(version <= tbl->mn_version);
211 res->mcr_size = tbl->mn_version;
212 res->mcr_offset = nobuf ? version : tbl->mn_version;
213 cfs_mutex_unlock(&tbl->mn_lock);
214 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
216 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
217 tbl->mn_fsdb->fsdb_name, rc, version);
221 static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
223 struct lvfs_run_ctxt saved;
224 struct file *file = NULL;
225 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
231 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
232 LASSERT(sizeof(filename) < 32);
234 sprintf(filename, "%s/%s",
235 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
237 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
239 file = l_filp_open(filename, O_RDWR|O_CREAT, 0660);
241 version = cpu_to_le64(tbl->mn_version);
242 rc = lustre_fwrite(file, &version, sizeof(version), &off);
243 if (rc == sizeof(version))
246 fsfilt_sync(obd, obd->u.mgs.mgs_sb);
251 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
255 #define MGS_NIDTBL_VERSION_INIT 2
257 static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
259 struct lvfs_run_ctxt saved;
260 struct file *file = NULL;
261 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
267 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
268 LASSERT(sizeof(filename) < 32);
270 sprintf(filename, "%s/%s",
271 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
273 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
275 file = l_filp_open(filename, O_RDONLY, 0);
277 rc = lustre_fread(file, &version, sizeof(version), &off);
278 if (rc == sizeof(version))
279 rc = cpu_to_le64(version);
281 rc = MGS_NIDTBL_VERSION_INIT;
283 CERROR("read version file %s error %d\n", filename, rc);
288 rc = MGS_NIDTBL_VERSION_INIT;
291 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
295 static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
297 struct mgs_nidtbl *tbl;
298 struct mgs_nidtbl_target *tgt;
300 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
304 type &= ~LDD_F_SV_TYPE_MGS;
307 tbl = &fsdb->fsdb_nidtbl;
308 cfs_mutex_lock(&tbl->mn_lock);
309 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
310 struct mgs_target_info *info = &tgt->mnt_mti;
311 if (type == tgt->mnt_type &&
312 mti->mti_stripe_index == info->mti_stripe_index) {
320 GOTO(out, rc = -ENOMEM);
322 CFS_INIT_LIST_HEAD(&tgt->mnt_list);
324 tgt->mnt_version = 0; /* 0 means invalid */
325 tgt->mnt_type = type;
327 ++tbl->mn_nr_targets;
330 tgt->mnt_version = ++tbl->mn_version;
333 cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
335 rc = nidtbl_update_version(fsdb->fsdb_obd, tbl);
339 cfs_mutex_unlock(&tbl->mn_lock);
341 CERROR("Write NID table version for file system %s error %d\n",
342 fsdb->fsdb_name, rc);
346 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
348 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
351 cfs_mutex_lock(&tbl->mn_lock);
352 tbl->mn_nr_targets = 0;
353 cfs_list_splice_init(&tbl->mn_targets, &head);
354 cfs_mutex_unlock(&tbl->mn_lock);
356 while (!cfs_list_empty(&head)) {
357 struct mgs_nidtbl_target *tgt;
358 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
359 cfs_list_del(&tgt->mnt_list);
364 static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
366 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
368 CFS_INIT_LIST_HEAD(&tbl->mn_targets);
369 cfs_mutex_init(&tbl->mn_lock);
370 tbl->mn_nr_targets = 0;
372 cfs_mutex_lock(&tbl->mn_lock);
373 tbl->mn_version = nidtbl_read_version(fsdb->fsdb_obd, tbl);
374 cfs_mutex_unlock(&tbl->mn_lock);
375 CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
380 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
381 void mgs_ir_notify_complete(struct fs_db *fsdb)
384 cfs_duration_t delta;
386 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
389 fsdb->fsdb_notify_count++;
390 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
391 fsdb->fsdb_notify_total += delta;
392 if (delta > fsdb->fsdb_notify_max)
393 fsdb->fsdb_notify_max = delta;
395 cfs_duration_usec(delta, &tv);
396 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
397 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
400 static int mgs_ir_notify(void *arg)
402 struct fs_db *fsdb = arg;
403 struct ldlm_res_id resid;
405 char name[sizeof(fsdb->fsdb_name) + 20];
407 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
408 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
411 cfs_complete(&fsdb->fsdb_notify_comp);
413 set_user_nice(current, -2);
415 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
417 struct l_wait_info lwi = { 0 };
419 l_wait_event(fsdb->fsdb_notify_waitq,
420 fsdb->fsdb_notify_stop ||
421 cfs_atomic_read(&fsdb->fsdb_notify_phase),
423 if (fsdb->fsdb_notify_stop)
426 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
427 name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
429 fsdb->fsdb_notify_start = cfs_time_current();
430 mgs_revoke_lock(fsdb->fsdb_obd, fsdb, CONFIG_T_RECOVER);
433 cfs_complete(&fsdb->fsdb_notify_comp);
437 int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
439 struct mgs_obd *mgs = &obd->u.mgs;
443 ir_timeout = OBD_IR_MGS_TIMEOUT;
445 fsdb->fsdb_ir_state = IR_FULL;
446 if (cfs_time_before(cfs_time_current_sec(),
447 mgs->mgs_start_time + ir_timeout))
448 fsdb->fsdb_ir_state = IR_STARTUP;
449 fsdb->fsdb_nonir_clients = 0;
450 CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
452 /* start notify thread */
453 fsdb->fsdb_obd = obd;
454 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
455 cfs_waitq_init(&fsdb->fsdb_notify_waitq);
456 cfs_init_completion(&fsdb->fsdb_notify_comp);
457 rc = cfs_create_thread(mgs_ir_notify, fsdb, CFS_DAEMON_FLAGS);
459 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
461 CERROR("Start notify thread error %d\n", rc);
463 mgs_nidtbl_init_fs(fsdb);
467 void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
469 if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
472 mgs_fsc_cleanup_by_fsdb(fsdb);
474 mgs_nidtbl_fini_fs(fsdb);
476 LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
478 fsdb->fsdb_notify_stop = 1;
479 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
480 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
483 /* caller must have held fsdb_mutex */
484 static inline void ir_state_graduate(struct fs_db *fsdb)
486 struct mgs_obd *mgs = &fsdb->fsdb_obd->u.mgs;
488 if (fsdb->fsdb_ir_state == IR_STARTUP) {
489 if (cfs_time_before(mgs->mgs_start_time + ir_timeout,
490 cfs_time_current_sec())) {
491 fsdb->fsdb_ir_state = IR_FULL;
492 if (fsdb->fsdb_nonir_clients)
493 fsdb->fsdb_ir_state = IR_PARTIAL;
498 int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
504 if (mti->mti_instance == 0)
507 rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
511 rc = mgs_nidtbl_write(fsdb, mti);
516 cfs_mutex_lock(&fsdb->fsdb_mutex);
517 ir_state_graduate(fsdb);
518 switch (fsdb->fsdb_ir_state) {
520 mti->mti_flags |= LDD_F_IR_CAPABLE;
530 cfs_mutex_unlock(&fsdb->fsdb_mutex);
532 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
534 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
536 cfs_atomic_inc(&fsdb->fsdb_notify_phase);
537 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
542 /* NID table can be cached by two entities: Clients and MDTs */
548 static int delogname(char *logname, char *fsname, int *typ)
554 ptr = strrchr(logname, '-');
558 /* decouple file system name. The llog name may be:
559 * - "prefix-fsname", prefix is "cliir" or "mdtir"
561 if (strncmp(ptr, "-mdtir", 6) == 0)
563 else if (strncmp(ptr, "-cliir", 6) == 0)
572 memcpy(fsname, logname, len);
579 int mgs_get_ir_logs(struct ptlrpc_request *req)
581 struct obd_device *obd = req->rq_export->exp_obd;
583 struct mgs_config_body *body;
584 struct mgs_config_res *res;
585 struct ptlrpc_bulk_desc *desc;
586 struct l_wait_info lwi;
597 cfs_page_t **pages = NULL;
600 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
604 if (body->mcb_type != CONFIG_T_RECOVER)
607 rc = delogname(body->mcb_name, fsname, &type);
611 rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
615 bufsize = body->mcb_units << body->mcb_bits;
616 nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
617 if (nrpages > PTLRPC_MAX_BRW_PAGES)
620 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
621 body->mcb_name, bufsize);
623 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
627 rc = req_capsule_server_pack(&req->rq_pill);
631 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
633 GOTO(out, rc = -EINVAL);
635 res->mcr_offset = body->mcb_offset;
636 unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
637 bytes = mgs_nidtbl_read(obd, &fsdb->fsdb_nidtbl, res, pages, nrpages,
638 bufsize / unit_size, unit_size);
640 GOTO(out, rc = bytes);
642 /* start bulk transfer */
643 page_count = (bytes + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
644 LASSERT(page_count <= nrpages);
645 desc = ptlrpc_prep_bulk_exp(req, page_count,
646 BULK_PUT_SOURCE, MGS_BULK_PORTAL);
648 GOTO(out, rc = -ENOMEM);
650 for (i = 0; i < page_count && bytes > 0; i++) {
651 ptlrpc_prep_bulk_page(desc, pages[i], 0,
652 min_t(int, bytes, CFS_PAGE_SIZE));
653 bytes -= CFS_PAGE_SIZE;
656 rc = target_bulk_io(req->rq_export, desc, &lwi);
657 ptlrpc_free_bulk(desc);
661 for (i = 0; i < nrpages; i++) {
662 if (pages[i] == NULL)
664 cfs_free_page(pages[i]);
666 OBD_FREE(pages, sizeof(*pages) * nrpages);
671 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
673 const char *strings[] = IR_STRINGS;
677 for (i = 0; i < ARRAY_SIZE(strings); i++) {
678 if (strcmp(strings[i], buf) == 0) {
686 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
687 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
688 cfs_mutex_lock(&fsdb->fsdb_mutex);
689 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
691 fsdb->fsdb_ir_state = state;
692 cfs_mutex_unlock(&fsdb->fsdb_mutex);
697 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
702 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
707 fsdb->fsdb_notify_total = 0;
708 fsdb->fsdb_notify_max = 0;
709 fsdb->fsdb_notify_count = 0;
713 static struct lproc_ir_cmd {
716 int (*handler)(struct fs_db *, const char *);
718 { "state=", 6, lprocfs_ir_set_state },
719 { "timeout=", 8, lprocfs_ir_set_timeout },
720 { "0", 1, lprocfs_ir_clear_stats }
723 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
724 unsigned long count, void *data)
726 struct fs_db *fsdb = data;
731 if (count > CFS_PAGE_SIZE)
734 OBD_ALLOC(kbuf, count + 1);
738 if (copy_from_user(kbuf, buffer, count)) {
739 OBD_FREE(kbuf, count);
743 kbuf[count] = 0; /* buffer is supposed to end with 0 */
744 if (kbuf[count - 1] == '\n')
748 /* fsname=<file system name> must be the 1st entry */
749 while (ptr != NULL) {
753 tmpptr = strchr(ptr, ';');
758 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
759 struct lproc_ir_cmd *cmd;
763 cmdlen = cmd->namelen;
764 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
766 rc = cmd->handler(fsdb, ptr);
776 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
777 OBD_FREE(kbuf, count + 1);
781 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
783 struct fs_db *fsdb = data;
784 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
785 const char *ir_strings[] = IR_STRINGS;
786 struct timeval tv_max;
789 /* mgs_live_seq_show() already holds fsdb_mutex. */
790 ir_state_graduate(fsdb);
792 seq_printf(seq, "\nimperative_recovery_state:\n");
795 " nonir_clients: %d\n"
796 " nidtbl_version: %lld\n",
797 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
800 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
801 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
803 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
804 " notify_duation_max: %lu.%06lu\n"
805 " notify_count: %u\n",
806 tv.tv_sec, tv.tv_usec,
807 tv_max.tv_sec, tv_max.tv_usec,
808 fsdb->fsdb_notify_count);
813 int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
814 int *eof, void *data)
817 return snprintf(page, count, "%d\n", ir_timeout);
820 int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
821 unsigned long count, void *data)
823 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
826 /* --------------- Handle non IR support clients --------------- */
827 /* attach a lustre file system to an export */
828 int mgs_fsc_attach(struct obd_export *exp, char *fsname)
830 struct mgs_export_data *data = &exp->u.eu_mgs_data;
831 struct obd_device *obd = exp->exp_obd;
833 struct mgs_fsc *fsc = NULL;
834 struct mgs_fsc *new_fsc = NULL;
839 rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
843 /* allocate a new fsc in case we need it in spinlock. */
844 OBD_ALLOC_PTR(new_fsc);
848 CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
849 CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
850 new_fsc->mfc_fsdb = fsdb;
851 new_fsc->mfc_export = class_export_get(exp);
852 new_fsc->mfc_ir_capable =
853 !!(exp->exp_connect_flags & OBD_CONNECT_IMP_RECOV);
856 cfs_mutex_lock(&fsdb->fsdb_mutex);
858 /* tend to find it in export list because this list is shorter. */
859 cfs_spin_lock(&data->med_lock);
860 cfs_list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
861 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
870 /* add it into export list. */
871 cfs_list_add(&fsc->mfc_export_list, &data->med_clients);
873 /* add into fsdb list. */
874 cfs_list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
875 if (!fsc->mfc_ir_capable) {
876 ++fsdb->fsdb_nonir_clients;
877 if (fsdb->fsdb_ir_state == IR_FULL)
878 fsdb->fsdb_ir_state = IR_PARTIAL;
882 cfs_spin_unlock(&data->med_lock);
883 cfs_mutex_unlock(&fsdb->fsdb_mutex);
886 class_export_put(new_fsc->mfc_export);
887 OBD_FREE_PTR(new_fsc);
892 void mgs_fsc_cleanup(struct obd_export *exp)
894 struct mgs_export_data *data = &exp->u.eu_mgs_data;
895 struct mgs_fsc *fsc, *tmp;
898 cfs_spin_lock(&data->med_lock);
899 cfs_list_splice_init(&data->med_clients, &head);
900 cfs_spin_unlock(&data->med_lock);
902 cfs_list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
903 struct fs_db *fsdb = fsc->mfc_fsdb;
905 LASSERT(fsc->mfc_export == exp);
907 cfs_mutex_lock(&fsdb->fsdb_mutex);
908 cfs_list_del_init(&fsc->mfc_fsdb_list);
909 if (fsc->mfc_ir_capable == 0) {
910 --fsdb->fsdb_nonir_clients;
911 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
912 if (fsdb->fsdb_nonir_clients == 0 &&
913 fsdb->fsdb_ir_state == IR_PARTIAL)
914 fsdb->fsdb_ir_state = IR_FULL;
916 cfs_mutex_unlock(&fsdb->fsdb_mutex);
917 cfs_list_del_init(&fsc->mfc_export_list);
918 class_export_put(fsc->mfc_export);
923 /* must be called with fsdb->fsdb_mutex held */
924 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
926 struct mgs_fsc *fsc, *tmp;
928 cfs_list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
930 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
932 LASSERT(fsdb == fsc->mfc_fsdb);
933 cfs_list_del_init(&fsc->mfc_fsdb_list);
935 cfs_spin_lock(&data->med_lock);
936 cfs_list_del_init(&fsc->mfc_export_list);
937 cfs_spin_unlock(&data->med_lock);
938 class_export_put(fsc->mfc_export);
942 fsdb->fsdb_nonir_clients = 0;
943 if (fsdb->fsdb_ir_state == IR_PARTIAL)
944 fsdb->fsdb_ir_state = IR_FULL;