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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mgs/mgs_nids.c
34 * NID table management for lustre.
36 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
39 #define DEBUG_SUBSYSTEM S_MGS
40 #define D_MGS D_CONFIG
42 #include <linux/kthread.h>
43 #include <linux/pagemap.h>
46 #include <obd_class.h>
47 #include <lustre_disk.h>
49 #include "mgs_internal.h"
51 static unsigned int ir_timeout;
53 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
55 struct mgs_nidtbl_target *tgt;
58 LASSERT(mutex_is_locked(&tbl->mn_lock));
59 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
60 if (!tgt->mnt_version)
63 if (version >= tgt->mnt_version)
66 version = tgt->mnt_version;
72 * Fetch nidtbl entries whose version are not less than @version
73 * nidtbl entries will be packed in @pages by @unit_size units - entries
74 * shouldn't cross unit boundaries.
76 static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
77 struct mgs_config_res *res, struct page **pages,
78 int nrpages, int units_total, int unit_size)
80 struct mgs_nidtbl_target *tgt;
81 struct mgs_nidtbl_entry *entry;
82 struct mgs_nidtbl_entry *last_in_unit = NULL;
83 struct mgs_target_info *mti;
84 __u64 version = res->mcr_offset;
87 int bytes_in_unit = 0;
88 int units_in_page = 0;
93 /* make sure unit_size is power 2 */
94 LASSERT((unit_size & (unit_size - 1)) == 0);
95 LASSERT(nrpages << PAGE_SHIFT >= units_total * unit_size);
97 mutex_lock(&tbl->mn_lock);
98 LASSERT(nidtbl_is_sane(tbl));
100 /* no more entries ? */
101 if (version > tbl->mn_version) {
102 version = tbl->mn_version;
106 /* iterate over all targets to compose a bitmap by the type of llog.
107 * If the llog is for MDTs, llog entries for OSTs will be returned;
108 * otherwise, it's for clients, then llog entries for both OSTs and
109 * MDTs will be returned.
111 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
112 int entry_len = sizeof(*entry);
114 if (tgt->mnt_version < version)
117 /* write target recover information */
119 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
120 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
122 if (entry_len > unit_size) {
123 CWARN("nidtbl: too large entry: entry length %d,"
124 "unit size: %d\n", entry_len, unit_size);
125 GOTO(out, rc = -EOVERFLOW);
128 if (bytes_in_unit < entry_len) {
129 if (units_total == 0) {
134 /* check if we need to consume remaining bytes. */
135 if (last_in_unit != NULL && bytes_in_unit) {
136 last_in_unit->mne_length += bytes_in_unit;
138 buf += bytes_in_unit;
141 LASSERT((rc & (unit_size - 1)) == 0);
143 if (units_in_page == 0) {
144 /* allocate a new page */
145 pages[index] = alloc_page(GFP_KERNEL);
146 if (pages[index] == NULL) {
151 /* destroy previous map */
153 kunmap(pages[index - 1]);
155 /* reassign buffer */
156 buf = kmap(pages[index]);
159 units_in_page = PAGE_SIZE / unit_size;
160 LASSERT(units_in_page > 0);
163 /* allocate an unit */
164 LASSERT(((long)buf & (unit_size - 1)) == 0);
165 bytes_in_unit = unit_size;
171 entry = (struct mgs_nidtbl_entry *)buf;
172 entry->mne_version = tgt->mnt_version;
173 entry->mne_instance = mti->mti_instance;
174 entry->mne_index = mti->mti_stripe_index;
175 entry->mne_length = entry_len;
176 entry->mne_type = tgt->mnt_type;
177 entry->mne_nid_type = 0;
178 entry->mne_nid_size = sizeof(lnet_nid_t);
179 entry->mne_nid_count = mti->mti_nid_count;
180 memcpy(entry->u.nids, mti->mti_nids,
181 mti->mti_nid_count * sizeof(lnet_nid_t));
183 version = tgt->mnt_version;
187 bytes_in_unit -= entry_len;
188 last_in_unit = entry;
190 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
191 tbl->mn_fsdb->fsdb_name, entry_len,
192 bytes_in_unit, index, nrpages, units_total);
195 kunmap(pages[index - 1]);
197 LASSERT(version <= tbl->mn_version);
198 res->mcr_size = tbl->mn_version;
199 res->mcr_offset = nobuf ? version : tbl->mn_version;
200 mutex_unlock(&tbl->mn_lock);
201 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
203 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
204 tbl->mn_fsdb->fsdb_name, rc, version);
208 static int nidtbl_update_version(const struct lu_env *env,
209 struct mgs_device *mgs,
210 struct mgs_nidtbl *tbl)
212 struct dt_object *fsdb;
215 struct lu_buf buf = {
217 .lb_len = sizeof(version)
223 LASSERT(mutex_is_locked(&tbl->mn_lock));
225 fsdb = local_file_find_or_create(env, mgs->mgs_los, mgs->mgs_nidtbl_dir,
226 tbl->mn_fsdb->fsdb_name,
227 S_IFREG | S_IRUGO | S_IWUSR);
229 RETURN(PTR_ERR(fsdb));
231 th = dt_trans_create(env, mgs->mgs_bottom);
233 GOTO(out_put, rc = PTR_ERR(th));
235 th->th_sync = 1; /* update table synchronously */
236 rc = dt_declare_record_write(env, fsdb, &buf, off, th);
240 rc = dt_trans_start_local(env, mgs->mgs_bottom, th);
244 version = cpu_to_le64(tbl->mn_version);
245 rc = dt_record_write(env, fsdb, &buf, &off, th);
248 dt_trans_stop(env, mgs->mgs_bottom, th);
250 lu_object_put(env, &fsdb->do_lu);
254 #define MGS_NIDTBL_VERSION_INIT 2
256 static int nidtbl_read_version(const struct lu_env *env,
257 struct mgs_device *mgs, struct mgs_nidtbl *tbl,
260 struct dt_object *fsdb;
263 struct lu_buf buf = {
265 .lb_len = sizeof(tmpver)
271 LASSERT(mutex_is_locked(&tbl->mn_lock));
273 LASSERT(mgs->mgs_nidtbl_dir);
274 rc = dt_lookup_dir(env, mgs->mgs_nidtbl_dir, tbl->mn_fsdb->fsdb_name,
277 *version = MGS_NIDTBL_VERSION_INIT;
283 fsdb = dt_locate_at(env, mgs->mgs_bottom, &fid,
284 &mgs->mgs_dt_dev.dd_lu_dev, NULL);
286 RETURN(PTR_ERR(fsdb));
288 rc = dt_read(env, fsdb, &buf, &off);
289 if (rc == buf.lb_len) {
290 *version = le64_to_cpu(tmpver);
292 } else if (rc == 0) {
293 *version = MGS_NIDTBL_VERSION_INIT;
295 CERROR("%s: read version file %s error %d\n",
296 mgs->mgs_obd->obd_name, tbl->mn_fsdb->fsdb_name, rc);
298 lu_object_put(env, &fsdb->do_lu);
302 static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
303 struct mgs_target_info *mti)
305 struct mgs_nidtbl *tbl;
306 struct mgs_nidtbl_target *tgt;
308 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
312 type &= ~LDD_F_SV_TYPE_MGS;
315 tbl = &fsdb->fsdb_nidtbl;
316 mutex_lock(&tbl->mn_lock);
317 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
318 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 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 list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
344 rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
348 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;
358 struct list_head head = LIST_HEAD_INIT(head);
360 mutex_lock(&tbl->mn_lock);
361 tbl->mn_nr_targets = 0;
362 list_splice_init(&tbl->mn_targets, &head);
363 mutex_unlock(&tbl->mn_lock);
365 while (!list_empty(&head)) {
366 struct mgs_nidtbl_target *tgt;
367 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
368 list_del(&tgt->mnt_list);
373 static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
375 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
378 INIT_LIST_HEAD(&tbl->mn_targets);
379 mutex_init(&tbl->mn_lock);
380 tbl->mn_nr_targets = 0;
382 mutex_lock(&tbl->mn_lock);
383 rc = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl, &tbl->mn_version);
384 mutex_unlock(&tbl->mn_lock);
386 CERROR("%s: IR: failed to read current version, rc = %d\n",
387 fsdb->fsdb_mgs->mgs_obd->obd_name, rc);
389 CDEBUG(D_MGS, "IR: current version is %llu\n",
395 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
396 void mgs_ir_notify_complete(struct fs_db *fsdb)
399 cfs_duration_t delta;
401 atomic_set(&fsdb->fsdb_notify_phase, 0);
404 fsdb->fsdb_notify_count++;
405 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
406 fsdb->fsdb_notify_total += delta;
407 if (delta > fsdb->fsdb_notify_max)
408 fsdb->fsdb_notify_max = delta;
410 cfs_duration_usec(delta, &tv);
411 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
412 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
415 static int mgs_ir_notify(void *arg)
417 struct fs_db *fsdb = arg;
418 struct ldlm_res_id resid;
419 char name[sizeof(fsdb->fsdb_name) + 16];
421 LASSERTF(sizeof(name) < 40, "name is too large to be in stack.\n");
423 snprintf(name, sizeof(name) - 1, "mgs_%s_notify", fsdb->fsdb_name);
424 complete(&fsdb->fsdb_notify_comp);
425 set_user_nice(current, -2);
426 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
428 struct l_wait_info lwi = { 0 };
430 l_wait_event(fsdb->fsdb_notify_waitq,
431 fsdb->fsdb_notify_stop ||
432 atomic_read(&fsdb->fsdb_notify_phase),
434 if (fsdb->fsdb_notify_stop)
437 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
438 name, atomic_read(&fsdb->fsdb_notify_phase));
440 fsdb->fsdb_notify_start = cfs_time_current();
441 mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
444 complete(&fsdb->fsdb_notify_comp);
448 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
451 struct task_struct *task;
454 ir_timeout = OBD_IR_MGS_TIMEOUT;
456 fsdb->fsdb_ir_state = IR_FULL;
457 if (cfs_time_before(cfs_time_current_sec(),
458 mgs->mgs_start_time + ir_timeout))
459 fsdb->fsdb_ir_state = IR_STARTUP;
460 fsdb->fsdb_nonir_clients = 0;
461 /* start notify thread */
462 fsdb->fsdb_mgs = mgs;
463 task = kthread_run(mgs_ir_notify, fsdb,
464 "mgs_%s_notify", fsdb->fsdb_name);
466 wait_for_completion(&fsdb->fsdb_notify_comp);
468 CERROR("Start notify thread error %ld\n", PTR_ERR(task));
470 mgs_nidtbl_init_fs(env, fsdb);
474 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
476 if (test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
479 mgs_fsc_cleanup_by_fsdb(fsdb);
481 mgs_nidtbl_fini_fs(fsdb);
483 LASSERT(list_empty(&fsdb->fsdb_clients));
485 fsdb->fsdb_notify_stop = 1;
486 wake_up(&fsdb->fsdb_notify_waitq);
487 wait_for_completion(&fsdb->fsdb_notify_comp);
490 /* caller must have held fsdb_mutex */
491 static inline void ir_state_graduate(struct fs_db *fsdb)
493 if (fsdb->fsdb_ir_state == IR_STARTUP) {
494 if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
495 cfs_time_current_sec())) {
496 fsdb->fsdb_ir_state = IR_FULL;
497 if (fsdb->fsdb_nonir_clients)
498 fsdb->fsdb_ir_state = IR_PARTIAL;
503 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
504 struct mgs_target_info *mti)
510 if (mti->mti_instance == 0)
513 rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
517 rc = mgs_nidtbl_write(env, fsdb, mti);
522 mutex_lock(&fsdb->fsdb_mutex);
523 ir_state_graduate(fsdb);
524 switch (fsdb->fsdb_ir_state) {
526 mti->mti_flags |= LDD_F_IR_CAPABLE;
536 mutex_unlock(&fsdb->fsdb_mutex);
538 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
540 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
542 atomic_inc(&fsdb->fsdb_notify_phase);
543 wake_up(&fsdb->fsdb_notify_waitq);
547 mgs_put_fsdb(mgs, fsdb);
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 lu_env *env = req->rq_svc_thread->t_env;
591 struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
592 struct fs_db *fsdb = NULL;
593 struct mgs_config_body *body;
594 struct mgs_config_res *res;
595 struct ptlrpc_bulk_desc *desc;
596 struct l_wait_info lwi;
606 struct page **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 bufsize = body->mcb_units << body->mcb_bits;
621 nrpages = (bufsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
622 if (nrpages > PTLRPC_MAX_BRW_PAGES)
625 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
629 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
630 body->mcb_name, bufsize);
632 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
634 GOTO(out, rc = -ENOMEM);
636 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
638 GOTO(out, rc = -EINVAL);
640 res->mcr_offset = body->mcb_offset;
641 unit_size = min_t(int, 1 << body->mcb_bits, PAGE_SIZE);
642 bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
643 pages, nrpages, bufsize / unit_size, unit_size);
645 GOTO(out, rc = bytes);
647 /* start bulk transfer */
648 page_count = (bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
649 LASSERT(page_count <= nrpages);
650 desc = ptlrpc_prep_bulk_exp(req, page_count, 1,
651 PTLRPC_BULK_PUT_SOURCE |
652 PTLRPC_BULK_BUF_KIOV,
654 &ptlrpc_bulk_kiov_pin_ops);
656 GOTO(out, rc = -ENOMEM);
658 for (i = 0; i < page_count && bytes > 0; i++) {
659 desc->bd_frag_ops->add_kiov_frag(desc, pages[i], 0,
665 rc = target_bulk_io(req->rq_export, desc, &lwi);
666 ptlrpc_free_bulk(desc);
672 for (i = 0; i < nrpages; i++) {
676 __free_page(pages[i]);
679 OBD_FREE(pages, sizeof(*pages) * nrpages);
683 mgs_put_fsdb(mgs, fsdb);
688 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
690 const char *strings[] = IR_STRINGS;
694 for (i = 0; i < ARRAY_SIZE(strings); i++) {
695 if (strcmp(strings[i], buf) == 0) {
703 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
704 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
705 mutex_lock(&fsdb->fsdb_mutex);
706 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
708 fsdb->fsdb_ir_state = state;
709 mutex_unlock(&fsdb->fsdb_mutex);
714 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
719 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
724 fsdb->fsdb_notify_total = 0;
725 fsdb->fsdb_notify_max = 0;
726 fsdb->fsdb_notify_count = 0;
730 static struct lproc_ir_cmd {
733 int (*handler)(struct fs_db *, const char *);
735 { "state=", 6, lprocfs_ir_set_state },
736 { "timeout=", 8, lprocfs_ir_set_timeout },
737 { "0", 1, lprocfs_ir_clear_stats }
740 int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
741 size_t count, void *data)
743 struct fs_db *fsdb = data;
748 if (count == 0 || count >= PAGE_SIZE)
751 OBD_ALLOC(kbuf, count + 1);
755 if (copy_from_user(kbuf, buffer, count)) {
756 OBD_FREE(kbuf, count + 1);
760 kbuf[count] = 0; /* buffer is supposed to end with 0 */
761 if (kbuf[count - 1] == '\n')
765 /* fsname=<file system name> must be the 1st entry */
766 while (ptr != NULL) {
770 tmpptr = strchr(ptr, ';');
775 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
776 struct lproc_ir_cmd *cmd;
780 cmdlen = cmd->namelen;
781 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
783 rc = cmd->handler(fsdb, ptr);
793 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
794 OBD_FREE(kbuf, count + 1);
798 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
800 struct fs_db *fsdb = data;
801 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
802 const char *ir_strings[] = IR_STRINGS;
803 struct timeval tv_max;
806 /* mgs_live_seq_show() already holds fsdb_mutex. */
807 ir_state_graduate(fsdb);
809 seq_printf(seq, "\nimperative_recovery_state:\n");
812 " nonir_clients: %d\n"
813 " nidtbl_version: %lld\n",
814 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
817 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
818 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
820 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
821 " notify_duation_max: %lu.%06lu\n"
822 " notify_count: %u\n",
823 tv.tv_sec, tv.tv_usec,
824 tv_max.tv_sec, tv_max.tv_usec,
825 fsdb->fsdb_notify_count);
830 int lprocfs_ir_timeout_seq_show(struct seq_file *m, void *data)
832 return lprocfs_uint_seq_show(m, &ir_timeout);
835 ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
836 const char __user *buffer,
837 size_t count, loff_t *off)
839 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
842 /* --------------- Handle non IR support clients --------------- */
843 /* attach a lustre file system to an export */
844 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
847 struct mgs_export_data *data = &exp->u.eu_mgs_data;
848 struct mgs_device *mgs = exp2mgs_dev(exp);
849 struct fs_db *fsdb = NULL;
850 struct mgs_fsc *fsc = NULL;
851 struct mgs_fsc *new_fsc = NULL;
856 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
860 /* allocate a new fsc in case we need it in spinlock. */
861 OBD_ALLOC_PTR(new_fsc);
863 GOTO(out, rc = -ENOMEM);
865 INIT_LIST_HEAD(&new_fsc->mfc_export_list);
866 INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
867 new_fsc->mfc_fsdb = fsdb;
868 new_fsc->mfc_export = class_export_get(exp);
869 new_fsc->mfc_ir_capable = !!(exp_connect_flags(exp) &
870 OBD_CONNECT_IMP_RECOV);
873 mutex_lock(&fsdb->fsdb_mutex);
875 /* tend to find it in export list because this list is shorter. */
876 spin_lock(&data->med_lock);
877 list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
878 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
887 /* add it into export list. */
888 list_add(&fsc->mfc_export_list, &data->med_clients);
890 /* add into fsdb list. */
891 list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
892 if (!fsc->mfc_ir_capable) {
893 ++fsdb->fsdb_nonir_clients;
894 if (fsdb->fsdb_ir_state == IR_FULL)
895 fsdb->fsdb_ir_state = IR_PARTIAL;
899 spin_unlock(&data->med_lock);
900 mutex_unlock(&fsdb->fsdb_mutex);
903 class_export_put(new_fsc->mfc_export);
904 OBD_FREE_PTR(new_fsc);
908 mgs_put_fsdb(mgs, fsdb);
912 void mgs_fsc_cleanup(struct obd_export *exp)
914 struct mgs_export_data *data = &exp->u.eu_mgs_data;
915 struct mgs_fsc *fsc, *tmp;
916 struct list_head head = LIST_HEAD_INIT(head);
918 spin_lock(&data->med_lock);
919 list_splice_init(&data->med_clients, &head);
920 spin_unlock(&data->med_lock);
922 list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
923 struct fs_db *fsdb = fsc->mfc_fsdb;
925 LASSERT(fsc->mfc_export == exp);
927 mutex_lock(&fsdb->fsdb_mutex);
928 list_del_init(&fsc->mfc_fsdb_list);
929 if (fsc->mfc_ir_capable == 0) {
930 --fsdb->fsdb_nonir_clients;
931 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
932 if (fsdb->fsdb_nonir_clients == 0 &&
933 fsdb->fsdb_ir_state == IR_PARTIAL)
934 fsdb->fsdb_ir_state = IR_FULL;
936 mutex_unlock(&fsdb->fsdb_mutex);
937 list_del_init(&fsc->mfc_export_list);
938 class_export_put(fsc->mfc_export);
943 /* must be called with fsdb->fsdb_mutex held */
944 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
946 struct mgs_fsc *fsc, *tmp;
948 list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
950 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
952 LASSERT(fsdb == fsc->mfc_fsdb);
953 list_del_init(&fsc->mfc_fsdb_list);
955 spin_lock(&data->med_lock);
956 list_del_init(&fsc->mfc_export_list);
957 spin_unlock(&data->med_lock);
958 class_export_put(fsc->mfc_export);
962 fsdb->fsdb_nonir_clients = 0;
963 if (fsdb->fsdb_ir_state == IR_PARTIAL)
964 fsdb->fsdb_ir_state = IR_FULL;