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 /* entry has been swapped. */
150 __swab32s(&last_in_unit->mne_length);
151 last_in_unit->mne_length += bytes_in_unit;
152 __swab32s(&last_in_unit->mne_length);
154 buf += bytes_in_unit;
157 LASSERT((rc & (unit_size - 1)) == 0);
159 if (units_in_page == 0) {
160 /* allocate a new page */
161 pages[index] = cfs_alloc_page(CFS_ALLOC_STD);
162 if (pages[index] == NULL) {
167 /* destroy previous map */
169 cfs_kunmap(pages[index - 1]);
171 /* reassign buffer */
172 buf = cfs_kmap(pages[index]);
175 units_in_page = CFS_PAGE_SIZE / unit_size;
176 LASSERT(units_in_page > 0);
179 /* allocate an unit */
180 LASSERT(((long)buf & (unit_size - 1)) == 0);
181 bytes_in_unit = unit_size;
187 entry = (struct mgs_nidtbl_entry *)buf;
188 entry->mne_version = tgt->mnt_version;
189 entry->mne_instance = mti->mti_instance;
190 entry->mne_index = mti->mti_stripe_index;
191 entry->mne_length = entry_len;
192 entry->mne_type = tgt->mnt_type;
193 entry->mne_nid_type = 0;
194 entry->mne_nid_size = sizeof(lnet_nid_t);
195 entry->mne_nid_count = mti->mti_nid_count;
196 memcpy(entry->u.nids, mti->mti_nids,
197 mti->mti_nid_count * sizeof(lnet_nid_t));
198 lustre_swab_mgs_nidtbl_entry(entry);
200 version = tgt->mnt_version;
204 bytes_in_unit -= entry_len;
205 last_in_unit = entry;
207 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
208 tbl->mn_fsdb->fsdb_name, entry_len,
209 bytes_in_unit, index, nrpages, units_total);
212 cfs_kunmap(pages[index - 1]);
214 LASSERT(version <= tbl->mn_version);
215 res->mcr_size = tbl->mn_version;
216 res->mcr_offset = nobuf ? version : tbl->mn_version;
217 cfs_mutex_unlock(&tbl->mn_lock);
218 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
220 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
221 tbl->mn_fsdb->fsdb_name, rc, version);
225 static int nidtbl_update_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
227 struct lvfs_run_ctxt saved;
228 struct file *file = NULL;
229 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
235 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
236 LASSERT(sizeof(filename) < 32);
238 sprintf(filename, "%s/%s",
239 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
241 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
243 file = l_filp_open(filename, O_RDWR|O_CREAT, 0660);
245 version = cpu_to_le64(tbl->mn_version);
246 rc = lustre_fwrite(file, &version, sizeof(version), &off);
247 if (rc == sizeof(version))
250 fsfilt_sync(obd, obd->u.mgs.mgs_sb);
255 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
259 #define MGS_NIDTBL_VERSION_INIT 2
261 static int nidtbl_read_version(struct obd_device *obd, struct mgs_nidtbl *tbl)
263 struct lvfs_run_ctxt saved;
264 struct file *file = NULL;
265 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
271 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
272 LASSERT(sizeof(filename) < 32);
274 sprintf(filename, "%s/%s",
275 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
277 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
279 file = l_filp_open(filename, O_RDONLY, 0);
281 rc = lustre_fread(file, &version, sizeof(version), &off);
282 if (rc == sizeof(version))
283 rc = cpu_to_le64(version);
285 rc = MGS_NIDTBL_VERSION_INIT;
287 CERROR("read version file %s error %d\n", filename, rc);
292 rc = MGS_NIDTBL_VERSION_INIT;
295 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
299 static int mgs_nidtbl_write(struct fs_db *fsdb, struct mgs_target_info *mti)
301 struct mgs_nidtbl *tbl;
302 struct mgs_nidtbl_target *tgt;
304 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
308 type &= ~LDD_F_SV_TYPE_MGS;
311 tbl = &fsdb->fsdb_nidtbl;
312 cfs_mutex_lock(&tbl->mn_lock);
313 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
314 struct mgs_target_info *info = &tgt->mnt_mti;
315 if (type == tgt->mnt_type &&
316 mti->mti_stripe_index == info->mti_stripe_index) {
324 GOTO(out, rc = -ENOMEM);
326 CFS_INIT_LIST_HEAD(&tgt->mnt_list);
328 tgt->mnt_version = 0; /* 0 means invalid */
329 tgt->mnt_type = type;
331 ++tbl->mn_nr_targets;
334 tgt->mnt_version = ++tbl->mn_version;
337 cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
339 rc = nidtbl_update_version(fsdb->fsdb_obd, tbl);
343 cfs_mutex_unlock(&tbl->mn_lock);
345 CERROR("Write NID table version for file system %s error %d\n",
346 fsdb->fsdb_name, rc);
350 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
352 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
355 cfs_mutex_lock(&tbl->mn_lock);
356 tbl->mn_nr_targets = 0;
357 cfs_list_splice_init(&tbl->mn_targets, &head);
358 cfs_mutex_unlock(&tbl->mn_lock);
360 while (!cfs_list_empty(&head)) {
361 struct mgs_nidtbl_target *tgt;
362 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
363 cfs_list_del(&tgt->mnt_list);
368 static int mgs_nidtbl_init_fs(struct fs_db *fsdb)
370 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
372 CFS_INIT_LIST_HEAD(&tbl->mn_targets);
373 cfs_mutex_init(&tbl->mn_lock);
374 tbl->mn_nr_targets = 0;
376 cfs_mutex_lock(&tbl->mn_lock);
377 tbl->mn_version = nidtbl_read_version(fsdb->fsdb_obd, tbl);
378 cfs_mutex_unlock(&tbl->mn_lock);
379 CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
384 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
385 void mgs_ir_notify_complete(struct fs_db *fsdb)
388 cfs_duration_t delta;
390 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
393 fsdb->fsdb_notify_count++;
394 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
395 fsdb->fsdb_notify_total += delta;
396 if (delta > fsdb->fsdb_notify_max)
397 fsdb->fsdb_notify_max = delta;
399 cfs_duration_usec(delta, &tv);
400 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
401 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
404 static int mgs_ir_notify(void *arg)
406 struct fs_db *fsdb = arg;
407 struct ldlm_res_id resid;
409 char name[sizeof(fsdb->fsdb_name) + 20];
411 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
412 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
415 cfs_complete(&fsdb->fsdb_notify_comp);
417 set_user_nice(current, -2);
419 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
421 struct l_wait_info lwi = { 0 };
423 l_wait_event(fsdb->fsdb_notify_waitq,
424 fsdb->fsdb_notify_stop ||
425 cfs_atomic_read(&fsdb->fsdb_notify_phase),
427 if (fsdb->fsdb_notify_stop)
430 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
431 name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
433 fsdb->fsdb_notify_start = cfs_time_current();
434 mgs_revoke_lock(fsdb->fsdb_obd, fsdb, CONFIG_T_RECOVER);
437 cfs_complete(&fsdb->fsdb_notify_comp);
441 int mgs_ir_init_fs(struct obd_device *obd, struct fs_db *fsdb)
443 struct mgs_obd *mgs = &obd->u.mgs;
447 ir_timeout = OBD_IR_MGS_TIMEOUT;
449 fsdb->fsdb_ir_state = IR_FULL;
450 if (cfs_time_before(cfs_time_current_sec(),
451 mgs->mgs_start_time + ir_timeout))
452 fsdb->fsdb_ir_state = IR_STARTUP;
453 fsdb->fsdb_nonir_clients = 0;
454 CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
456 /* start notify thread */
457 fsdb->fsdb_obd = obd;
458 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
459 cfs_waitq_init(&fsdb->fsdb_notify_waitq);
460 cfs_init_completion(&fsdb->fsdb_notify_comp);
461 rc = cfs_create_thread(mgs_ir_notify, fsdb, CFS_DAEMON_FLAGS);
463 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
465 CERROR("Start notify thread error %d\n", rc);
467 mgs_nidtbl_init_fs(fsdb);
471 void mgs_ir_fini_fs(struct obd_device *obd, struct fs_db *fsdb)
473 if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
476 mgs_fsc_cleanup_by_fsdb(fsdb);
478 mgs_nidtbl_fini_fs(fsdb);
480 LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
482 fsdb->fsdb_notify_stop = 1;
483 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
484 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
487 /* caller must have held fsdb_mutex */
488 static inline void ir_state_graduate(struct fs_db *fsdb)
490 struct mgs_obd *mgs = &fsdb->fsdb_obd->u.mgs;
492 if (fsdb->fsdb_ir_state == IR_STARTUP) {
493 if (cfs_time_before(mgs->mgs_start_time + ir_timeout,
494 cfs_time_current_sec())) {
495 fsdb->fsdb_ir_state = IR_FULL;
496 if (fsdb->fsdb_nonir_clients)
497 fsdb->fsdb_ir_state = IR_PARTIAL;
502 int mgs_ir_update(struct obd_device *obd, struct mgs_target_info *mti)
508 if (mti->mti_instance == 0)
511 rc = mgs_find_or_make_fsdb(obd, mti->mti_fsname, &fsdb);
515 rc = mgs_nidtbl_write(fsdb, mti);
520 cfs_mutex_lock(&fsdb->fsdb_mutex);
521 ir_state_graduate(fsdb);
522 switch (fsdb->fsdb_ir_state) {
524 mti->mti_flags |= LDD_F_IR_CAPABLE;
534 cfs_mutex_unlock(&fsdb->fsdb_mutex);
536 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
538 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
540 cfs_atomic_inc(&fsdb->fsdb_notify_phase);
541 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
546 /* NID table can be cached by two entities: Clients and MDTs */
552 static int delogname(char *logname, char *fsname, int *typ)
558 ptr = strrchr(logname, '-');
562 /* decouple file system name. The llog name may be:
563 * - "prefix-fsname", prefix is "cliir" or "mdtir"
565 if (strncmp(ptr, "-mdtir", 6) == 0)
567 else if (strncmp(ptr, "-cliir", 6) == 0)
576 memcpy(fsname, logname, len);
583 int mgs_get_ir_logs(struct ptlrpc_request *req)
585 struct obd_device *obd = req->rq_export->exp_obd;
587 struct mgs_config_body *body;
588 struct mgs_config_res *res;
589 struct ptlrpc_bulk_desc *desc;
590 struct l_wait_info lwi;
601 cfs_page_t **pages = NULL;
604 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
608 if (body->mcb_type != CONFIG_T_RECOVER)
611 rc = delogname(body->mcb_name, fsname, &type);
615 rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
619 bufsize = body->mcb_units << body->mcb_bits;
620 nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
621 if (nrpages > PTLRPC_MAX_BRW_PAGES)
624 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
625 body->mcb_name, bufsize);
627 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
631 rc = req_capsule_server_pack(&req->rq_pill);
635 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
637 GOTO(out, rc = -EINVAL);
639 res->mcr_offset = body->mcb_offset;
640 unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
641 bytes = mgs_nidtbl_read(obd, &fsdb->fsdb_nidtbl, res, pages, nrpages,
642 bufsize / unit_size, unit_size);
644 GOTO(out, rc = bytes);
646 /* start bulk transfer */
647 page_count = (bytes + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
648 LASSERT(page_count <= nrpages);
649 desc = ptlrpc_prep_bulk_exp(req, page_count,
650 BULK_PUT_SOURCE, MGS_BULK_PORTAL);
652 GOTO(out, rc = -ENOMEM);
654 for (i = 0; i < page_count && bytes > 0; i++) {
655 ptlrpc_prep_bulk_page(desc, pages[i], 0,
656 min_t(int, bytes, CFS_PAGE_SIZE));
657 bytes -= CFS_PAGE_SIZE;
660 rc = target_bulk_io(req->rq_export, desc, &lwi);
661 ptlrpc_free_bulk(desc);
665 for (i = 0; i < nrpages; i++) {
666 if (pages[i] == NULL)
668 cfs_free_page(pages[i]);
670 OBD_FREE(pages, sizeof(*pages) * nrpages);
675 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
677 const char *strings[] = IR_STRINGS;
681 for (i = 0; i < ARRAY_SIZE(strings); i++) {
682 if (strcmp(strings[i], buf) == 0) {
690 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
691 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
692 cfs_mutex_lock(&fsdb->fsdb_mutex);
693 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
695 fsdb->fsdb_ir_state = state;
696 cfs_mutex_unlock(&fsdb->fsdb_mutex);
701 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
706 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
711 fsdb->fsdb_notify_total = 0;
712 fsdb->fsdb_notify_max = 0;
713 fsdb->fsdb_notify_count = 0;
717 static struct lproc_ir_cmd {
720 int (*handler)(struct fs_db *, const char *);
722 { "state=", 6, lprocfs_ir_set_state },
723 { "timeout=", 8, lprocfs_ir_set_timeout },
724 { "0", 1, lprocfs_ir_clear_stats }
727 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
728 unsigned long count, void *data)
730 struct fs_db *fsdb = data;
735 if (count > CFS_PAGE_SIZE)
738 OBD_ALLOC(kbuf, count + 1);
742 if (copy_from_user(kbuf, buffer, count)) {
743 OBD_FREE(kbuf, count);
747 kbuf[count] = 0; /* buffer is supposed to end with 0 */
748 if (kbuf[count - 1] == '\n')
752 /* fsname=<file system name> must be the 1st entry */
753 while (ptr != NULL) {
757 tmpptr = strchr(ptr, ';');
762 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
763 struct lproc_ir_cmd *cmd;
767 cmdlen = cmd->namelen;
768 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
770 rc = cmd->handler(fsdb, ptr);
780 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
781 OBD_FREE(kbuf, count + 1);
785 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
787 struct fs_db *fsdb = data;
788 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
789 const char *ir_strings[] = IR_STRINGS;
790 struct timeval tv_max;
793 /* mgs_live_seq_show() already holds fsdb_mutex. */
794 ir_state_graduate(fsdb);
796 seq_printf(seq, "\nimperative_recovery_state:\n");
799 " nonir_clients: %d\n"
800 " nidtbl_version: %lld\n",
801 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
804 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
805 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
807 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
808 " notify_duation_max: %lu.%06lu\n"
809 " notify_count: %u\n",
810 tv.tv_sec, tv.tv_usec,
811 tv_max.tv_sec, tv_max.tv_usec,
812 fsdb->fsdb_notify_count);
817 int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
818 int *eof, void *data)
821 return snprintf(page, count, "%d\n", ir_timeout);
824 int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
825 unsigned long count, void *data)
827 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
830 /* --------------- Handle non IR support clients --------------- */
831 /* attach a lustre file system to an export */
832 int mgs_fsc_attach(struct obd_export *exp, char *fsname)
834 struct mgs_export_data *data = &exp->u.eu_mgs_data;
835 struct obd_device *obd = exp->exp_obd;
837 struct mgs_fsc *fsc = NULL;
838 struct mgs_fsc *new_fsc = NULL;
843 rc = mgs_find_or_make_fsdb(obd, fsname, &fsdb);
847 /* allocate a new fsc in case we need it in spinlock. */
848 OBD_ALLOC_PTR(new_fsc);
852 CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
853 CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
854 new_fsc->mfc_fsdb = fsdb;
855 new_fsc->mfc_export = class_export_get(exp);
856 new_fsc->mfc_ir_capable =
857 !!(exp->exp_connect_flags & OBD_CONNECT_IMP_RECOV);
860 cfs_mutex_lock(&fsdb->fsdb_mutex);
862 /* tend to find it in export list because this list is shorter. */
863 cfs_spin_lock(&data->med_lock);
864 cfs_list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
865 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
874 /* add it into export list. */
875 cfs_list_add(&fsc->mfc_export_list, &data->med_clients);
877 /* add into fsdb list. */
878 cfs_list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
879 if (!fsc->mfc_ir_capable) {
880 ++fsdb->fsdb_nonir_clients;
881 if (fsdb->fsdb_ir_state == IR_FULL)
882 fsdb->fsdb_ir_state = IR_PARTIAL;
886 cfs_spin_unlock(&data->med_lock);
887 cfs_mutex_unlock(&fsdb->fsdb_mutex);
890 class_export_put(new_fsc->mfc_export);
891 OBD_FREE_PTR(new_fsc);
896 void mgs_fsc_cleanup(struct obd_export *exp)
898 struct mgs_export_data *data = &exp->u.eu_mgs_data;
899 struct mgs_fsc *fsc, *tmp;
902 cfs_spin_lock(&data->med_lock);
903 cfs_list_splice_init(&data->med_clients, &head);
904 cfs_spin_unlock(&data->med_lock);
906 cfs_list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
907 struct fs_db *fsdb = fsc->mfc_fsdb;
909 LASSERT(fsc->mfc_export == exp);
911 cfs_mutex_lock(&fsdb->fsdb_mutex);
912 cfs_list_del_init(&fsc->mfc_fsdb_list);
913 if (fsc->mfc_ir_capable == 0) {
914 --fsdb->fsdb_nonir_clients;
915 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
916 if (fsdb->fsdb_nonir_clients == 0 &&
917 fsdb->fsdb_ir_state == IR_PARTIAL)
918 fsdb->fsdb_ir_state = IR_FULL;
920 cfs_mutex_unlock(&fsdb->fsdb_mutex);
921 cfs_list_del_init(&fsc->mfc_export_list);
922 class_export_put(fsc->mfc_export);
927 /* must be called with fsdb->fsdb_mutex held */
928 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
930 struct mgs_fsc *fsc, *tmp;
932 cfs_list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
934 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
936 LASSERT(fsdb == fsc->mfc_fsdb);
937 cfs_list_del_init(&fsc->mfc_fsdb_list);
939 cfs_spin_lock(&data->med_lock);
940 cfs_list_del_init(&fsc->mfc_export_list);
941 cfs_spin_unlock(&data->med_lock);
942 class_export_put(fsc->mfc_export);
946 fsdb->fsdb_nonir_clients = 0;
947 if (fsdb->fsdb_ir_state == IR_PARTIAL)
948 fsdb->fsdb_ir_state = IR_FULL;