1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/mgs/mgs_nids.c
40 * NID table management for lustre.
42 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
48 #define DEBUG_SUBSYSTEM S_MGS
49 #define D_MGS D_CONFIG
52 #include <linux/module.h>
53 #include <linux/pagemap.h>
59 #include <obd_class.h>
60 #include <lustre_log.h>
62 #include <libcfs/list.h>
63 #include <linux/lvfs.h>
64 #include <lustre_fsfilt.h>
65 #include <lustre_disk.h>
66 #include <lustre_param.h>
67 #include "mgs_internal.h"
69 static unsigned int ir_timeout;
71 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
73 struct mgs_nidtbl_target *tgt;
76 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
77 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
78 if (!tgt->mnt_version)
81 if (version >= tgt->mnt_version)
84 version = tgt->mnt_version;
90 * Fetch nidtbl entries whose version are not less than @version
91 * nidtbl entries will be packed in @pages by @unit_size units - entries
92 * shouldn't cross unit boundaries.
94 static int mgs_nidtbl_read(struct obd_device *unused, struct mgs_nidtbl *tbl,
95 struct mgs_config_res *res, cfs_page_t **pages,
96 int nrpages, int units_total, int unit_size)
98 struct mgs_nidtbl_target *tgt;
99 struct mgs_nidtbl_entry *entry;
100 struct mgs_nidtbl_entry *last_in_unit = NULL;
101 struct mgs_target_info *mti;
102 __u64 version = res->mcr_offset;
105 int bytes_in_unit = 0;
106 int units_in_page = 0;
111 /* make sure unit_size is power 2 */
112 LASSERT((unit_size & (unit_size - 1)) == 0);
113 LASSERT(nrpages << CFS_PAGE_SHIFT >= units_total * unit_size);
115 cfs_mutex_lock(&tbl->mn_lock);
116 LASSERT(nidtbl_is_sane(tbl));
118 /* no more entries ? */
119 if (version > tbl->mn_version) {
120 version = tbl->mn_version;
124 /* iterate over all targets to compose a bitmap by the type of llog.
125 * If the llog is for MDTs, llog entries for OSTs will be returned;
126 * otherwise, it's for clients, then llog entries for both OSTs and
127 * MDTs will be returned.
129 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
130 int entry_len = sizeof(*entry);
132 if (tgt->mnt_version < version)
135 /* write target recover information */
137 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
138 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
140 if (entry_len > unit_size) {
141 CWARN("nidtbl: too large entry: entry length %d,"
142 "unit size: %d\n", entry_len, unit_size);
143 GOTO(out, rc = -EOVERFLOW);
146 if (bytes_in_unit < entry_len) {
147 if (units_total == 0) {
152 /* check if we need to consume remaining bytes. */
153 if (last_in_unit != NULL && bytes_in_unit) {
154 /* entry has been swapped. */
155 __swab32s(&last_in_unit->mne_length);
156 last_in_unit->mne_length += bytes_in_unit;
157 __swab32s(&last_in_unit->mne_length);
159 buf += bytes_in_unit;
162 LASSERT((rc & (unit_size - 1)) == 0);
164 if (units_in_page == 0) {
165 /* allocate a new page */
166 pages[index] = cfs_alloc_page(CFS_ALLOC_STD);
167 if (pages[index] == NULL) {
172 /* destroy previous map */
174 cfs_kunmap(pages[index - 1]);
176 /* reassign buffer */
177 buf = cfs_kmap(pages[index]);
180 units_in_page = CFS_PAGE_SIZE / unit_size;
181 LASSERT(units_in_page > 0);
184 /* allocate an unit */
185 LASSERT(((long)buf & (unit_size - 1)) == 0);
186 bytes_in_unit = unit_size;
192 entry = (struct mgs_nidtbl_entry *)buf;
193 entry->mne_version = tgt->mnt_version;
194 entry->mne_instance = mti->mti_instance;
195 entry->mne_index = mti->mti_stripe_index;
196 entry->mne_length = entry_len;
197 entry->mne_type = tgt->mnt_type;
198 entry->mne_nid_type = 0;
199 entry->mne_nid_size = sizeof(lnet_nid_t);
200 entry->mne_nid_count = mti->mti_nid_count;
201 memcpy(entry->u.nids, mti->mti_nids,
202 mti->mti_nid_count * sizeof(lnet_nid_t));
203 lustre_swab_mgs_nidtbl_entry(entry);
205 version = tgt->mnt_version;
209 bytes_in_unit -= entry_len;
210 last_in_unit = entry;
212 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
213 tbl->mn_fsdb->fsdb_name, entry_len,
214 bytes_in_unit, index, nrpages, units_total);
217 cfs_kunmap(pages[index - 1]);
219 LASSERT(version <= tbl->mn_version);
220 res->mcr_size = tbl->mn_version;
221 res->mcr_offset = nobuf ? version : tbl->mn_version;
222 cfs_mutex_unlock(&tbl->mn_lock);
223 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
225 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
226 tbl->mn_fsdb->fsdb_name, rc, version);
230 static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
232 struct lvfs_run_ctxt saved;
233 struct file *file = NULL;
234 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
240 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
241 LASSERT(sizeof(filename) < 32);
243 sprintf(filename, "%s/%s",
244 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
246 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
248 file = l_filp_open(filename, O_RDWR|O_CREAT, 0660);
250 version = cpu_to_le64(tbl->mn_version);
251 rc = lustre_fwrite(file, &version, sizeof(version), &off);
252 if (rc == sizeof(version))
255 fsfilt_sync(obd, obd->u.mgs.mgs_sb);
260 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
264 #define MGS_NIDTBL_VERSION_INIT 2
266 static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
268 struct lvfs_run_ctxt saved;
269 struct file *file = NULL;
270 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
276 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
277 LASSERT(sizeof(filename) < 32);
279 sprintf(filename, "%s/%s",
280 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
282 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
284 file = l_filp_open(filename, O_RDONLY, 0);
286 rc = lustre_fread(file, &version, sizeof(version), &off);
287 if (rc == sizeof(version))
288 rc = cpu_to_le64(version);
290 rc = MGS_NIDTBL_VERSION_INIT;
292 CERROR("read version file %s error %d\n", filename, rc);
297 rc = MGS_NIDTBL_VERSION_INIT;
300 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
304 static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
306 struct mgs_nidtbl *tbl;
307 struct mgs_nidtbl_target *tgt;
309 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
313 type &= ~LDD_F_SV_TYPE_MGS;
316 tbl = &fsdb->fsdb_nidtbl;
317 cfs_mutex_lock(&tbl->mn_lock);
318 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
319 struct mgs_target_info *info = &tgt->mnt_mti;
320 if (type == tgt->mnt_type &&
321 mti->mti_stripe_index == info->mti_stripe_index) {
329 GOTO(out, rc = -ENOMEM);
331 CFS_INIT_LIST_HEAD(&tgt->mnt_list);
333 tgt->mnt_version = 0; /* 0 means invalid */
334 tgt->mnt_type = type;
336 ++tbl->mn_nr_targets;
339 tgt->mnt_version = ++tbl->mn_version;
342 cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
344 rc = nidtbl_update_version(fsdb->fsdb_obd, tbl);
348 cfs_mutex_unlock(&tbl->mn_lock);
350 CERROR("Write NID table version for file system %s error %d\n",
351 fsdb->fsdb_name, rc);
355 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
357 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
360 cfs_mutex_lock(&tbl->mn_lock);
361 tbl->mn_nr_targets = 0;
362 cfs_list_splice_init(&tbl->mn_targets, &head);
363 cfs_mutex_unlock(&tbl->mn_lock);
365 while (!cfs_list_empty(&head)) {
366 struct mgs_nidtbl_target *tgt;
367 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
368 cfs_list_del(&tgt->mnt_list);
373 static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
375 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
377 CFS_INIT_LIST_HEAD(&tbl->mn_targets);
378 cfs_mutex_init(&tbl->mn_lock);
379 tbl->mn_nr_targets = 0;
381 cfs_mutex_lock(&tbl->mn_lock);
382 tbl->mn_version = nidtbl_read_version(fsdb->fsdb_obd, tbl);
383 cfs_mutex_unlock(&tbl->mn_lock);
384 CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
389 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
390 void mgs_ir_notify_complete(struct fs_db *fsdb)
393 cfs_duration_t delta;
395 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
398 fsdb->fsdb_notify_count++;
399 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
400 fsdb->fsdb_notify_total += delta;
401 if (delta > fsdb->fsdb_notify_max)
402 fsdb->fsdb_notify_max = delta;
404 cfs_duration_usec(delta, &tv);
405 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
406 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
409 static int mgs_ir_notify(void *arg)
411 struct fs_db *fsdb = arg;
412 struct ldlm_res_id resid;
414 char name[sizeof(fsdb->fsdb_name) + 20];
416 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
417 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
420 cfs_complete(&fsdb->fsdb_notify_comp);
422 set_user_nice(current, -2);
424 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
426 struct l_wait_info lwi = { 0 };
428 l_wait_event(fsdb->fsdb_notify_waitq,
429 fsdb->fsdb_notify_stop ||
430 cfs_atomic_read(&fsdb->fsdb_notify_phase),
432 if (fsdb->fsdb_notify_stop)
435 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
436 name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
438 fsdb->fsdb_notify_start = cfs_time_current();
439 mgs_revoke_lock(fsdb->fsdb_obd, fsdb, CONFIG_T_RECOVER);
442 cfs_complete(&fsdb->fsdb_notify_comp);
446 int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
448 struct mgs_obd *mgs = &obd->u.mgs;
452 ir_timeout = OBD_IR_MGS_TIMEOUT;
454 fsdb->fsdb_ir_state = IR_FULL;
455 if (cfs_time_before(cfs_time_current_sec(),
456 mgs->mgs_start_time + ir_timeout))
457 fsdb->fsdb_ir_state = IR_STARTUP;
458 fsdb->fsdb_nonir_clients = 0;
459 CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
461 /* start notify thread */
462 fsdb->fsdb_obd = obd;
463 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
464 cfs_waitq_init(&fsdb->fsdb_notify_waitq);
465 cfs_init_completion(&fsdb->fsdb_notify_comp);
466 rc = cfs_create_thread(mgs_ir_notify, fsdb, CFS_DAEMON_FLAGS);
468 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
470 CERROR("Start notify thread error %d\n", rc);
472 mgs_nidtbl_init_fs(fsdb);
476 void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
478 if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
481 mgs_fsc_cleanup_by_fsdb(fsdb);
483 mgs_nidtbl_fini_fs(fsdb);
485 LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
487 fsdb->fsdb_notify_stop = 1;
488 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
489 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
492 /* caller must have held fsdb_mutex */
493 static inline void ir_state_graduate(struct fs_db *fsdb)
495 struct mgs_obd *mgs = &fsdb->fsdb_obd->u.mgs;
497 if (fsdb->fsdb_ir_state == IR_STARTUP) {
498 if (cfs_time_before(mgs->mgs_start_time + ir_timeout,
499 cfs_time_current_sec())) {
500 fsdb->fsdb_ir_state = IR_FULL;
501 if (fsdb->fsdb_nonir_clients)
502 fsdb->fsdb_ir_state = IR_PARTIAL;
507 int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
513 if (mti->mti_instance == 0)
516 rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
520 rc = mgs_nidtbl_write(fsdb, mti);
525 cfs_mutex_lock(&fsdb->fsdb_mutex);
526 ir_state_graduate(fsdb);
527 switch (fsdb->fsdb_ir_state) {
529 mti->mti_flags |= LDD_F_IR_CAPABLE;
539 cfs_mutex_unlock(&fsdb->fsdb_mutex);
541 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
543 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
545 cfs_atomic_inc(&fsdb->fsdb_notify_phase);
546 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
551 /* NID table can be cached by two entities: Clients and MDTs */
557 static int delogname(char *logname, char *fsname, int *typ)
563 ptr = strrchr(logname, '-');
567 /* decouple file system name. The llog name may be:
568 * - "prefix-fsname", prefix is "cliir" or "mdtir"
570 if (strncmp(ptr, "-mdtir", 6) == 0)
572 else if (strncmp(ptr, "-cliir", 6) == 0)
581 memcpy(fsname, logname, len);
588 int mgs_get_ir_logs(struct ptlrpc_request *req)
590 struct obd_device *obd = req->rq_export->exp_obd;
592 struct mgs_config_body *body;
593 struct mgs_config_res *res;
594 struct ptlrpc_bulk_desc *desc;
595 struct l_wait_info lwi;
606 cfs_page_t **pages = NULL;
609 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
613 if (body->mcb_type != CONFIG_T_RECOVER)
616 rc = delogname(body->mcb_name, fsname, &type);
620 rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
624 bufsize = body->mcb_units << body->mcb_bits;
625 nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
626 if (nrpages > PTLRPC_MAX_BRW_PAGES)
629 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
630 body->mcb_name, bufsize);
632 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
636 rc = req_capsule_server_pack(&req->rq_pill);
640 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
642 GOTO(out, rc = -EINVAL);
644 res->mcr_offset = body->mcb_offset;
645 unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
646 bytes = mgs_nidtbl_read(obd, &fsdb->fsdb_nidtbl, res, pages, nrpages,
647 bufsize / unit_size, unit_size);
649 GOTO(out, rc = bytes);
651 /* start bulk transfer */
652 page_count = (bytes + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
653 LASSERT(page_count <= nrpages);
654 desc = ptlrpc_prep_bulk_exp(req, page_count,
655 BULK_PUT_SOURCE, MGS_BULK_PORTAL);
657 GOTO(out, rc = -ENOMEM);
659 for (i = 0; i < page_count && bytes > 0; i++) {
660 ptlrpc_prep_bulk_page(desc, pages[i], 0,
661 min_t(int, bytes, CFS_PAGE_SIZE));
662 bytes -= CFS_PAGE_SIZE;
665 rc = target_bulk_io(req->rq_export, desc, &lwi);
666 ptlrpc_free_bulk(desc);
670 for (i = 0; i < nrpages; i++) {
671 if (pages[i] == NULL)
673 cfs_free_page(pages[i]);
675 OBD_FREE(pages, sizeof(*pages) * nrpages);
680 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
682 const char *strings[] = IR_STRINGS;
686 for (i = 0; i < ARRAY_SIZE(strings); i++) {
687 if (strcmp(strings[i], buf) == 0) {
695 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
696 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
697 cfs_mutex_lock(&fsdb->fsdb_mutex);
698 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
700 fsdb->fsdb_ir_state = state;
701 cfs_mutex_unlock(&fsdb->fsdb_mutex);
706 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
711 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
716 fsdb->fsdb_notify_total = 0;
717 fsdb->fsdb_notify_max = 0;
718 fsdb->fsdb_notify_count = 0;
722 static struct lproc_ir_cmd {
725 int (*handler)(struct fs_db *, const char *);
727 { "state=", 6, lprocfs_ir_set_state },
728 { "timeout=", 8, lprocfs_ir_set_timeout },
729 { "0", 1, lprocfs_ir_clear_stats }
732 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
733 unsigned long count, void *data)
735 struct fs_db *fsdb = data;
740 if (count > CFS_PAGE_SIZE)
743 OBD_ALLOC(kbuf, count + 1);
747 if (copy_from_user(kbuf, buffer, count)) {
748 OBD_FREE(kbuf, count);
752 kbuf[count] = 0; /* buffer is supposed to end with 0 */
753 if (kbuf[count - 1] == '\n')
757 /* fsname=<file system name> must be the 1st entry */
758 while (ptr != NULL) {
762 tmpptr = strchr(ptr, ';');
767 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
768 struct lproc_ir_cmd *cmd;
772 cmdlen = cmd->namelen;
773 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
775 rc = cmd->handler(fsdb, ptr);
785 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
786 OBD_FREE(kbuf, count + 1);
790 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
792 struct fs_db *fsdb = data;
793 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
794 const char *ir_strings[] = IR_STRINGS;
795 struct timeval tv_max;
798 /* mgs_live_seq_show() already holds fsdb_mutex. */
799 ir_state_graduate(fsdb);
801 seq_printf(seq, "\nimperative_recovery_state:\n");
804 " nonir_clients: %d\n"
805 " nidtbl_version: %lld\n",
806 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
809 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
810 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
812 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
813 " notify_duation_max: %lu.%06lu\n"
814 " notify_count: %u\n",
815 tv.tv_sec, tv.tv_usec,
816 tv_max.tv_sec, tv_max.tv_usec,
817 fsdb->fsdb_notify_count);
822 int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
823 int *eof, void *data)
826 return snprintf(page, count, "%d\n", ir_timeout);
829 int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
830 unsigned long count, void *data)
832 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
835 /* --------------- Handle non IR support clients --------------- */
836 /* attach a lustre file system to an export */
837 int mgs_fsc_attach(struct obd_export *exp, char *fsname)
839 struct mgs_export_data *data = &exp->u.eu_mgs_data;
840 struct obd_device *obd = exp->exp_obd;
842 struct mgs_fsc *fsc = NULL;
843 struct mgs_fsc *new_fsc = NULL;
848 rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
852 /* allocate a new fsc in case we need it in spinlock. */
853 OBD_ALLOC_PTR(new_fsc);
857 CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
858 CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
859 new_fsc->mfc_fsdb = fsdb;
860 new_fsc->mfc_export = class_export_get(exp);
861 new_fsc->mfc_ir_capable =
862 !!(exp->exp_connect_flags & OBD_CONNECT_IMP_RECOV);
865 cfs_mutex_lock(&fsdb->fsdb_mutex);
867 /* tend to find it in export list because this list is shorter. */
868 cfs_spin_lock(&data->med_lock);
869 cfs_list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
870 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
879 /* add it into export list. */
880 cfs_list_add(&fsc->mfc_export_list, &data->med_clients);
882 /* add into fsdb list. */
883 cfs_list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
884 if (!fsc->mfc_ir_capable) {
885 ++fsdb->fsdb_nonir_clients;
886 if (fsdb->fsdb_ir_state == IR_FULL)
887 fsdb->fsdb_ir_state = IR_PARTIAL;
891 cfs_spin_unlock(&data->med_lock);
892 cfs_mutex_unlock(&fsdb->fsdb_mutex);
895 class_export_put(new_fsc->mfc_export);
896 OBD_FREE_PTR(new_fsc);
901 void mgs_fsc_cleanup(struct obd_export *exp)
903 struct mgs_export_data *data = &exp->u.eu_mgs_data;
904 struct mgs_fsc *fsc, *tmp;
907 cfs_spin_lock(&data->med_lock);
908 cfs_list_splice_init(&data->med_clients, &head);
909 cfs_spin_unlock(&data->med_lock);
911 cfs_list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
912 struct fs_db *fsdb = fsc->mfc_fsdb;
914 LASSERT(fsc->mfc_export == exp);
916 cfs_mutex_lock(&fsdb->fsdb_mutex);
917 cfs_list_del_init(&fsc->mfc_fsdb_list);
918 if (fsc->mfc_ir_capable == 0) {
919 --fsdb->fsdb_nonir_clients;
920 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
921 if (fsdb->fsdb_nonir_clients == 0 &&
922 fsdb->fsdb_ir_state == IR_PARTIAL)
923 fsdb->fsdb_ir_state = IR_FULL;
925 cfs_mutex_unlock(&fsdb->fsdb_mutex);
926 cfs_list_del_init(&fsc->mfc_export_list);
927 class_export_put(fsc->mfc_export);
932 /* must be called with fsdb->fsdb_mutex held */
933 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
935 struct mgs_fsc *fsc, *tmp;
937 cfs_list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
939 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
941 LASSERT(fsdb == fsc->mfc_fsdb);
942 cfs_list_del_init(&fsc->mfc_fsdb_list);
944 cfs_spin_lock(&data->med_lock);
945 cfs_list_del_init(&fsc->mfc_export_list);
946 cfs_spin_unlock(&data->med_lock);
947 class_export_put(fsc->mfc_export);
951 fsdb->fsdb_nonir_clients = 0;
952 if (fsdb->fsdb_ir_state == IR_PARTIAL)
953 fsdb->fsdb_ir_state = IR_FULL;